tsan: enable clone interceptor only on Linux
authorDmitry Vyukov <dvyukov@google.com>
Thu, 11 Nov 2021 18:17:17 +0000 (19:17 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 11 Nov 2021 18:27:47 +0000 (19:27 +0100)
Clone does not exist on Mac.
There are chances it will break on other OSes.
Enable it incrementally starting with Linux only,
other OSes can enable it later as needed.

Reviewed By: melver, thakis

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

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
compiler-rt/test/tsan/Linux/clone_deadlock.cpp [moved from compiler-rt/test/tsan/clone_deadlock.cpp with 97% similarity]

index a712a3a..c7dcd07 100644 (file)
@@ -2210,6 +2210,7 @@ TSAN_INTERCEPTOR(int, vfork, int fake) {
   return WRAP(fork)(fake);
 }
 
+#if SANITIZER_LINUX
 TSAN_INTERCEPTOR(int, clone, int (*fn)(void *), void *stack, int flags,
                  void *arg, int *parent_tid, void *tls, pid_t *child_tid) {
   SCOPED_INTERCEPTOR_RAW(clone, fn, stack, flags, arg, parent_tid, tls,
@@ -2233,6 +2234,7 @@ TSAN_INTERCEPTOR(int, clone, int (*fn)(void *), void *stack, int flags,
   ForkParentAfter(thr, pc);
   return pid;
 }
+#endif
 
 #if !SANITIZER_MAC && !SANITIZER_ANDROID
 typedef int (*dl_iterate_phdr_cb_t)(__sanitizer_dl_phdr_info *info, SIZE_T size,
@@ -2865,7 +2867,9 @@ void InitializeInterceptors() {
 
   TSAN_INTERCEPT(fork);
   TSAN_INTERCEPT(vfork);
+#if SANITIZER_LINUX
   TSAN_INTERCEPT(clone);
+#endif
 #if !SANITIZER_ANDROID
   TSAN_INTERCEPT(dl_iterate_phdr);
 #endif
similarity index 97%
rename from compiler-rt/test/tsan/clone_deadlock.cpp
rename to compiler-rt/test/tsan/Linux/clone_deadlock.cpp
index 317ccda..70846da 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=0 %run %t 2>&1 | FileCheck %s
-#include "test.h"
+#include "../test.h"
 #include <errno.h>
 #include <sched.h>
 #include <sys/types.h>