[Q] linking only some functions in an object file

Nick Clifton nickc@cambridge.redhat.com
Wed Apr 18 23:50:00 GMT 2001


Hi jw,

> For example, when I link test.o test2.o and make
> test.elf, all of functions in test.o test2.o gets in
> test.elf. 
> 
> But I don't want not-used-functions to get in
> test.elf. How can I do this? 

Another possible solution, if you are using gcc, is to use the command
line switch -ffunction-sections.  This places each function compiled by
gcc into its own, individually named section.  Then when you link
together the object files, add the linker command line switch
--gc-sections.  This will cause the linker to throw away all sections
that it finds are not needed, which I believe is what you want.

Please note the support for -ffunction-sections is not present in all
gcc targets, so you may not be able to use this method.

Cheers
        Nick



More information about the Binutils mailing list