From patchwork Sat Dec 4 13:29:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luigi.mantellini@idf-hit.com X-Patchwork-Id: 74264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C6529B70D4 for ; Sun, 5 Dec 2010 00:29:42 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5F7A92820A; Sat, 4 Dec 2010 14:29:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nhAMI3f40awN; Sat, 4 Dec 2010 14:29:38 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 18149281FB; Sat, 4 Dec 2010 14:29:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ED9CE281F3 for ; Sat, 4 Dec 2010 14:29:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RtWLhie5ugaR for ; Sat, 4 Dec 2010 14:29:25 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx102.fabbricadigitale.it (mx2.fabbricadigitale.it [217.169.111.37]) by theia.denx.de (Postfix) with ESMTPS id A5077281E0 for ; Sat, 4 Dec 2010 14:29:23 +0100 (CET) Received: from localhost (mx102.fabbricadigitale.it [127.0.0.1]) by mx102.fabbricadigitale.it (MM4Csmtpd) with ESMTP id 3B4D3E000210 for ; Sat, 4 Dec 2010 14:29:23 +0100 (CET) X-Virus-Scanned: amavisd-new at fabbricadigitale.it Received: from mx102.fabbricadigitale.it ([127.0.0.1]) by localhost (mx102.fabbricadigitale.it [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8v-IctRSn1ei for ; Sat, 4 Dec 2010 14:29:23 +0100 (CET) Received: from EX02MailShare.fdmsha.local (unknown [172.16.26.10]) by mx102.fabbricadigitale.it (MM4Csmtpd) with ESMTPS id 256DBE00010A for ; Sat, 4 Dec 2010 14:29:23 +0100 (CET) Received: from abel.dialface.net (85.40.213.226) by EX02MailShare.fdmsha.local (172.16.26.10) with Microsoft SMTP Server id 8.1.340.0; Sat, 4 Dec 2010 14:29:20 +0100 From: Luigi 'Comio' Mantellini To: Date: Sat, 4 Dec 2010 14:29:15 +0100 Message-ID: <1291469358-25023-4-git-send-email-luigi.mantellini@idf-hit.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1291469358-25023-1-git-send-email-luigi.mantellini@idf-hit.com> References: <1291469358-25023-1-git-send-email-luigi.mantellini@idf-hit.com> MIME-Version: 1.0 Cc: Luigi 'Comio' Mantellini Subject: [U-Boot] [PATCH 3/6 v2] Enable garbage collelction of unused input sections. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de When available, enable the CC -ffunction-sections option and the LD --gc-sections in order to isolate and remove from final executable the unused functions. From ld manpages: --gc-sections --no-gc-sections Enable garbage collection of unused input sections. It is ignored on targets that do not support this option. The default behaviour (of not performing this garbage collection) can be restored by specifying --no-gc-sections on the command line. --gc-sections decides which input sections are used by examining symbols and relocations. The section containing the entry symbol and all sections containing symbols undefined on the command-line will be kept, as will sections containing symbols referenced by dynamic objects. Note that when building shared libraries, the linker must assume that any visible symbol is referenced. Once this initial set of sections has been determined, the linker recursively marks as used any section referenced by their relocations. See --entry and --undefined. From gcc manpages: -ffunction-sections -fdata-sections Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file. Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. Most systems using the ELF object format and SPARC processors running Solaris 2 have linkers with such optimizations. AIX may have these optimizations in the future. Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker will create larger object and executable files and will also be slower. You will not be able to use "gprof" on all systems if you specify this option and you may have problems with debugging if you specify both this option and -g. Signed-off-by: Luigi 'Comio' Mantellini --- config.mk | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/config.mk b/config.mk index c6d6f7b..591b490 100644 --- a/config.mk +++ b/config.mk @@ -23,6 +23,10 @@ ######################################################################### +comma := , +empty := +space := $(empty) $(empty) + ifneq ($(OBJTREE),$(SRCTREE)) ifeq ($(CURDIR),$(SRCTREE)) dir := @@ -97,6 +101,8 @@ HOSTCFLAGS += -pedantic # cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) +ld-option = $(shell if $(CC) -Wl$(comma)$(1) -nostdlib -xc /dev/null -o /dev/null \ + > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) # # Include the make variables (CC, etc...) @@ -191,6 +197,13 @@ endif CFLAGS += $(call cc-option,-fno-stack-protector) +# Create a section for each function or data (useful for sections garbage collector) +CFLAGS += $(call cc-option,-ffunction-sections) +CFLAGS += $(call cc-option,-fdata-sections) + +# Sections garbage collector +LDFLAGS += $(call ld-option,--gc-sections) + # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g # option to the assembler. AFLAGS_DEBUG :=