We need to intercept libdispatch APIs (dispatch_sync, dispatch_async, etc.) to add synchronization between the code that submits the task and the code that gets executed (possibly on a different thread).
This code adds release+acquire semantics for dispatch_sync, dispatch_async, dispatch_after and dispatch_apply (plus their "_f" variants). Added a simple testcase using dispatch_async, I'll add more GCD tests later.
For a program using libdispatch, TSan produces a bunch of false positives (from libxpc, libobjc, etc.). In order to suppress those, I added a few system libraries into a list of default suppressions.
Secondly, dispatch_once is not properly interceptible, because part of it is inlined, see the comment in the patch. To avoid false positives here, this patch ignores all reads and writes coming from the initializer within dispatch_once.
s/tsan_platform_mac.cc/tsan_libdispatch_mac.cc/