Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC][sanitizer] Early returns in DTLS_on_tls_get_addr #109539

Conversation

vitalybuka
Copy link
Collaborator

No description provided.

Created using spr 1.3.4
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 21, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/109539.diff

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp (+12-9)
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;
 }
 

@vitalybuka vitalybuka merged commit b620fde into main Sep 21, 2024
10 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/nfcsanitizer-early-returns-in-dtls_on_tls_get_addr branch September 21, 2024 19:27
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Sep 26, 2024
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants