This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Add Mutex annotation flag for constant-initialized __tsan_mutex_linker_init behavior
ClosedPublic

Authored by gfalcon on Oct 19 2017, 7:49 AM.

Details

Reviewers
dvyukov
Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

gfalcon created this revision.Oct 19 2017, 7:49 AM
gfalcon edited the summary of this revision. (Show Details)Oct 19 2017, 7:51 AM
dvyukov edited edge metadata.Oct 20 2017, 5:04 AM

LGTM except that ninja check-tsan fails:

compiler-rt/test/tsan/custom_mutex4.cc:17: Extra space before ( in function call [whitespace/parens] [4]
compiler-rt/test/tsan/custom_mutex4.cc:24: Extra space before ( in function call [whitespace/parens] [4]
ninja: build stopped: subcommand failed.

This revision is now accepted and ready to land.Oct 20 2017, 5:09 AM