[compiler-rt] [NFC][sanitizer] Early returns in `DTLS_on_tls_get_addr` (PR #109539)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 21 11:11:48 PDT 2024
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/109539
None
>From a34745154d92a3219165b838537368b150c91b7a Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Sat, 21 Sep 2024 11:11:33 -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_tls_get_addr.cpp | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 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 6f3b6af3c58474..6d5fad3e7b4a4b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -136,7 +136,6 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
if (!dtv || dtv->beg)
return nullptr;
CHECK_LE(static_tls_begin, static_tls_end);
- uptr tls_size = 0;
uptr tls_beg = reinterpret_cast<uptr>(res) - arg->offset - kDtvOffset;
VReport(2,
"__tls_get_addr: %p {0x%zx,0x%zx} => %p; tls_beg: %p; sp: %p "
@@ -148,16 +147,20 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
// This is the static TLS block which was initialized / unpoisoned at thread
// creation.
VReport(2, "__tls_get_addr: static tls: %p\n", (void *)tls_beg);
- tls_size = 0;
- } else {
- tls_size = __sanitizer_get_dtls_size(reinterpret_cast<void *>(tls_beg));
- if (!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.
- }
+ dtv->beg = tls_beg;
+ dtv->size = 0;
+ return nullptr;
+ }
+ if (uptr tls_size =
+ __sanitizer_get_dtls_size(reinterpret_cast<void *>(tls_beg))) {
+ dtv->beg = tls_beg;
+ dtv->size = tls_size;
+ return dtv;
}
+ VReport(2, "__tls_get_addr: Can't guess glibc version\n");
+ // This may happen inside the DTOR of main thread, so just ignore it.
dtv->beg = tls_beg;
- dtv->size = tls_size;
+ dtv->size = 0;
return dtv;
}
More information about the llvm-commits
mailing list