diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -855,9 +855,15 @@ constexpr u32 kGuardRunning = 1 << 16; constexpr u32 kGuardWaiter = 1 << 17; -static int guard_acquire(ThreadState *thr, uptr pc, atomic_uint32_t *g) { - OnPotentiallyBlockingRegionBegin(); - auto on_exit = at_scope_exit(&OnPotentiallyBlockingRegionEnd); +static int guard_acquire(ThreadState *thr, uptr pc, atomic_uint32_t *g, + bool blocking_hooks = true) { + if (blocking_hooks) + OnPotentiallyBlockingRegionBegin(); + auto on_exit = at_scope_exit([blocking_hooks] { + if (blocking_hooks) + OnPotentiallyBlockingRegionEnd(); + }); + for (;;) { u32 cmp = atomic_load(g, memory_order_acquire); if (cmp == kGuardInit) { @@ -1509,7 +1515,9 @@ else a = static_cast(o); - if (guard_acquire(thr, pc, a)) { + // Mac OS X appears to use pthread_once() where calling BlockingRegion hooks + // result in crashes due to too little stack space. + if (guard_acquire(thr, pc, a, !SANITIZER_MAC)) { (*f)(); guard_release(thr, pc, a); }