This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Forcing a constructor to be linked
Darin Johnson <chezdj@earthlink.net> writes:
> I'm running across a linking problem when porting to embedded PowerPC with
> GNU tools. There's a file that was normally linked in because it has a static
> constructor (and thus a .ctors section), but there are no other external
> references to that file. Ie, the static constructor registers a hardware test
> to a central list that will be run later, and the tests that are included depend
> upon the libraries included in the build, not upon modifying a source file to
> add or remove test functions.
>
> This works fine with GNU ld if the the object file is listed on the command line.
> However if the file is inside of a library it will not be linked in, even though
> there's a KEEP() around the .ctors. Is there an ld option to cause files like
> this to be linked without having to explicitly create references to them?
Not really. The linker will only bring in files from an archive if
they are referenced. Merely having a .ctors section is not a reference.
You could use --whole-archive, but that is probably not what you are
after.
Ian