Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31694549rwd; Fri, 7 Jul 2023 03:08:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEGRE+d+12GEbJfZ/RQ2AXdSO30dse96ubtrZzyEkEgu9ElCD21qiZ/QcjEov73OIayl5Xx X-Received: by 2002:a17:902:7b88:b0:1b7:e478:6bcd with SMTP id w8-20020a1709027b8800b001b7e4786bcdmr3086277pll.33.1688724497951; Fri, 07 Jul 2023 03:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688724497; cv=none; d=google.com; s=arc-20160816; b=ag31EmQ5GNhYaGXirGXVgHFLzk2UJE14dlJ2P4vhg4yVxr56yBcFj8hQWb5XKO8SRn xt7RnU6O0QWnQMEhX+ivqCif2pV2jnnZayAjbQ6sSfxWmXTagG7JTZXd5Lul9Y1kMRiq iXgVmub0tEwgYlKPOv/Jk7MqGm6wGbujjdgQIhTcBWkm65BIrS0/PlmQflPL/aCal3gJ CQi7jdaUiSTMyZBtog3wErK2BY8Ss70bnuU3JSwyOFjk+n0r4CaP15gxIkBSHMiWxSUy 69azsT4/0flg9l0GcXEZZAT2OUv1jdVctP0Nkljg1THWod4WQIEoEBANm+Dmq6em8O6X Ej2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0j1Mjil1srPw084knHzYgXyHjdm+Cb0b+kJmKHhJ9iw=; fh=sV/gukC4NCNZALHhM21y7ktDTysxjO2pQm8XIIjX3Zg=; b=hTa6x8mocjdnvFXe/corlbmd3UjMsrmvTV4hmEGNF+3Z87Xlv1v+3uniBlG+fZ8nY+ uYiUVEHAKpvu3FmTzcsCW4RJILilCv4j09zw9EZkvxOSs17c4KXtWJqUi4JuZYUQga2K WmmFr7ztDbj4FG6Syy8yh7S9NVbLl/Q4bkBpVhWIH+TeaTlZJsOWu1L0cKb1NJRtaPnf m5y8+rjxO055/Bfy4CmH976ISMD5bcDKmw/pjxp33hpwR2mvNQPvUSRPeNvfDVmvb8zh 3X4XLXXqx7qQcjrr5qT5ggyfLHIt8eIgEQ8ncoMrziNCCEjZM/E85Y9rdT13GoNNFvN4 jQAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=xtk8m8TF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a170902f68b00b001b8a7588efbsi2959962plg.564.2023.07.07.03.08.03; Fri, 07 Jul 2023 03:08:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=xtk8m8TF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232597AbjGGJHN (ORCPT + 99 others); Fri, 7 Jul 2023 05:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjGGJHJ (ORCPT ); Fri, 7 Jul 2023 05:07:09 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8966E2123 for ; Fri, 7 Jul 2023 02:07:07 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-307d58b3efbso1560229f8f.0 for ; Fri, 07 Jul 2023 02:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1688720826; x=1691312826; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0j1Mjil1srPw084knHzYgXyHjdm+Cb0b+kJmKHhJ9iw=; b=xtk8m8TFBcFOq13Z3Zw12EKrYYQ+LbR5rqu9t6AGXK9ZX6Sfp5+Omo5+lBVZQzg/V3 V+YFD6FCjrpdblAP4MBzcbLbDoblYvdUgoSVkUD2icnXQ6T55qMkxZb1fPBGSBvG0MuB J4wefxvJ3A+AN338vyJJx7bGlxxPlCghTeCrSfZwfYp+4wbLWyYtzh5PPlTHHnhKhstZ 15haP3D1AGLmW3e+aKghSStCwHzvvqcetiIHDoXSrnpC5S/Ht2KN4/9XWivlog+pc3QW 2XE8rfV86Q/3Ko3cqCl8a1cQ2tSH4tA/+Rxo2km3Hoi1ksLYXwyTttR/8ozfTPy4Kp4B Ybrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688720826; x=1691312826; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0j1Mjil1srPw084knHzYgXyHjdm+Cb0b+kJmKHhJ9iw=; b=NMh+R8fPY4V2kgBWZ6n7XFRuuIyeFmfm9s6sVKj4N8Age7IwMZHe/DuAmA8tjKeQ+k 1kPWiu0cqMwTC6b956QuWzZGLAZjF3/VRlwkc/la0Uihm0Bj8+SGin3EE1Vn1/RtuqRK 3M01zEqal9/pFRMoLyfN+GhAmgR4HdCdzp2M4DEP0tIwVhNu/onPKhbVeNk5n+eFUqSJ swAYOB7wP+e7Pd9GT32Ej4onzskAmHb7Mk5vSPUVHWDAm4YO0yr5LYAIeuZcQtJJzjft biAqbHrUVMYHpLLzpOf9lfqrv0gqrv8HP3m+1E5OqdBrIV7lkITdUfncLmX+dijvN58S CzSg== X-Gm-Message-State: ABy/qLbTzpWhl/8Jx7oFL5t/f6rPNj3+CMbF4balSC17ca5kOCuzcamd KUnuFR1SfroXmwa5P7SLUCop4gEWJSkRRVxX65zueaGo4zYk618C X-Received: by 2002:a5d:5683:0:b0:314:c9c:94dd with SMTP id f3-20020a5d5683000000b003140c9c94ddmr3503054wrv.20.1688720825889; Fri, 07 Jul 2023 02:07:05 -0700 (PDT) MIME-Version: 1.0 References: <20230621114439.42851-1-alexghiti@rivosinc.com> <20230621114439.42851-2-alexghiti@rivosinc.com> In-Reply-To: From: Alexandre Ghiti Date: Fri, 7 Jul 2023 11:06:55 +0200 Message-ID: Subject: Re: [RFC PATCH 1/1] libstub: zboot: Use -ffunction-sections + --gc-sections To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 7, 2023 at 10:47=E2=80=AFAM Ard Biesheuvel wr= ote: > > On Fri, 7 Jul 2023 at 10:44, Alexandre Ghiti wro= te: > > > > Hi Ard, > > > > On Wed, Jun 21, 2023 at 1:45=E2=80=AFPM Alexandre Ghiti wrote: > > > > > > Static linking is done at an object file (actually section) granulari= ty, > > > meaning that if a function in an object has an undefined reference, t= he > > > link will fail, even though this function is not used in the resultin= g > > > ELF. > > > > > > To avoid such failures, allow the linker to garbage collect unused se= ctions > > > (which actually are functions). > > > > > > Signed-off-by: Alexandre Ghiti > > > --- > > > drivers/firmware/efi/libstub/Makefile | 1 + > > > drivers/firmware/efi/libstub/Makefile.zboot | 2 +- > > > 2 files changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware= /efi/libstub/Makefile > > > index 3abb2b357482..6182366d00c0 100644 > > > --- a/drivers/firmware/efi/libstub/Makefile > > > +++ b/drivers/firmware/efi/libstub/Makefile > > > @@ -40,6 +40,7 @@ KBUILD_CFLAGS :=3D $(subst $(CC_FLA= GS_FTRACE),,$(cflags-y)) \ > > > -ffreestanding \ > > > -fno-stack-protector \ > > > $(call cc-option,-fno-addrsig) \ > > > + -ffunction-sections \ > > > -D__DISABLE_EXPORTS > > > > > > # > > > diff --git a/drivers/firmware/efi/libstub/Makefile.zboot b/drivers/fi= rmware/efi/libstub/Makefile.zboot > > > index 89ef820f3b34..5bb52d262133 100644 > > > --- a/drivers/firmware/efi/libstub/Makefile.zboot > > > +++ b/drivers/firmware/efi/libstub/Makefile.zboot > > > @@ -51,7 +51,7 @@ $(obj)/zboot-header.o: $(srctree)/drivers/firmware/= efi/libstub/zboot-header.S FO > > > > > > ZBOOT_DEPS :=3D $(obj)/zboot-header.o $(objtree)/drivers/firmware/ef= i/libstub/lib.a > > > > > > -LDFLAGS_vmlinuz.efi.elf :=3D -T $(srctree)/drivers/firmware/efi/libs= tub/zboot.lds > > > +LDFLAGS_vmlinuz.efi.elf :=3D -T $(srctree)/drivers/firmware/efi/libs= tub/zboot.lds --gc-sections > > > $(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE > > > $(call if_changed,ld) > > > > > > -- > > > 2.39.2 > > > > > > > Sorry to bother you, do you have any opinion about this patch? Does > > that make sense? If not, I should find another solution for my riscv > > KASLR series! > > > > Hi, > > Apologies for the delay in responding. I have been away and email > tends to pile up a bit. No worries! > > The patch by itself looks fine to me, but I do wonder if your series > could be improved slightly by moving those newly shared pieces into a > separate source file, rather than to an existing one. If you prefer this solution, I'll do that then. But I'm happy the patch makes sense to you, I'll probably use this to fix some issues/limitations with the riscv pre-mmu code :) Thanks for your quick answer! Alex