This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: garbage collection of unused code
- From: Ian Lance Taylor <iant at google dot com>
- To: Da Zheng <zhengda1936 at gmail dot com>
- Cc: "gcc-help\ at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 09 Jun 2010 00:08:16 -0700
- Subject: Re: garbage collection of unused code
- References: <4C0F194F.2040500@gmail.com>
Da Zheng <zhengda1936@gmail.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
> collection?
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.
Ian