Skip to content

Commit 79d9ea2

Browse files
alternative approach
1 parent 3d6301f commit 79d9ea2

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

libc/src/__support/threads/thread.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ void call_atexit_callbacks(ThreadAttributes *attrib) {
166166
}
167167
}
168168

169+
void call_atexit_callbacks() { call_atexit_callbacks(self.attrib); }
170+
169171
} // namespace internal
170172

171173
cpp::optional<unsigned int> new_tss_key(TSSDtor *dtor) {

libc/src/stdlib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ add_entrypoint_object(
598598
CXX_STANDARD
599599
20 # For constinit
600600
DEPENDS
601-
libc.src.__support.threads.thread
602601
.exit_handler
603602
)
604603

libc/src/stdlib/atexit.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "hdr/types/atexithandler_t.h"
1111
#include "src/__support/common.h"
1212
#include "src/__support/macros/config.h"
13-
#include "src/__support/threads/thread.h"
1413
#include "src/stdlib/exit_handler.h"
1514

1615
namespace LIBC_NAMESPACE_DECL {
@@ -19,6 +18,10 @@ constinit ExitCallbackList atexit_callbacks;
1918
Mutex handler_list_mtx(false, false, false, false);
2019
[[gnu::weak]] extern void teardown_main_tls();
2120

21+
namespace internal {
22+
[[gnu::weak]] extern void call_atexit_callbacks();
23+
}
24+
2225
extern "C" {
2326

2427
int __cxa_atexit(AtExitCallback *callback, void *payload, void *) {
@@ -27,7 +30,10 @@ int __cxa_atexit(AtExitCallback *callback, void *payload, void *) {
2730

2831
void __cxa_finalize(void *dso) {
2932
if (!dso) {
30-
internal::call_atexit_callbacks(self.attrib);
33+
// cxa callback also need to handle local static destructors.
34+
// see
35+
// https://refspecs.linuxbase.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/baselib---cxa-finalize.html
36+
internal::call_atexit_callbacks();
3137
call_exit_callbacks(atexit_callbacks);
3238
if (teardown_main_tls)
3339
teardown_main_tls();

libc/test/src/__support/threads/linux/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
add_libc_test(
22
raw_mutex_test
3-
HERMETIC_TEST_ONLY
43
SUITE
54
libc-support-threads-tests
65
SRCS

0 commit comments

Comments
 (0)