public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
@ 2023-11-09  1:55 Alexandre Oliva
  2023-11-09  8:20 ` Jonathan Wakely
  2023-12-05 16:10 ` David Edelsohn
  0 siblings, 2 replies; 14+ messages in thread
From: Alexandre Oliva @ 2023-11-09  1:55 UTC (permalink / raw)
  To: gcc-patches, libstdc++


g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
a platform that lacks __cxa_thread_atexit_impl, even if the program is
built and run using that toolchain on a (later) platform that offers
__cxa_thread_atexit_impl.

This patch adds runtime testing for __cxa_thread_atexit_impl on
platforms that support weak symbols.

Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and
x86_64-, and with ac_cv_func___cxa_thread_atexit_impl=no, that, on a
distro that lacks __cxa_thread_atexit in libc, forces the newly-added
code to be exercised, and that enabled thread_local-order2.C to pass
where the runtime libc has __cxa_thread_atexit_impl.  Ok to install?


for  libstdc++-v3/ChangeLog

	* libsupc++/atexit_thread.cc [__GXX_WEAK__]: Add dynamic
	detection of __cxa_thread_atexit_impl.
---
 libstdc++-v3/libsupc++/atexit_thread.cc |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
index 9346d50f5dafe..cabd7c0a4a057 100644
--- a/libstdc++-v3/libsupc++/atexit_thread.cc
+++ b/libstdc++-v3/libsupc++/atexit_thread.cc
@@ -138,11 +138,24 @@ namespace {
   }
 }
 
+#if __GXX_WEAK__
+extern "C"
+int __attribute__ ((__weak__))
+__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
+			  void *arg, void *d);
+#endif
+
+// ??? We can't make it an ifunc, can we?
 extern "C" int
 __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
-				 void *obj, void */*dso_handle*/)
+				 void *obj, void *dso_handle)
   _GLIBCXX_NOTHROW
 {
+#if __GXX_WEAK__
+  if (__cxa_thread_atexit_impl)
+    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
+#endif
+
   // Do this initialization once.
   if (__gthread_active_p ())
     {

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-11-09  1:55 [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime Alexandre Oliva
@ 2023-11-09  8:20 ` Jonathan Wakely
  2023-12-01 20:40   ` Alexandre Oliva
  2023-12-05 16:10 ` David Edelsohn
  1 sibling, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2023-11-09  8:20 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, libstdc++, Jason Merrill

On Thu, 9 Nov 2023 at 01:56, Alexandre Oliva <oliva@adacore.com> wrote:
>
>
> g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
> a platform that lacks __cxa_thread_atexit_impl, even if the program is
> built and run using that toolchain on a (later) platform that offers
> __cxa_thread_atexit_impl.
>
> This patch adds runtime testing for __cxa_thread_atexit_impl on
> platforms that support weak symbols.
>
> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and
> x86_64-, and with ac_cv_func___cxa_thread_atexit_impl=no, that, on a
> distro that lacks __cxa_thread_atexit in libc, forces the newly-added
> code to be exercised, and that enabled thread_local-order2.C to pass
> where the runtime libc has __cxa_thread_atexit_impl.  Ok to install?

Seems fine to me. Any objections, Jason?


>
>
> for  libstdc++-v3/ChangeLog
>
>         * libsupc++/atexit_thread.cc [__GXX_WEAK__]: Add dynamic
>         detection of __cxa_thread_atexit_impl.
> ---
>  libstdc++-v3/libsupc++/atexit_thread.cc |   15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
> index 9346d50f5dafe..cabd7c0a4a057 100644
> --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> @@ -138,11 +138,24 @@ namespace {
>    }
>  }
>
> +#if __GXX_WEAK__
> +extern "C"
> +int __attribute__ ((__weak__))
> +__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
> +                         void *arg, void *d);
> +#endif
> +
> +// ??? We can't make it an ifunc, can we?
>  extern "C" int
>  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> -                                void *obj, void */*dso_handle*/)
> +                                void *obj, void *dso_handle)
>    _GLIBCXX_NOTHROW
>  {
> +#if __GXX_WEAK__
> +  if (__cxa_thread_atexit_impl)
> +    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> +#endif
> +
>    // Do this initialization once.
>    if (__gthread_active_p ())
>      {
>
> --
> Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
>    Free Software Activist                   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-11-09  8:20 ` Jonathan Wakely
@ 2023-12-01 20:40   ` Alexandre Oliva
  2023-12-01 20:41     ` Jason Merrill
  0 siblings, 1 reply; 14+ messages in thread
From: Alexandre Oliva @ 2023-12-01 20:40 UTC (permalink / raw)
  To: Jonathan Wakely, Jason Merrill; +Cc: gcc-patches, libstdc++

On Nov  9, 2023, Jonathan Wakely <jwakely@redhat.com> wrote:

> On Thu, 9 Nov 2023 at 01:56, Alexandre Oliva <oliva@adacore.com> wrote:

>> g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
>> a platform that lacks __cxa_thread_atexit_impl, even if the program is
>> built and run using that toolchain on a (later) platform that offers
>> __cxa_thread_atexit_impl.
>> 
>> This patch adds runtime testing for __cxa_thread_atexit_impl on
>> platforms that support weak symbols.
>> 
>> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and
>> x86_64-, and with ac_cv_func___cxa_thread_atexit_impl=no, that, on a
>> distro that lacks __cxa_thread_atexit in libc, forces the newly-added
>> code to be exercised, and that enabled thread_local-order2.C to pass
>> where the runtime libc has __cxa_thread_atexit_impl.  Ok to install?

> Seems fine to me. Any objections, Jason?

Jason, ping?
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635750.html

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-01 20:40   ` Alexandre Oliva
@ 2023-12-01 20:41     ` Jason Merrill
  0 siblings, 0 replies; 14+ messages in thread
From: Jason Merrill @ 2023-12-01 20:41 UTC (permalink / raw)
  To: Alexandre Oliva, Jonathan Wakely; +Cc: gcc-patches, libstdc++

On 12/1/23 15:40, Alexandre Oliva wrote:
> On Nov  9, 2023, Jonathan Wakely <jwakely@redhat.com> wrote:
> 
>> On Thu, 9 Nov 2023 at 01:56, Alexandre Oliva <oliva@adacore.com> wrote:
> 
>>> g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
>>> a platform that lacks __cxa_thread_atexit_impl, even if the program is
>>> built and run using that toolchain on a (later) platform that offers
>>> __cxa_thread_atexit_impl.
>>>
>>> This patch adds runtime testing for __cxa_thread_atexit_impl on
>>> platforms that support weak symbols.
>>>
>>> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and
>>> x86_64-, and with ac_cv_func___cxa_thread_atexit_impl=no, that, on a
>>> distro that lacks __cxa_thread_atexit in libc, forces the newly-added
>>> code to be exercised, and that enabled thread_local-order2.C to pass
>>> where the runtime libc has __cxa_thread_atexit_impl.  Ok to install?
> 
>> Seems fine to me. Any objections, Jason?
> 
> Jason, ping?
> https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635750.html

OK by me.

Jason


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
@ 2023-12-05 16:10 ` David Edelsohn
  2023-12-05 23:15   ` David Edelsohn
  2023-12-06  0:54   ` Alexandre Oliva
  0 siblings, 2 replies; 14+ messages in thread
From: David Edelsohn @ 2023-12-05 16:10 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 137 bytes --]

Alex,

This patch broke bootstrap on AIX.  The stage1 compiler is not able to
build a program and stage2 configure fails.

Thanks, David

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-05 16:10 ` David Edelsohn
@ 2023-12-05 23:15   ` David Edelsohn
  2023-12-05 23:19     ` Andrew Pinski
  2023-12-06  5:18     ` Alexandre Oliva
  2023-12-06  0:54   ` Alexandre Oliva
  1 sibling, 2 replies; 14+ messages in thread
From: David Edelsohn @ 2023-12-05 23:15 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

The error is:

ld: 0711-317 ERROR: Undefined symbol: __cxa_thread_atexit_impl


from the new, weak reference.


Also, earlier in atexit_thread.cc, there is another definition protected by


_GLIBCXX_HAVE___CXA_THREAD_ATEXIT_IMPL


not utilized by the new reference.


Thanks, David

On Tue, Dec 5, 2023 at 11:10 AM David Edelsohn <dje.gcc@gmail.com> wrote:

> Alex,
>
> This patch broke bootstrap on AIX.  The stage1 compiler is not able to
> build a program and stage2 configure fails.
>
> Thanks, David
>
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-05 23:15   ` David Edelsohn
@ 2023-12-05 23:19     ` Andrew Pinski
  2023-12-06  5:18     ` Alexandre Oliva
  1 sibling, 0 replies; 14+ messages in thread
From: Andrew Pinski @ 2023-12-05 23:19 UTC (permalink / raw)
  To: David Edelsohn; +Cc: Alexandre Oliva, GCC Patches

On Tue, Dec 5, 2023 at 3:15 PM David Edelsohn <dje.gcc@gmail.com> wrote:
>
> The error is:
>
> ld: 0711-317 ERROR: Undefined symbol: __cxa_thread_atexit_impl
>
>
> from the new, weak reference.

By the way this seems like the same issue on nvptx too. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112858 which has a
similar analysis as below too.

Thanks,
Andrew

>
>
> Also, earlier in atexit_thread.cc, there is another definition protected by
>
>
> _GLIBCXX_HAVE___CXA_THREAD_ATEXIT_IMPL
>
>
> not utilized by the new reference.
>
>
> Thanks, David
>
>
> On Tue, Dec 5, 2023 at 11:10 AM David Edelsohn <dje.gcc@gmail.com> wrote:
>>
>> Alex,
>>
>> This patch broke bootstrap on AIX.  The stage1 compiler is not able to build a program and stage2 configure fails.
>>
>> Thanks, David
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-05 16:10 ` David Edelsohn
  2023-12-05 23:15   ` David Edelsohn
@ 2023-12-06  0:54   ` Alexandre Oliva
  2023-12-06  5:28     ` Alexandre Oliva
  1 sibling, 1 reply; 14+ messages in thread
From: Alexandre Oliva @ 2023-12-06  0:54 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches

Hello, David,

On Dec  5, 2023, David Edelsohn <dje.gcc@gmail.com> wrote:

> This patch broke bootstrap on AIX.  The stage1 compiler is not able to
> build a program and stage2 configure fails.

Thanks for the report. sorry about the breakage.

If the patch makes any difference, this suggests that __GXX_WEAK__ is
defined on AIX, but that we can't rely on a weak undefined symbol for
this purpose.  Back to the drawing board...  I'm reverting this for now.

Maybe we should narrow it down to targets in which weak undefined
symbols are available with the expected semantics, and where the symbol
is known to have ever been defined in libc.  On it...

Or maybe a weak definition (or weak alias to a definition) in that file
would enable us to test whether the weak definition was preempted, and
use it if so.  Or even move the fallback definition into the weak
symbol.

Thanks again,

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-05 23:15   ` David Edelsohn
  2023-12-05 23:19     ` Andrew Pinski
@ 2023-12-06  5:18     ` Alexandre Oliva
  1 sibling, 0 replies; 14+ messages in thread
From: Alexandre Oliva @ 2023-12-06  5:18 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches

On Dec  5, 2023, David Edelsohn <dje.gcc@gmail.com> wrote:

> The error is:
> ld: 0711-317 ERROR: Undefined symbol: __cxa_thread_atexit_impl
> from the new, weak reference.

Thanks.

> Also, earlier in atexit_thread.cc, there is another definition protected by

> _GLIBCXX_HAVE___CXA_THREAD_ATEXIT_IMPL

> not utilized by the new reference.

*nod*, the one I recently added covers a different situation, in which
the _impl symbol is not found in libc at build time.

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-06  0:54   ` Alexandre Oliva
@ 2023-12-06  5:28     ` Alexandre Oliva
  2023-12-06 12:30       ` Thomas Schwinge
  0 siblings, 1 reply; 14+ messages in thread
From: Alexandre Oliva @ 2023-12-06  5:28 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches

On Dec  5, 2023, Alexandre Oliva <oliva@adacore.com> wrote:

> Maybe we should narrow it down to targets in which weak undefined
> symbols are available with the expected semantics, and where the symbol
> is known to have ever been defined in libc.  On it...

This patch reintroduces the weak symbol reference only on GNU systems,
where they're most likely to be useful.  If other systems could benefit,
we can always add them later.

> Or maybe a weak definition (or weak alias to a definition) in that file
> would enable us to test whether the weak definition was preempted

Uhh...  'cept libc wouldn't preempt from libstdc++; the opposite would
occur, but that doesn't help.


Regstrapped on x86_64-linux-gnu, also tested with
ac_cv_func___cxa_thread_atexit_impl=no.  Ok to (re)install?


libsupc++: try cxa_thread_atexit_impl at runtime

g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
a platform that lacks __cxa_thread_atexit_impl, even if the program is
built and run using that toolchain on a (later) platform that offers
__cxa_thread_atexit_impl.

This patch adds runtime testing for __cxa_thread_atexit_impl on select
platforms (GNU variants, for starters) that support weak symbols.


for  libstdc++-v3/ChangeLog

	* config/os/gnu-linux/os_defines.h
	(_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define.
	* libsupc++/atexit_thread.cc [__GXX_WEAK__ &&
	_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL]
	(__cxa_thread_atexit): Add dynamic detection of
	__cxa_thread_atexit_impl.
---
 libstdc++-v3/config/os/gnu-linux/os_defines.h |    5 +++++
 libstdc++-v3/libsupc++/atexit_thread.cc       |   23 ++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
index 87317031fcd71..a2e4baec069d5 100644
--- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
+++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
@@ -60,6 +60,11 @@
 # define _GLIBCXX_HAVE_FLOAT128_MATH 1
 #endif
 
+// Enable __cxa_thread_atexit to rely on a (presumably libc-provided)
+// __cxa_thread_atexit_impl, if it happens to be defined, even if
+// configure couldn't find it during the build.
+#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1
+
 #ifdef __linux__
 // The following libpthread properties only apply to Linux, not GNU/Hurd.
 
diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
index 9346d50f5dafe..aa4ed5312bfe3 100644
--- a/libstdc++-v3/libsupc++/atexit_thread.cc
+++ b/libstdc++-v3/libsupc++/atexit_thread.cc
@@ -138,11 +138,32 @@ namespace {
   }
 }
 
+#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
+extern "C"
+int __attribute__ ((__weak__))
+__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
+			  void *arg, void *d);
+#endif
+
+// ??? We can't make it an ifunc, can we?
 extern "C" int
 __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
-				 void *obj, void */*dso_handle*/)
+				 void *obj, void *dso_handle)
   _GLIBCXX_NOTHROW
 {
+#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
+  if (__cxa_thread_atexit_impl)
+    // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl,
+    // if it happens to be defined, even if configure couldn't find it
+    // during the build.  _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
+    // may be defined e.g. in os_defines.h on platforms where some
+    // versions of libc have a __cxa_thread_atexit_impl definition,
+    // but whose earlier versions didn't.  This enables programs build
+    // by toolchains compatible with earlier libc versions to still
+    // benefit from a libc-provided __cxa_thread_atexit_impl.
+    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
+#endif
+
   // Do this initialization once.
   if (__gthread_active_p ())
     {


-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-06  5:28     ` Alexandre Oliva
@ 2023-12-06 12:30       ` Thomas Schwinge
  2023-12-06 13:52         ` Jonathan Wakely
  0 siblings, 1 reply; 14+ messages in thread
From: Thomas Schwinge @ 2023-12-06 12:30 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, libstdc++, David Edelsohn

Hi Alexandre!

On 2023-12-06T02:28:42-0300, Alexandre Oliva <oliva@adacore.com> wrote:
> libsupc++: try cxa_thread_atexit_impl at runtime
>
> g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
> a platform that lacks __cxa_thread_atexit_impl, even if the program is
> built and run using that toolchain on a (later) platform that offers
> __cxa_thread_atexit_impl.
>
> This patch adds runtime testing for __cxa_thread_atexit_impl on select
> platforms (GNU variants, for starters) that support weak symbols.

Need something like:

    --- libstdc++-v3/libsupc++/atexit_thread.cc
    +++ libstdc++-v3/libsupc++/atexit_thread.cc
    @@ -164,2 +164,4 @@ __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
         return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
    +#else
    +  (void) dso_handle;
     #endif

... to avoid:

    [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc: In function ‘int __cxxabiv1::__cxa_thread_atexit(void (*)(void*), void*, void*)’:
    [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc:151:51: error: unused parameter ‘dso_handle’ [-Werror=unused-parameter]
      151 |                                  void *obj, void *dso_handle)
          |                                             ~~~~~~^~~~~~~~~~
    cc1plus: all warnings being treated as errors
    make[4]: *** [atexit_thread.lo] Error 1

With that, GCC/nvptx then is back to:

    UNSUPPORTED: g++.dg/tls/thread_local6.C  -std=c++98
    PASS: g++.dg/tls/thread_local6.C  -std=c++14 (test for excess errors)
    PASS: g++.dg/tls/thread_local6.C  -std=c++14 execution test
    PASS: g++.dg/tls/thread_local6.C  -std=c++17 (test for excess errors)
    PASS: g++.dg/tls/thread_local6.C  -std=c++17 execution test
    PASS: g++.dg/tls/thread_local6.C  -std=c++20 (test for excess errors)
    PASS: g++.dg/tls/thread_local6.C  -std=c++20 execution test


Grüße
 Thomas


> for  libstdc++-v3/ChangeLog
>
>       * config/os/gnu-linux/os_defines.h
>       (_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define.
>       * libsupc++/atexit_thread.cc [__GXX_WEAK__ &&
>       _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL]
>       (__cxa_thread_atexit): Add dynamic detection of
>       __cxa_thread_atexit_impl.
> ---
>  libstdc++-v3/config/os/gnu-linux/os_defines.h |    5 +++++
>  libstdc++-v3/libsupc++/atexit_thread.cc       |   23 ++++++++++++++++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> index 87317031fcd71..a2e4baec069d5 100644
> --- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
> +++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> @@ -60,6 +60,11 @@
>  # define _GLIBCXX_HAVE_FLOAT128_MATH 1
>  #endif
>
> +// Enable __cxa_thread_atexit to rely on a (presumably libc-provided)
> +// __cxa_thread_atexit_impl, if it happens to be defined, even if
> +// configure couldn't find it during the build.
> +#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1
> +
>  #ifdef __linux__
>  // The following libpthread properties only apply to Linux, not GNU/Hurd.
>
> diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
> index 9346d50f5dafe..aa4ed5312bfe3 100644
> --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> @@ -138,11 +138,32 @@ namespace {
>    }
>  }
>
> +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> +extern "C"
> +int __attribute__ ((__weak__))
> +__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
> +                       void *arg, void *d);
> +#endif
> +
> +// ??? We can't make it an ifunc, can we?
>  extern "C" int
>  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> -                              void *obj, void */*dso_handle*/)
> +                              void *obj, void *dso_handle)
>    _GLIBCXX_NOTHROW
>  {
> +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> +  if (__cxa_thread_atexit_impl)
> +    // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl,
> +    // if it happens to be defined, even if configure couldn't find it
> +    // during the build.  _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> +    // may be defined e.g. in os_defines.h on platforms where some
> +    // versions of libc have a __cxa_thread_atexit_impl definition,
> +    // but whose earlier versions didn't.  This enables programs build
> +    // by toolchains compatible with earlier libc versions to still
> +    // benefit from a libc-provided __cxa_thread_atexit_impl.
> +    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> +#endif
> +
>    // Do this initialization once.
>    if (__gthread_active_p ())
>      {
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-06 12:30       ` Thomas Schwinge
@ 2023-12-06 13:52         ` Jonathan Wakely
  2023-12-06 14:40           ` Jonathan Wakely
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2023-12-06 13:52 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Alexandre Oliva, gcc-patches, libstdc++, David Edelsohn

On Wed, 6 Dec 2023 at 12:30, Thomas Schwinge <thomas@codesourcery.com> wrote:
>
> Hi Alexandre!
>
> On 2023-12-06T02:28:42-0300, Alexandre Oliva <oliva@adacore.com> wrote:
> > libsupc++: try cxa_thread_atexit_impl at runtime
> >
> > g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
> > a platform that lacks __cxa_thread_atexit_impl, even if the program is
> > built and run using that toolchain on a (later) platform that offers
> > __cxa_thread_atexit_impl.
> >
> > This patch adds runtime testing for __cxa_thread_atexit_impl on select
> > platforms (GNU variants, for starters) that support weak symbols.
>
> Need something like:
>
>     --- libstdc++-v3/libsupc++/atexit_thread.cc
>     +++ libstdc++-v3/libsupc++/atexit_thread.cc
>     @@ -164,2 +164,4 @@ __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
>          return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
>     +#else
>     +  (void) dso_handle;
>      #endif

I would prefer:

--- a/libstdc++-v3/libsupc++/atexit_thread.cc
+++ b/libstdc++-v3/libsupc++/atexit_thread.cc
@@ -148,7 +148,7 @@ __cxa_thread_atexit_impl (void
(_GLIBCXX_CDTOR_CALLABI *func) (void *),
 // ??? We can't make it an ifunc, can we?
 extern "C" int
 __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
-                                void *obj, void *dso_handle)
+                                void *obj, [[maybe_unused]] void *dso_handle)
   _GLIBCXX_NOTHROW
 {
 #if __GXX_WEAK__





>
> ... to avoid:
>
>     [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc: In function ‘int __cxxabiv1::__cxa_thread_atexit(void (*)(void*), void*, void*)’:
>     [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc:151:51: error: unused parameter ‘dso_handle’ [-Werror=unused-parameter]
>       151 |                                  void *obj, void *dso_handle)
>           |                                             ~~~~~~^~~~~~~~~~
>     cc1plus: all warnings being treated as errors
>     make[4]: *** [atexit_thread.lo] Error 1
>
> With that, GCC/nvptx then is back to:
>
>     UNSUPPORTED: g++.dg/tls/thread_local6.C  -std=c++98
>     PASS: g++.dg/tls/thread_local6.C  -std=c++14 (test for excess errors)
>     PASS: g++.dg/tls/thread_local6.C  -std=c++14 execution test
>     PASS: g++.dg/tls/thread_local6.C  -std=c++17 (test for excess errors)
>     PASS: g++.dg/tls/thread_local6.C  -std=c++17 execution test
>     PASS: g++.dg/tls/thread_local6.C  -std=c++20 (test for excess errors)
>     PASS: g++.dg/tls/thread_local6.C  -std=c++20 execution test
>
>
> Grüße
>  Thomas
>
>
> > for  libstdc++-v3/ChangeLog
> >
> >       * config/os/gnu-linux/os_defines.h
> >       (_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define.
> >       * libsupc++/atexit_thread.cc [__GXX_WEAK__ &&
> >       _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL]
> >       (__cxa_thread_atexit): Add dynamic detection of
> >       __cxa_thread_atexit_impl.
> > ---
> >  libstdc++-v3/config/os/gnu-linux/os_defines.h |    5 +++++
> >  libstdc++-v3/libsupc++/atexit_thread.cc       |   23 ++++++++++++++++++++++-
> >  2 files changed, 27 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > index 87317031fcd71..a2e4baec069d5 100644
> > --- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > +++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > @@ -60,6 +60,11 @@
> >  # define _GLIBCXX_HAVE_FLOAT128_MATH 1
> >  #endif
> >
> > +// Enable __cxa_thread_atexit to rely on a (presumably libc-provided)
> > +// __cxa_thread_atexit_impl, if it happens to be defined, even if
> > +// configure couldn't find it during the build.
> > +#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1
> > +
> >  #ifdef __linux__
> >  // The following libpthread properties only apply to Linux, not GNU/Hurd.
> >
> > diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
> > index 9346d50f5dafe..aa4ed5312bfe3 100644
> > --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> > +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> > @@ -138,11 +138,32 @@ namespace {
> >    }
> >  }
> >
> > +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > +extern "C"
> > +int __attribute__ ((__weak__))
> > +__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
> > +                       void *arg, void *d);
> > +#endif
> > +
> > +// ??? We can't make it an ifunc, can we?
> >  extern "C" int
> >  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> > -                              void *obj, void */*dso_handle*/)
> > +                              void *obj, void *dso_handle)
> >    _GLIBCXX_NOTHROW
> >  {
> > +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > +  if (__cxa_thread_atexit_impl)
> > +    // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl,
> > +    // if it happens to be defined, even if configure couldn't find it
> > +    // during the build.  _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > +    // may be defined e.g. in os_defines.h on platforms where some
> > +    // versions of libc have a __cxa_thread_atexit_impl definition,
> > +    // but whose earlier versions didn't.  This enables programs build
> > +    // by toolchains compatible with earlier libc versions to still
> > +    // benefit from a libc-provided __cxa_thread_atexit_impl.
> > +    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> > +#endif
> > +
> >    // Do this initialization once.
> >    if (__gthread_active_p ())
> >      {
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-06 13:52         ` Jonathan Wakely
@ 2023-12-06 14:40           ` Jonathan Wakely
  2023-12-06 22:46             ` Alexandre Oliva
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2023-12-06 14:40 UTC (permalink / raw)
  To: Jonathan Wakely
  Cc: Thomas Schwinge, Alexandre Oliva, gcc-patches, libstdc++, David Edelsohn

On Wed, 6 Dec 2023 at 13:53, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Wed, 6 Dec 2023 at 12:30, Thomas Schwinge <thomas@codesourcery.com> wrote:
> >
> > Hi Alexandre!
> >
> > On 2023-12-06T02:28:42-0300, Alexandre Oliva <oliva@adacore.com> wrote:
> > > libsupc++: try cxa_thread_atexit_impl at runtime
> > >
> > > g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
> > > a platform that lacks __cxa_thread_atexit_impl, even if the program is
> > > built and run using that toolchain on a (later) platform that offers
> > > __cxa_thread_atexit_impl.
> > >
> > > This patch adds runtime testing for __cxa_thread_atexit_impl on select
> > > platforms (GNU variants, for starters) that support weak symbols.
> >
> > Need something like:
> >
> >     --- libstdc++-v3/libsupc++/atexit_thread.cc
> >     +++ libstdc++-v3/libsupc++/atexit_thread.cc
> >     @@ -164,2 +164,4 @@ __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> >          return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> >     +#else
> >     +  (void) dso_handle;
> >      #endif
>
> I would prefer:
>
> --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> @@ -148,7 +148,7 @@ __cxa_thread_atexit_impl (void
> (_GLIBCXX_CDTOR_CALLABI *func) (void *),
>  // ??? We can't make it an ifunc, can we?
>  extern "C" int
>  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> -                                void *obj, void *dso_handle)
> +                                void *obj, [[maybe_unused]] void *dso_handle)
>    _GLIBCXX_NOTHROW
>  {
>  #if __GXX_WEAK__


The patch is OK with that change.


>
>
>
>
> >
> > ... to avoid:
> >
> >     [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc: In function ‘int __cxxabiv1::__cxa_thread_atexit(void (*)(void*), void*, void*)’:
> >     [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc:151:51: error: unused parameter ‘dso_handle’ [-Werror=unused-parameter]
> >       151 |                                  void *obj, void *dso_handle)
> >           |                                             ~~~~~~^~~~~~~~~~
> >     cc1plus: all warnings being treated as errors
> >     make[4]: *** [atexit_thread.lo] Error 1
> >
> > With that, GCC/nvptx then is back to:
> >
> >     UNSUPPORTED: g++.dg/tls/thread_local6.C  -std=c++98
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++14 (test for excess errors)
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++14 execution test
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++17 (test for excess errors)
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++17 execution test
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++20 (test for excess errors)
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++20 execution test
> >
> >
> > Grüße
> >  Thomas
> >
> >
> > > for  libstdc++-v3/ChangeLog
> > >
> > >       * config/os/gnu-linux/os_defines.h
> > >       (_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define.
> > >       * libsupc++/atexit_thread.cc [__GXX_WEAK__ &&
> > >       _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL]
> > >       (__cxa_thread_atexit): Add dynamic detection of
> > >       __cxa_thread_atexit_impl.
> > > ---
> > >  libstdc++-v3/config/os/gnu-linux/os_defines.h |    5 +++++
> > >  libstdc++-v3/libsupc++/atexit_thread.cc       |   23 ++++++++++++++++++++++-
> > >  2 files changed, 27 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > > index 87317031fcd71..a2e4baec069d5 100644
> > > --- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > > +++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > > @@ -60,6 +60,11 @@
> > >  # define _GLIBCXX_HAVE_FLOAT128_MATH 1
> > >  #endif
> > >
> > > +// Enable __cxa_thread_atexit to rely on a (presumably libc-provided)
> > > +// __cxa_thread_atexit_impl, if it happens to be defined, even if
> > > +// configure couldn't find it during the build.
> > > +#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1
> > > +
> > >  #ifdef __linux__
> > >  // The following libpthread properties only apply to Linux, not GNU/Hurd.
> > >
> > > diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
> > > index 9346d50f5dafe..aa4ed5312bfe3 100644
> > > --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> > > +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> > > @@ -138,11 +138,32 @@ namespace {
> > >    }
> > >  }
> > >
> > > +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > > +extern "C"
> > > +int __attribute__ ((__weak__))
> > > +__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
> > > +                       void *arg, void *d);
> > > +#endif
> > > +
> > > +// ??? We can't make it an ifunc, can we?
> > >  extern "C" int
> > >  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> > > -                              void *obj, void */*dso_handle*/)
> > > +                              void *obj, void *dso_handle)
> > >    _GLIBCXX_NOTHROW
> > >  {
> > > +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > > +  if (__cxa_thread_atexit_impl)
> > > +    // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl,
> > > +    // if it happens to be defined, even if configure couldn't find it
> > > +    // during the build.  _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > > +    // may be defined e.g. in os_defines.h on platforms where some
> > > +    // versions of libc have a __cxa_thread_atexit_impl definition,
> > > +    // but whose earlier versions didn't.  This enables programs build
> > > +    // by toolchains compatible with earlier libc versions to still
> > > +    // benefit from a libc-provided __cxa_thread_atexit_impl.
> > > +    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> > > +#endif
> > > +
> > >    // Do this initialization once.
> > >    if (__gthread_active_p ())
> > >      {
> > -----------------
> > Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
> >
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
  2023-12-06 14:40           ` Jonathan Wakely
@ 2023-12-06 22:46             ` Alexandre Oliva
  0 siblings, 0 replies; 14+ messages in thread
From: Alexandre Oliva @ 2023-12-06 22:46 UTC (permalink / raw)
  To: Jonathan Wakely
  Cc: Jonathan Wakely, Thomas Schwinge, gcc-patches, libstdc++, David Edelsohn

On Dec  6, 2023, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:

>> -                                void *obj, void *dso_handle)
>> +                                void *obj, [[maybe_unused]] void *dso_handle)

> The patch is OK with that change.

Thanks, here's what I'm going to install.  Regstrapped on
x86_64-linux-gnu, with and without
ac_cv_func___cxa_thread_atexit_impl=no, on a machine that has
__cxa_thread_atexit_impl (but not __cxa_thread_atexit) in libc.


libsupc++: try cxa_thread_atexit_impl at runtime

g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
a platform that lacks __cxa_thread_atexit_impl, even if the program is
built and run using that toolchain on a (later) platform that offers
__cxa_thread_atexit_impl.

This patch adds runtime testing for __cxa_thread_atexit_impl on select
platforms (GNU variants, for starters) that support weak symbols.


for  libstdc++-v3/ChangeLog

	PR libstdc++/112858
	* config/os/gnu-linux/os_defines.h
	(_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define.
	* libsupc++/atexit_thread.cc [__GXX_WEAK__ &&
	_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL]
	(__cxa_thread_atexit): Add dynamic detection of
	__cxa_thread_atexit_impl.
---
 libstdc++-v3/config/os/gnu-linux/os_defines.h |    5 +++++
 libstdc++-v3/libsupc++/atexit_thread.cc       |   23 ++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
index 87317031fcd71..a2e4baec069d5 100644
--- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
+++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
@@ -60,6 +60,11 @@
 # define _GLIBCXX_HAVE_FLOAT128_MATH 1
 #endif
 
+// Enable __cxa_thread_atexit to rely on a (presumably libc-provided)
+// __cxa_thread_atexit_impl, if it happens to be defined, even if
+// configure couldn't find it during the build.
+#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1
+
 #ifdef __linux__
 // The following libpthread properties only apply to Linux, not GNU/Hurd.
 
diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
index 9346d50f5dafe..28423344a0f34 100644
--- a/libstdc++-v3/libsupc++/atexit_thread.cc
+++ b/libstdc++-v3/libsupc++/atexit_thread.cc
@@ -138,11 +138,32 @@ namespace {
   }
 }
 
+#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
+extern "C"
+int __attribute__ ((__weak__))
+__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
+			  void *arg, void *d);
+#endif
+
+// ??? We can't make it an ifunc, can we?
 extern "C" int
 __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
-				 void *obj, void */*dso_handle*/)
+				 void *obj, [[maybe_unused]] void *dso_handle)
   _GLIBCXX_NOTHROW
 {
+#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
+  if (__cxa_thread_atexit_impl)
+    // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl,
+    // if it happens to be defined, even if configure couldn't find it
+    // during the build.  _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
+    // may be defined e.g. in os_defines.h on platforms where some
+    // versions of libc have a __cxa_thread_atexit_impl definition,
+    // but whose earlier versions didn't.  This enables programs build
+    // by toolchains compatible with earlier libc versions to still
+    // benefit from a libc-provided __cxa_thread_atexit_impl.
+    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
+#endif
+
   // Do this initialization once.
   if (__gthread_active_p ())
     {

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-12-06 22:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09  1:55 [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime Alexandre Oliva
2023-11-09  8:20 ` Jonathan Wakely
2023-12-01 20:40   ` Alexandre Oliva
2023-12-01 20:41     ` Jason Merrill
2023-12-05 16:10 ` David Edelsohn
2023-12-05 23:15   ` David Edelsohn
2023-12-05 23:19     ` Andrew Pinski
2023-12-06  5:18     ` Alexandre Oliva
2023-12-06  0:54   ` Alexandre Oliva
2023-12-06  5:28     ` Alexandre Oliva
2023-12-06 12:30       ` Thomas Schwinge
2023-12-06 13:52         ` Jonathan Wakely
2023-12-06 14:40           ` Jonathan Wakely
2023-12-06 22:46             ` Alexandre Oliva

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