[libc-commits] [libc] [libc] Fix return value of __cxa_thread_atexit_impl function. (PR #122171)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Wed Jan 8 13:23:09 PST 2025


https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/122171

This has been added in 0071a79532e8d664b734956a431d8c8c942cc25e to support TLS destructors. Return value of __cxa_thread_atexit is supposed to be the same as std::atexit - zero on success, non-zero on failure. Update the code to do just that (also be consistent with llvm-libc's existing atexit / at_quick_exit implementations).

>From c29b9ae901175447343529b8b8b64a3c2d416dd4 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <samsonov at google.com>
Date: Wed, 8 Jan 2025 13:20:13 -0800
Subject: [PATCH] [libc] Fix return value of __cxa_thread_atexit_impl function.

This has been added in 0071a79532e8d664b734956a431d8c8c942cc25e to
support TLS destructors. Return value of __cxa_thread_atexit is
supposed to be the same as std::atexit - zero on success, non-zero
on failure. Update the code to do just that (also be consistent
with llvm-libc's existing atexit / at_quick_exit implementations).
---
 libc/src/__support/threads/thread.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/threads/thread.cpp b/libc/src/__support/threads/thread.cpp
index dad4f75f092ede..6f6b75be5766d0 100644
--- a/libc/src/__support/threads/thread.cpp
+++ b/libc/src/__support/threads/thread.cpp
@@ -117,7 +117,9 @@ class ThreadAtExitCallbackMgr {
 
   int add_callback(AtExitCallback *callback, void *obj) {
     cpp::lock_guard lock(mtx);
-    return callback_list.push_back({callback, obj});
+    if (callback_list.push_back({callback, obj}))
+      return 0;
+    return -1;
   }
 
   void call() {



More information about the libc-commits mailing list