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: Mon, 29 Aug 2022 21:21:24 +0200 [thread overview]
Message-ID: <87sfle26vf.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <fce79f68-cbbd-b353-8c61-de512f0d5a54@linaro.org> (Adhemerval Zanella Netto's message of "Mon, 29 Aug 2022 15:59:00 -0300")
* 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.
> 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.
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.
Thanks,
Florian
next prev parent reply other threads:[~2022-08-29 19:21 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 [this message]
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
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=87sfle26vf.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).