[libc-commits] [libc] [libc] Fix atexit_test in hermetic mode (PR #210656)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Jul 20 00:59:17 PDT 2026


https://github.com/labath created https://github.com/llvm/llvm-project/pull/210656

We never unlocked the ThreadAtExit mutex, which meant the second call to exit deadlocked. This was detected in the unit tests as they were calling __cxa_thread_atexit from the system C library.

>From 51fab842c0e70a222099ad830f7ac40365f5d28f Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Mon, 20 Jul 2026 07:55:56 +0000
Subject: [PATCH] [libc] Fix atexit_test in hermetic mode

We never unlocked the ThreadAtExit mutex, which meant the second call to
exit deadlocked. This was detected in the unit tests as they were
calling __cxa_thread_atexit from the system C library.
---
 libc/src/__support/threads/thread.cpp | 1 +
 libc/test/src/stdlib/CMakeLists.txt   | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/libc/src/__support/threads/thread.cpp b/libc/src/__support/threads/thread.cpp
index ae179f068b88e..babcfdc5aea15 100644
--- a/libc/src/__support/threads/thread.cpp
+++ b/libc/src/__support/threads/thread.cpp
@@ -131,6 +131,7 @@ class ThreadAtExitCallbackMgr {
       atexit_unit.callback(atexit_unit.obj);
       mtx.lock();
     }
+    mtx.unlock();
   }
 };
 
diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index 6a1b0069424d3..8e77d3fd08e11 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -531,8 +531,6 @@ if(LLVM_LIBC_FULL_BUILD)
 
   add_libc_test(
     atexit_test
-    # TODO: Fix this test in hermetic mode.
-    UNIT_TEST_ONLY
     SUITE
       libc-stdlib-tests
     SRCS



More information about the libc-commits mailing list