From patchwork Thu Sep 5 09:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kele Zhang X-Patchwork-Id: 1981176 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=yw3Yo8op; 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=Y6M9JwvT; 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 4WzvLV6gshz1yXY for ; Thu, 5 Sep 2024 19:33:36 +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=xhJmoVi5P5zIjZWrtM0NXzRrQTm4jjAP6BexF8pawHw=; b=yw3Yo8op7kSeWC XCZ53wbfnZN0QG82/pSncgviPrio0pHWkTBPGtoItwKUG7TmNeokVyCn0uzF6SVcpbEBRtJHZlErg btt3p15/WvHFyganv+os4jiSEnAM7MWbY3yhvXQ5JtP9WRlts2jRHm3aWEO8rKH03LiaK+OnAiYlF A+UrYMOtC3HRxXLyD/CPDS+OTdcnP+ySKHEUnZXMqK41hDVzXbkHVX8V3PleTKjd0KDZmjTlAEHzU Blx2l7twX9GrCGlHbpS9otnFqi5qe43yKc/0ohEJSE/BdEUt5AixgHy8Pz1gb96cawtR3oEfjsVjF TRoTYyWBTVIe4lHUUEUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm8rp-00000007mwq-1nBq; Thu, 05 Sep 2024 09:33:29 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm8qE-00000007mUV-3gqR for opensbi@lists.infradead.org; Thu, 05 Sep 2024 09:31:52 +0000 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2054feabfc3so5718355ad.1 for ; Thu, 05 Sep 2024 02:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725528710; x=1726133510; 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=4Sm3bRdX+xyy/2HR0jpYWSpvtyiqlK155isFe1Uy0xY=; b=Y6M9JwvTrbtfvY+/voMDjepKNZbeWNPSXXpOzavQ3yu9il8ZC+wQe4/bjznHoVVt+w Ps0qXTC7DkB9yZENHQB5h7Ss7903v+JK7f82ueSDOBnQ4Lc3LHnnheo3iGs2m7jY2Zyl 1aJbySThJBhCNsxTv+Y7yozQoKAuJTvQPQ2D/hdp9NBsuIJWC8eIq/qavKXhtM6d/3N8 11ZRp3OtocPFbCFw2famiTPuX9sMjnmx+QrqztCLgbrctR0stTXoRDLfDA7RWhQ4Z25B wn4RH+48DDsmqsuvWRDmXaYx6c7+Zizq5/WxKpfNZu8xGvM3uhV0I1StcT1f/C/6KhVI Dxug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725528710; x=1726133510; 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=4Sm3bRdX+xyy/2HR0jpYWSpvtyiqlK155isFe1Uy0xY=; b=Ec30nNNNtGQeFZ3rT70eWaNrwbOcP7L8za7GghmLx5jcL/tyGQg/Hh1/fDykviOHP1 nQgBxRGui1PJHIdUGqP8NKhKXjpgx/h99+x1ayZ652uuQQRY3yr9szyZM0be5UjQHNN4 lBs9Gg3RG5gi7K3jDKGuEXyI7DNjHAnWwfTULSK5lqFHe31zab/24+a4zO7RfvRKOQxD l8DIi5DgIgt2QypRqKSsj6hIEeIv3VzqKJFpt4ro22Dzh0C3eub2IR52XeopJh8y1pmW PMX/Roq8DnTFVpBGZU4lLbABO04XyoUYgLhUkrSJBn5hssJuw3pSjZ0VyAL/y7P1STEf ZpWw== X-Forwarded-Encrypted: i=1; AJvYcCWTmL0KTcgcOSkE+6sXzmZQD41iTKNy2PTs8J+u5jC6g0oI+bSkd+OIpAREnivCzFFKQaee64wi@lists.infradead.org X-Gm-Message-State: AOJu0Yxu7sqBZ6lYQIgacmbnbIFLlYftikVelSzUsg6ioxF3Deqgoaj/ IkGtICRNI9tuQFYm9HUnrXZDs/v+fh2lS4zAExoKYCP9U1LPdF38 X-Google-Smtp-Source: AGHT+IGaLRtrlVcaHqn3jt+cqSNZ43wUYbr6gGuRfm7LmSMUAQvOjc1jXuTovXqxY6rQjHE849fqsg== X-Received: by 2002:a17:903:22cb:b0:206:9693:7d5b with SMTP id d9443c01a7336-2069693918cmr95073665ad.55.1725528710149; Thu, 05 Sep 2024 02:31:50 -0700 (PDT) Received: from localhost.localdomain ([2a01:4ff:1f0:1c14::1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae95589dsm25400795ad.115.2024.09.05.02.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 02:31:49 -0700 (PDT) From: Kele Zhang To: wxjstz@126.com, bmeng.cn@gmail.com, opensbi@lists.infradead.org Cc: tanyuan@tinylab.org, falcon@tinylab.org, Kele Zhang Subject: [PATCH v3 1/1] Makefile: enable --gc-sections Date: Thu, 5 Sep 2024 09:31:46 +0000 Message-Id: <272cb6e3f54b13f6a21319a9c1f0a1d7c5dd83fa.1725521174.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-20240905_023150_946981_F2599AE6 X-CRM114-Status: GOOD ( 10.34 ) X-Spam-Score: -1.9 (-) 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.9 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:644 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zhangcola2003(at)gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zhangcola2003(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 --- Makefile | 15 +++++++++------ firmware/fw_base.ldS | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e5a0f19..30ba3b6 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 = .); }