From 69fcf6a79e3678c56b8a75f41f5dda5abf180533 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 13 Apr 2022 10:36:11 +0200 Subject: [PATCH] Revert "[ubsan] Simplify ubsan_GetStackTrace" This reverts commit 63f2d1f4d4b8ee284b4ab977242e322a9458a168. I don't quite understand why, but this causes a linker error for me and a number of buildbots: /home/npopov/repos/llvm-project/compiler-rt/lib/ubsan/../sanitizer_common/sanitizer_stacktrace.h:130: error: undefined reference to '__sanitizer::BufferedStackTrace::UnwindImpl(unsigned long, unsigned long, void*, bool, unsigned int)' --- compiler-rt/lib/ubsan/ubsan_diag.cpp | 14 +++++++++----- compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cpp b/compiler-rt/lib/ubsan/ubsan_diag.cpp index d88b32225e80..3673e66539d0 100644 --- a/compiler-rt/lib/ubsan/ubsan_diag.cpp +++ b/compiler-rt/lib/ubsan/ubsan_diag.cpp @@ -32,9 +32,13 @@ using namespace __ubsan; // Windows. // TODO(yln): This is a temporary workaround. GetStackTrace functions will be // removed in the future. -void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr pc, uptr bp, - void *context, bool request_fast) { - stack->Unwind(pc, bp, context, request_fast); +void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc, + uptr bp, void *context, bool request_fast) { + uptr top = 0; + uptr bottom = 0; + GetThreadStackTopAndBottom(false, &top, &bottom); + bool fast = StackTrace::WillUseFastUnwind(request_fast); + stack->Unwind(max_depth, pc, bp, context, top, bottom, fast); } static void MaybePrintStackTrace(uptr pc, uptr bp) { @@ -44,8 +48,8 @@ static void MaybePrintStackTrace(uptr pc, uptr bp) { return; BufferedStackTrace stack; - ubsan_GetStackTrace(&stack, pc, bp, nullptr, - common_flags()->fast_unwind_on_fatal); + ubsan_GetStackTrace(&stack, kStackTraceMax, pc, bp, nullptr, + common_flags()->fast_unwind_on_fatal); stack.Print(); } diff --git a/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp b/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp index 126be527427d..2c91db8ca397 100644 --- a/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp +++ b/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp @@ -38,14 +38,15 @@ void InitializeDeadlySignals() {} #include "sanitizer_common/sanitizer_signal_interceptors.inc" // TODO(yln): Temporary workaround. Will be removed. -void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr pc, uptr bp, - void *context, bool fast); +void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth, + uptr pc, uptr bp, void *context, bool fast); namespace __ubsan { static void OnStackUnwind(const SignalContext &sig, const void *, BufferedStackTrace *stack) { - ubsan_GetStackTrace(stack, StackTrace::GetNextInstructionPc(sig.pc), sig.bp, + ubsan_GetStackTrace(stack, kStackTraceMax, + StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context, common_flags()->fast_unwind_on_fatal); }