[compiler-rt] r264261 - [tsan] Fix fork() and fork-based tests for OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 04:54:33 PDT 2016


Author: kuba.brecka
Date: Thu Mar 24 06:54:33 2016
New Revision: 264261

URL: http://llvm.org/viewvc/llvm-project?rev=264261&view=rev
Log:
[tsan] Fix fork() and fork-based tests for OS X

On OS X, fork() under TSan asserts (in debug builds only) because REAL(fork) calls some intercepted functions, which check that no internal locks are held via CheckNoLocks(). But the wrapper of fork intentionally holds some locks. This patch fixes that by using ScopedIgnoreInterceptors during the call to REAL(fork). After that, all the fork-based tests seem to pass on OS X, so let's just remove all the UNSUPPORTED: darwin annotations we have.

Differential Revision: http://reviews.llvm.org/D18409


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/test/tsan/fork_atexit.cc
    compiler-rt/trunk/test/tsan/fork_deadlock.cc
    compiler-rt/trunk/test/tsan/fork_multithreaded.cc
    compiler-rt/trunk/test/tsan/fork_multithreaded3.cc
    compiler-rt/trunk/test/tsan/vfork.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=264261&r1=264260&r2=264261&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Mar 24 06:54:33 2016
@@ -2168,7 +2168,13 @@ TSAN_INTERCEPTOR(int, fork, int fake) {
     return REAL(fork)(fake);
   SCOPED_INTERCEPTOR_RAW(fork, fake);
   ForkBefore(thr, pc);
-  int pid = REAL(fork)(fake);
+  int pid;
+  {
+    // On OS X, REAL(fork) can call intercepted functions (OSSpinLockLock), and
+    // we'll assert in CheckNoLocks() unless we ignore interceptors.
+    ScopedIgnoreInterceptors ignore;
+    pid = REAL(fork)(fake);
+  }
   if (pid == 0) {
     // child
     ForkChildAfter(thr, pc);

Modified: compiler-rt/trunk/test/tsan/fork_atexit.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_atexit.cc?rev=264261&r1=264260&r2=264261&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/fork_atexit.cc (original)
+++ compiler-rt/trunk/test/tsan/fork_atexit.cc Thu Mar 24 06:54:33 2016
@@ -1,5 +1,4 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck %s
-// UNSUPPORTED: darwin
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>

Modified: compiler-rt/trunk/test/tsan/fork_deadlock.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_deadlock.cc?rev=264261&r1=264260&r2=264261&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/fork_deadlock.cc (original)
+++ compiler-rt/trunk/test/tsan/fork_deadlock.cc Thu Mar 24 06:54:33 2016
@@ -1,5 +1,4 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck %s
-// UNSUPPORTED: darwin
 #include "test.h"
 #include <errno.h>
 #include <sys/types.h>

Modified: compiler-rt/trunk/test/tsan/fork_multithreaded.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_multithreaded.cc?rev=264261&r1=264260&r2=264261&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/fork_multithreaded.cc (original)
+++ compiler-rt/trunk/test/tsan/fork_multithreaded.cc Thu Mar 24 06:54:33 2016
@@ -1,6 +1,5 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE
 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=die_after_fork=0 %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE
-// UNSUPPORTED: darwin
 #include "test.h"
 #include <errno.h>
 #include <sys/types.h>

Modified: compiler-rt/trunk/test/tsan/fork_multithreaded3.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_multithreaded3.cc?rev=264261&r1=264260&r2=264261&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/fork_multithreaded3.cc (original)
+++ compiler-rt/trunk/test/tsan/fork_multithreaded3.cc Thu Mar 24 06:54:33 2016
@@ -1,5 +1,4 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-// UNSUPPORTED: darwin
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>

Modified: compiler-rt/trunk/test/tsan/vfork.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vfork.cc?rev=264261&r1=264260&r2=264261&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/vfork.cc (original)
+++ compiler-rt/trunk/test/tsan/vfork.cc Thu Mar 24 06:54:33 2016
@@ -1,5 +1,4 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-// UNSUPPORTED: darwin
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>




More information about the llvm-commits mailing list