Problem with atexit and _dl_fini

Nat! nat@mulle-kybernetik.com
Tue Jun 11 20:20:00 GMT 2019


On 11.06.19 20:39, Adhemerval Zanella wrote:
>
> It seems that this requirement seems to come from LSB, although I am not
> sure which one came first (the specification or the implementation).
> It also states that __cxa_atexit should register a function to be called
> by exit or when a shared library is unloaded.

I don't really have much further to add to this topic, so this is just 
some commentary and speculation... and I am probably repeating myself.


https://pubs.opengroup.org/onlinepubs/009695399/functions/atexit.htmlstates: 


    The /atexit/() function shall register the function pointed to by 
/func/, to be called without arguments at normal program termination.

That's "normal program termination" not anytime before. dlclose is 
anytime before. What is happening is a violation of `atexit`.


When I read 
http://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.html#BASELIB---CXA-FINALIZE

I see that it's *Intels* version of C++ that originally dictated this 
violation of the C standard. Possibly Intel was writing this with 
Windows in mind ?

> And __cxa_finalize requires to call atexit registers functions as well. It
> also states __cxa_finalize should be called on dlclose.

In my opinion the__cxa_finalize requirement is wrong. It's further my 
opinion, that a vendors requirement for its C++ ABI, does not "trump" 
open standards. :)

>
> I think it might due the fact old gcc version uses atexit to register C++
> destructors for local static and global objects. However it seems to be
> enabled as default for GLIBC (since it support __cxa_atexit since initial
> versions).
>
> So I think there is no impeding reason to make atexit not be called from
> __cxa_finalize, although I am not sure how we would handle the LSB deviation.
> I will write down a libc-alpha to check what other developer think.

I think the proper solution is to rewrite __cxa__finalize and remove 
atexit functionality completely from it.
Alas I am not hopeful, that this will be resolved to my taste :)


>
> [1] http://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.pdf
>

Ciao

    Nat!





More information about the Libc-help mailing list