This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: garbage collection of unused code


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]