Skip to content

Commit 5fa0345

Browse files
authored
[tsan] Unwind for CHECK according to fast_unwind_on_fatal (#117470)
It's needed for #116409, which hangs with slow unwind.
1 parent eb4d2f2 commit 5fa0345

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ void CheckUnwind() {
673673
thr->ignore_reads_and_writes++;
674674
atomic_store_relaxed(&thr->in_signal_handler, 0);
675675
#endif
676-
PrintCurrentStackSlow(StackTrace::GetCurrentPc());
676+
PrintCurrentStack(StackTrace::GetCurrentPc(),
677+
common_flags()->fast_unwind_on_fatal);
677678
}
678679

679680
bool is_initialized;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ bool IsExpectedReport(uptr addr, uptr size);
514514
StackID CurrentStackId(ThreadState *thr, uptr pc);
515515
ReportStack *SymbolizeStackId(StackID stack_id);
516516
void PrintCurrentStack(ThreadState *thr, uptr pc);
517-
void PrintCurrentStackSlow(uptr pc); // uses libunwind
517+
void PrintCurrentStack(uptr pc, bool fast); // may uses libunwind
518518
MBlock *JavaHeapBlock(uptr addr, uptr *start);
519519

520520
void Initialize(ThreadState *thr);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,18 +828,18 @@ void PrintCurrentStack(ThreadState *thr, uptr pc) {
828828
PrintStack(SymbolizeStack(trace));
829829
}
830830

831-
// Always inlining PrintCurrentStackSlow, because LocatePcInTrace assumes
831+
// Always inlining PrintCurrentStack, because LocatePcInTrace assumes
832832
// __sanitizer_print_stack_trace exists in the actual unwinded stack, but
833-
// tail-call to PrintCurrentStackSlow breaks this assumption because
833+
// tail-call to PrintCurrentStack breaks this assumption because
834834
// __sanitizer_print_stack_trace disappears after tail-call.
835835
// However, this solution is not reliable enough, please see dvyukov's comment
836836
// http://reviews.llvm.org/D19148#406208
837837
// Also see PR27280 comment 2 and 3 for breaking examples and analysis.
838-
ALWAYS_INLINE USED void PrintCurrentStackSlow(uptr pc) {
838+
ALWAYS_INLINE USED void PrintCurrentStack(uptr pc, bool fast) {
839839
#if !SANITIZER_GO
840840
uptr bp = GET_CURRENT_FRAME();
841841
auto *ptrace = New<BufferedStackTrace>();
842-
ptrace->Unwind(pc, bp, nullptr, false);
842+
ptrace->Unwind(pc, bp, nullptr, fast);
843843

844844
for (uptr i = 0; i < ptrace->size / 2; i++) {
845845
uptr tmp = ptrace->trace_buffer[i];
@@ -857,6 +857,6 @@ using namespace __tsan;
857857
extern "C" {
858858
SANITIZER_INTERFACE_ATTRIBUTE
859859
void __sanitizer_print_stack_trace() {
860-
PrintCurrentStackSlow(StackTrace::GetCurrentPc());
860+
PrintCurrentStack(StackTrace::GetCurrentPc(), false);
861861
}
862862
} // extern "C"

0 commit comments

Comments
 (0)