garbage collection of unused code
Ian Lance Taylor
Wed Jun 9 13:17:00 GMT 2010
Da Zheng <firstname.lastname@example.org> writes:
> gc-selections in ld can enable garbage collection of unused input sections. I
> hope some functions can be preserved even though they are not called by other
> parts of the code. I don't want to change the code. Could I somehow specify in
> the command line so that some specific functions are excluded from ld's garbage
The easiest way is to find some set of symbols in the sections you can
to keep and add a -u option to the linker for each such symbol. When
linking using the compiler, as you should, write -Wl,-u,SYMBOL.
Another way is to use a linker script and use KEEP with the sections
you want to keep. I don't recommend this approach unless you can't
use the first one for some reason. See the linker manual.
More information about the Gcc-help