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 depending on .a or .o input


Hal Black <black at ieee dot org> writes:

> What I'm saying is not to use all the symbols, but to include all
> static initializers as "symbols that are being looked for".  Even if
> they aren't explicitly referenced by annother piece of code, they are
> implicitly referenced by virtue of being static initializers.

That would mean that every static initializer in a .a file would be
brought in, which would doubtless bring in other object files as well.
It means that including any class with a static initializer in a .a
file would mean that that class would be included in all programs
linked with that .a file.  This would go against the very idea of a .a
file, which is that only required objects are included.

> I would say that not looking for static initializers constitutes
> eliminating them...

No, because they were never included in the first place.

It's reasonably easy to avoid this problem: put the static initializer
in the same source file as a class virtual function.  Since the
class virtual function must be included, the initializer will be
brought in as well.

If you don't have any virtual functions, then you do need to take some
other action to force that object file to be included, such as using
global variables in some way.

Or maybe .a files are simply the wrong tool for the job.  Maybe you
should use ld -r to form several .o files into one large .o file.
Linking against that will ensure that everything is brought in.

Ian


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