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


Ian Lance Taylor wrote:

Hal Black <black at ieee dot org> writes:


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.

Yes. That's the desired behavior. If a developer were to develop a library with a static initializer with side-effects, it would be something that should be called whenever that library was used.


No Unix linker has ever worked that way.

Well, for most of the lifetime of Unix, there were no static initializers, since there was no C++, so this is not surprising.


Also, while this is not the reason for not making the change, it turns
out that it is not an efficient change to make.  It would require the
linker to examine every object in every archive, which obviates the
entire point of having archives in the first place.  Again, this
inefficiency, while severe, is not the reason for not making the
change; the reason for not making the change is that ld and ar
implement behaviour which has not changed for decades, and should not
be changed now.

For the C code that ld has been linking for decades, I agree with you 100%.


But, C++ has additional requirements. Either the tool needs to change to meet these requirements, or a different tool needs to be used to meet them.

If .a is meant only for what it has been used for decades without changing to accomodate the full C++ specification, you're right, I misunderstood the usage for it. That is definately not what I want. Based on the other replies, I guess that .so can be used to acheive the desired behavior even though it includes too much.

Anyway, thank you for responding and for your time, Ian.


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