[compiler-rt] [TSan] Fix deadlocks during TSan error reporting on Apple platforms (PR #151495)
Dan Blackwell via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 07:51:08 PDT 2025
================
@@ -2141,13 +2142,23 @@ static void ReportErrnoSpoiling(ThreadState *thr, uptr pc, int sig) {
// StackTrace::GetNestInstructionPc(pc) is used because return address is
// expected, OutputReport() will undo this.
ObtainCurrentStack(thr, StackTrace::GetNextInstructionPc(pc), &stack);
- ThreadRegistryLock l(&ctx->thread_registry);
- ScopedReport rep(ReportTypeErrnoInSignal);
- rep.SetSigNum(sig);
- if (!IsFiredSuppression(ctx, ReportTypeErrnoInSignal, stack)) {
- rep.AddStack(stack, true);
- OutputReport(thr, rep);
- }
+ ScopedReport *_rep = (ScopedReport *)__builtin_alloca(sizeof(ScopedReport));
+ // Take a new scope as Apple platforms require the below locks released
+ // before symbolizing in order to avoid a deadlock
+ {
+ ThreadRegistryLock l(&ctx->thread_registry);
+ new (_rep) ScopedReport(ReportTypeErrnoInSignal);
+ ScopedReport &rep = *_rep;
+ rep.SetSigNum(sig);
+ if (!IsFiredSuppression(ctx, ReportTypeErrnoInSignal, stack)) {
+ rep.AddStack(stack, true);
+ OutputReport(thr, rep);
+ }
+ } // Close this scope to release the locks
+
+ OutputReport(thr, *_rep);
+ // Need to manually destroy this because we used placement new to allocate
----------------
DanBlackwell wrote:
https://github.com/llvm/llvm-project/blob/0398ad41bdf1ce5f74c80a74494bfe733fe3e214/compiler-rt/lib/tsan/rtl/tsan_rtl.h#L19
I _think_ we can use unique_ptr in the .cpp files actually based on this.
https://github.com/llvm/llvm-project/pull/151495
More information about the llvm-commits
mailing list