__cxa_finalize and `on_exit'

Martin von Loewis loewis at informatik.hu-berlin.de
Mon Dec 20 11:27:46 UTC 1999


> How so?  I would think you could just register __cxa_finalize (NULL) (or
> equivalent) with the C atexit.  Then exit runs all the destructors, and the
> calls in .fini do nothing, because everything has already been
> deregistered.  The atexit chain is run before .fini stuff, I'm
> pretty sure.

The current draft says, in C-3

# Finally, a main program should be linked with a FINI call to
# __cxa_finalize with NULL parameter.

I'd agree that registering cxa_finalize(0) with the C atexit is indeed
an option; the ABI says otherwise.

>  > My proposal: it is left unspecified by the ABI how exactly the
>  > __cxa_atexit list is invoked - whoever provides the implementation of
>  > __cxa_atexit and __cxa_finalize is also responsible for having the
>  > finalizers called at the right point in time (i.e. as a result of
>  > std::exit invocation).
> 
> That won't work; anything that involves .fini must be specified by the ABI.

Maybe. My concern was the extra call to __cxa_finalize if __cxa_atexit
is integrated with C atexit. This is probably not a problem, since
multiple calls to __cxa_finalize do not hurt - provided there really
is a guarantee that C atexit functions will be run before DT_FINI.

Regards,
Martin




More information about the cxx-abi-dev mailing list