Skip to content

Commit dc2f888

Browse files
committed
Avoid usage of __cxa_thread_atexit_impl from glibc
We already have this trick inside our glibc-compatibility library. Now it is moved directly to libc++abi. Cross-ported from: ClickHouse/libcxxabi#1
1 parent 28debae commit dc2f888

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

libcxxabi/src/cxa_thread_atexit.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
/** This file was edited for ClickHouse.
10+
* This is needed to avoid linking with "__cxa_thread_atexit_impl" function, that require too new (2.18) glibc library.
11+
*
12+
* Note: "__cxa_thread_atexit_impl" may provide sophisticated implementation to correct destruction of thread-local objects,
13+
* that was created in different DSO. Read https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
14+
* We simply don't need this implementation, because we don't use thread-local objects from different DSO.
15+
*/
16+
917
#include "abort_message.h"
1018
#include "cxxabi.h"
1119
#include <__threading_support>
@@ -21,15 +29,6 @@ namespace __cxxabiv1 {
2129

2230
using Dtor = void(*)(void*);
2331

24-
extern "C"
25-
#ifndef HAVE___CXA_THREAD_ATEXIT_IMPL
26-
// A weak symbol is used to detect this function's presence in the C library
27-
// at runtime, even if libc++ is built against an older libc
28-
_LIBCXXABI_WEAK
29-
#endif
30-
int __cxa_thread_atexit_impl(Dtor, void*, void*);
31-
32-
#ifndef HAVE___CXA_THREAD_ATEXIT_IMPL
3332

3433
namespace {
3534
// This implementation is used if the C library does not provide
@@ -104,17 +103,10 @@ namespace {
104103
};
105104
} // namespace
106105

107-
#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
108106

109107
extern "C" {
110108

111-
_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {
112-
#ifdef HAVE___CXA_THREAD_ATEXIT_IMPL
113-
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
114-
#else
115-
if (__cxa_thread_atexit_impl) {
116-
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
117-
} else {
109+
_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit_impl(Dtor dtor, void* obj, void* dso_symbol) throw() {
118110
// Initialize the dtors std::__libcpp_tls_key (uses __cxa_guard_*() for
119111
// one-time initialization and __cxa_atexit() for destruction)
120112
static DtorsManager manager;
@@ -137,8 +129,11 @@ extern "C" {
137129
dtors = head;
138130

139131
return 0;
140-
}
141-
#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
132+
}
133+
134+
int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw()
135+
{
136+
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
142137
}
143138

144139
} // extern "C"

0 commit comments

Comments
 (0)