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

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