commit de7f32a67d127620a640ecc60ec2925fbaf61d6a
parent 48032775acf3e84f4a03a41faf81bb22a9521b5e
Author: cowmonk <cowmonk@based.pt>
Date: Sat, 10 Oct 2026 15:58:35 -0700
Fix libc++abi thread exit detection for musl
Use the libc++abi fallback for the hook missing in musl.
Check thread_local destruction in the C++ smoke test.
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/scripts/build.sh b/scripts/build.sh
@@ -193,6 +193,8 @@ atomic()
runtimes()
{
if ! done_stage runtimes; then
+ # musl lacks __cxa_thread_atexit_impl
+ # compile only probes cannot detect missing symbols
target_cmake -S "$LLVM_SOURCE/runtimes" -B "$BUILD_DIR/runtimes" \
-DCMAKE_INSTALL_PREFIX=/usr -DLLVM_ENABLE_RUNTIMES='libunwind;libcxxabi;libcxx' \
-DLIBCXX_HAS_MUSL_LIBC=ON -DLIBCXX_USE_COMPILER_RT=ON \
@@ -201,6 +203,7 @@ runtimes()
-DLIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY=OFF -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
-DLIBCXX_INCLUDE_TESTS=OFF -DLIBCXX_INCLUDE_BENCHMARKS=OFF \
-DLIBCXXABI_USE_COMPILER_RT=ON -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
+ -DLIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL=OFF \
-DLIBCXXABI_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_STATIC=ON \
-DLIBCXXABI_INCLUDE_TESTS=OFF -DLIBUNWIND_USE_COMPILER_RT=ON \
-DLIBUNWIND_ENABLE_SHARED=ON -DLIBUNWIND_ENABLE_STATIC=ON \
diff --git a/tests/hello.cpp b/tests/hello.cpp
@@ -5,15 +5,31 @@
#include <thread>
#include <vector>
+struct thread_state {
+ std::atomic<int> &destroyed;
+
+ ~thread_state()
+ {
+ destroyed.fetch_add(1);
+ }
+};
+
int
main()
{
std::vector<int> values(128, 2);
std::atomic<int> total{0};
+ std::atomic<int> destroyed{0};
std::atomic<unsigned __int128> wide{0};
- std::thread worker([&]() { total.store(std::accumulate(values.begin(), values.end(), 0)); });
+ std::thread worker([&]() {
+ thread_local thread_state state{destroyed};
+
+ total.store(std::accumulate(values.begin(), values.end(), 0));
+ });
worker.join();
+ if (destroyed.load() != 1)
+ return 1;
wide.store((unsigned __int128)1 << 100);
if (wide.load() != (unsigned __int128)1 << 100)
return 1;