This is a regression from g++ 3.3.x and earlier 3.4 CVS versions. A call to dlclose() for a previously loaded shared library closes ALL shared libraries and destructs all global object in the process. Very serious bug imho. In previous versions (g++-3.1, g++-3.1.1 and g++-3.2) even the standard streams were closed as a result of a call to dlclose() - I didn't check yet if that is now the case too. HOW TO REPRODUCE I wrote a little test case. Please download the tar ball, untar and run 'make' in the resulting directory. This was tested on i686-pc-linux-gnu with CVS binutils 2.14.90 20031118 installed. Using g++ 3.3.2: ~/c++/g++.bugs/bug15>make g++-3.3.2 -I. -shared -fpic libA.cc -Wl,-soname,libA.so.0 -o libA.so.0.0.0 ln -sf libA.so.0.0.0 libA.so.0 ln -sf libA.so.0 libA.so g++-3.3.2 -I. -shared -fpic libB.cc -Wl,-soname,libB.so.0 -o libB.so.0.0.0 ln -sf libB.so.0.0.0 libB.so.0 ln -sf libB.so.0 libB.so g++-3.3.2 -I. main.cc -L. -lA -Wl,-rpath,./ -ldl -o main ~/c++/g++.bugs/bug15>main Constructor of A Constructor of B Destructor of B Program exitted successfully. Destructor of A And using a recent CVS version: ~/c++/g++.bugs/bug15>make g++-cvs-3.4 -I. -shared -fpic libA.cc -Wl,-soname,libA.so.0 -o libA.so.0.0.0 ln -sf libA.so.0.0.0 libA.so.0 ln -sf libA.so.0 libA.so g++-cvs-3.4 -I. -shared -fpic libB.cc -Wl,-soname,libB.so.0 -o libB.so.0.0.0 ln -sf libB.so.0.0.0 libB.so.0 ln -sf libB.so.0 libB.so g++-cvs-3.4 -I. main.cc -L. -lA -Wl,-rpath,./ -ldl -o main ~/c++/g++.bugs/bug15>main Constructor of A Constructor of B Destructor of A Destructor of B 'a' was destroyed before it should be.
Created attachment 5228 [details] Test case. Untar and run 'make'.
It is not a bug as you forgot to configure with --enable-__cxa_atexit.
As we find out online... But - I then updated from CVS, reconfigured the compiler, re-bootstrapped it from scratch (includes a rm -rf objdir), re-installed it... and get the very same bug. ~/c++/g++.bugs/bug15>make g++-3.3.2 -I. -save-temps -shared -fpic libA.cc -Wl,-soname,libA.so.0 -o libA.so.0.0.0 ln -sf libA.so.0.0.0 libA.so.0 ln -sf libA.so.0 libA.so g++-3.3.2 -I. -save-temps -shared -fpic libB.cc -Wl,-soname,libB.so.0 -o libB.so.0.0.0 ln -sf libB.so.0.0.0 libB.so.0 ln -sf libB.so.0 libB.so g++-3.3.2 -I. -save-temps main.cc -L. -lA -Wl,-rpath,./ -ldl -o main ~/c++/g++.bugs/bug15>g++-3.3.2 -v Reading specs from /usr/local/gcc-3.3.2/lib/gcc-lib/i386-redhat-linux/3.3.2/specs Configured with: /usr/src/gcc/gcc-3.3.2/configure --prefix=/usr/local/gcc-3.3.2 --enable-shared --with-gnu-as --with-gnu-ld --enable-languages=c++ --enable-debug --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux Thread model: posix gcc version 3.3.2 ~/c++/g++.bugs/bug15>./main Constructor of A Constructor of B Destructor of B Program exitted successfully. Destructor of A ~/c++/g++.bugs/bug15>vi Makefile ~/c++/g++.bugs/bug15>make clean rm -f main libA.so* libB.so* ~/c++/g++.bugs/bug15>make g++-cvs-3.4 -I. -save-temps -shared -fpic libA.cc -Wl,-soname,libA.so.0 -o libA.so.0.0.0 ln -sf libA.so.0.0.0 libA.so.0 ln -sf libA.so.0 libA.so g++-cvs-3.4 -I. -save-temps -shared -fpic libB.cc -Wl,-soname,libB.so.0 -o libB.so.0.0.0 ln -sf libB.so.0.0.0 libB.so.0 ln -sf libB.so.0 libB.so g++-cvs-3.4 -I. -save-temps main.cc -L. -lA -Wl,-rpath,./ -ldl -o main ~/c++/g++.bugs/bug15>g++-cvs-3.4 -v Reading specs from /usr/src/GNU/install/bin/../lib/gcc/i686-redhat-linux/3.4/specs Configured with: /usr/src/gcc/gcc-cvs-3.4/configure --prefix=/usr/local/gcc-cvs-3.4 --enable-shared --with-gnu-as --with-gnu-ld --enable-languages=c++ --enable-debug --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i686-redhat-linux Thread model: posix gcc version 3.4 20031129 (experimental) ~/c++/g++.bugs/bug15>./main Constructor of A Constructor of B Destructor of B Destructor of A 'a' was destroyed before it should be.
Created attachment 5237 [details] Test case after being run with g++-3.3.2 -save-temps Added because Andrew has no access to an i686-pc-linux-gnu box.
Created attachment 5238 [details] Test case after being run with g++-cvs-3.4 -save-temps Added because Andrew has no access to an i686-pc-linux-gnu box.
The cause of this bug is that the Visibility attribute is ignored, see PR 13134 so this is just a dup of that bug. *** This bug has been marked as a duplicate of 13134 ***