Skip to content

[libc++abi] Revert gating of __cxa_thread_atexit on Linux||Fuchsia#186054

Open
whitequark wants to merge 1 commit intollvm:mainfrom
whitequark:wasi-__cxa_thread_atexit
Open

[libc++abi] Revert gating of __cxa_thread_atexit on Linux||Fuchsia#186054
whitequark wants to merge 1 commit intollvm:mainfrom
whitequark:wasi-__cxa_thread_atexit

Conversation

@whitequark
Copy link
Copy Markdown
Collaborator

This was done in the commit 3c100d5 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:

// repro.cc
struct c { ~c() {} };
thread_local c v;
int main() { (void)v; }
$ ./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)

@whitequark whitequark requested a review from a team as a code owner March 12, 2026 08:26
@llvmbot llvmbot added the libc++abi libc++abi C++ Runtime Library. Not libc++. label Mar 12, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Mar 12, 2026

@llvm/pr-subscribers-libcxxabi

Author: Catherine (whitequark)

Changes

This was done in the commit 3c100d5 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:

// repro.cc
struct c { ~c() {} };
thread_local c v;
int main() { (void)v; }
$ ./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)

Full diff: https://github.com/llvm/llvm-project/pull/186054.diff

1 Files Affected:

  • (modified) libcxxabi/src/cxa_thread_atexit.cpp (-2)
diff --git a/libcxxabi/src/cxa_thread_atexit.cpp b/libcxxabi/src/cxa_thread_atexit.cpp
index 402a52c741012..370e76344e89c 100644
--- a/libcxxabi/src/cxa_thread_atexit.cpp
+++ b/libcxxabi/src/cxa_thread_atexit.cpp
@@ -106,7 +106,6 @@ namespace {
 
 #endif // HAVE___CXA_THREAD_ATEXIT_IMPL
 
-#if defined(__linux__) || defined(__Fuchsia__)
 extern "C" {
 
   _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {
@@ -142,5 +141,4 @@ extern "C" {
 #endif // HAVE___CXA_THREAD_ATEXIT_IMPL
   }
 } // extern "C"
-#endif // defined(__linux__) || defined(__Fuchsia__)
 } // namespace __cxxabiv1

@whitequark
Copy link
Copy Markdown
Collaborator Author

cc @philnik777; could you explain a bit more about the rationale for that #ifdef? I removed it entirely because it seemed like a mistake to me, but in principle I don't see anything wrong with adding || defined(__wasi__) to the condition list.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 12, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@whitequark whitequark force-pushed the wasi-__cxa_thread_atexit branch from d263f09 to f71fdfc Compare March 12, 2026 08:29
alexcrichton added a commit to alexcrichton/wasi-sdk that referenced this pull request Mar 12, 2026
Pulls in llvm/llvm-project#186054 and adds a regression test which
previously failed.

Closes WebAssembly#610
alexcrichton added a commit to WebAssembly/wasi-sdk that referenced this pull request Mar 12, 2026
Pulls in llvm/llvm-project#186054 and adds a regression test which
previously failed.

Closes #610
@whitequark whitequark force-pushed the wasi-__cxa_thread_atexit branch 2 times, most recently from ad2a084 to 1924b87 Compare March 28, 2026 18:03
This was done in the commit 3c100d5 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)
```
@outtersg
Copy link
Copy Markdown

outtersg commented Apr 2, 2026

FWIW (just trying to build clang 22 on a FreeBSD 10.2, whose stock clang is a 3.4.1…), I'm not really fond of the addition of every OS to the #if, while the "no #if" policy worked well until now, except for the -Wmissing-prototypes.

Following up my comment on #116261, I successfully built a full 22.1.2 ecosystem (llvm, clang, libc++, libc++abi, openmp, clang-rt, lld, lldb, flang, flang-rt), both on FreeBSD 10.2 and 15.0 by removing the #if, for 2 passes (first "bootstrap" pass without lld, lldb, flang, flang-rt).
Of course I got the warning: no previous prototype for function '__cxa_thread_atexit' [-Wmissing-prototypes] that caused the CI failure you mentioned @ldionne; but this seems due to a 2014 commit which added a __cxa_thread_atexit implementation with diverging conditions:

  • UNIX in the CMakeLists.txt
  • __Linux__ only in cxxabi.h

Thus the warning (that the CI errors) on non-Linux Unix platforms.

So, with the example of my FreeBSD 10.2 and 15.0 sandboxes, wouldn't a cleaner solution be to
remove those limiting #ifs, and instead make cxxabi.h consistent with its CMakeLists by declaring and defining __cxa_thread_atexit on every non-Apple-or-Cygwin Unix platform?

@whitequark
Copy link
Copy Markdown
Collaborator Author

My position is that right now an architecture is broken. We should fix that first and then discuss a cleaner solution later.

@outtersg
Copy link
Copy Markdown

outtersg commented Apr 2, 2026

@whitequark wrote:

My position is that right now an architecture is broken. We should fix that first and then discuss a cleaner solution later.

I'm semi-agreeing with that:
on one hand, the initial culprit change dates back 12 years ago, and I'm militating to repair the build on another platform which is nearly as old;
on the other hand, won't we have other platforms that will emerge as broken, and require transforming the #if in a chaplet of opted-in platforms?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++abi libc++abi C++ Runtime Library. Not libc++.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants