[BUG] ld behavior varies for C++ static initializer depending on .a or .o input

Ian Lance Taylor ian@airs.com
Mon Apr 14 05:30:00 GMT 2003


Hal Black <black@ieee.org> writes:

> > 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.

C++ has had static initializers at least since 1985, so it's not all
that new.

> 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.

I'm not sure in what sense a .so file includes too much.  A .so file
is a very rough replacement for a .a file, so the fact that it
includes everything which is in the .a file is a feature.  It's true
that a .so file will always run all the static initializers which are
found in the .a file, but that's the very feature you want to
implement.  There are various differences in the implementation of
common symbols, but C++ disallows common symbols so that shouldn't
matter too much.  Warning symbols no longer work correctly, but that
is a GNU extension anyhow.  A .so is admittedly slightly slower, but
that rarely matters these days.

So what are your concerns with using a .so?

Ian



More information about the Binutils mailing list