__cxa_finalize and `on_exit'

Mark Mitchell mark at codesourcery.com
Fri Dec 17 05:28:30 UTC 1999


>>>>> "Jim" == Jim Dehnert <dehnert at baalbek.engr.sgi.com> writes:

    >> From: Mark Mitchell <mark at codesourcery.com> Date: Thu, 16 Dec
    >> 1999 15:51:16 -0800
    >> 
    >> Why does the ABI says that __cxa_finalize should be called with
    >> a NULL parameter from the main program in the .fini section?
    >> Why not just let normal atexit processing take place when exit
    >> is called?

    Jim> There's a circularity problem, due to the need to register
    Jim> "normal" atexit calls to get them in the proper sequence.
    Jim> Rather than do a traditional atexit registration, in C++
    Jim> atexit must register the calls in the same sequence used for
    Jim> destructors.  So you can't just register __cxa_finalize with
    Jim> atexit, because it would end up invoking itself.

Oh, I understand; that's not what I was suggesting.

What I'm suggesting is:

  o As in the ABI, atexit calls __cxa_atexit.

  o When `exit' is called, it invokes all the things registered with
    all of __cxa_atexit, atexit, and (possibly) on_exit.

  o When a shared library is unloaded, it calls __cxa_finalize, which
    behaves exactly as in the ABI.

  o When a main program exits, it does not call __cxa_finalize.
    Instead, it just calls exit.  That does the things described
    above.

There's no circularity there.  And on_exit calls still work.  There's
no need to call on_exit functions when a dso is unloaded, so there's
no need to modify __cxa_finalize in any way.  Whether __cxa_finalize
and exit actually share common code or not is up to the implementors;
what is clear is that they must share the same list of registered
functions.

--
Mark Mitchell                   mark at codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com




More information about the cxx-abi-dev mailing list