[compiler-rt] [sanitizer][Darwin] Define TlsSize on arm64 (PR #133989)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 23 21:17:24 PDT 2025


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/133989

>From c643503f2bfbcc34275e8d68fa2042c7eacea213 Mon Sep 17 00:00:00 2001
From: Leonard Grey <lgrey at chromium.org>
Date: Tue, 1 Apr 2025 17:07:33 -0400
Subject: [PATCH 1/2] [sanitizer][Darwin] Define TlsSize on arm64

---
 compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 0b8a75391136d..8df089e8e07a0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -558,15 +558,13 @@ uptr TlsBaseAddr() {
   return segbase;
 }
 
-// The size of the tls on darwin does not appear to be well documented,
-// however the vm memory map suggests that it is 1024 uptrs in size,
-// with a size of 0x2000 bytes on x86_64 and 0x1000 bytes on i386.
+// The size of the tls on darwin does not appear to be well documented.
+// but `pthread_s`'s `tsd` member (see libpthread/src/types_internal.h) is
+// defined as `_INTERNAL_POSIX_THREAD_KEYS_MAX +
+// `_INTERNAL_POSIX_THREAD_KEYS_END` (512 pointers on iPhone and 768 elsewhere).
+// Keep at 1024 for backwards compatibility.
 uptr TlsSize() {
-#if defined(__x86_64__) || defined(__i386__)
   return 1024 * sizeof(uptr);
-#else
-  return 0;
-#endif
 }
 
 void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,

>From 081ce760c09dd7e35ecb805c328d72186952cde9 Mon Sep 17 00:00:00 2001
From: Leonard Grey <lgrey at chromium.org>
Date: Tue, 1 Apr 2025 17:34:07 -0400
Subject: [PATCH 2/2] Format

---
 compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 8df089e8e07a0..70d8cddc6e573 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -563,9 +563,7 @@ uptr TlsBaseAddr() {
 // defined as `_INTERNAL_POSIX_THREAD_KEYS_MAX +
 // `_INTERNAL_POSIX_THREAD_KEYS_END` (512 pointers on iPhone and 768 elsewhere).
 // Keep at 1024 for backwards compatibility.
-uptr TlsSize() {
-  return 1024 * sizeof(uptr);
-}
+uptr TlsSize() { return 1024 * sizeof(uptr); }
 
 void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
                           uptr *tls_begin, uptr *tls_end) {



More information about the llvm-commits mailing list