garbage collection of unused code
Thu Jun 10 00:06:00 GMT 2010
On 10-6-9 ä¸å3:08, Ian Lance Taylor wrote:
> Da Zheng <email@example.com> 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.
Thanks. The -u option works for me pretty well.
More information about the Gcc-help