[libcxx-commits] [libcxxabi] [libc++abi] Revert gating of `__cxa_thread_atexit` on Linux||Fuchsia (PR #186054)

Guillaume Outters via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 20 08:42:55 PDT 2026


outtersg wrote:

@philnik777 wrote:

> This change was based on the fact that `cxxabi.h` guards this function behind `#if defined(__linux__) || defined(__Fuchsia__)`. If this is wrong, that header needs to be updated as well.

Thanks for your feedback. This assymetry introduced in 2014 was what puzzled me in [my previous comment](https://github.com/llvm/llvm-project/pull/186054#issuecomment-4176418850).
However, as `cxxabi.h` gets installed as a public header, I'm now wondering if there was a wish to:
* have it always _defined_ (well, on all non-Apple non-Cygwin `UNIX` platforms, as said in the `CMakeLists.txt`), for internal use by libc++abi.so
* but not _declared_ (to prevent accidental calls), except on `__Linux__` that maybe had an obscure requirement?

That's not a very satisfying explanation… IMO removing it entirely (as you did @whitequark in your initial commit), or at least **making the declaration in `cxxabi.h` consistent with the definition in `CMakeLists.txt`** would be the KISS solution, if only we could get a hint from the CI that it doesn't break some other platform.

Note that [`CMakeLists.txt` has now a more complex condition](https://github.com/llvm/llvm-project/blob/eff4d473c3fc4efd21136f818933b443de7817a6/libcxxabi/src/CMakeLists.txt#L39-L44):
```cmake
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()
```

… So perhaps the complete solution would be to:
* remove the condition entirely in `cxa_thread_at_exit.cpp` (if it's included by `CMakeLists.txt`, then it should be compiled)
* in `cxxabi.h`, replace the condition by something like `#ifdef _LIBCXXABI_CXA_THREAD_ATEXIT`
* … which the `CMakeLists.txt` would add to `__cxxabi_config.h` _at the same time it decides to include `cxa_thread_atexit.cpp`_ 

> However, it's not clear to me at all which platforms actually expect this function if it's not declared on platforms that use it (probably through compiler magic?).

So for now we know that it is necessary on:
* Linux
* Fuchsia
* WASM
* FreeBSD 10.2
* and that having it defined on FreeBSD 15.0 is not necessary, but doesn't hurt

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


More information about the libcxx-commits mailing list