From patchwork Wed Jun 21 11:44:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 110995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4308787vqr; Wed, 21 Jun 2023 05:04:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7B5118dlZL/YMOGHWn78tpbIpgS53Ip+9tpIJnqdgH5eLVvUhUAgQb15OGRebWGFlHsFZW X-Received: by 2002:a05:6a00:22c1:b0:66a:4a45:e023 with SMTP id f1-20020a056a0022c100b0066a4a45e023mr657061pfj.26.1687349072101; Wed, 21 Jun 2023 05:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687349072; cv=none; d=google.com; s=arc-20160816; b=J1YILEWN5/+sKAovm66w8N64XTy8kSpKxXkG49q16KDNcpe/ENb/ePy5rSrbrdjSBX aseHCn1501PFxNxdXyF0QmAjtKp7JPRsPJ/RSLlwPE/y4lI7RprDampcfPbN07AshK0Y F72Vz5rpt+sOpopYK9qBuyd0MzJTJ/A4uwBAW7WhK89Txw27NbpJFjasNAnU1HC8cKRB +UCC6Dt53+w9fdJf5NGOA9Ap2QROjXqRzAtoEL2pVD81tvq7fpKJYQ3Ow/Bg8/gwDw/+ XK4ZqHZigpY9qamkfc3EFPKfPNN2D0uGhrcZDXXhcH70H0GX6vTgEe/LZgnI++kHrgVp hfRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9diQLvSxjMs6xAGnA2pdApMjgni3zVWKA+Wt7BjIAVs=; b=MOzSqdbesO8upWOOm9kImajZq0PiiQjWUyyzR+Lzl00iip1jnwXs4fgMCEKP5LJ+yA IV6ue+3geMaRBOJR6UFfOap88tXGeY+WYCOVmA/d/wYev+a5ZWDd/cLK6l3xTdOgimtJ NG4qBcXzeFz/k4QP2nfJKhnfvpASiF84DP308vLA8DRQPPjuOnpXGksuyjwfIzs0zPks IuSAvNDpnBf3EY4vr5n4wwdcqkHrWOb4HTd6gBvDfqZ0qQD2xdPmdYcQwChngMQi7EFq 5L+aqnSsUFk47kgj1Umwx4xXRdbMvG5C88OuThpadSvIdSwke0tJwV3IaFw8rm5ZfUXT a1IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Dy+0Xpyk; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y27-20020a056a00181b00b00660f49fdc5dsi4395267pfa.258.2023.06.21.05.04.01; Wed, 21 Jun 2023 05:04:32 -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=Dy+0Xpyk; 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 S229871AbjFULpr (ORCPT + 99 others); Wed, 21 Jun 2023 07:45:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbjFULpp (ORCPT ); Wed, 21 Jun 2023 07:45:45 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 271931B4 for ; Wed, 21 Jun 2023 04:45:44 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f9b258f3a2so33192765e9.0 for ; Wed, 21 Jun 2023 04:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1687347942; x=1689939942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9diQLvSxjMs6xAGnA2pdApMjgni3zVWKA+Wt7BjIAVs=; b=Dy+0Xpykwbo8prZFI97d/boX6VfR8V7t3mPscGNYupuffVuSsN+OIVNiBfwuadRBPt dbBfLs1KQh1g2gAwl4OZKWwrHROh4D20WpcsiAjh7fIYsMLN+MKoxqnNmaRF4ZqAiv8g 5ants6B6Fah9aVcwXA94xxFJfew05/+MhpB7qrb28/49u8QJVOFhgr6Pc0+pg4njlYDk ZZHaMoUkSMuOePdfBP1Zu3jNxKaeJHbZDkPvMxbcqsPcRY9Og1W8pfLvrcEkQ7yZa/is JmVvCps1ZO/NLB+npPy2sRFIKHlWMQwYv35RQVe3vg513lhxT2g8xFBn57uJvJFyHa9T yZTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687347942; x=1689939942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9diQLvSxjMs6xAGnA2pdApMjgni3zVWKA+Wt7BjIAVs=; b=DiU9/Bg9Nz2Ytzck/aGnLwOYhX1ImG0zoR/6GHmoJk3G90xa+h15r0b5gcZtcatxZe uLPxsGa4T2K2QUX5p5z42qk+vGvgQGm2EtmNvc4mkm35df5vKdF2q8L97FoQg0+Zz6G0 TD1biiMAC7g7iVRs6cTp6Ic4ASO3JPvRgSaGVO6V9QUWtO+aC2BWidy/308VzPtOalNv wiWjmPdRleR9wCLl3aqIhVYx69Mdiu7FTjVV45M7VQ2w/B3Ke0L9PE/PY/V1ZvrDI/o0 MLEJCNQVNGD0tLbSSXua8oY8FNxIlI1XNbYkf7JLnZmkzh9cE+LdNIrqR5o84bGGOMsD +sig== X-Gm-Message-State: AC+VfDyFcorBS+Gvsnmgbt+DQNxBgHmz4ZzpU6m5dNI0gvxWz59I6Lq/ uaOMKXfVrd3DfAV8fJBAzFd1PF2PHLps8vRCWb4= X-Received: by 2002:a7b:ca57:0:b0:3f9:b4a0:6062 with SMTP id m23-20020a7bca57000000b003f9b4a06062mr4993654wml.24.1687347942509; Wed, 21 Jun 2023 04:45:42 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id v15-20020a1cf70f000000b003f8d770e935sm16097220wmh.0.2023.06.21.04.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 04:45:42 -0700 (PDT) From: Alexandre Ghiti To: Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Cc: Alexandre Ghiti Subject: [RFC PATCH 1/1] libstub: zboot: Use -ffunction-sections + --gc-sections Date: Wed, 21 Jun 2023 13:44:39 +0200 Message-Id: <20230621114439.42851-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230621114439.42851-1-alexghiti@rivosinc.com> References: <20230621114439.42851-1-alexghiti@rivosinc.com> MIME-Version: 1.0 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=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769313740460159553?= X-GMAIL-MSGID: =?utf-8?q?1769313740460159553?= Static linking is done at an object file (actually section) granularity, meaning that if a function in an object has an undefined reference, the link will fail, even though this function is not used in the resulting ELF. To avoid such failures, allow the linker to garbage collect unused sections (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 := $(subst $(CC_FLAGS_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/firmware/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 := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a -LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds +LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds --gc-sections $(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE $(call if_changed,ld)