From patchwork Tue Oct 1 23:05:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kele Zhang X-Patchwork-Id: 1991748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=mn4rR8Cg; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jJB5NoSb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJGNC1mqBz1xtq for ; Wed, 2 Oct 2024 10:46:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ndgV8bac5cGMrgKwKjuvX/MpZcRZNS7XXdhCFKWAVAI=; b=mn4rR8CgfRHxft WXC1bKvv+yG/BNYxoWbufr8RBcRMUhDM92tM7RrJ7E0Isr+tHeb5NaNQX0QzQu+iBqZiWkWc9I7a7 stsKCYx8Y4Q1HkpVpuMpO5P8+XXDSMtAL4jKhk1CuIzmlJXSfCVRDBwRvrgtcjQhjSNgk/2D/6cj6 Gv4Y5+3ojYLNPogJQXMfRd1JhoLlSWqQ8fuHZfV41/ZqqWepi4s+XrgN6KVBDlD9t4UX48MpzvtrG e+vXr41/Mp7PCvmoRFWZw6EZJG+8xD+muMBx8eQXrhEzLccoeZXa4oOuIm1lpOda/swdgozeIUCc5 qFU8ONwGYlABPnL+6bZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svnVs-00000004TZj-35Kv; Wed, 02 Oct 2024 00:46:44 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svlwI-00000004IQ0-36YQ for opensbi@lists.infradead.org; Tue, 01 Oct 2024 23:05:56 +0000 Received: by mail-pg1-x543.google.com with SMTP id 41be03b00d2f7-7e6ed072cdaso2188736a12.0 for ; Tue, 01 Oct 2024 16:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727823953; x=1728428753; darn=lists.infradead.org; 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=v1X8v9wtiThuwH/FVGH/6yk6+JHxv8kYDuGfYflkBD8=; b=jJB5NoSbmRmnfS21IezhZqW04SQzvAwx+d8JqSFdqGLOeNoTOwa7EhCk51kxixi+nq LGlgkmtjKOh6pRY/yb9zYeT1dtTsD46LCC68yDaKyIwvLSQfwFegNT2oEvPKy0kyWUkr AifIs9LmFidh6/ktwJNT++uj/EmCnX5w9Gyp5T74urn7U0VFIts0algUldW3i9+bDz5+ 4i61fHzoLfNv2rmcTqliHzsUNkABar0B5xD3OcpDmlG+nLbAsOPsrGTLh5Yr+CRZpWqW WdiJI8pIGbwoHJhOVFgnnR9ab7U2/uqI3ySulFGvsUprnKWV2u5CHOlXYyyaiq384c/0 6l7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727823953; x=1728428753; 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=v1X8v9wtiThuwH/FVGH/6yk6+JHxv8kYDuGfYflkBD8=; b=WxdiEQBB2qIUeGZe8FjX4YglqDx4NaM4KUKvn/TIy8bQGeA/riK0nzUfXDyytYMBoE S9jF+5ehv2xWPJzqOWtW8E0hZcQHCxZ8g/kGdaX258GhOTzomnlXljLZvnHgBvYe9wd/ 4Vj/XlHmmmuf8abMM7c6jQlQ+yG0pOzf2zjwLrceXqqrdyv2kzkVf+i9dE5suTwCphcm F3yICU3qz/9cud62vzobpmdie6En4am7CSc4NXsAZE2hXgPWSy3MzQQVw+uFF+dKaw7t FklqTYpiZmQoMpT+Rxa7pHndy1iYpc7eEwV9fwk0Y0rwX/MC904ekYaGba5dcmaAsdiR 0UKw== X-Forwarded-Encrypted: i=1; AJvYcCWjwiLOtGbHn5hm+JC2b3AhjIgI1iZoAmv1njDZPW6MmFK9obvvZpVykrEHM5KT9tFKNPO+Qq7Q@lists.infradead.org X-Gm-Message-State: AOJu0Yw9bjWd2/zMwqw9REjO2lq/iEtv8GARqjDZMuUR/XLx6Tsj+0VC jPOt2om9HwtCAa+6tuYpZKFW1VuMNJ5GuORpSn4BApv1/17Ejyo+ X-Google-Smtp-Source: AGHT+IFPDBmVA/V4BgPXxnPAsYjQXI3jDa2B/kV27AM+4BMG0VX5ofPKWFnlCEmldXOENKZNaTADQQ== X-Received: by 2002:a17:90a:77c6:b0:2e0:6c5f:4eb9 with SMTP id 98e67ed59e1d1-2e1846721cemr1495567a91.12.1727823953447; Tue, 01 Oct 2024 16:05:53 -0700 (PDT) Received: from localhost.localdomain ([2a01:4ff:1f0:1c14::1]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e18f541bbesm164791a91.11.2024.10.01.16.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 16:05:53 -0700 (PDT) From: Kele Zhang To: wxjstz@126.com, bmeng.cn@gmail.com, opensbi@lists.infradead.org, jrtc27@jrtc27.com Cc: tanyuan@tinylab.org, falcon@tinylab.org, Kele Zhang Subject: [PATCH v4 1/1] Makefile: enable --gc-sections Date: Tue, 1 Oct 2024 23:05:51 +0000 Message-Id: <09f89be252e5ea08820909ad6a1bb93866b438c8.1727823614.git.zhangcola2003@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241001_160554_799927_DFF149EC X-CRM114-Status: GOOD ( 10.48 ) X-Spam-Score: -1.8 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The --gc-sections option enables the linker to perform garbage collection of unreferenced code and data, thereby reducing the binary size. The -ffunction-sections option will place each function into a separate section, so it is necessary to add .text.* to the linker script. Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:543 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zhangcola2003(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zhangcola2003(at)gmail.com] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The --gc-sections option enables the linker to perform garbage collection of unreferenced code and data, thereby reducing the binary size. The -ffunction-sections option will place each function into a separate section, so it is necessary to add .text.* to the linker script. Signed-off-by: Kele Zhang Signed-off-by: Yuan Tan Signed-off-by: Zhangjin Wu Reviewed-by: Bin Meng Reviewed-by: Xiang W --- Makefile | 15 +++++++++------ firmware/fw_base.ldS | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f0012f6..dae282c 100644 --- a/Makefile +++ b/Makefile @@ -355,12 +355,7 @@ GENFLAGS += $(libsbiutils-genflags-y) GENFLAGS += $(platform-genflags-y) GENFLAGS += $(firmware-genflags-y) -CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ifneq ($(DEBUG),) -CFLAGS += -O0 -else -CFLAGS += -O2 -endif +CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls # Optionally supported flags ifeq ($(CC_SUPPORT_SAVE_RESTORE),y) @@ -406,6 +401,7 @@ ASFLAGS += $(firmware-asflags-y) ARFLAGS = rcs ELFFLAGS += $(USE_LD_FLAG) +ELFFLAGS += -Wl,--gc-sections ifeq ($(OPENSBI_LD_EXCLUDE_LIBS),y) ELFFLAGS += -Wl,--exclude-libs,ALL endif @@ -424,6 +420,13 @@ MERGEFLAGS += -m elf$(PLATFORM_RISCV_XLEN)lriscv DTSCPPFLAGS = $(CPPFLAGS) -nostdinc -nostdlib -fno-builtin -D__DTS__ -x assembler-with-cpp +ifneq ($(DEBUG),) +CFLAGS += -O0 +ELFFLAGS += -Wl,--print-gc-sections +else +CFLAGS += -O2 +endif + # Setup functions for compilation define dynamic_flags -I$(shell dirname $(2)) -D__OBJNAME__=$(subst -,_,$(shell basename $(1) .o)) diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS index fb47984..a33746a 100644 --- a/firmware/fw_base.ldS +++ b/firmware/fw_base.ldS @@ -20,6 +20,7 @@ PROVIDE(_text_start = .); *(.entry) *(.text) + *(.text.*) . = ALIGN(8); PROVIDE(_text_end = .); }