[compiler-rt] r354282 - [Sanitizer] On Darwin `__sanitizer_print_stack_trace` only prints topmost frame

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 18 10:47:49 PST 2019


Author: yln
Date: Mon Feb 18 10:47:49 2019
New Revision: 354282

URL: http://llvm.org/viewvc/llvm-project?rev=354282&view=rev
Log:
[Sanitizer] On Darwin `__sanitizer_print_stack_trace` only prints topmost frame

In compiler-rt we have the notion of a `fast` and a `slow` stack
unwinder. Darwin currently only supports the fast unwinder.

>From reading the code, my understanding is that
`BufferedStackTrace::Unwind` can be called with `bp=0, stack_top=0,
stack_bottom=0, request_fast_unwind=false`. If
`request_fast_unwind=true`, then we alos need to supply bp, stack_top,
and stack_bottom.

However, `BufferedStackTrace::Unwind` uses
`StackTrace::WillUseFastUnwind` which will adapt `request_fast_unwind`
if the requested unwinder is not supported. On Darwin, the result is
that we don't pass actual values for bp, stack_top, and stack_bottom,
but end up using the fast unwinder. The tests then fail because we only
print the topmost stack frame.

This patch adds a check to `WillUseFastUnwind` at the point of usage to
avoid the mismatch between `request_fast_unwind` and what `Unwind`
actually does. I am also interested in cleaning up the
`request_fast_unwind` machinery so this patch just the simplest thing
possible so I can enable the tests.

Reviewers: vitalybuka, vsk

Differential Revision: https://reviews.llvm.org/D58156

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
    compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_stack.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc?rev=354282&r1=354281&r2=354282&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Mon Feb 18 10:47:49 2019
@@ -49,6 +49,7 @@ void BufferedStackTrace::Init(const uptr
 static inline uhwptr *GetCanonicFrame(uptr bp,
                                       uptr stack_top,
                                       uptr stack_bottom) {
+  CHECK_GT(stack_top, stack_bottom);
 #ifdef __arm__
   if (!IsValidFrame(bp, stack_top, stack_bottom)) return 0;
   uhwptr *bp_prev = (uhwptr *)bp;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=354282&r1=354281&r2=354282&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Mon Feb 18 10:47:49 2019
@@ -729,10 +729,17 @@ void PrintCurrentStack(ThreadState *thr,
 ALWAYS_INLINE
 void PrintCurrentStackSlow(uptr pc) {
 #if !SANITIZER_GO
+  uptr bp = 0;
+  uptr top = 0;
+  uptr bottom = 0;
+  if (__sanitizer::StackTrace::WillUseFastUnwind(false)) {
+    bp = GET_CURRENT_FRAME();
+    __sanitizer::GetThreadStackTopAndBottom(false, &top, &bottom);
+  }
   BufferedStackTrace *ptrace =
       new(internal_alloc(MBlockStackTrace, sizeof(BufferedStackTrace)))
           BufferedStackTrace();
-  ptrace->Unwind(kStackTraceMax, pc, 0, 0, 0, 0, false);
+  ptrace->Unwind(kStackTraceMax, pc, bp, nullptr, top, bottom, false);
   for (uptr i = 0; i < ptrace->size / 2; i++) {
     uptr tmp = ptrace->trace_buffer[i];
     ptrace->trace_buffer[i] = ptrace->trace_buffer[ptrace->size - i - 1];

Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc?rev=354282&r1=354281&r2=354282&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc Mon Feb 18 10:47:49 2019
@@ -22,7 +22,7 @@ void __sanitizer_print_stack_trace() {
   uptr top = 0;
   uptr bottom = 0;
   bool request_fast_unwind = common_flags()->fast_unwind_on_fatal;
-  if (request_fast_unwind)
+  if (__sanitizer::StackTrace::WillUseFastUnwind(request_fast_unwind))
     __sanitizer::GetThreadStackTopAndBottom(false, &top, &bottom);
 
   GET_CURRENT_PC_BP_SP;

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc?rev=354282&r1=354281&r2=354282&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc Mon Feb 18 10:47:49 2019
@@ -1,8 +1,8 @@
 // RUN: %clangxx -O0 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s
 // RUN: %env_tool_opts=stack_trace_format='"frame:%n lineno:%l"' %run %t 2>&1 | FileCheck %s --check-prefix=CUSTOM
 
-// FIXME(dliew): Make this test work with other sanitizers
-// XFAIL: darwin && (lsan || tsan || ubsan)
+// FIXME(dliew): Make this test work on Darwin with LSan
+// XFAIL: darwin && lsan
 
 #include <sanitizer/common_interface_defs.h>
 

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_stack.cc?rev=354282&r1=354281&r2=354282&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_stack.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_stack.cc Mon Feb 18 10:47:49 2019
@@ -2,8 +2,8 @@
 
 // Test that symbolizer does not crash on frame with large function name.
 
-// FIXME(dliew): Make this test work with the other sanitizers.
-// XFAIL: darwin && (lsan || tsan || ubsan)
+// FIXME(dliew): Make this test work on Darwin with LSan
+// XFAIL: darwin && lsan
 
 #include <sanitizer/common_interface_defs.h>
 #include <vector>




More information about the llvm-commits mailing list