Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: atexit(), dlclose() and more atexit()



On 28.06.2020 23:57, Joerg Sonnenberger wrote:
> On Sun, Jun 28, 2020 at 11:48:15PM +0200, Kamil Rytarowski wrote:
>> On 28.06.2020 23:29, Joerg Sonnenberger wrote:
>>> It is fundamentally wrong to use a handler in a library that can be
>>> unloaded. Some systems hack around that problem by looping over all
>>> atexit handlers on dlclose, but that's exactly that, a costly hack. The
>>> most common way this triggers is a segfault, actually.
>>
>> The world disagrees and NetBSD is different for no good reason.
> 
> You sound like a broken record. Have you *thought* about the reasons at
> all? Like for example the very definition of atexit: "Run a handler at
> process exit". The Linux variant does not do that. Heck, they only
> document it as a side note.
> 

atexit is implemented today as 'The atexit() function registers the
function pointed to by func to be called without arguments on normal
termination of the program or when the object defining the function is
unloaded.' for around 20 years now.

NetBSD is a leftover with a broken implementation.

>> We shall add support for this.
> 
> We shall not. It is a bad design.
> 

The world standardized on integration with dlclose(3).

>> On 28.06.2020 23:29, Joerg Sonnenberger wrote:
>>> The code should be using either a C dtor with the appropiate attribute
>>> or __cxa_atexit directly, but the former is preferable.
>>
>> This replacement forces to use a hack with a GCC extension (destructor
>> attribute) instead of C complaint code.
> 
> So what? It can be spelled out differently and the library here
> certainly contains enough dependencies on GCC extensions already.
> 

Destructor is a C++ feature, available in C as a GCC extension.

>> __cxa_atexit is a C++ thing so another hack for our atexit(3).
> 
> Where the heck did you arrive at the conclusion that __cxa_atexit is a
> C++ thing? It is support infrastructure having dynamic cleanup handlers
> on a per DSO base. Just because C++ was the first language to desire
> that doesn't mean it is C++ only. In fact, the above extension is using
> exactly the same code.
> 

__cxa_atexit is an internal symbol in Itanium C++ ABI, nothing to do with C.

> Joerg
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index