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 <luigi.mantell...@idf-hit.com>
---
 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<format>
 # option to the assembler.
 AFLAGS_DEBUG :=
-- 
1.7.3

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to