__cxa_finalize and `on_exit'

Mark Mitchell mark at codesourcery.com
Mon Dec 20 01:39:20 UTC 1999


>>>>> "Jason" == Jason Merrill <jason at cygnus.com> writes:

>>>>> Mark Mitchell <mark at codesourcery.com> writes:

    >> Perhaps you missed the earlier thread.  The problem is that
    >> __cxa_finalize does not take the exit code, so it cannot call
    >> on_exit functions.

    Jason> Yes, I remember the earlier discussion; I'm talking about
    Jason> the case Martin brought up.  That is, when we can't modify
    Jason> the C library, so we need to handle destructors and
    Jason> std::atexit separately.  In that case, we would need to
    Jason> keep a separate list for C++ bits.

I'm a little bit confused.  The ABI documents clearly say that
inegration with the C library is expected.  So, why are we worrying
about this case?  But OK.

The problem is that something different needs to happen in the
integrated and unintegrated cases:

  o Integrated case

    Calling __cxa_finalize from the main program, either directly
    or via atexit, is bad: it means that __cxa_atexit/atexit calls
    may not be properly interleaved with on_exit.

  o Unintegrated case

    We need to call __cxa_finalize from the main program to run
    cleanups.

But, an ABI-compliant program doesn't know which case it's going to
wind up with.  So, what's it to do?

One possibility: check a weak variable, defined to a non-zero value in
an integrated library.  If the variable is non-zero, we don't need to
register __cxa_finalize for the main program.  If it is zero, then we
know we've got an unintegrated library, and we have to register
__cxa_finalize, either in via fini processing or via the C atexit
routine.  Does that work?

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




More information about the cxx-abi-dev mailing list