C++, ld, and Solaris weirdness
Posted: Thu Jan 27, 2005 1:45 pm
I'm wondering if anyone can help me with a linker-related problem I'm having on Solaris 8...
There's a really old shared library being built with an equally old makefile... Once upon a time it only contained C code, but somewhat recently some C++ stuff has been added to it, including a few static objects.
Through a painful process of diagnosis, I have figured out that the ld switch '-B symbolic' is for some reason preventing the constructors of static C++ objects in the .so from being called. I have no idea why. The problem is, if I remove -B symbolic, some other things break somewhat mysteriously. One of my colleagues hypothesizes that a global variable declare in a static lib that is linked into the .so is conflicting with (being merged with...?) the same variable in another copy of the static lib that is linked into the executable that is loading the .so, and that -B symbolic may have been added to the makefile years ago specifically to address this problem.
If that was confusing, here is some ASCII art:
mylib.a defines global variable 'foo'.
a.out -> mylib.a -> foo <-------------------+
| |
+----> mysharedlib.so -> mylib.a -> foo ---+
I don't understand enough details to verify his hypothesis... I've read the ld man pages ad nauseum... Can anyone give me a simpler explanation (or a link to one... no pun intended)?
There's a really old shared library being built with an equally old makefile... Once upon a time it only contained C code, but somewhat recently some C++ stuff has been added to it, including a few static objects.
Through a painful process of diagnosis, I have figured out that the ld switch '-B symbolic' is for some reason preventing the constructors of static C++ objects in the .so from being called. I have no idea why. The problem is, if I remove -B symbolic, some other things break somewhat mysteriously. One of my colleagues hypothesizes that a global variable declare in a static lib that is linked into the .so is conflicting with (being merged with...?) the same variable in another copy of the static lib that is linked into the executable that is loading the .so, and that -B symbolic may have been added to the makefile years ago specifically to address this problem.
If that was confusing, here is some ASCII art:
mylib.a defines global variable 'foo'.
a.out -> mylib.a -> foo <-------------------+
| |
+----> mysharedlib.so -> mylib.a -> foo ---+
I don't understand enough details to verify his hypothesis... I've read the ld man pages ad nauseum... Can anyone give me a simpler explanation (or a link to one... no pun intended)?