Bug 2034497

Summary: compiler-rt: Use _thread_db_sizeof_pthread in ThreadDescriptorSize
Product: Red Hat Enterprise Linux 9 Reporter: Florian Weimer <fweimer>
Component: compiler-rtAssignee: Tom Stellard <tstellar>
Status: CLOSED CURRENTRELEASE QA Contact: qe-baseos-tools-bugs
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: ahajkova, fweimer, jakub, mpolacek, mprchlik, ohudlick, qe-baseos-tools-bugs
Target Milestone: rcKeywords: Bugfix, Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2034494 Environment:
Last Closed: 2023-06-20 11:49:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Florian Weimer 2021-12-21 06:46:14 UTC
+++ This bug was initially created as a clone of Bug #2034494 +++

LLVM currently hard-codes the size of struct pthread in the sanitizers, in ThreadDescriptorSize in compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp.

Starting with glibc 2.34 and this commit

commit fef400a2f976d1fd6a4639e6980f6c50ee13fbf5
Author: Florian Weimer <fweimer>
Date:   Mon Jun 28 14:33:53 2021 +0200

    nptl: Export libthread_db-used symbols under GLIBC_PRIVATE
    
    This allows distributions to strip debugging information from
    libc.so.6 without impacting the debugging experience.
    
    Reviewed-by: Carlos O'Donell <carlos>

it is possible to determine sizeof (struct pthread) using dl(v)sym, like this:

  const unsigned int *psize = dlvsym(RTLD_DEFAULT, "_thread_db_sizeof_pthread",
                                     "GLIBC_PRIVATE");
  if (psize != nullptr) {
    val = *psize;
    atomic_store_relaxed(&thread_descriptor_size, val);
    return val;
  }

I'm not sure if upstream will take this change, but we should definitely make it downstream, to avoid mysterious sanitizer problems if we need to change struct pthread in glibc.

Comment 1 Florian Weimer 2022-02-04 17:23:09 UTC
Upstream patch review: https://reviews.llvm.org/D119007