[compiler-rt] r252160 - [tsan] Fix pthread_once interceptor for OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 05:59:07 PST 2015


Author: kuba.brecka
Date: Thu Nov  5 07:59:07 2015
New Revision: 252160

URL: http://llvm.org/viewvc/llvm-project?rev=252160&view=rev
Log:
[tsan] Fix pthread_once interceptor for OS X

TSan has a re-implementation of `pthread_once` in its interceptor, which assumes that the `pthread_once_t *once_control` pointer is actually pointing to a "storage" which is zero-initialized and used for the atomic operations. However, that's not true on OS X, where pthread_once_t is a structure, that contains a header (with a magic value) and the actual storage follows after that. This patch skips the header to make the interceptor work on OS X.

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


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=252160&r1=252159&r2=252160&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Nov  5 07:59:07 2015
@@ -1293,7 +1293,11 @@ TSAN_INTERCEPTOR(int, pthread_once, void
   SCOPED_INTERCEPTOR_RAW(pthread_once, o, f);
   if (o == 0 || f == 0)
     return EINVAL;
-  atomic_uint32_t *a = static_cast<atomic_uint32_t*>(o);
+  atomic_uint32_t *a;
+  if (!SANITIZER_MAC)
+    a = static_cast<atomic_uint32_t*>(o);
+  else  // On OS X, pthread_once_t has a header with a long-sized signature.
+    a = static_cast<atomic_uint32_t*>((void *)((char *)o + sizeof(long)));
   u32 v = atomic_load(a, memory_order_acquire);
   if (v == 0 && atomic_compare_exchange_strong(a, &v, 1,
                                                memory_order_relaxed)) {




More information about the llvm-commits mailing list