[compiler-rt] 19b137f - [compiler-rt] Unify Linux and *BSD interceptors more

Marco Elver via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 03:01:46 PDT 2023


Author: Marco Elver
Date: 2023-05-25T12:01:10+02:00
New Revision: 19b137f0c2be6955f2712d2f79b72aebed5feb42

URL: https://github.com/llvm/llvm-project/commit/19b137f0c2be6955f2712d2f79b72aebed5feb42
DIFF: https://github.com/llvm/llvm-project/commit/19b137f0c2be6955f2712d2f79b72aebed5feb42.diff

LOG: [compiler-rt] Unify Linux and *BSD interceptors more

The Linux and *BSD interceptors are almost identical, except for *BSD,
where the overridden intercepted function is not defined weak due to
some incompliant linker behaviour.

Since most of the interception machinery is shared between Linux and
*BSD (see INTERCEPT_FUNCTION macro), it makes sense to unify interceptor
definition and declarations as much as possible to ease future changes.

NFC.

Reviewed By: dvyukov, vitalybuka

Differential Revision: https://reviews.llvm.org/D151318

Added: 
    

Modified: 
    compiler-rt/lib/interception/interception.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 1b069bd42621d..dfb8237921e1c 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -130,23 +130,21 @@ const interpose_substitution substitution_##func_name[] \
     extern "C" ret_type func(__VA_ARGS__);
 # define DECLARE_WRAPPER_WINAPI(ret_type, func, ...) \
     extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
-#elif SANITIZER_FREEBSD || SANITIZER_NETBSD
+#elif !SANITIZER_FUCHSIA  // LINUX, FREEBSD, NETBSD, SOLARIS
 # define WRAP(x) __interceptor_ ## x
 # define TRAMPOLINE(x) WRAP(x)
 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
+# if SANITIZER_FREEBSD || SANITIZER_NETBSD
 // FreeBSD's dynamic linker (incompliantly) gives non-weak symbols higher
 // priority than weak ones so weak aliases won't work for indirect calls
 // in position-independent (-fPIC / -fPIE) mode.
-# define DECLARE_WRAPPER(ret_type, func, ...) \
-     extern "C" ret_type func(__VA_ARGS__) \
-     __attribute__((alias("__interceptor_" #func), visibility("default")));
-#elif !SANITIZER_FUCHSIA
-# define WRAP(x) __interceptor_ ## x
-# define TRAMPOLINE(x) WRAP(x)
-# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
-# define DECLARE_WRAPPER(ret_type, func, ...) \
-    extern "C" ret_type func(__VA_ARGS__) \
-    __attribute__((weak, alias("__interceptor_" #func), visibility("default")));
+# define OVERRIDE_ATTRIBUTE
+# else  // SANITIZER_FREEBSD || SANITIZER_NETBSD
+# define OVERRIDE_ATTRIBUTE __attribute__((weak))
+# endif  // SANITIZER_FREEBSD || SANITIZER_NETBSD
+# define DECLARE_WRAPPER(ret_type, func, ...)                                  \
+    extern "C" ret_type func(__VA_ARGS__) INTERCEPTOR_ATTRIBUTE                \
+      OVERRIDE_ATTRIBUTE ALIAS(WRAP(func));
 #endif
 
 #if SANITIZER_FUCHSIA


        


More information about the llvm-commits mailing list