Symbols which were not used, still in binary

Brian Dessent brian@dessent.net
Wed Jun 28 21:20:00 GMT 2006


Michael Eager wrote:

> Arguably, the linker should know
> that add is not referenced and could remove it, but linkers are not
> usually able to slice and dice object files.

You address this limitation by compiling with "-ffunction-sections
-fdata-sections -Wl,--gc-sections".  However, it's still better to use
"static" on these kinds of local functions that are only used from the
same .o file.  This has a number of benefits:

- it ensures that internal functions of a library are not exported for
use by other code when they are not part of the defined ABI/API
- it prevents them from taking up needless relocations, which can slow
linking
- when compiled -fpic (as in a shared library) it allows for direct
calls to the function instead of having to go through the PLT which is
slower
- it allows the compiler freedom to inline

Brian



More information about the Gcc-help mailing list