Blame SOURCES/gcc11-libsanitizer-pthread.patch

e7fd42
Backported from LLVM upstream:
e7fd42
e7fd42
commit ef14b78d9a144ba81ba02083fe21eb286a88732b
e7fd42
Author: Florian Weimer <fweimer@redhat.com>
e7fd42
Date:   Tue Feb 8 12:46:41 2022 -0800
e7fd42
e7fd42
    [sanitizer] Use _thread_db_sizeof_pthread to obtain struct pthread size
e7fd42
    
e7fd42
    This symbol has been exported (as an internal GLIBC_PRIVATE symbol) from libc.so.6 starting with glibc 2.34. glibc uses it internally for its libthread_db implementation to enable thread debugging on GDB, so it is unlikely to go away for now.
e7fd42
    
e7fd42
    Fixes #52989.
e7fd42
    
e7fd42
    Reviewed By: #sanitizers, MaskRay, vitalybuka
e7fd42
    
e7fd42
    Differential Revision: https://reviews.llvm.org/D119007
e7fd42
e7fd42
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
e7fd42
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
e7fd42
@@ -265,10 +265,8 @@ void InitTlsSize() { }
e7fd42
 // sizeof(struct pthread) from glibc.
e7fd42
 static atomic_uintptr_t thread_descriptor_size;
e7fd42
 
e7fd42
-uptr ThreadDescriptorSize() {
e7fd42
-  uptr val = atomic_load_relaxed(&thread_descriptor_size);
e7fd42
-  if (val)
e7fd42
-    return val;
e7fd42
+static uptr ThreadDescriptorSizeFallback() {
e7fd42
+  uptr val = 0;
e7fd42
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
e7fd42
   int major;
e7fd42
   int minor;
e7fd42
@@ -323,8 +321,21 @@ uptr ThreadDescriptorSize() {
e7fd42
 #elif defined(__s390__)
e7fd42
   val = FIRST_32_SECOND_64(1152, 1776); // valid for glibc 2.22
e7fd42
 #endif
e7fd42
+  return val;
e7fd42
+}
e7fd42
+
e7fd42
+uptr ThreadDescriptorSize() {
e7fd42
+  uptr val = atomic_load_relaxed(&thread_descriptor_size);
e7fd42
   if (val)
e7fd42
-    atomic_store_relaxed(&thread_descriptor_size, val);
e7fd42
+    return val;
e7fd42
+  // _thread_db_sizeof_pthread is a GLIBC_PRIVATE symbol that is exported in
e7fd42
+  // glibc 2.34 and later.
e7fd42
+  if (unsigned *psizeof = static_cast<unsigned *>(
e7fd42
+          dlsym(RTLD_DEFAULT, "_thread_db_sizeof_pthread")))
e7fd42
+    val = *psizeof;
e7fd42
+  if (!val)
e7fd42
+    val = ThreadDescriptorSizeFallback();
e7fd42
+  atomic_store_relaxed(&thread_descriptor_size, val);
e7fd42
   return val;
e7fd42
 }
e7fd42