From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7B73E3858D20; Tue, 15 Feb 2022 10:21:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B73E3858D20 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7238] sanitizer: Use glibc _thread_db_sizeof_pthread symbol if present X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 6a0d6e7ca9b9e338e82572db79c26168684a7441 X-Git-Newrev: c4c0aa60891daeb4ea5a7c265bd681038f6d8271 Message-Id: <20220215102116.7B73E3858D20@sourceware.org> Date: Tue, 15 Feb 2022 10:21:16 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Feb 2022 10:21:16 -0000 https://gcc.gnu.org/g:c4c0aa60891daeb4ea5a7c265bd681038f6d8271 commit r12-7238-gc4c0aa60891daeb4ea5a7c265bd681038f6d8271 Author: Jakub Jelinek Date: Tue Feb 15 11:18:56 2022 +0100 sanitizer: Use glibc _thread_db_sizeof_pthread symbol if present I've cherry-picked following fix from llvm-project. Recent glibcs have _thread_db_sizeof_pthread symbol variable which contains the size of struct pthread, so that sanitizers don't need to guess that and risk that it will change again. 2022-02-15 Jakub Jelinek * sanitizer_common/sanitizer_linux_libcdep.cpp: Cherry-pick llvm-project revision ef14b78d9a144ba81ba02083fe21eb286a88732b. Diff: --- .../sanitizer_common/sanitizer_linux_libcdep.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp index fc5619e4b37..0c260b6b516 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -220,10 +220,8 @@ void InitTlsSize() { } // sizeof(struct pthread) from glibc. static atomic_uintptr_t thread_descriptor_size; -uptr ThreadDescriptorSize() { - uptr val = atomic_load_relaxed(&thread_descriptor_size); - if (val) - return val; +static uptr ThreadDescriptorSizeFallback() { + uptr val = 0; #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) int major; int minor; @@ -285,8 +283,21 @@ uptr ThreadDescriptorSize() { #elif defined(__powerpc64__) val = 1776; // from glibc.ppc64le 2.20-8.fc21 #endif + return val; +} + +uptr ThreadDescriptorSize() { + uptr val = atomic_load_relaxed(&thread_descriptor_size); if (val) - atomic_store_relaxed(&thread_descriptor_size, val); + return val; + // _thread_db_sizeof_pthread is a GLIBC_PRIVATE symbol that is exported in + // glibc 2.34 and later. + if (unsigned *psizeof = static_cast( + dlsym(RTLD_DEFAULT, "_thread_db_sizeof_pthread"))) + val = *psizeof; + if (!val) + val = ThreadDescriptorSizeFallback(); + atomic_store_relaxed(&thread_descriptor_size, val); return val; }