[compiler-rt] r206980 - tsan: fix atexit handling after fork

Dmitry Vyukov dvyukov at google.com
Wed Apr 23 06:42:16 PDT 2014


Author: dvyukov
Date: Wed Apr 23 08:42:16 2014
New Revision: 206980

URL: http://llvm.org/viewvc/llvm-project?rev=206980&view=rev
Log:
tsan: fix atexit handling after fork
fixes issue http://code.google.com/p/thread-sanitizer/issues/detail?id=57


Added:
    compiler-rt/trunk/test/tsan/fork_atexit.cc
Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.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=206980&r1=206979&r2=206980&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Wed Apr 23 08:42:16 2014
@@ -333,7 +333,9 @@ static AtExitContext *atexit_ctx;
 TSAN_INTERCEPTOR(int, atexit, void (*f)()) {
   if (cur_thread()->in_symbolizer)
     return 0;
-  SCOPED_TSAN_INTERCEPTOR(atexit, f);
+  // We want to setup the atexit callback even if we are in ignored lib
+  // or after fork.
+  SCOPED_INTERCEPTOR_RAW(atexit, f);
   return atexit_ctx->atexit(thr, pc, false, (void(*)())f, 0);
 }
 

Added: compiler-rt/trunk/test/tsan/fork_atexit.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_atexit.cc?rev=206980&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/fork_atexit.cc (added)
+++ compiler-rt/trunk/test/tsan/fork_atexit.cc Wed Apr 23 08:42:16 2014
@@ -0,0 +1,37 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && TSAN_OPTIONS="atexit_sleep_ms=50" %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+void foo() {
+  printf("CHILD ATEXIT\n");
+}
+
+void *worker(void *unused) {
+  return 0;
+}
+
+int main() {
+  pthread_t t;
+  pthread_create(&t, NULL, worker, NULL);
+  int pid = fork();
+  if (pid == 0) {
+    // child
+    atexit(foo);
+    fprintf(stderr, "CHILD DONE\n");
+  } else {
+    pthread_join(t, 0);
+    if (waitpid(pid, 0, 0) == -1) {
+      perror("waitpid");
+      exit(1);
+    }
+    fprintf(stderr, "PARENT DONE\n");
+  }
+}
+
+// CHECK: CHILD DONE
+// CHECK: CHILD ATEXIT
+// CHECK: PARENT DONE





More information about the llvm-commits mailing list