On Sat, Aug 4, 2012 at 2:43 PM, Perry Smith <pedz...@gmail.com> wrote:
>
> I hope I've researched this enough to ask decent questions.
>
> I'm running gcc 4.5.2.  AIX 6.1 TL07 SP03.
>
> The essence of the problem is when a shared library is loaded, sometimes 
> atexit is called with a pointer to a destructor.  This call (I gather) is 
> produced by gcc itself (or g++).
>
> The problem is when the shared library is unloaded (dlclose() is called), the 
> TOC is blasted.  Later, when the program terminates, atexit runs and crashes 
> because it can't get to the TOC or the destructor.
>
> I tried -fuse-cxa-atexit but __cxa_atexit is not defined on AIX.
>
> The module's ctor (if that is the right term?) calls a routine per file (it 
> looks like) which sometimes calls atexit -- I assume to register a dtor.
>
> The dlclose routine does call the module's dtor (e.g. 
> _GLOBAL__FD_mod_passenger_so) but it does not end up calling unatexit (which 
> may be an AIX'ism) to remove the atexit entry.
>
> I don't know if this is significant but the "passenger" module depends upon 
> libstdc++.  Both register an atexit routine however the first one (which 
> appears to be for passenger), the TOC entry resides in the normal data space 
> (0x3xxxxxxx in this case).  It is actually libstdc++ that registers the 
> atexit routine that resides in the 0xfxxxxxxx space which gets zeroed out 
> when it is unloaded.
>
> The stack when the 2nd atexit call is made is:
>
> #0  0xd019b644 in atexit () from /usr/lib/libc.a(shr.o)
> #1  0xd57c6f3c in _GLOBAL__I_65535_0__ZSt15future_category () at  _start_ :132
> #2  0xd58044c8 in _GLOBAL__FI_libstdc___so () from 
> /gsa/ausgsa-p9/06/ruby/lib/pthread/libstdc++.a(libstdc++.so.6)
> #3  0xd0197828 in mod_init1 () from /usr/lib/libc.a(shr.o)
>  ...
>
> The more I research this the more twists and turns it takes so I may have 
> stopped too early to ask my questions but I hope not.
>
> The question is: what can I do about this?  It seems like either atexit 
> should not be used or a call to unatexit should be rigged up to remove it 
> when the module's dtor is called.

On AIX, does the _GLOBAL__FD routine get called reliably on both
dlclose and program exit?  If so, it seems that there is no need to
call atexit.  If the routine is called reliably on dlclose but not
program end, then I agree that it should call unatexit.  As far as I
know that function is specific to AIX, so it sounds like some
AIX-specific code will need to be written.

As you know, this is not an issue on GNU/Linux, where the compiler can
simply use __cxa_atexit.

Ian

Reply via email to