This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils 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: [BUG] ld behavior varies for C++ static initializer dependingon .a or .o input


Alexandre Oliva wrote:
On Apr 11, 2003, Hal Black <hablack at vt dot edu> wrote:


But when linking .a files composed
of those .o files, static initializers are not called.


And, if you look closer, you'll notice the object files that contain
the initializers aren't linked in at all.  Which is perfectly fine,
given that no symbols from it are referenced.  Maybe you want
--whole-archive?


Thanks Alexandre, for replying and the --whole-archive tip - it works great (has to be -Wl,-whole-archive when passed to g++, though, as noted on the man page).


I still believe this is a bug, however. Even though there aren't any references to static intializers, there is an implicit reference to them. When using .o files, there are no references either, but the static intializer is included in that case. Why should it be different for a .a file with the same .o files in it? Should .a files not be used for C++?

Perhaps the solution is to pass --whole-archive by default to ld when linking with g++.

But, at least there is a workaround.

Thanks also to Alan for the reference, I don't know how I missed that thread.


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