[patch] Check for -Wl,--gc-sections

Curtis Maloney cmaloney at cardgate.net
Mon Jun 18 16:27:50 PDT 2007


Havoc Pennington wrote:
> Richard Hughes wrote:
>> Havoc mentioned I should try using --gc-sections to reduce the size of
>> the setuid binary.
>>
> 
> I think you need a compiler flag to put each function in a separate 
> section also, at least to get maximum benefit.
> 
> Though since this isn't the default I've always assumed there must be 
> some sort of downside, I can't tell you what it might be.

According to the GCC manual:
http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Optimize-Options.html#Optimize-Options

-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.


... so, the downsides are larger object files and slower builds, as well as 
possibly making debugging difficult.

However, with a modern linker (as Richard has shown) it can improve the final 
program size.  There's a couple of other related switches that might improve 
performance (function and block reordering to improve code locality), though 
from memory they're not very useful unless you're doing a profiled build.

--
Curtis Maloney
cmaloney at cardgate.net


More information about the dbus mailing list