public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: Calling __cxa_thread_atexit_impl directly, from C code
Date: Tue, 06 Sep 2022 08:44:15 +0200	[thread overview]
Message-ID: <87k06hatog.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <dc87488b-05f3-f208-94a2-97a677ca6624@linaro.org> (Adhemerval Zanella Netto's message of "Tue, 30 Aug 2022 09:56:09 -0300")

* Adhemerval Zanella Netto:

> On 30/08/22 04:37, Florian Weimer wrote:
>> * Adhemerval Zanella Netto:
>> 
>>> 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).
>> 
>> The fallback implementation also has to allocate memory.
>> 
>> The alternative would be to throw std::bad_alloc.
>
> Yeah, but the suboptimal is not solely for the allocation memory part,
> but also for the missing synchronization and ordering.  But I also think
> moving the failing handling to caller it still better than the hard hammer
> or aborting the process (even though I agree it won't improve that much).

But I think this argues indirectly for making a __cxa_thread_atexit_impl
variant callable from C code: C++ code with -fno-exceptions might want
to use this as well, and there is really no good way to handle such
fallible C++ constructs (here: implicit destructor registration) without
exceptions.

>>> 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).
>> 
>> Yes, there is the general problem that for registering an object for
>> destruction, as a matter of principle, you need to try to allocate the
>> data structure in the registry first, and if that is successful, create
>> the object.  Otherwise you may end up with an object and no way to
>> register its destructor.  Perhaps you should just call the destructor at
>> this point and throw std::bad_alloc.
>> 
>> I guess we should go with the static destructor counting approach
>> instead. 8-/
>
> Why strategy more specially do you mean the counting approach?

If we know how many TLS variables with d'tors there can be, we can
allocate the memory upfront during thread creation.

> I just reread the 'Counting static __cxa_atexit calls' thread and tend
> to agree with you that having the number of required unique
> __cxa_atexit calls seems slight better than a failable .init_array
> mode.

Please say so on the thread as well. 8-)

Thanks,
Florian


      reply	other threads:[~2022-09-06  6:44 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
2022-08-30  7:37       ` Florian Weimer
2022-08-30 12:56         ` Adhemerval Zanella Netto
2022-09-06  6:44           ` Florian Weimer [this message]

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=87k06hatog.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --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).