Bug 13227 - [3.4 Regression] dlclose() causes destruction of global objects in ALL shared C++ libraries.
Summary: [3.4 Regression] dlclose() causes destruction of global objects in ALL shared...
Status: RESOLVED DUPLICATE of bug 13134
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-29 01:03 UTC by Carlo Wood
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test case. Untar and run 'make'. (1.15 KB, application/octet-stream)
2003-11-29 01:04 UTC, Carlo Wood
Details
Test case after being run with g++-3.3.2 -save-temps (14.36 KB, application/octet-stream)
2003-11-29 22:39 UTC, Carlo Wood
Details
Test case after being run with g++-cvs-3.4 -save-temps (14.59 KB, application/octet-stream)
2003-11-29 22:40 UTC, Carlo Wood
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carlo Wood 2003-11-29 01:03:26 UTC
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.
Comment 1 Carlo Wood 2003-11-29 01:04:53 UTC
Created attachment 5228 [details]
Test case.  Untar and run 'make'.
Comment 2 Andrew Pinski 2003-11-29 01:43:25 UTC
It is not a bug as you forgot to configure with --enable-__cxa_atexit.
Comment 3 Carlo Wood 2003-11-29 22:29:56 UTC
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.
Comment 4 Carlo Wood 2003-11-29 22:39:50 UTC
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.
Comment 5 Carlo Wood 2003-11-29 22:40:51 UTC
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.
Comment 6 Andrew Pinski 2003-11-30 00:32:57 UTC
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 ***