[tsan] Add Mutex annotation flag for constant-initialized __tsan_mutex_linker_init...
authorDmitry Vyukov <dvyukov@google.com>
Fri, 20 Oct 2017 12:08:53 +0000 (12:08 +0000)
committerDmitry Vyukov <dvyukov@google.com>
Fri, 20 Oct 2017 12:08:53 +0000 (12:08 +0000)
commit9e2cd1c1256c05537f6a464154c45905ce5be078
treec43b2e667e475d3867614a33abe5b48a3bcea5b2
parentfa8c5514c52b180bf62972fd8e8c69af5942fa36
[tsan] Add Mutex annotation flag for constant-initialized __tsan_mutex_linker_init behavior

Add a new flag, _⁠_tsan_mutex_not_static, which has the opposite sense
of _⁠_tsan_mutex_linker_init. When the new _⁠_tsan_mutex_not_static flag
is passed to _⁠_tsan_mutex_destroy, tsan ignores the destruction unless
the mutex was also created with the _⁠_tsan_mutex_not_static flag.

This is useful for constructors that otherwise woud set
_⁠_tsan_mutex_linker_init but cannot, because they are declared constexpr.

Google has a custom mutex with two constructors, a "linker initialized"
constructor that relies on zero-initialization and sets
⁠_⁠_tsan_mutex_linker_init, and a normal one which sets no tsan flags.
The "linker initialized" constructor is morally constexpr, but we can't
declare it constexpr because of the need to call into tsan as a side effect.

With this new flag, the normal c'tor can set _⁠_tsan_mutex_not_static,
the "linker initialized" constructor can rely on tsan's lazy initialization,
and _⁠_tsan_mutex_destroy can still handle both cases correctly.

Author: Greg Falcon (gfalcon)
Reviewed in: https://reviews.llvm.org/D39095

llvm-svn: 316209
compiler-rt/include/sanitizer/tsan_interface.h
compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
compiler-rt/lib/tsan/rtl/tsan_sync.h
compiler-rt/test/tsan/custom_mutex.h