This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
RE: Forcing a constructor to be linked
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Ian Lance Taylor'" <ian at airs dot com>,"'Darin Johnson'" <darin at usa dot net>
- Cc: <binutils at sources dot redhat dot com>
- Date: Tue, 12 Jul 2005 13:39:11 +0100
- Subject: RE: Forcing a constructor to be linked
----Original Message----
>From: Ian Lance Taylor
>Sent: 12 July 2005 03:56
> Darin Johnson 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
The approach we use is to generate a whole load of -u options as part of
the make process that we pass in to ld at final-link time to ensure that
everything from unreferenced .ctor/.dtor sections gets pulled in. You can
perhaps extract the necessary symbols by using nm on newly-generated .o
files, as part of the makefile rule, and keep them handy somewhere in a
similar way to autogenerated dependency files.
cheers,
DaveK
--
Can't think of a witty .sigline today....