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, 30 Aug 2022 09:37:21 +0200	[thread overview]
Message-ID: <87pmgi5gi6.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <65d24a0f-2fc4-010f-e26a-a344e63a9d49@linaro.org> (Adhemerval Zanella Netto's message of "Mon, 29 Aug 2022 16:56:45 -0300")

* 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.

> 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-/

Thanks,
Florian


  reply	other threads:[~2022-08-30  7:37 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 [this message]
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=87pmgi5gi6.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).