From 175fcd6fd24cda6bcdafb9718da8122b5654a047 Mon Sep 17 00:00:00 2001 From: Marco Elver Date: Wed, 24 May 2023 11:31:40 +0200 Subject: [PATCH] [compiler-rt] Simplify ALIAS() attribute macro Most uses of ALIAS() are in conjunction with WRAPPER_NAME(). Simplify the code and just make ALIAS() turn its argument into a string (similar to Linux kernel's __alias macro). This in turn allows removing WRAPPER_NAME(). NFC. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D151216 --- compiler-rt/lib/asan/asan_interceptors.cpp | 2 +- .../hwasan/hwasan_allocation_functions.cpp | 6 ++--- compiler-rt/lib/interception/interception.h | 4 ---- compiler-rt/lib/lsan/lsan_interceptors.cpp | 2 +- .../lib/memprof/memprof_interceptors.cpp | 2 +- compiler-rt/lib/msan/msan_interceptors.cpp | 2 +- .../sanitizer_common_interceptors.inc | 2 +- .../sanitizer_internal_defs.h | 2 +- .../sanitizer_win_dll_thunk.h | 2 +- .../tests/sanitizer_allocator_testlib.cpp | 22 +++++++++---------- compiler-rt/lib/tsan/rtl/tsan_interceptors.h | 8 +++---- 11 files changed, 25 insertions(+), 29 deletions(-) diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp index 122bb7b0cba7..ad11c822be80 100644 --- a/compiler-rt/lib/asan/asan_interceptors.cpp +++ b/compiler-rt/lib/asan/asan_interceptors.cpp @@ -443,7 +443,7 @@ INTERCEPTOR(_Unwind_Reason_Code, _Unwind_SjLj_RaiseException, #if ASAN_INTERCEPT_INDEX # if ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX INTERCEPTOR(char*, index, const char *string, int c) - ALIAS(WRAPPER_NAME(strchr)); + ALIAS(WRAP(strchr)); # else # if SANITIZER_APPLE DECLARE_REAL(char*, index, const char *string, int c) diff --git a/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp b/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp index 59ad633879bd..75d91ed09ce1 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp @@ -159,13 +159,13 @@ void *__sanitizer_malloc(uptr size) { // Fuchsia does not use WRAP/wrappers used for the interceptor infrastructure. # define INTERCEPTOR_ALIAS(RET, FN, ARGS...) \ extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE RET FN( \ - ARGS) ALIAS("__sanitizer_" #FN) + ARGS) ALIAS(__sanitizer_##FN) #else # define INTERCEPTOR_ALIAS(RET, FN, ARGS...) \ extern "C" SANITIZER_INTERFACE_ATTRIBUTE RET WRAP(FN)(ARGS) \ - ALIAS("__sanitizer_" #FN); \ + ALIAS(__sanitizer_##FN); \ extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE RET FN( \ - ARGS) ALIAS("__sanitizer_" #FN) + ARGS) ALIAS(__sanitizer_##FN) #endif INTERCEPTOR_ALIAS(int, posix_memalign, void **memptr, SIZE_T alignment, diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h index d97974ee9074..4663fa48cdb3 100644 --- a/compiler-rt/lib/interception/interception.h +++ b/compiler-rt/lib/interception/interception.h @@ -118,13 +118,11 @@ const interpose_substitution substitution_##func_name[] \ } # define WRAP(x) wrap_##x -# define WRAPPER_NAME(x) "wrap_"#x # define INTERCEPTOR_ATTRIBUTE # define DECLARE_WRAPPER(ret_type, func, ...) #elif SANITIZER_WINDOWS # define WRAP(x) __asan_wrap_##x -# define WRAPPER_NAME(x) "__asan_wrap_"#x # define INTERCEPTOR_ATTRIBUTE __declspec(dllexport) # define DECLARE_WRAPPER(ret_type, func, ...) \ extern "C" ret_type func(__VA_ARGS__); @@ -132,7 +130,6 @@ const interpose_substitution substitution_##func_name[] \ extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__); #elif SANITIZER_FREEBSD || SANITIZER_NETBSD # define WRAP(x) __interceptor_ ## x -# define WRAPPER_NAME(x) "__interceptor_" #x # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default"))) // FreeBSD's dynamic linker (incompliantly) gives non-weak symbols higher // priority than weak ones so weak aliases won't work for indirect calls @@ -142,7 +139,6 @@ const interpose_substitution substitution_##func_name[] \ __attribute__((alias("__interceptor_" #func), visibility("default"))); #elif !SANITIZER_FUCHSIA # define WRAP(x) __interceptor_ ## x -# define WRAPPER_NAME(x) "__interceptor_" #x # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default"))) # define DECLARE_WRAPPER(ret_type, func, ...) \ extern "C" ret_type func(__VA_ARGS__) \ diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp index 360e0f220798..fe852b9fcfa8 100644 --- a/compiler-rt/lib/lsan/lsan_interceptors.cpp +++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp @@ -197,7 +197,7 @@ INTERCEPTOR(void*, pvalloc, uptr size) { #endif // SANITIZER_INTERCEPT_PVALLOC #if SANITIZER_INTERCEPT_CFREE -INTERCEPTOR(void, cfree, void *p) ALIAS(WRAPPER_NAME(free)); +INTERCEPTOR(void, cfree, void *p) ALIAS(WRAP(free)); #define LSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree) #else #define LSAN_MAYBE_INTERCEPT_CFREE diff --git a/compiler-rt/lib/memprof/memprof_interceptors.cpp b/compiler-rt/lib/memprof/memprof_interceptors.cpp index 459ad03e8dfe..31392a58f3da 100644 --- a/compiler-rt/lib/memprof/memprof_interceptors.cpp +++ b/compiler-rt/lib/memprof/memprof_interceptors.cpp @@ -192,7 +192,7 @@ INTERCEPTOR(int, pthread_join, void *t, void **arg) { DEFINE_REAL_PTHREAD_FUNCTIONS INTERCEPTOR(char *, index, const char *string, int c) -ALIAS(WRAPPER_NAME(strchr)); +ALIAS(WRAP(strchr)); // For both strcat() and strncat() we need to check the validity of |to| // argument irrespective of the |from| length. diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp index 8cf724b3949f..ed5e91483ae9 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cpp +++ b/compiler-rt/lib/msan/msan_interceptors.cpp @@ -1109,7 +1109,7 @@ INTERCEPTOR(int, pthread_key_create, __sanitizer_pthread_key_t *key, #if SANITIZER_NETBSD INTERCEPTOR(int, __libc_thr_keycreate, __sanitizer_pthread_key_t *m, void (*dtor)(void *value)) -ALIAS(WRAPPER_NAME(pthread_key_create)); +ALIAS(WRAP(pthread_key_create)); #endif INTERCEPTOR(int, pthread_join, void *thread, void **retval) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 01f28754ba8a..f1af74400fbc 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -4456,7 +4456,7 @@ INTERCEPTOR(void, _exit, int status) { #if SANITIZER_INTERCEPT___LIBC_MUTEX INTERCEPTOR(int, __libc_thr_setcancelstate, int state, int *oldstate) -ALIAS(WRAPPER_NAME(pthread_setcancelstate)); +ALIAS(WRAP(pthread_setcancelstate)); #define INIT___LIBC_THR_SETCANCELSTATE \ COMMON_INTERCEPT_FUNCTION(__libc_thr_setcancelstate) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h index 98186c429e9c..ee1b3156c779 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h @@ -217,7 +217,7 @@ typedef u64 tid_t; # define WARN_UNUSED_RESULT #else // _MSC_VER # define ALWAYS_INLINE inline __attribute__((always_inline)) -# define ALIAS(x) __attribute__((alias(x))) +# define ALIAS(x) __attribute__((alias(SANITIZER_STRINGIFY(x)))) // Please only use the ALIGNED macro before the type. // Using ALIGNED after the variable declaration is not portable! # define ALIGNED(x) __attribute__((aligned(x))) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win_dll_thunk.h b/compiler-rt/lib/sanitizer_common/sanitizer_win_dll_thunk.h index 48c73c4c98ad..639d91a2edae 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win_dll_thunk.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win_dll_thunk.h @@ -84,7 +84,7 @@ extern "C" int __dll_thunk_init(); // which isn't a big deal. #define INTERCEPT_LIBRARY_FUNCTION(name) \ extern "C" void name(); \ - INTERCEPT_OR_DIE(WRAPPER_NAME(name), name) + INTERCEPT_OR_DIE(STRINGIFY(WRAP(name)), name) // Use these macros for functions that could be called before __dll_thunk_init() // is executed and don't lead to errors if defined (free, malloc, etc). diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp index 93af8be17d10..5737bf31be78 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp @@ -165,13 +165,13 @@ void *valloc(size_t size) { } #if SANITIZER_INTERCEPT_CFREE -void cfree(void *p) ALIAS("free"); +void cfree(void *p) ALIAS(free); #endif // SANITIZER_INTERCEPT_CFREE #if SANITIZER_INTERCEPT_PVALLOC -void *pvalloc(size_t size) ALIAS("valloc"); +void *pvalloc(size_t size) ALIAS(valloc); #endif // SANITIZER_INTERCEPT_PVALLOC #if SANITIZER_INTERCEPT_MEMALIGN -void *__libc_memalign(size_t alignment, size_t size) ALIAS("memalign"); +void *__libc_memalign(size_t alignment, size_t size) ALIAS(memalign); #endif // SANITIZER_INTERCEPT_MEMALIGN void malloc_usable_size() { @@ -190,11 +190,11 @@ namespace std { struct nothrow_t; } -void *operator new(size_t size) ALIAS("malloc"); -void *operator new[](size_t size) ALIAS("malloc"); -void *operator new(size_t size, std::nothrow_t const&) ALIAS("malloc"); -void *operator new[](size_t size, std::nothrow_t const&) ALIAS("malloc"); -void operator delete(void *ptr) throw() ALIAS("free"); -void operator delete[](void *ptr) throw() ALIAS("free"); -void operator delete(void *ptr, std::nothrow_t const&) ALIAS("free"); -void operator delete[](void *ptr, std::nothrow_t const&) ALIAS("free"); +void *operator new(size_t size) ALIAS(malloc); +void *operator new[](size_t size) ALIAS(malloc); +void *operator new(size_t size, std::nothrow_t const&) ALIAS(malloc); +void *operator new[](size_t size, std::nothrow_t const&) ALIAS(malloc); +void operator delete(void *ptr) throw() ALIAS(free); +void operator delete[](void *ptr) throw() ALIAS(free); +void operator delete(void *ptr, std::nothrow_t const&) ALIAS(free); +void operator delete[](void *ptr, std::nothrow_t const&) ALIAS(free); diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.h b/compiler-rt/lib/tsan/rtl/tsan_interceptors.h index 60fbc58f988a..64a7fe2a9997 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.h +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.h @@ -82,7 +82,7 @@ inline bool MustIgnoreInterceptor(ThreadState *thr) { #if SANITIZER_FREEBSD # define TSAN_INTERCEPTOR_FREEBSD_ALIAS(ret, func, ...) \ TSAN_INTERCEPTOR(ret, _pthread_##func, __VA_ARGS__) \ - ALIAS(WRAPPER_NAME(pthread_##func)); + ALIAS(WRAP(pthread_##func)); #else # define TSAN_INTERCEPTOR_FREEBSD_ALIAS(ret, func, ...) #endif @@ -90,13 +90,13 @@ inline bool MustIgnoreInterceptor(ThreadState *thr) { #if SANITIZER_NETBSD # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...) \ TSAN_INTERCEPTOR(ret, __libc_##func, __VA_ARGS__) \ - ALIAS(WRAPPER_NAME(pthread_##func)); + ALIAS(WRAP(pthread_##func)); # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...) \ TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \ - ALIAS(WRAPPER_NAME(pthread_##func)); + ALIAS(WRAP(pthread_##func)); # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...) \ TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \ - ALIAS(WRAPPER_NAME(pthread_##func2)); + ALIAS(WRAP(pthread_##func2)); #else # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...) # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...)