[compiler-rt] [NFC][sanitizer] Extract GetDTLSRange (PR #107934)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 16:06:35 PDT 2024


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

>From 48b0e0552f43739c2831b477d9fb756c686696b0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Mon, 9 Sep 2024 16:05:11 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 .../sanitizer_tls_get_addr.cpp                | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
index e2a66142e584e6..97f7b55b79802c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -110,6 +110,18 @@ SANITIZER_WEAK_ATTRIBUTE
 const void *__sanitizer_get_allocated_begin(const void *p);
 }
 
+static bool GetDTLSRange(uptr& tls_beg, uptr& tls_size) {
+  const void *start =
+                 __sanitizer_get_allocated_begin((void *)tls_beg);
+  if (!start)
+    return false;
+  tls_beg = (uptr)start;
+  tls_size = __sanitizer_get_allocated_size(start);
+  VReport(2, "__tls_get_addr: glibc >=2.25 suspected; tls={%p,0x%zx}\n",
+          (void *)tls_beg, tls_size);
+  return true;
+}
+
 DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
                                 uptr static_tls_begin, uptr static_tls_end) {
   if (!common_flags()->intercept_tls_get_addr) return 0;
@@ -135,13 +147,7 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
     // creation.
     VReport(2, "__tls_get_addr: static tls: %p\n", (void *)tls_beg);
     tls_size = 0;
-  } else if (const void *start =
-                 __sanitizer_get_allocated_begin((void *)tls_beg)) {
-    tls_beg = (uptr)start;
-    tls_size = __sanitizer_get_allocated_size(start);
-    VReport(2, "__tls_get_addr: glibc >=2.25 suspected; tls={%p,0x%zx}\n",
-            (void *)tls_beg, tls_size);
-  } else {
+  } else if (!GetDTlsRange(tls_beg, tls_size)) {
     VReport(2, "__tls_get_addr: Can't guess glibc version\n");
     // This may happen inside the DTOR of main thread, so just ignore it.
     tls_size = 0;

>From 53676c6606068c93d92dc7dae7b827007f224379 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Mon, 9 Sep 2024 16:06:27 -0700
Subject: [PATCH 2/2] format

Created using spr 1.3.4
---
 compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
index 97f7b55b79802c..adae99861153a1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -110,9 +110,8 @@ SANITIZER_WEAK_ATTRIBUTE
 const void *__sanitizer_get_allocated_begin(const void *p);
 }
 
-static bool GetDTLSRange(uptr& tls_beg, uptr& tls_size) {
-  const void *start =
-                 __sanitizer_get_allocated_begin((void *)tls_beg);
+static bool GetDTLSRange(uptr &tls_beg, uptr &tls_size) {
+  const void *start = __sanitizer_get_allocated_begin((void *)tls_beg);
   if (!start)
     return false;
   tls_beg = (uptr)start;



More information about the llvm-commits mailing list