[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

llvm-svn: 252160
This commit is contained in:
Kuba Brecka 2015-11-05 13:59:07 +00:00
parent cd18f28751
commit 12bba1c2a0
1 changed files with 5 additions and 1 deletions

View File

@ -1293,7 +1293,11 @@ TSAN_INTERCEPTOR(int, pthread_once, void *o, void (*f)()) {
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)) {