Index: include/cxxabi.h =================================================================== --- include/cxxabi.h +++ include/cxxabi.h @@ -178,6 +178,12 @@ // Apple addition to support std::uncaught_exception() extern bool __cxa_uncaught_exception() throw(); +#ifdef __linux__ +// Linux TLS support. Not yet an official part of the Itanium ABI. +// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables +extern int __cxa_thread_atexit(void (*)(void *), void *, void *) throw(); +#endif + } // extern "C" } // namespace __cxxabiv1 Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -19,6 +19,10 @@ typeinfo.cpp ) +if (UNIX AND NOT (APPLE OR CYGWIN)) + list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp) +endif() + set(LIBCXXABI_HEADERS ../include/cxxabi.h) # Add all the headers to the project for IDEs. Index: src/cxa_thread_atexit.cpp =================================================================== --- /dev/null +++ src/cxa_thread_atexit.cpp @@ -0,0 +1,24 @@ +//===----------------------- cxa_thread_atexit.cpp ------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "cxxabi.h" + +namespace __cxxabiv1 { + +extern "C" { + +int __cxa_thread_atexit(void (*dtor)(void *), void *obj, + void *dso_symbol) throw() { + extern int __cxa_thread_atexit_impl(void (*)(void *), void *, void *); + return __cxa_thread_atexit_impl(dtor, obj, dso_symbol); +} + +} // extern "C" + +} // namespace __cxxabiv1 Index: test/cxa_thread_atexit_test.cpp =================================================================== --- /dev/null +++ test/cxa_thread_atexit_test.cpp @@ -0,0 +1,33 @@ +//===--------------------- cxa_thread_atexit_test.cpp ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: linux2 + +#include +#include + +static bool AtexitImplCalled = false; + +extern "C" int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, + void *dso_symbol) { + assert(dtor == reinterpret_cast(1)); + assert(obj == reinterpret_cast(2)); + assert(dso_symbol == reinterpret_cast(3)); + AtexitImplCalled = true; + return 4; +} + +int main() { + int RV = __cxxabiv1::__cxa_thread_atexit( + reinterpret_cast(1), reinterpret_cast(2), + reinterpret_cast(3)); + assert(RV = 4); + assert(AtexitImplCalled); + return 0; +} Index: test/lit.cfg =================================================================== --- test/lit.cfg +++ test/lit.cfg @@ -283,6 +283,8 @@ else: lit_config.fatal("unrecognized system") +config.available_features.add(sys.platform) + config.test_format = LibcxxabiTestFormat( cxx_under_test, cpp_flags = ['-nostdinc++'] + compile_flags + include_paths,