Commit d08b8a41 authored by Andrew Doran's avatar Andrew Doran Committed by Facebook GitHub Bot

Disable TSAN instrumentation across StaticMetaBase::onThreadExit().

Summary:
Disable TSAN instrumentation across StaticMetaBase::onThreadExit() to avoid a shortcoming in TSAN on Linux that produces sprurious failures.

This was recently worked around by ignoring TSAN failures in ld-linux's _dl_deallocate_tsd() (D20597534), but that turns out to be insufficient, because other TSAN failures can occur on the TLS area after the dynamic linker has called free() on it.  This diff backs out the change from D20597534, and works around the problem in a more direct & complete way.

Reviewed By: yfeldblum

Differential Revision: D20671620

fbshipit-source-id: 05a74e709b620391f18467c7a5e4d14dcf9f4a1e
parent bd44e567
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <folly/detail/ThreadLocalDetail.h> #include <folly/detail/ThreadLocalDetail.h>
#include <folly/synchronization/CallOnce.h> #include <folly/synchronization/CallOnce.h>
#include <folly/synchronization/SanitizeThread.h>
#include <list> #include <list>
#include <mutex> #include <mutex>
...@@ -118,6 +119,17 @@ bool StaticMetaBase::dying() { ...@@ -118,6 +119,17 @@ bool StaticMetaBase::dying() {
} }
void StaticMetaBase::onThreadExit(void* ptr) { void StaticMetaBase::onThreadExit(void* ptr) {
// Disable TSAN instrumentation for the duration of this method. This is
// called from pthread_exit(), as a thread-specific data destructor. On
// Linux, TSAN also uses that mechanism to intercept thread exit. There
// is no defined order for TSD destructor invocation. TSAN can therefore
// be informed of the thread's demise before this routine runs, which can
// later confuse TSAN when another thread running in ld-linux calls free()
// on this thread's TLS (not TSD) memory block, which is written to here.
Optional<annotate_ignore_thread_sanitizer_guard> tsanGuard;
if (kIsLinux) {
tsanGuard.emplace(__FILE__, __LINE__);
}
auto threadEntry = static_cast<ThreadEntry*>(ptr); auto threadEntry = static_cast<ThreadEntry*>(ptr);
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment