This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Problem with atexit and _dl_fini
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Nat! <nat at mulle-kybernetik dot com>
- Cc: libc-help at sourceware dot org
- Date: Sun, 19 May 2019 18:23:20 +0200
- Subject: Re: Problem with atexit and _dl_fini
- References: <b055481f-fea2-8a30-54de-6513c86e2e40@mulle-kybernetik.com>
* Nat!:
> So my problem is, that I observe that my atexit calls are not executed
> in the correct order.
>
> i.e. atexit( a); atexit( b); should result in b(), a() being called in
> that order. To quote the man page,
>
> "the registered functions are invoked in reverse order".
>
>
> When I register with `atexit` I can see my functions being added
> properly within `__internal_atexit` in the
>
> correct order. Finally after my functions, the elf-loader ? also adds
> itself there. So it is being called first by
>
> `__run_exit_handlers`.
>
>
> Then comes the part where it goes wrong. I registered my two function
> with `__internal_atexit`, but for some reason
>
> `_dl_fini` is calling `__cxa_finalize` and that is calling the wrong
> function first.
When atexit is called from a DSO, glibc calls the registered function
before the DSO is unloaded. This choice was made because after
unloading, the function pointer becomes invalid.
I haven't checked, but I suspect atexit still works this way even if
it doesn't have to (because the DSO is never unloaded).