[compiler-rt] [NFC][sanitizer] Remove DTLS_on_libc_memalign (PR #108120)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 17:38:05 PDT 2024
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/108120
>From f5d12ffdc27ad33368901d6f7dea06eaf704529f Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Sep 2024 17:24:19 -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
---
compiler-rt/lib/asan/asan_malloc_linux.cpp | 5 +----
compiler-rt/lib/dfsan/dfsan_interceptors.cpp | 5 +----
.../lib/hwasan/hwasan_allocation_functions.cpp | 6 +-----
compiler-rt/lib/lsan/lsan_interceptors.cpp | 5 +----
compiler-rt/lib/memprof/memprof_malloc_linux.cpp | 4 +---
compiler-rt/lib/msan/msan_interceptors.cpp | 6 +-----
.../sanitizer_common/sanitizer_tls_get_addr.cpp | 14 +-------------
.../lib/sanitizer_common/sanitizer_tls_get_addr.h | 4 ----
8 files changed, 7 insertions(+), 42 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cpp b/compiler-rt/lib/asan/asan_malloc_linux.cpp
index 08a63045c4e652..3d6b03fefab709 100644
--- a/compiler-rt/lib/asan/asan_malloc_linux.cpp
+++ b/compiler-rt/lib/asan/asan_malloc_linux.cpp
@@ -25,7 +25,6 @@
# include "sanitizer_common/sanitizer_allocator_checks.h"
# include "sanitizer_common/sanitizer_allocator_dlsym.h"
# include "sanitizer_common/sanitizer_errno.h"
-# include "sanitizer_common/sanitizer_tls_get_addr.h"
// ---------------------- Replacement functions ---------------- {{{1
using namespace __asan;
@@ -99,9 +98,7 @@ INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) {
GET_STACK_TRACE_MALLOC;
- void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC);
- DTLS_on_libc_memalign(res, size);
- return res;
+ return asan_memalign(boundary, size, &stack, FROM_MALLOC);
}
#endif // SANITIZER_INTERCEPT_MEMALIGN
diff --git a/compiler-rt/lib/dfsan/dfsan_interceptors.cpp b/compiler-rt/lib/dfsan/dfsan_interceptors.cpp
index 20e95c23c4bc92..198e6ee44f94ae 100644
--- a/compiler-rt/lib/dfsan/dfsan_interceptors.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_interceptors.cpp
@@ -39,10 +39,7 @@ INTERCEPTOR(void *, reallocarray, void *ptr, SIZE_T nmemb, SIZE_T size) {
}
INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
- void *ptr = dfsan_memalign(alignment, size);
- if (ptr)
- DTLS_on_libc_memalign(ptr, size);
- return ptr;
+ return dfsan_memalign(alignment, size);
}
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
diff --git a/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp b/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
index 9af09e2a4bedd4..25ca0a3b0b68e6 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
@@ -17,7 +17,6 @@
#include "sanitizer_common/sanitizer_allocator_dlsym.h"
#include "sanitizer_common/sanitizer_allocator_interface.h"
#include "sanitizer_common/sanitizer_mallinfo.h"
-#include "sanitizer_common/sanitizer_tls_get_addr.h"
using namespace __hwasan;
@@ -62,10 +61,7 @@ void *__sanitizer_aligned_alloc(uptr alignment, uptr size) {
SANITIZER_INTERFACE_ATTRIBUTE
void *__sanitizer___libc_memalign(uptr alignment, uptr size) {
GET_MALLOC_STACK_TRACE;
- void *ptr = hwasan_memalign(alignment, size, &stack);
- if (ptr)
- DTLS_on_libc_memalign(ptr, size);
- return ptr;
+ return hwasan_memalign(alignment, size, &stack);
}
SANITIZER_INTERFACE_ATTRIBUTE
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index b569c337e97641..adbd72801c4c93 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -26,7 +26,6 @@
#if SANITIZER_POSIX
#include "sanitizer_common/sanitizer_posix.h"
#endif
-#include "sanitizer_common/sanitizer_tls_get_addr.h"
#include "lsan.h"
#include "lsan_allocator.h"
#include "lsan_common.h"
@@ -133,9 +132,7 @@ INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE_MALLOC;
- void *res = lsan_memalign(alignment, size, stack);
- DTLS_on_libc_memalign(res, size);
- return res;
+ return lsan_memalign(alignment, size, stack);
}
#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
#else
diff --git a/compiler-rt/lib/memprof/memprof_malloc_linux.cpp b/compiler-rt/lib/memprof/memprof_malloc_linux.cpp
index aba6295a4a049c..2a028c7d0b4891 100644
--- a/compiler-rt/lib/memprof/memprof_malloc_linux.cpp
+++ b/compiler-rt/lib/memprof/memprof_malloc_linux.cpp
@@ -90,9 +90,7 @@ INTERCEPTOR(void *, memalign, uptr boundary, uptr size) {
INTERCEPTOR(void *, __libc_memalign, uptr boundary, uptr size) {
GET_STACK_TRACE_MALLOC;
- void *res = memprof_memalign(boundary, size, &stack, FROM_MALLOC);
- DTLS_on_libc_memalign(res, size);
- return res;
+ return memprof_memalign(boundary, size, &stack, FROM_MALLOC);
}
#endif // SANITIZER_INTERCEPT_MEMALIGN
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index c540523e0eaed9..f05c20618780b7 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -37,7 +37,6 @@
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
-#include "sanitizer_common/sanitizer_tls_get_addr.h"
#include "sanitizer_common/sanitizer_vector.h"
#if SANITIZER_NETBSD
@@ -185,10 +184,7 @@ INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
#if !SANITIZER_NETBSD
INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
GET_MALLOC_STACK_TRACE;
- void *ptr = msan_memalign(alignment, size, &stack);
- if (ptr)
- DTLS_on_libc_memalign(ptr, size);
- return ptr;
+ return msan_memalign(alignment, size, &stack);
}
#define MSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
#else
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 a1107ff7d24737..568f4caca9a7d1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -137,11 +137,7 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
(void *)arg, arg->dso_id, arg->offset, res, (void *)tls_beg,
(void *)&tls_beg,
atomic_load(&number_of_live_dtls, memory_order_relaxed));
- if (dtls.last_memalign_ptr == tls_beg) {
- tls_size = dtls.last_memalign_size;
- VReport(2, "__tls_get_addr: glibc <=2.24 suspected; tls={%p,0x%zx}\n",
- (void *)tls_beg, tls_size);
- } else if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
+ if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
// 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);
@@ -160,13 +156,6 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
return dtv;
}
-void DTLS_on_libc_memalign(void *ptr, uptr size) {
- if (!common_flags()->intercept_tls_get_addr) return;
- VReport(2, "DTLS_on_libc_memalign: %p 0x%zx\n", ptr, size);
- dtls.last_memalign_ptr = reinterpret_cast<uptr>(ptr);
- dtls.last_memalign_size = size;
-}
-
DTLS *DTLS_Get() { return &dtls; }
bool DTLSInDestruction(DTLS *dtls) {
@@ -175,7 +164,6 @@ bool DTLSInDestruction(DTLS *dtls) {
}
#else
-void DTLS_on_libc_memalign(void *ptr, uptr size) {}
DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res,
unsigned long, unsigned long) { return 0; }
DTLS *DTLS_Get() { return 0; }
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
index 0ddab61deb102f..2ef767296e17dc 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
@@ -55,10 +55,6 @@ struct DTLS {
static_assert(sizeof(DTVBlock) <= 4096UL, "Unexpected block size");
atomic_uintptr_t dtv_block;
-
- // Auxiliary fields, don't access them outside sanitizer_tls_get_addr.cpp
- uptr last_memalign_size;
- uptr last_memalign_ptr;
};
template <typename Fn>
>From 7db54986b666e1442e3e3850ab83c14946530cb7 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Sep 2024 17:37:51 -0700
Subject: [PATCH 2/2] fix trace message
Created using spr 1.3.4
---
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 568f4caca9a7d1..9a49b4999d9ac5 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -116,7 +116,7 @@ static bool GetDTLSRange(uptr &tls_beg, uptr &tls_size) {
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",
+ VReport(2, "__tls_get_addr: glibc DTLS suspected; tls={%p,0x%zx}\n",
(void *)tls_beg, tls_size);
return true;
}
More information about the llvm-commits
mailing list