dlclose not calling destructors of static variables.

Andrew West andrewwest@gmail.com
Thu Jan 28 15:00:00 GMT 2010


I seem to be having a problem with dlclose not calling the destructors 
of statically declared variables. I've attached a simple test case which 
I compile as follows;

testlib.cpp
g++ -g -shared testlib.cpp -o testlib

testrunner.cpp
g++ -g testrunner.cpp -o testrunner -ldl

When running testrunner, I get the following output;

Running test_runner
testlib:: start
TestClass::TestClass()
Running test_lib
testlib:: stop
Segmentation fault (core dumped)

Compiling and running the same code on linux gives me the expected 
result of;

Running test_runner
testlib:: start
TestClass::TestClass()
Running test_lib
TestClass::~TestClass()
testlib:: stop

Digging through with gdb, __EntryPoint() registers the destructor of 
TestClass with atexit but dlclose doesn't call the atexit for the dll 
it's unloading leaving the TestClass destructor in the atexit list when 
the program exits even thou testlib.dll has been unloaded, hence the 
segfault.

I'm afraid I'm don't really know much about how the internals of 
cygwin/library loading and unloading works. Is this a simply a case of 
dll_list::detach needing to call __cxa_finalize with a reference to the 
dll being unloaded?

Andy
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testrunner.cpp
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100128/7e7185e9/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testlib.cpp
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100128/7e7185e9/attachment-0001.ksh>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list