From 9387ace326d73f4bc78b6334f32008b41439b169 Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Sun, 7 Jan 2024 13:17:34 +0000 Subject: [PATCH] third_party/libcxxabi: Enable __cxa_thread_atexit Enable `__cxa_thread_atexit` from libcxxabi. `__cxa_thread_atexit_impl` is still implemented by the cosmo libc. The original `__cxa_thread_atexit` has been removed. --- libc/thread/__cxa_thread_atexit.c | 23 ----------------------- test/libc/thread/BUILD.mk | 1 + third_party/libcxxabi/BUILD.mk | 1 + third_party/libcxxabi/README.cosmo | 1 + third_party/libcxxabi/include/cxxabi.h | 2 +- 5 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 libc/thread/__cxa_thread_atexit.c diff --git a/libc/thread/__cxa_thread_atexit.c b/libc/thread/__cxa_thread_atexit.c deleted file mode 100644 index 2cb38f71e..000000000 --- a/libc/thread/__cxa_thread_atexit.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/cxaatexit.internal.h" - -int __cxa_thread_atexit(void *fun, void *arg, void *dso_symbol) { - return __cxa_thread_atexit_impl(fun, arg, dso_symbol); -} diff --git a/test/libc/thread/BUILD.mk b/test/libc/thread/BUILD.mk index d40095c18..5cadbff27 100644 --- a/test/libc/thread/BUILD.mk +++ b/test/libc/thread/BUILD.mk @@ -41,6 +41,7 @@ TEST_LIBC_THREAD_DIRECTDEPS = \ LIBC_THREAD \ LIBC_TIME \ LIBC_X \ + THIRD_PARTY_LIBCXXABI \ THIRD_PARTY_NSYNC \ THIRD_PARTY_NSYNC_MEM diff --git a/third_party/libcxxabi/BUILD.mk b/third_party/libcxxabi/BUILD.mk index 8eec30c7c..256ce3c45 100644 --- a/third_party/libcxxabi/BUILD.mk +++ b/third_party/libcxxabi/BUILD.mk @@ -90,6 +90,7 @@ $(THIRD_PARTY_LIBCXXABI_A_OBJS): private \ -frtti \ -D_LIBCXXABI_BUILDING_LIBRARY \ -D_LIBCPP_BUILDING_LIBRARY \ + -DHAVE___CXA_THREAD_ATEXIT_IMPL \ -D_LIBCPP_CONSTINIT=__constinit \ -Dconstinit=__constinit diff --git a/third_party/libcxxabi/README.cosmo b/third_party/libcxxabi/README.cosmo index 6167e2b8b..41e62149b 100644 --- a/third_party/libcxxabi/README.cosmo +++ b/third_party/libcxxabi/README.cosmo @@ -15,3 +15,4 @@ LOCAL CHANGES - Add <__memory/aligned_alloc.h> (contains a few inline functions) from upstream libcxx. + - Enable __cxa_thread_atexit for Cosmopolitan. diff --git a/third_party/libcxxabi/include/cxxabi.h b/third_party/libcxxabi/include/cxxabi.h index 51d534eed..d1d6912e3 100644 --- a/third_party/libcxxabi/include/cxxabi.h +++ b/third_party/libcxxabi/include/cxxabi.h @@ -160,7 +160,7 @@ __cxa_decrement_exception_refcount(void *primary_exception) throw(); extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw(); extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw(); -#if defined(__linux__) || defined(__Fuchsia__) +#if defined(__linux__) || defined(__Fuchsia__) || defined(__COSMOPOLITAN__) // Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI. // https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,