This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC] stdlib: Make atexit to not act as __cxa_atexit
On 02/07/2019 04:44, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> 3. exit is the only way where atexit handlers are actually called.
>> Unloading a library through dlclose does not issue the atexit
>> anymore (this is the main semantic change).
>
> Sorry, I don't think this is the right direction. We got the current
> atexit behavior from Solaris, and I think it is useful.
>
> <https://docs.oracle.com/cd/E88353_01/html/E37843/atexit-3c.html>
I am not sure this is also a good design, specially that we have elf
destructors that provide a similar semantic.
>
> I think the bug is that our implementation of that behavior interferes
> with the execution order when there is no dlclose at all. There should
> be a different way for fixing that.
>
> Maybe we can turn __cxa_finalize into a NOP and have the dynamic loader
> handle atexit handlers directly on dlclose (assuming that it's always
> called before the other ELF destructors)?
We need __cxa_finalize because it is called by __do_global_dtors_aux
from initfini callbacks. Also making the loader itself handler atexit
is not the best option IMHO: we will either to call a private symbol on
libc (which might require an additional lookup) or export the internal
data so loader can implement the callback issuing itself.
>
> Or otherwise use flags to mark things, but in such a way that the
> handlers are processed in reverse atexit order, unless a dlclose
> happens.
I think one possible option to still allow atexit handler being called
by atexit is to still register them as ef_at (using the new __atexit
symbol) and on __run_exit_handler first process et_at and them
ef_on and ef_cxa. This is still a semantic change of atexit regarding
the order of on_exit and __cxa_atexit, but we keep the Solaris like
one to call them on dlclose.
What do you think?