[llvm-commits] [compiler-rt] r170124 - in /compiler-rt/trunk/lib: asan/asan_linux.cc asan/lit_tests/Linux/malloc-in-qsort.cc sanitizer_common/sanitizer_linux.cc sanitizer_common/sanitizer_stacktrace.h
Kostya Serebryany
kcc at google.com
Thu Dec 13 04:31:56 PST 2012
Author: kcc
Date: Thu Dec 13 06:31:55 2012
New Revision: 170124
URL: http://llvm.org/viewvc/llvm-project?rev=170124&view=rev
Log:
[asan] pop the internal stack frames in SlowUnwindStack, extend the test to check this
Modified:
compiler-rt/trunk/lib/asan/asan_linux.cc
compiler-rt/trunk/lib/asan/lit_tests/Linux/malloc-in-qsort.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=170124&r1=170123&r2=170124&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Thu Dec 13 06:31:55 2012
@@ -129,7 +129,7 @@
fast = false;
#endif
if (!fast)
- return stack->SlowUnwindStack(pc, max_s, 3);
+ return stack->SlowUnwindStack(pc, max_s);
stack->size = 0;
stack->trace[0] = pc;
if (max_s > 1) {
Modified: compiler-rt/trunk/lib/asan/lit_tests/Linux/malloc-in-qsort.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Linux/malloc-in-qsort.cc?rev=170124&r1=170123&r2=170124&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Linux/malloc-in-qsort.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/Linux/malloc-in-qsort.cc Thu Dec 13 06:31:55 2012
@@ -37,4 +37,14 @@
// FIXME: this test does not properly work with slow unwind yet.
// CHECK-FAST: ERROR: AddressSanitizer: heap-buffer-overflow
+// CHECK-FAST: is located 0 bytes to the right
+// CHECK-FAST: #0{{.*}}operator new
+// CHECK-FAST-NEXT: #1{{.*}}QsortCallback
+// CHECK-FAST-NOT: MyQsort
+//
// CHECK-SLOW: ERROR: AddressSanitizer: heap-buffer-overflow
+// CHECK-SLOW: is located 0 bytes to the right
+// CHECK-SLOW: #0{{.*}}operator new
+// CHECK-SLOW-NEXT: #1{{.*}}QsortCallback
+// CHECK-SLOW: #{{.*}}MyQsort
+// CHECK-SLOW-NEXT: #{{.*}}main
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=170124&r1=170123&r2=170124&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Dec 13 06:31:55 2012
@@ -411,14 +411,24 @@
return UNWIND_CONTINUE;
}
-void StackTrace::SlowUnwindStack(uptr pc, uptr max_depth, uptr frames_to_pop) {
+static bool MatchPc(uptr cur_pc, uptr trace_pc) {
+ return cur_pc - trace_pc <= 8;
+}
+
+void StackTrace::SlowUnwindStack(uptr pc, uptr max_depth) {
this->size = 0;
- this->trace[0] = pc;
this->max_size = max_depth;
if (max_depth > 1) {
_Unwind_Backtrace(Unwind_Trace, this);
- this->PopStackFrames(frames_to_pop);
+ // We need to pop a few (up to 3) frames so that pc is on top.
+ // trace[0] belongs to the current function.
+ int to_pop = 1;
+ /**/ if (size >= 2 && MatchPc(pc, trace[1])) to_pop = 2;
+ else if (size >= 3 && MatchPc(pc, trace[2])) to_pop = 3;
+ else if (size >= 4 && MatchPc(pc, trace[3])) to_pop = 4;
+ this->PopStackFrames(to_pop);
}
+ this->trace[0] = pc;
}
} // namespace __sanitizer
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=170124&r1=170123&r2=170124&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Thu Dec 13 06:31:55 2012
@@ -44,7 +44,7 @@
}
void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom);
- void SlowUnwindStack(uptr pc, uptr max_depth, uptr frames_to_pop);
+ void SlowUnwindStack(uptr pc, uptr max_depth);
void PopStackFrames(uptr count);
More information about the llvm-commits
mailing list