diff mbox

[U-Boot] Enable garbage collection of unused input sections.

Message ID 1291545952-26761-2-git-send-email-luigi.mantellini@idf-hit.com
State Changes Requested
Headers show

Commit Message

luigi.mantellini@idf-hit.com Dec. 5, 2010, 10:45 a.m. UTC
When available, enable the CC -ffunction-sections/-fdata-sections options 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.mantellini@idf-hit.com>
---
 config.mk |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

Comments

Wolfgang Denk Dec. 5, 2010, 12:23 p.m. UTC | #1
Dear Luigi 'Comio' Mantellini,

In message <1291545952-26761-2-git-send-email-luigi.mantellini@idf-hit.com> you wrote:
> When available, enable the CC -ffunction-sections/-fdata-sections options and
> the LD --gc-sections in order to isolate and remove from final executable the
> unused functions.
...

> ---
>  config.mk |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)

Why do you ignore my previous review comments?

You cannot simply turn this feature on globally for all boards.  You
will have to make appropriate adjustments more or less everywhere:

- some architectures already have these options set, so these should
  be removed from the architecture / board specific config files

- other architectures have this NOT set, and they need adjustments to
  the respective inker scripts.

As is, your patch breaks a zillion of boards.

Best regards,

Wolfgang Denk
Luigi Mantellini Dec. 5, 2010, 12:33 p.m. UTC | #2
Hi Wolfgang,

On Sun, Dec 5, 2010 at 1:23 PM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Luigi 'Comio' Mantellini,
>
> In message <1291545952-26761-2-git-send-email-luigi.mantellini@idf-hit.com> you wrote:
>> When available, enable the CC -ffunction-sections/-fdata-sections options and
>> the LD --gc-sections in order to isolate and remove from final executable the
>> unused functions.
> ...
>
>> ---
>>  config.mk |    9 +++++++++
>>  1 files changed, 9 insertions(+), 0 deletions(-)
>
> Why do you ignore my previous review comments?

Sorry, I'm working essentially on MIPS arch and I haven't checked the
presence of this option in the others archs.
I'm wrong and I misunderstood your previous comments considering only
to split the patches.

I will consider to check just the mips boards.

Sorry again for this noise.

luigi

>
> You cannot simply turn this feature on globally for all boards.  You
> will have to make appropriate adjustments more or less everywhere:
>
> - some architectures already have these options set, so these should
>  be removed from the architecture / board specific config files
>
> - other architectures have this NOT set, and they need adjustments to
>  the respective inker scripts.
>
> As is, your patch breaks a zillion of boards.
>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
> To the systems programmer,  users  and  applications  serve  only  to
> provide a test load.
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>
diff mbox

Patch

diff --git a/config.mk b/config.mk
index c6d6f7b..94ca033 100644
--- a/config.mk
+++ b/config.mk
@@ -97,6 +97,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,$(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 +193,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)
+
+# Enable 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 :=