[compiler-rt] [sanitizer] Extract SANITIZER_FREEBSD version of ThreadDescriptorSizeFallback (PR #109743)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 11:16:26 PDT 2024
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/109743
>From dbfb4b50652831ddd8ba402fdb08a3134043ad38 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Mon, 23 Sep 2024 19:09:54 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
.../sanitizer_linux_libcdep.cpp | 55 +++++++++++++++----
1 file changed, 43 insertions(+), 12 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index 4fc99197aae3d5..6b83bbb9a9e94e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -219,25 +219,14 @@ static void GetGLibcVersion(int *major, int *minor, int *patch) {
}
# endif // SANITIZER_GLIBC && !SANITIZER_GO
-// On glibc x86_64, ThreadDescriptorSize() needs to be precise due to the usage
-// of g_tls_size. On other targets, ThreadDescriptorSize() is only used by lsan
-// to get the pointer to thread-specific data keys in the thread control block.
-# if (SANITIZER_FREEBSD || SANITIZER_GLIBC) && !SANITIZER_GO
-// sizeof(struct pthread) from glibc.
-static uptr thread_descriptor_size;
-
-// FIXME: Implementation is very GLIBC specific, but it's used by FreeBSD.
+# if SANITIZER_GLIBC && !SANITIZER_GO
static uptr ThreadDescriptorSizeFallback() {
# if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \
SANITIZER_RISCV64
-# if SANITIZER_GLIBC
int major;
int minor;
int patch;
GetGLibcVersion(&major, &minor, &patch);
-# else // SANITIZER_GLIBC
- return 0;
-# endif // SANITIZER_GLIBC
# endif
# if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
@@ -304,6 +293,48 @@ static uptr ThreadDescriptorSizeFallback() {
return 1776; // from glibc.ppc64le 2.20-8.fc21
# endif
}
+# endif // SANITIZER_GLIBC && !SANITIZER_GO
+
+# if SANITIZER_FREEBSD && !SANITIZER_GO
+// FIXME: Implementation is very GLIBC specific, but it's used by FreeBSD.
+static uptr ThreadDescriptorSizeFallback() {
+# if defined(__s390__) || defined(__sparc__)
+ // The size of a prefix of TCB including pthread::{specific_1stblock,specific}
+ // suffices. Just return offsetof(struct pthread, specific_used), which hasn't
+ // changed since 2007-05. Technically this applies to i386/x86_64 as well but
+ // we call _dl_get_tls_static_info and need the precise size of struct
+ // pthread.
+ return FIRST_32_SECOND_64(524, 1552);
+# endif
+
+# if defined(__mips__)
+ // TODO(sagarthakur): add more values as per different glibc versions.
+ return FIRST_32_SECOND_64(1152, 1776);
+# endif
+
+# if SANITIZER_LOONGARCH64
+ return 1856; // from glibc 2.36
+# endif
+
+# if defined(__aarch64__)
+ // The sizeof (struct pthread) is the same from GLIBC 2.17 to 2.22.
+ return 1776;
+# endif
+
+# if defined(__powerpc64__)
+ return 1776; // from glibc.ppc64le 2.20-8.fc21
+# endif
+
+ return 0;
+}
+# endif // SANITIZER_FREEBSD && !SANITIZER_GO
+
+# if (SANITIZER_FREEBSD || SANITIZER_GLIBC) && !SANITIZER_GO
+// On glibc x86_64, ThreadDescriptorSize() needs to be precise due to the usage
+// of g_tls_size. On other targets, ThreadDescriptorSize() is only used by lsan
+// to get the pointer to thread-specific data keys in the thread control block.
+// sizeof(struct pthread) from glibc.
+static uptr thread_descriptor_size;
uptr ThreadDescriptorSize() { return thread_descriptor_size; }
More information about the llvm-commits
mailing list