This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] stdlib: Make atexit to not act as __cxa_atexit


* Adhemerval Zanella:

> 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.

It's what's in various quasi-standard documents, so we need to support
it.

>> 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.

(Note: The comment is about crtbeginS.o built from libgcc sources.)

If all versions of the ELF constructor in crtbeginS.o call
__cxa_finalize as their first action, then we can turn __cxa_finalize
into a NOP and have the dynamic linker perform the original actions of
__cxa_finalize directly, before running the ELF destructors for this
object.

> 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.

Anything would be better than this pointless indirection through libgcc.
We have accumlated lots of cruft in the crt* objects which serve no
purpose at all for current binaries, and eventually, we will have to
clean this up.

I think crtbegin*.o could completely go away if we turn __cxa_finalize
into a NOP on the glibc side.

>> 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.

Sorry, can you rephrase?  There seem to be a few typos in this
paragraph.

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]