Skip to content

Commit 27156dd

Browse files
committed
Revert "[TSAN] Add __tsan_check_no_mutexes_held helper (#69372)"
The new lit test fails, see comment on the PR. This also reverts the follow-up commit, see below. > This adds a new helper that can be called from application code to > ensure that no mutexes are held on specific code paths. This is useful > for multiple scenarios, including ensuring no locks are held: > > - at thread exit > - in peformance-critical code > - when a coroutine is suspended (can cause deadlocks) > > See this discourse thread for more discussion: > > https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051 This reverts commit bd84111. This reverts commit 16a395b.
1 parent 8ee9da0 commit 27156dd

File tree

8 files changed

+3
-70
lines changed

8 files changed

+3
-70
lines changed

compiler-rt/include/sanitizer/tsan_interface.h

-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ void SANITIZER_CDECL __tsan_mutex_post_signal(void *addr, unsigned flags);
127127
void SANITIZER_CDECL __tsan_mutex_pre_divert(void *addr, unsigned flags);
128128
void SANITIZER_CDECL __tsan_mutex_post_divert(void *addr, unsigned flags);
129129

130-
// Check that the current thread does not hold any mutexes,
131-
// report a bug report otherwise.
132-
void SANITIZER_CDECL __tsan_check_no_mutexes_held();
133-
134130
// External race detection API.
135131
// Can be used by non-instrumented libraries to detect when their objects are
136132
// being used in an unsafe manner.

compiler-rt/lib/tsan/rtl/tsan.syms.extra

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ __tsan_mutex_pre_signal
2222
__tsan_mutex_post_signal
2323
__tsan_mutex_pre_divert
2424
__tsan_mutex_post_divert
25-
__tsan_check_no_mutexes_held
2625
__tsan_get_current_fiber
2726
__tsan_create_fiber
2827
__tsan_destroy_fiber

compiler-rt/lib/tsan/rtl/tsan_debugging.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ static const char *ReportTypeDescription(ReportType typ) {
3535
case ReportTypeSignalUnsafe: return "signal-unsafe-call";
3636
case ReportTypeErrnoInSignal: return "errno-in-signal-handler";
3737
case ReportTypeDeadlock: return "lock-order-inversion";
38-
case ReportTypeMutexHeldWrongContext:
39-
return "mutex-held-in-wrong-context";
40-
// No default case so compiler warns us if we miss one
38+
// No default case so compiler warns us if we miss one
4139
}
4240
UNREACHABLE("missing case");
4341
}

compiler-rt/lib/tsan/rtl/tsan_interface_ann.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -435,26 +435,4 @@ void __tsan_mutex_post_divert(void *addr, unsigned flagz) {
435435
ThreadIgnoreBegin(thr, 0);
436436
ThreadIgnoreSyncBegin(thr, 0);
437437
}
438-
439-
static void ReportMutexHeldWrongContext(ThreadState *thr, uptr pc) {
440-
ThreadRegistryLock l(&ctx->thread_registry);
441-
ScopedReport rep(ReportTypeMutexHeldWrongContext);
442-
for (uptr i = 0; i < thr->mset.Size(); ++i) {
443-
MutexSet::Desc desc = thr->mset.Get(i);
444-
rep.AddMutex(desc.addr, desc.stack_id);
445-
}
446-
VarSizeStackTrace trace;
447-
ObtainCurrentStack(thr, pc, &trace);
448-
rep.AddStack(trace, true);
449-
OutputReport(thr, rep);
450-
}
451-
452-
INTERFACE_ATTRIBUTE
453-
void __tsan_check_no_mutexes_held() {
454-
SCOPED_ANNOTATION(__tsan_check_no_mutexes_held);
455-
if (thr->mset.Size() == 0) {
456-
return;
457-
}
458-
ReportMutexHeldWrongContext(thr, pc);
459-
}
460438
} // extern "C"

compiler-rt/lib/tsan/rtl/tsan_report.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ static const char *ReportTypeString(ReportType typ, uptr tag) {
9393
return "signal handler spoils errno";
9494
case ReportTypeDeadlock:
9595
return "lock-order-inversion (potential deadlock)";
96-
case ReportTypeMutexHeldWrongContext:
97-
return "mutex held in the wrong context";
98-
// No default case so compiler warns us if we miss one
96+
// No default case so compiler warns us if we miss one
9997
}
10098
UNREACHABLE("missing case");
10199
}

compiler-rt/lib/tsan/rtl/tsan_report.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ enum ReportType {
3434
ReportTypeMutexBadReadUnlock,
3535
ReportTypeSignalUnsafe,
3636
ReportTypeErrnoInSignal,
37-
ReportTypeDeadlock,
38-
ReportTypeMutexHeldWrongContext
37+
ReportTypeDeadlock
3938
};
4039

4140
struct ReportStack {

compiler-rt/lib/tsan/rtl/tsan_suppressions.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static const char *conv(ReportType typ) {
8181
case ReportTypeMutexBadUnlock:
8282
case ReportTypeMutexBadReadLock:
8383
case ReportTypeMutexBadReadUnlock:
84-
case ReportTypeMutexHeldWrongContext:
8584
return kSuppressionMutex;
8685
case ReportTypeSignalUnsafe:
8786
case ReportTypeErrnoInSignal:

compiler-rt/test/tsan/mutex_held_wrong_context.cpp

-34
This file was deleted.

0 commit comments

Comments
 (0)