Problem with atexit and _dl_fini

Manfred mx2927@gmail.com
Fri Jun 14 12:29:00 GMT 2019


Interesting,

In fact the link you posted is about the LSB, not specific to the 
Itanium C++ ABI, and indeed it does the right thing.

As a side note, it leaves up to user code the following:
- do not register with atexit functions residing in dso's that can be 
unloaded early (i.e. by dlclose() during execution, not at exit()).
- do not instantate global/static C++ objects whose type is defined in 
the main program and derived from classes defined in dso's that can be 
unloaded early.

Both requirements descend (implicitly?) from the C and C++ standards, 
though.

I'm cross-posting to alpha, in case anyone is interested.


On 6/14/2019 12:53 AM, Nat! wrote:
> Funnily enough, if you read the Itanium C++ ABI, on which __cxa_finalize 
> is based, then the algorithm described
> there is doing exactly the right thing.
> Beause the wording of __cxa_finalize is so shortened, it its hard to 
> pick out the original meaning. But the description is
> actually fully compatible with how `atexit` is supposed to function.
> 
> The gist is this. For atexit, functions are stored in a unique way in 
> the termination function table (clarifications in []):
> 
> http://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.html#BASELIB---CXA-FINALIZE 
> 
> 
> ```
> In the latter case [atexit] the pointer to the function is the pointer 
> passed to atexit(), while the other pointers [operand, handle] are NULL.
> ```
> 
> When dlclose hits, the handle to be closed is `d` and not NULL:
> 
> ```
> The implementation shall arrange for__cxa_finalize() to be called during 
> early shared library unload (e.g. dlclose()) with a handle to the shared 
> library.
> ```
> 
> And then
> 
> ```
> When __cxa_finalize(d) is called, it shall walk the termination function 
> list, calling each in turn if d matches the handle of the termination 
> function entry.
> ```
> 
> So `atexit`s don't match, since the handle stored is NULL. Only if `d` 
> is NULL (the base process terminates), then will the atexits be called. 
> Currently though at `dlclose` time all handlers are called, which breaks 
> the `atexit` specification as well as your own LSB.
> 
> Well it's a goof up, but FreeBSD and MacOS aren't doing any better.
> 
> Ciao
>    Nat!
> 
> 



More information about the Libc-alpha mailing list