[libcxx-commits] [libcxxabi] [libc++abi] Revert gating of `__cxa_thread_atexit` on Linux||Fuchsia (PR #186054)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 3 13:47:45 PDT 2026
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/186054
>From 46301f073b8cc85ad0d2f1dcdda923209bff173b Mon Sep 17 00:00:00 2001
From: Catherine <whitequark at whitequark.org>
Date: Thu, 12 Mar 2026 08:19:49 +0000
Subject: [PATCH 1/3] [libc++abi] Revert gating of `__cxa_thread_atexit` on
Wasm/WASI
This was done in the commit 3c100d5d548d with the description
"Enable -Wmissing-prototypes" which seems incongruent to me.
Since then it's made its way into a release and broke the use of
`thread_local` variables with destructors on Wasm/WASI:
```cc
// repro.cc
struct c { ~c() {} };
thread_local c v;
int main() { (void)v; }
```
```console
$ ./wasi-sdk-31.0-x86_64-linux/bin/clang++ repro.cc
wasm-ld: error: /tmp/repro-dd1ad7.o: undefined symbol: __cxa_thread_atexit
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
---
libcxxabi/src/cxa_thread_atexit.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libcxxabi/src/cxa_thread_atexit.cpp b/libcxxabi/src/cxa_thread_atexit.cpp
index 402a52c741012..099be242c6dc6 100644
--- a/libcxxabi/src/cxa_thread_atexit.cpp
+++ b/libcxxabi/src/cxa_thread_atexit.cpp
@@ -106,7 +106,7 @@ namespace {
#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
-#if defined(__linux__) || defined(__Fuchsia__)
+#if defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
extern "C" {
_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {
@@ -141,6 +141,7 @@ extern "C" {
}
#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
}
+
} // extern "C"
-#endif // defined(__linux__) || defined(__Fuchsia__)
+#endif // defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
} // namespace __cxxabiv1
>From c15c52ff34166b3ad5deb6633a897c2e6e5f2b0f Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 3 Aug 2026 16:40:57 -0400
Subject: [PATCH 2/3] Make header consistent with .cpp file
---
libcxxabi/include/cxxabi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 66301d308282d..c8a2c3b7b8935 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -179,7 +179,7 @@ __cxa_decrement_exception_refcount(void *primary_exception) _LIBCXXABI_NOEXCEPT;
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _LIBCXXABI_NOEXCEPT;
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _LIBCXXABI_NOEXCEPT;
-#if defined(__linux__) || defined(__Fuchsia__)
+#if defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
>From edecf53f872925bb01316509a016b7d0ea783a67 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 3 Aug 2026 16:47:31 -0400
Subject: [PATCH 3/3] Move logic to source file, not CMake
---
libcxxabi/src/CMakeLists.txt | 8 +-------
libcxxabi/src/cxa_thread_atexit.cpp | 17 ++++++++++-------
2 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index dd23e9bb5bf79..8f779d913e0a9 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -9,6 +9,7 @@ set(LIBCXXABI_SOURCES
cxa_handlers.cpp
cxa_vector.cpp
cxa_virtual.cpp
+ cxa_thread_atexit.cpp
# C++ STL files
stdlib_exception.cpp
stdlib_stdexcept.cpp
@@ -36,13 +37,6 @@ else()
)
endif()
-if (LIBCXXABI_ENABLE_THREADS AND (UNIX OR FUCHSIA) AND NOT (APPLE OR CYGWIN)
- AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "AIX"))
- list(APPEND LIBCXXABI_SOURCES
- cxa_thread_atexit.cpp
- )
-endif()
-
set(LIBCXXABI_HEADERS
../include/cxxabi.h
)
diff --git a/libcxxabi/src/cxa_thread_atexit.cpp b/libcxxabi/src/cxa_thread_atexit.cpp
index 099be242c6dc6..66c86426ba204 100644
--- a/libcxxabi/src/cxa_thread_atexit.cpp
+++ b/libcxxabi/src/cxa_thread_atexit.cpp
@@ -6,16 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#include "abort_message.h"
#include "cxxabi.h"
+
+#if !defined(_LIBCXXABI_HAS_NO_THREADS) && defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
+
#include <__thread/support.h>
-#ifndef _LIBCXXABI_HAS_NO_THREADS
+#include <stdlib.h>
+
+#include "abort_message.h"
+
#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
#pragma comment(lib, "pthread")
#endif
-#endif
-
-#include <stdlib.h>
namespace __cxxabiv1 {
@@ -106,7 +108,6 @@ namespace {
#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
-#if defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
extern "C" {
_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {
@@ -143,5 +144,7 @@ extern "C" {
}
} // extern "C"
-#endif // defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
+
} // namespace __cxxabiv1
+
+#endif // !defined(_LIBCXXABI_HAS_NO_THREADS) && defined(__linux__) || defined(__Fuchsia__) || defined(__wasm__)
More information about the libcxx-commits
mailing list