On Sat, 20 Dec 2025 15:55:26 +0000 (UTC)
RVP <[email protected]> wrote:

> On Sat, 20 Dec 2025, Sad Clouds wrote:
> 
> > I've never seen anyone using atexit() with shared libraries. The usual
> > mechanisms for these things are _init/_fini or
> > __attribute__((constructor))/__attribute__((destructor)).
> >
> 
> Shared libs. should use __cxa_atexit() with a non-NULL `dso' parameter.
> 
> -RVP

I think this API was originally designed for C++ due to atexit() being
inadequate for use with object destructors. The closest to the standard
definition that I can find:
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#dso-dtor-runtime-api

To provide binary compatibility between C and C++, atexit() was probably
modified to use __cxa_atexit() but in such a way that keeps the
original spec:

  When the user registers exit functions with atexit, they should be
  registered with NULL parameters and DSO handles, i.e.
  __cxa_atexit ( f, NULL, NULL );

I'm not a C++ person, but I think __cxa_atexit() is not meant to be
exposed externally. If you are not using C++ to automatically generate
object destructors, this leaves various non-portable compiler
attributes and pragmas.

I could be wrong about all this, but this is my current understanding.

Reply via email to