[compiler-rt] [TSan] Fix deadlocks during TSan error reporting on Apple platforms (PR #151495)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 10:48:46 PDT 2025


================
@@ -2141,13 +2142,29 @@ 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));
+  bool suppressed;
+  // 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);
+    rep->SetSigNum(sig);
+    suppressed = IsFiredSuppression(ctx, ReportTypeErrnoInSignal, stack);
+    if (!suppressed)
+      rep->AddStack(stack, true);
+#if SANITIZER_APPLE
+  }  // Close this scope to release the locks before writing report
+  if (!suppressed)
+    OutputReport(thr, *rep);
+#else
+    if (!suppressed)
+      OutputReport(thr, *rep);
   }
+#endif
----------------
thurstond wrote:

Nit: there's less duplication with:

```
#if SANITIZER_APPLE
  }  // Close this scope to release the locks before writing report
#endif

  if (!suppressed)
    OutputReport(thr, *rep);

#if !SANITIZER_APPLE
  }
#endif
```

OTOH this suggestion is arguably less clear because the code indentation is wrong. WDYT?


https://github.com/llvm/llvm-project/pull/151495


More information about the llvm-commits mailing list