[PATCH] D14811: [tsan] Handle dispatch_once on OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 01:41:40 PST 2015


kubabrecka created this revision.
kubabrecka added reviewers: dvyukov, kcc, glider, samsonov.
kubabrecka added subscribers: llvm-commits, zaks.anna, ismailp.

Reimplement dispatch_once in an interceptor to solve these issues that may produce false positives with TSan on OS X:

1) there is a racy load inside an inlined part of dispatch_once,
2) the fast path in dispatch_once doesn't perform an acquire load, so we don't properly synchronize the initialization and subsequent uses of whatever is initialized,
3) dispatch_once is already used in a lot of already-compiled code, so TSan doesn't see the inlined fast-path.

This patch uses a trick to avoid ever taking the fast path (by never storing ~0 into the predicate), which means the interceptor will always be called even from already-compiled code.  Within the interceptor, our own atomic reads and writes are not written into shadow cells, so the race in the inlined part is not reported (because the accesses are only loads).


http://reviews.llvm.org/D14811

Files:
  lib/tsan/CMakeLists.txt
  lib/tsan/rtl/tsan_interceptors.cc
  lib/tsan/rtl/tsan_interceptors.h
  lib/tsan/rtl/tsan_libdispatch_mac.cc
  test/tsan/Darwin/gcd-once.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14811.40613.patch
Type: text/x-patch
Size: 6233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151119/3c2ef46f/attachment.bin>


More information about the llvm-commits mailing list