[compiler-rt] r190989 - tsan: prevent the following false positive due to __cxa_atexit

Dmitry Vyukov dvyukov at google.com
Wed Sep 18 21:49:00 PDT 2013


Author: dvyukov
Date: Wed Sep 18 23:48:59 2013
New Revision: 190989

URL: http://llvm.org/viewvc/llvm-project?rev=190989&view=rev
Log:
tsan: prevent the following false positive due to __cxa_atexit

WARNING: ThreadSanitizer: data race (pid=29103)
  Write of size 8 at 0x7d64003bbf00 by main thread:
    #0 free tsan_interceptors.cc:477
    #1 __run_exit_handlers <null>:0 (libc.so.6+0x000000050cb7)

  Previous write of size 8 at 0x7d64003bbf00 by thread T78 (mutexes: write M9896):
    #0 calloc tsan_interceptors.cc:449
    #1 ...




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=190989&r1=190988&r2=190989&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Wed Sep 18 23:48:59 2013
@@ -313,8 +313,14 @@ TSAN_INTERCEPTOR(int, __cxa_atexit, void
   if (cur_thread()->in_symbolizer)
     return 0;
   SCOPED_TSAN_INTERCEPTOR(__cxa_atexit, f, arg, dso);
-  if (dso)
-    return REAL(__cxa_atexit)(f, arg, dso);
+  if (dso) {
+    // Memory allocation in __cxa_atexit will race with free during exit,
+    // because we do not see synchronization around atexit callback list.
+    ThreadIgnoreBegin(thr);
+    int res = REAL(__cxa_atexit)(f, arg, dso);
+    ThreadIgnoreEnd(thr);
+    return res;
+  }
   return atexit_ctx->atexit(thr, pc, false, (void(*)())f, arg);
 }
 





More information about the llvm-commits mailing list