There is a “well-known” TSan false positive when using C++ weak_ptr/shared_ptr and code in destructors, e.g. described at https://llvm.org/bugs/show_bug.cgi?id=22324. The “standard" solution is to build and use a TSan-instrumented version of libcxx, which is not trivial for end-users. This patch tries a different approach (on OS X): It adds an interceptor for the specific function in libc++.dylib, which implements the atomic operation that needs to be visible to TSan.
The API/ABI of libc++.dylib is stable on OS X, so adding this interceptor is compatible with all OS versions. I went through the sources of libcxx and this seems to be the only function that needs to be intercepted.