[PATCH] D92521: [tsan] Fix build failure with _FORTIFY_SOURCE

Tom Stellard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 16:01:03 PST 2020


tstellar created this revision.
tstellar added reviewers: serge-sans-paille, dvyukov.
Herald added subscribers: Sanitizers, krytarowski.
Herald added a project: Sanitizers.
tstellar requested review of this revision.

When _FORTIFY_SOURCE is defined, the glibc headers define realpath which
clashes with the definition in compiler-rt.  In order to fix this for
realpath and also to protect us from future failues, when _FORTIFY_SOURCE
is defined, define our interceptor function with the __interceptor_ prefix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92521

Files:
  compiler-rt/lib/interception/interception.h
  compiler-rt/lib/interception/interception_linux.h


Index: compiler-rt/lib/interception/interception_linux.h
===================================================================
--- compiler-rt/lib/interception/interception_linux.h
+++ compiler-rt/lib/interception/interception_linux.h
@@ -32,7 +32,7 @@
   ::__interception::InterceptFunction(            \
       #func,                                      \
       (::__interception::uptr *) & REAL(func),    \
-      (::__interception::uptr) & (func),          \
+      (::__interception::uptr) & (DECLARED_FUNC(func)),       \
       (::__interception::uptr) & WRAP(func))
 
 // Android and Solaris do not have dlvsym
@@ -41,7 +41,7 @@
   ::__interception::InterceptFunction(                        \
       #func, symver,                                          \
       (::__interception::uptr *) & REAL(func),                \
-      (::__interception::uptr) & (func),                      \
+      (::__interception::uptr) & (DECLARED_FUNC(func)),       \
       (::__interception::uptr) & WRAP(func))
 #else
 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
Index: compiler-rt/lib/interception/interception.h
===================================================================
--- compiler-rt/lib/interception/interception.h
+++ compiler-rt/lib/interception/interception.h
@@ -121,6 +121,7 @@
 # define WRAPPER_NAME(x) "wrap_"#x
 # define INTERCEPTOR_ATTRIBUTE
 # define DECLARE_WRAPPER(ret_type, func, ...)
+# define DECLARED_FUNC(func) func
 
 #elif SANITIZER_WINDOWS
 # define WRAP(x) __asan_wrap_##x
@@ -135,6 +136,14 @@
 # define WRAPPER_NAME(x) #x
 # define INTERCEPTOR_ATTRIBUTE
 # define DECLARE_WRAPPER(ret_type, func, ...)
+#elif defined(_FORTIFY_SOURCE) && (SANITIZER_FREEBSD || SANITIZER_NETBSD || !SANITIZER_FUCHSIA)
+# define WRAP(x) __interceptor_ ## x
+# define WRAPPER_NAME(x) "__interceptor_" #x
+# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
+# define DECLARED_FUNC(func) WRAP(func)
+# define DECLARE_WRAPPER(ret_type, func, ...) \
+    extern "C" ret_type __interceptor_ ## func(__VA_ARGS__) \
+    __attribute__((visibility("default")));
 #elif SANITIZER_FREEBSD || SANITIZER_NETBSD
 # define WRAP(x) __interceptor_ ## x
 # define WRAPPER_NAME(x) "__interceptor_" #x


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92521.309089.patch
Type: text/x-patch
Size: 2234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201203/c1de6d03/attachment.bin>


More information about the llvm-commits mailing list