@@ -224,7 +224,7 @@ static void GetGLibcVersion(int *major, int *minor, int *patch) {
224
224
// to get the pointer to thread-specific data keys in the thread control block.
225
225
# if (SANITIZER_FREEBSD || SANITIZER_GLIBC) && !SANITIZER_GO
226
226
// sizeof(struct pthread) from glibc.
227
- static atomic_uintptr_t thread_descriptor_size;
227
+ static uptr thread_descriptor_size;
228
228
229
229
// FIXME: Implementation is very GLIBC specific, but it's used by FREEBSD.
230
230
static uptr ThreadDescriptorSizeFallback () {
@@ -305,20 +305,7 @@ static uptr ThreadDescriptorSizeFallback() {
305
305
# endif
306
306
}
307
307
308
- uptr ThreadDescriptorSize () {
309
- uptr val = atomic_load_relaxed (&thread_descriptor_size);
310
- if (val)
311
- return val;
312
- // _thread_db_sizeof_pthread is a GLIBC_PRIVATE symbol that is exported in
313
- // glibc 2.34 and later.
314
- if (unsigned *psizeof = static_cast <unsigned *>(
315
- dlsym (RTLD_DEFAULT, " _thread_db_sizeof_pthread" )))
316
- val = *psizeof;
317
- if (!val)
318
- val = ThreadDescriptorSizeFallback ();
319
- atomic_store_relaxed (&thread_descriptor_size, val);
320
- return val;
321
- }
308
+ uptr ThreadDescriptorSize () { return thread_descriptor_size; }
322
309
323
310
# if SANITIZER_GLIBC
324
311
__attribute__ ((unused)) static size_t g_tls_size;
@@ -330,6 +317,15 @@ void InitTlsSize() {
330
317
GetGLibcVersion (&major, &minor, &patch);
331
318
g_use_dlpi_tls_data = major == 2 && minor >= 25 ;
332
319
320
+ if (major == 2 && minor >= 34 ) {
321
+ // _thread_db_sizeof_pthread is a GLIBC_PRIVATE symbol that is exported in
322
+ // glibc 2.34 and later.
323
+ if (unsigned *psizeof = static_cast <unsigned *>(
324
+ dlsym (RTLD_DEFAULT, " _thread_db_sizeof_pthread" ))) {
325
+ thread_descriptor_size = *psizeof;
326
+ }
327
+ }
328
+
333
329
# if defined(__aarch64__) || defined(__x86_64__) || \
334
330
defined (__powerpc64__) || defined (__loongarch__)
335
331
auto *get_tls_static_info = (void (*)(size_t *, size_t *))dlsym (
@@ -339,7 +335,11 @@ void InitTlsSize() {
339
335
if (get_tls_static_info)
340
336
get_tls_static_info (&g_tls_size, &tls_align);
341
337
# endif
338
+
342
339
# endif // SANITIZER_GLIBC
340
+
341
+ if (!thread_descriptor_size)
342
+ thread_descriptor_size = ThreadDescriptorSizeFallback ();
343
343
}
344
344
345
345
# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64 || \
0 commit comments