This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/24189] New: crash at exit after dlclose with -fuse-cxa-atexit
- From: "hidden_peak at mail dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Oct 2005 13:40:50 -0000
- Subject: [Bug c++/24189] New: crash at exit after dlclose with -fuse-cxa-atexit
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Program open DSO with dlopen; DSO has has any C++ global (static) object;
program close DSO with dlclose; crash at program exit. Compiler use
-fuse-cxa-atexit option, compiler was builded as
Reading specs from /opt/gcc-3.4.4/lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: ./configure --enable-__cxa_atexit --enable-threads
--with-system-zlib --enable-languages=c,c++,java --prefix=/opt/gcc-3.4.4
Thread model: posix
gcc version 3.4.4
Possible crash reason: call of dtor of static object in DSO after DSO was
unloaded.
Test:
> cat test.cc
#include <dlfcn.h>
//#include <iostream>
//#include <iomanip>
//using namespace std;
typedef void *(*func_type)();
int main()
{
void *lh = dlopen( "./libtestg.so", RTLD_LAZY );
//cerr << hex << (unsigned)lh << dec << endl;
func_type f = (func_type)dlsym( lh, "func" );
f();
dlclose( lh );
return 0;
}
> cat testlib.cc
//#include <iostream>
//using namespace std;
extern "C" void func();
class A
{
public:
A();
~A();
private:
char *p;
};
A::A()
{ /* p = new char [50]; */ }
A::~A()
{ /* delete [] p; */ }
static A a; // <- crash at call cxa_atexit after dlclose?
//static char b[30];
void func()
{
// A a;
//a = new A;
// cerr << "Hello\n";
}
> cat x.sh
#!/bin/bash
CXX=c++
${CXX} -pthread -fexceptions -fident -g -fuse-cxa-atexit -c -o test.o test.cc
${CXX} -pthread -fexceptions -fident -g -fuse-cxa-atexit -nostdlib -o test
`for o in crt{1,i,begin}.o; do ${CXX} -print-file-name=\$o; done` test.o
-lsupc++ -ldl -lgcc_s -lpthread -lc -lm `for o in crt{end,n}.o; do ${CXX}
-print-file-name=\$o; done`
${CXX} -pthread -fexceptions -fident -fPIC -g -fuse-cxa-atexit -c -o testlib.o
testlib.cc
${CXX} -pthread -fexceptions -fident -fPIC -g -fuse-cxa-atexit -shared
-Wl,-hlibtestg.so.0.0 -nostdlib -o libtestg.so.0.0.0 `for o in
crt{i,beginS}.o; do ${CXX} -print-file-name=\$o; done` testlib.o -lgcc_s
-lsupc++ -lpthread -lc -lm `for o in crt{endS,n}.o; do ${CXX}
-print-file-name=\$o; done`
rm -f libtestg.so.0.0; ln -s libtestg.so.0.0.0 libtestg.so.0.0;
rm -f libtestg.so.0; ln -s libtestg.so.0.0 libtestg.so.0;
rm -f libtestg.so; ln -s libtestg.so.0 libtestg.so
./test
--
Summary: crash at exit after dlclose with -fuse-cxa-atexit
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hidden_peak at mail dot ru
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24189