public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: Calling __cxa_thread_atexit_impl directly, from C code
Date: Mon, 29 Aug 2022 16:56:45 -0300	[thread overview]
Message-ID: <65d24a0f-2fc4-010f-e26a-a344e63a9d49@linaro.org> (raw)
In-Reply-To: <87sfle26vf.fsf@oldenburg.str.redhat.com>



On 29/08/22 16:21, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
>> Although it seems to be used solely by C++ and the interface is generic enough
>> so any runtime/language might use it as well for any thread exit deallocation
>> cleanup, I am not sure it would be feasible to export or support calling it
>> from C code.
> 
> It's an exported symbol, and usually we treat those as part of the ABI.

Right, but the double underscore also notes this is an implementation specific
symbol similar to fortify ones (where although glibc is bounded to supported
them indefinitely, it might not call them for if fortify changes to a compiler
generated builtin for instance).

> 
>> The interface also have two annoying peculiarities where calling from C code
>> is not straightforward: 
>>
>>   1. Any memory failure aborts the process, which is far from ideal to a
>>      generic interface.
>>
>>   2. User need to correctly declare __dso_handle; using NULL (or any invalid
>>      value) will bound the to callback to main program (which is not correct
>>      if use within a shared library).
>>
>> So I think it would be better to provide a different interface.
> 
> We could add this:
> 
> static inline int
> thread_atexit (void (*__callback) (void *__data), void *__data)
> {
>   extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
>   extern int __cxa_thread_atexit_impl (void (*__callback) (void *__data),
>                                         void *__caller);
>   return __cxa_thread_atexit_impl (__callback, __data, &__dso_handle);
> }
> 
> to <stdlib.h> with some approriate preprocessor conditionals.

Or make it similar to atexit and provide it with static-only-routines.
It would simplify the prototype and header definitions.

> 
> Maybe libgcc_s should do the error checking in its __cxa_thread_atexit
> function?  Then we could simply use the existing implementation in the
> function above, remove our abort, and defer the problem to the
> thread_atexit caller.

It would mean that libgcc_s would need to build and use the fallback
implementation in the case of failure, which is suboptimal (although not
sure it would be an improvement over abort on failure).  

But I also think for compat reasons we can't really change 
__cxa_thread_atexit_impl, since C++ constructors will be the ones responsible
to call __cxa_thread_atexit and afaik it assumes it can not fail (meaning
that any failure will be ignored).

  reply	other threads:[~2022-08-29 19:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26  8:31 Florian Weimer
2022-08-29 18:59 ` Adhemerval Zanella Netto
2022-08-29 19:21   ` Florian Weimer
2022-08-29 19:56     ` Adhemerval Zanella Netto [this message]
2022-08-30  7:37       ` Florian Weimer
2022-08-30 12:56         ` Adhemerval Zanella Netto
2022-09-06  6:44           ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65d24a0f-2fc4-010f-e26a-a344e63a9d49@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).