Skip to content

Commit fdd424e

Browse files
committed
[ubsan] Fix print_stacktrace=1:fast_unwind_on_fatal=0 to correctly fallback to fast unwinder
ubsan_GetStackTrace (from 52b7510) called by ~ScopeReport leaves top/bottom zeroes in the `!WillUseFastUnwind(request_fast_unwind)` code path. When BufferedStackTrace::Unwind falls back to UnwindFast, `if (stack_top < 4096) return;` will return early, leaving just one frame in the stack trace. Fix this by always initializing top/bottom like 261d6e0. Reviewed By: eugenis, yln Differential Revision: https://reviews.llvm.org/D123562
1 parent deadda7 commit fdd424e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

compiler-rt/lib/ubsan/ubsan_diag.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ using namespace __ubsan;
3232
// Windows.
3333
// TODO(yln): This is a temporary workaround. GetStackTrace functions will be
3434
// removed in the future.
35-
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth,
36-
uptr pc, uptr bp, void *context, bool fast) {
35+
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc,
36+
uptr bp, void *context, bool request_fast) {
3737
uptr top = 0;
3838
uptr bottom = 0;
39-
if (StackTrace::WillUseFastUnwind(fast)) {
40-
GetThreadStackTopAndBottom(false, &top, &bottom);
41-
stack->Unwind(max_depth, pc, bp, nullptr, top, bottom, true);
42-
} else
43-
stack->Unwind(max_depth, pc, bp, context, 0, 0, false);
39+
GetThreadStackTopAndBottom(false, &top, &bottom);
40+
bool fast = StackTrace::WillUseFastUnwind(request_fast);
41+
stack->Unwind(max_depth, pc, bp, context, top, bottom, fast);
4442
}
4543

4644
static void MaybePrintStackTrace(uptr pc, uptr bp) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// Fast unwinder does not work with Thumb code
2+
// UNSUPPORTED: thumb
3+
4+
// RUN: %clangxx -fsanitize=return %gmlt -O2 -fno-omit-frame-pointer -fasynchronous-unwind-tables %s -o %t
5+
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s
6+
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s
7+
// RUN: %clangxx -fsanitize=return %gmlt -O2 -fno-omit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables %s -o %t
8+
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s
9+
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s
10+
11+
// CHECK: runtime error: execution reached the end of a value-returning function without returning a value
12+
// CHECK-NEXT: #0 {{.*}}f() {{.*}}.cpp:[[#@LINE+1]]
13+
__attribute__((noinline)) int f() {}
14+
15+
// CHECK-NEXT: #1 {{.*}}g() {{.*}}.cpp:[[#@LINE+1]]
16+
__attribute__((noinline)) void g() { f(); }
17+
18+
// CHECK-NEXT: #2 {{.*}}h() {{.*}}.cpp:[[#@LINE+1]]
19+
__attribute__((noinline)) void h() { g(); }
20+
21+
// CHECK-NEXT: #3 {{.*}}main {{.*}}.cpp:[[#@LINE+1]]
22+
int main() { h(); }

0 commit comments

Comments
 (0)