at exit alternative for AIX

David Edelsohn
Sun Aug 5 18:09:00 GMT 2012

On Sun, Aug 5, 2012 at 9:56 AM, Perry Smith <> wrote:

> I was planning on exploring when _GLOBAL__FD was called today.  I
> need to figure out when gcc puts the call to the dtor in _GLOBAL__FD
> path rather than in the atexit path.  The net implies that "static" uses
> atexit while a global non-static uses _GLOBAL__FD
> I'm also exploring what it would take to port a version of GNU's
> __cxa_atexit to AIX.  I think after I figure out when various dtors
> get called, I should be able to figure out if / how to do that.
> Part of my confusion / concern is "why have two methods?"
> Does the spec say that dtors much be called at different times?

Destructors are added to _GLOBAL__FD by collect2 at link time.  It
scans the object files for destructor functions, sorts them by
priority and creates a function connected to _GLOBAL__FD to call them.
 Collect2 performs the same grouping for constructors, creates a
function and connects it to _GLOBAL__FI.  The uniquely named functions
are added to the AIX linker command line as arguments to the
-binitfini option to establish them as initializer/finalizer functions
for the shared object.

AIX does not have a ctor/dtor or init/fini section in object files,
nor _cxa_atexit.

AIX dlclose() should call AIX terminateAndUnload() service that will
call the fini routine registered by -binitfini.  If something else in
GCC is trying to register the termination function for systems without
_cxa_atexit() using atexit(), it probably is conflicting and trying to
run the destructors twice.

Another difference between AIX and SVR4 is AIX invokes init and fini
functions for multiple, dependent shared objects breadth first, while
SVR4 invokes them depth first based on library dependencies.  There is
an old Bugzilla entry with a proposal to push init functions onto a
stack as they are seen when libraries are loaded and then run them in
SVR4 dependency order.

- David

More information about the Gcc mailing list