www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/01/06:47:02

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4B66BF2F.4060802@gmail.com>
Date: Mon, 01 Feb 2010 11:46:55 +0000
From: Andrew West <andrewwest AT gmail DOT com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: dlclose not calling destructors of static variables.
References: <4B61732F DOT 4030804 AT gmail DOT com> <4B62DDE6 DOT 5070106 AT gmail DOT com> <4B62F118 DOT 8010305 AT gmail DOT com> <20100129184514 DOT GA9550 AT ednor DOT casa DOT cgf DOT cx>
In-Reply-To: <20100129184514.GA9550@ednor.casa.cgf.cx>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------010203020804030507070308
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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.

For what it's worth the small change is attached as a patch.

Andy


--------------010203020804030507070308
Content-Type: text/plain;
 name="dll_init.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="dll_init.patch"

Index: winsup/cygwin/dll_init.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dll_init.cc,v
retrieving revision 1.68
diff -u -p -r1.68 dll_init.cc
--- winsup/cygwin/dll_init.cc	29 Jan 2010 18:34:09 -0000	1.68
+++ winsup/cygwin/dll_init.cc	1 Feb 2010 11:43:17 -0000
@@ -155,8 +155,8 @@ dll_list::alloc (HINSTANCE h, per_proces
 static void
 remove_dll_atexit (MEMORY_BASIC_INFORMATION& m)
 {
-  unsigned char *dll_beg = (unsigned char *) m.AllocationBase;
-  unsigned char *dll_end = (unsigned char *) m.AllocationBase + m.RegionSize;
+  unsigned char *dll_beg = (unsigned char *) m.BaseAddress;
+  unsigned char *dll_end = (unsigned char *) m.BaseAddress + m.RegionSize;
   struct _atexit *p = _GLOBAL_REENT->_atexit;
   for (int n = p->_ind - 1; n >= 0; n--)
     {


--------------010203020804030507070308
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019