__cxa_finalize and `on_exit'
Martin von Loewis
loewis at informatik.hu-berlin.de
Sat Dec 18 18:58:35 UTC 1999
> I believe I did; I just implemented this in GNU libc. All of atexit,
> on_exit, and __cxa_atexit share the same list of exit functions. When
> __cxa_finalize is called from a DSO, only __cxa_atexit functions are
> called. When exit is called (on exit from the main executable), all
> of the functions are called, in reverse order of registration. The
> main executable therefore does not call __cxa_finalize at all. Works
> like a charm, as far as I can tell.
I believe the issue here is the support of non-integrated C and C++
libraries. You've been modifying the C library, which is the right
approach if possible. In some cases, it might not be feasible, and I
believe Jim's proposal is to offer a fall-back for this case, with
degraded functionality. I don't know whether this actually works,
though.
If you don't have integrated C and C++ libraries, you'll still have
the need for cxa_atexit, but you can't put that into the C libraries'
atexit. Fortunately, that is not required by the international
standards - all that is required is interworking with std::atexit. So
you have std::atexit invoke __cxa_atexit, and get the right
interleaving. Of course, that won't cover atexit calls made from C
objects, but that is not feasible, anyway.
Then, of course, the question is how to run the __cxa_atexit list at
the end of the program. To do so, the proposal is to put a
__cxa_finalize call into the .fini section.
Unfortunately, it seems that this approach breaks the case when you do
integrate the C and C++ libraries; in this case, the extra call gets
in the way of extern "C" atexit processing, which must be placed into
the runtime system very cautiously.
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).
Regards,
Martin
More information about the cxx-abi-dev
mailing list