From 19b137f0c2be6955f2712d2f79b72aebed5feb42 Mon Sep 17 00:00:00 2001 From: Marco Elver Date: Thu, 25 May 2023 11:07:55 +0200 Subject: [PATCH] [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 --- compiler-rt/lib/interception/interception.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h index 1b069bd..dfb8237 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 -- 2.7.4