Calling __cxa_thread_atexit_impl directly, from C code

Florian Weimer fweimer@redhat.com
Tue Aug 30 07:37:21 GMT 2022


* Adhemerval Zanella Netto:

> It would mean that libgcc_s would need to build and use the fallback
> implementation in the case of failure, which is suboptimal (although not
> sure it would be an improvement over abort on failure).

The fallback implementation also has to allocate memory.

The alternative would be to throw std::bad_alloc.

> But I also think for compat reasons we can't really change 
> __cxa_thread_atexit_impl, since C++ constructors will be the ones responsible
> to call __cxa_thread_atexit and afaik it assumes it can not fail (meaning
> that any failure will be ignored).

Yes, there is the general problem that for registering an object for
destruction, as a matter of principle, you need to try to allocate the
data structure in the registry first, and if that is successful, create
the object.  Otherwise you may end up with an object and no way to
register its destructor.  Perhaps you should just call the destructor at
this point and throw std::bad_alloc.

I guess we should go with the static destructor counting approach
instead. 8-/

Thanks,
Florian



More information about the Libc-alpha mailing list