[compiler-rt] 38752ff - [sanitizer] Adjust size for begin/start mismatch (#109079)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 16:10:20 PDT 2024


Author: Vitaly Buka
Date: 2024-09-18T16:10:16-07:00
New Revision: 38752ffd417103621232e6ba6ba70e970e0d6356

URL: https://github.com/llvm/llvm-project/commit/38752ffd417103621232e6ba6ba70e970e0d6356
DIFF: https://github.com/llvm/llvm-project/commit/38752ffd417103621232e6ba6ba70e970e0d6356.diff

LOG: [sanitizer] Adjust size for begin/start mismatch (#109079)

Follow up to 51d913af827567e6a0999609e7e624a422781870.

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp

Removed: 
    


################################################################################
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 0db8547268f4e2..6f3b6af3c58474 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -15,6 +15,7 @@
 #include "sanitizer_allocator_interface.h"
 #include "sanitizer_atomic.h"
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_internal_defs.h"
 #include "sanitizer_flags.h"
 #include "sanitizer_platform_interceptors.h"
 
@@ -116,10 +117,14 @@ SANITIZER_INTERFACE_WEAK_DEF(uptr, __sanitizer_get_dtls_size,
   const void *start = __sanitizer_get_allocated_begin(tls_begin);
   if (!start)
     return 0;
+  CHECK_LE(start, tls_begin);
   uptr tls_size = __sanitizer_get_allocated_size(start);
   VReport(2, "__tls_get_addr: glibc DTLS suspected; tls={%p,0x%zx}\n",
           tls_begin, tls_size);
-  return tls_size;
+  uptr offset =
+      (reinterpret_cast<uptr>(tls_begin) - reinterpret_cast<uptr>(start));
+  CHECK_LE(offset, tls_size);
+  return tls_size - offset;
 }
 
 DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,


        


More information about the llvm-commits mailing list