This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

dlclose not calling destructors of static variables.


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

Attachment: testrunner.cpp
Description: Text document

Attachment: testlib.cpp
Description: Text document

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]