[compiler-rt] b84673b - [NFC][sanitizer] Remove unnececary HOOK macros
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 12 19:47:55 PDT 2022
Author: Vitaly Buka
Date: 2022-04-12T19:47:44-07:00
New Revision: b84673b3f424882c4c1961fb2c49b6302b68f344
URL: https://github.com/llvm/llvm-project/commit/b84673b3f424882c4c1961fb2c49b6302b68f344
DIFF: https://github.com/llvm/llvm-project/commit/b84673b3f424882c4c1961fb2c49b6302b68f344.diff
LOG: [NFC][sanitizer] Remove unnececary HOOK macros
Added:
Modified:
compiler-rt/lib/asan/asan_allocator.cpp
compiler-rt/lib/asan/asan_internal.h
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_allocator.cpp
compiler-rt/lib/memprof/memprof_allocator.cpp
compiler-rt/lib/memprof/memprof_internal.h
compiler-rt/lib/msan/msan.h
compiler-rt/lib/msan/msan_allocator.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index f9f1cfcd9f87d..e6a22585eeb41 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -597,7 +597,9 @@ struct Allocator {
CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg);
reinterpret_cast<LargeChunkHeader *>(alloc_beg)->Set(m);
}
- ASAN_MALLOC_HOOK(res, size);
+ if (&__sanitizer_malloc_hook)
+ __sanitizer_malloc_hook(res, size);
+ RunMallocHooks(res, size);
return res;
}
@@ -678,7 +680,9 @@ struct Allocator {
return;
}
- ASAN_FREE_HOOK(ptr);
+ if (&__sanitizer_free_hook)
+ __sanitizer_free_hook(ptr);
+ RunFreeHooks(ptr);
// Must mark the chunk as quarantined before any changes to its metadata.
// Do not quarantine given chunk if we failed to set CHUNK_QUARANTINE flag.
diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h
index 27f8949ffdb05..7468f126d37b1 100644
--- a/compiler-rt/lib/asan/asan_internal.h
+++ b/compiler-rt/lib/asan/asan_internal.h
@@ -125,22 +125,6 @@ bool HandleDlopenInit();
void InstallAtExitCheckLeaks();
-// Add convenient macro for interface functions that may be represented as
-// weak hooks.
-#define ASAN_MALLOC_HOOK(ptr, size) \
- do { \
- if (&__sanitizer_malloc_hook) \
- __sanitizer_malloc_hook(ptr, size); \
- RunMallocHooks(ptr, size); \
- } while (false)
-
-#define ASAN_FREE_HOOK(ptr) \
- do { \
- if (&__sanitizer_free_hook) \
- __sanitizer_free_hook(ptr); \
- RunFreeHooks(ptr); \
- } while (false)
-
#define ASAN_ON_ERROR() \
if (&__asan_on_error) \
__asan_on_error()
diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h
index 6c5c0b6986c79..3cc2fc40b5f68 100644
--- a/compiler-rt/lib/hwasan/hwasan.h
+++ b/compiler-rt/lib/hwasan/hwasan.h
@@ -172,22 +172,6 @@ void HwasanTagMismatch(uptr addr, uptr access_info, uptr *registers_frame,
} // namespace __hwasan
-#define HWASAN_MALLOC_HOOK(ptr, size) \
- do { \
- if (&__sanitizer_malloc_hook) { \
- __sanitizer_malloc_hook(ptr, size); \
- } \
- RunMallocHooks(ptr, size); \
- } while (false)
-
-#define HWASAN_FREE_HOOK(ptr) \
- do { \
- if (&__sanitizer_free_hook) { \
- __sanitizer_free_hook(ptr); \
- } \
- RunFreeHooks(ptr); \
- } while (false)
-
#if HWASAN_WITH_INTERCEPTORS
// For both bionic and glibc __sigset_t is an unsigned long.
typedef unsigned long __hw_sigset_t;
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index 84e183f2384f2..787ac7da66f0b 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -199,7 +199,9 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
}
}
- HWASAN_MALLOC_HOOK(user_ptr, size);
+ if (&__sanitizer_malloc_hook)
+ __sanitizer_malloc_hook(user_ptr, size);
+ RunMallocHooks(user_ptr, size);
return user_ptr;
}
@@ -226,7 +228,9 @@ static bool CheckInvalidFree(StackTrace *stack, void *untagged_ptr,
static void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) {
CHECK(tagged_ptr);
- HWASAN_FREE_HOOK(tagged_ptr);
+ if (&__sanitizer_free_hook)
+ __sanitizer_free_hook(tagged_ptr);
+ RunFreeHooks(tagged_ptr);
bool in_taggable_region =
InTaggableRegion(reinterpret_cast<uptr>(tagged_ptr));
diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp
index 1475e2cf36bd2..d41640eeeca4b 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.cpp
+++ b/compiler-rt/lib/memprof/memprof_allocator.cpp
@@ -430,7 +430,9 @@ struct Allocator {
CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg);
reinterpret_cast<LargeChunkHeader *>(alloc_beg)->Set(m);
}
- MEMPROF_MALLOC_HOOK(res, size);
+ if (&__sanitizer_malloc_hook)
+ __sanitizer_malloc_hook(res, size);
+ RunMallocHooks(res, size);
return res;
}
@@ -440,7 +442,9 @@ struct Allocator {
if (p == 0)
return;
- MEMPROF_FREE_HOOK(ptr);
+ if (&__sanitizer_free_hook)
+ __sanitizer_free_hook(ptr);
+ RunFreeHooks(ptr);
uptr chunk_beg = p - kChunkHeaderSize;
MemprofChunk *m = reinterpret_cast<MemprofChunk *>(chunk_beg);
diff --git a/compiler-rt/lib/memprof/memprof_internal.h b/compiler-rt/lib/memprof/memprof_internal.h
index 0ebf9e0bbeee2..1adb368e3e41d 100644
--- a/compiler-rt/lib/memprof/memprof_internal.h
+++ b/compiler-rt/lib/memprof/memprof_internal.h
@@ -76,22 +76,6 @@ void PlatformTSDDtor(void *tsd);
void *MemprofDlSymNext(const char *sym);
-// Add convenient macro for interface functions that may be represented as
-// weak hooks.
-#define MEMPROF_MALLOC_HOOK(ptr, size) \
- do { \
- if (&__sanitizer_malloc_hook) \
- __sanitizer_malloc_hook(ptr, size); \
- RunMallocHooks(ptr, size); \
- } while (false)
-
-#define MEMPROF_FREE_HOOK(ptr) \
- do { \
- if (&__sanitizer_free_hook) \
- __sanitizer_free_hook(ptr); \
- RunFreeHooks(ptr); \
- } while (false)
-
extern int memprof_inited;
extern int memprof_timestamp_inited;
extern int memprof_init_done;
diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h
index b018b1337b3f3..30efce94af540 100644
--- a/compiler-rt/lib/msan/msan.h
+++ b/compiler-rt/lib/msan/msan.h
@@ -375,21 +375,4 @@ void MsanTSDDtor(void *tsd);
} // namespace __msan
-#define MSAN_MALLOC_HOOK(ptr, size) \
- do { \
- if (&__sanitizer_malloc_hook) { \
- UnpoisonParam(2); \
- __sanitizer_malloc_hook(ptr, size); \
- } \
- RunMallocHooks(ptr, size); \
- } while (false)
-#define MSAN_FREE_HOOK(ptr) \
- do { \
- if (&__sanitizer_free_hook) { \
- UnpoisonParam(1); \
- __sanitizer_free_hook(ptr); \
- } \
- RunFreeHooks(ptr); \
- } while (false)
-
#endif // MSAN_H
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp
index dc006457a59ff..6b50ac10754fe 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -194,13 +194,22 @@ static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
__msan_set_origin(allocated, size, o.raw_id());
}
}
- MSAN_MALLOC_HOOK(allocated, size);
+ if (&__sanitizer_malloc_hook) {
+ UnpoisonParam(2);
+ __sanitizer_malloc_hook(allocated, size);
+ }
+ RunMallocHooks(allocated, size);
return allocated;
}
void MsanDeallocate(StackTrace *stack, void *p) {
CHECK(p);
- MSAN_FREE_HOOK(p);
+ if (&__sanitizer_free_hook) {
+ UnpoisonParam(1);
+ __sanitizer_free_hook(p);
+ }
+ RunFreeHooks(p);
+
Metadata *meta = reinterpret_cast<Metadata *>(allocator.GetMetaData(p));
uptr size = meta->requested_size;
meta->requested_size = 0;
More information about the llvm-commits
mailing list