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]

Re: dlclose not calling destructors of static variables.


On Mon, Feb 01, 2010 at 11:46:55AM +0000, Andrew West wrote:
>On 29/01/2010 18:45, Christopher Faylor wrote:
>> On Fri, Jan 29, 2010 at 02:30:48PM +0000, Andrew West wrote:
>>    
>>> On 29/01/2010 13:08, Dave Korn wrote:
>>>      
>>>> On 28/01/2010 11:21, Andrew West wrote:
>>>>        
>>>>> 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;
>>>>>
>>>>>          
>>>> Thanks for the report and the STC; this should work.  I'll take a look
>>>> at it over the weekend or the start of next week if nobody else gets
>>>> there first.
>>>>
>>>>        
>>> Thanks for looking into this, it looks a little more complex than I
>>> first thought.
>>>
>>> I've tried calling __call_exitprocs during dlclose ( after run_dtors
>>> for the unloading library ) just to see if I was thinking along the
>>> right lines.  Unfortunately this didn't work as when the destructor is
>>> registered with atexit it isn't associated with the loaded library but
>>> with the main executable.
>>>
>>> Which brings me on to the bigger problem, the static variables are
>>> registered with atexit rather than with __cxa_atexit which seems to be
>>> a violation of the C++ standard (1).
>>>
>>> Worse still gcc isn't compiled with cxa_atexit enabled.  So I assume
>>> the right course of action here is to enable __cxa_atexit in gcc, and
>>> then make sure __cxa_finalize gets called when the library is unloaded?
>>>      
>> I agree with your assessment here.  I've checked in a change which works
>> around the problem you've uncovered but it is not foolproof.  It should
>> fix the immediate problem but, in the long run, I agree that gcc should
>> be emitting code which calls __cxa_atexit.  Of course I have no idea
>> what the other ramifications of doing that might be.  Hopefully Dave can
>> enlighten us.
>>
>> This is in today's snapshot at http://cygwin.com/snapshots/ .
>>
>> cgf
>>
>>    
>
>Hi,
>
>I checked out the changes and it still crashed for me. Digging into it 
>the destructor for testlib fell outside of dll_end ( m.AllocationBase + 
>m.RegionSize ). On a whim I change m.AllocationBase to m.BaseAddress and 
>that seemed to fix it for me! The destructor ran on dlclose and the 
>testrunner.exe didn't segfault.

Could you clarify?  Are you saying that your test case still failed?

cgf

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