[compiler-rt] 175fcd6 - [compiler-rt] Simplify ALIAS() attribute macro

Marco Elver via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 02:58:10 PDT 2023


Author: Marco Elver
Date: 2023-05-24T11:57:17+02:00
New Revision: 175fcd6fd24cda6bcdafb9718da8122b5654a047

URL: https://github.com/llvm/llvm-project/commit/175fcd6fd24cda6bcdafb9718da8122b5654a047
DIFF: https://github.com/llvm/llvm-project/commit/175fcd6fd24cda6bcdafb9718da8122b5654a047.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_interceptors.cpp
    compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
    compiler-rt/lib/interception/interception.h
    compiler-rt/lib/lsan/lsan_interceptors.cpp
    compiler-rt/lib/memprof/memprof_interceptors.cpp
    compiler-rt/lib/msan/msan_interceptors.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
    compiler-rt/lib/sanitizer_common/sanitizer_win_dll_thunk.h
    compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp
    compiler-rt/lib/tsan/rtl/tsan_interceptors.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 122bb7b0cba7b..ad11c822be802 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 59ad633879bd5..75d91ed09ce1b 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 d97974ee9074e..4663fa48cdb39 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 360e0f2207988..fe852b9fcfa8d 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 459ad03e8dfe2..31392a58f3dab 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 8cf724b3949f2..ed5e91483ae93 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 01f28754ba8ad..f1af74400fbcc 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 98186c429e9c0..ee1b3156c779e 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 48c73c4c98ad5..639d91a2edaec 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 93af8be17d10c..5737bf31be783 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 60fbc58f988a2..64a7fe2a9997b 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, ...)


        


More information about the llvm-commits mailing list