diff options
| author | Alexey Samsonov <samsonov@google.com> | 2013-10-11 09:58:30 +0000 |
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2013-10-11 09:58:30 +0000 |
| commit | 9d8385453b896e06fb621993c0dcf5e248aa25b9 (patch) | |
| tree | aabd0354e5cde3c1e8e9aa0521a774ad29f2e6e8 /compiler-rt | |
| parent | 8e5c2788f64fabfdb87807a20bedda27bd8439e1 (diff) | |
| download | bcm5719-llvm-9d8385453b896e06fb621993c0dcf5e248aa25b9.tar.gz bcm5719-llvm-9d8385453b896e06fb621993c0dcf5e248aa25b9.zip | |
[Sanitizer] Simplify StackTrace::FastUnwindStack interface and fix a bug with one-frame stack traces
llvm-svn: 192428
Diffstat (limited to 'compiler-rt')
6 files changed, 34 insertions, 30 deletions
diff --git a/compiler-rt/lib/msan/msan.cc b/compiler-rt/lib/msan/msan.cc index 6b52c727330..aebbd052b2a 100644 --- a/compiler-rt/lib/msan/msan.cc +++ b/compiler-rt/lib/msan/msan.cc @@ -190,10 +190,7 @@ void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, uptr stack_top, stack_bottom; GetCurrentStackBounds(&stack_top, &stack_bottom); - stack->size = 0; - stack->trace[0] = pc; - stack->max_size = max_s; - stack->FastUnwindStack(pc, bp, stack_top, stack_bottom); + stack->FastUnwindStack(pc, bp, stack_top, stack_bottom, max_s); } void PrintWarning(uptr pc, uptr bp) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc index 7342261672e..036f97b9d51 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc @@ -32,6 +32,10 @@ void ParseCommonFlagsFromString(const char *str) { ParseFlag(str, &f->detect_leaks, "detect_leaks"); ParseFlag(str, &f->leak_check_at_exit, "leak_check_at_exit"); ParseFlag(str, &f->allocator_may_return_null, "allocator_may_return_null"); + + // Do a sanity check for certain flags. + if (f->malloc_context_size < 1) + f->malloc_context_size = 1; } static bool GetFlagValue(const char *env, const char *name, diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc index 429f5de28f7..24ba3caf5d7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -92,22 +92,16 @@ int internal_isatty(fd_t fd) { #ifndef SANITIZER_GO void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, bool fast) { -#if !SANITIZER_CAN_FAST_UNWIND - fast = false; -#endif -#if SANITIZER_MAC - // Always unwind fast on Mac. - (void)fast; -#else + // Check if fast unwind is available. Fast unwind is the only option on Mac. + if (!SANITIZER_CAN_FAST_UNWIND) + fast = false; + else if (SANITIZER_MAC) + fast = true; + if (!fast) - return stack->SlowUnwindStack(pc, max_s); -#endif // SANITIZER_MAC - stack->size = 0; - stack->trace[0] = pc; - if (max_s > 1) { - stack->max_size = max_s; - stack->FastUnwindStack(pc, bp, stack_top, stack_bottom); - } + stack->SlowUnwindStack(pc, max_s); + else + stack->FastUnwindStack(pc, bp, stack_top, stack_bottom, max_s); } #endif // SANITIZER_GO diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc index e9ecfc9c5e0..a87b647ad45 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc @@ -106,8 +106,14 @@ uptr StackTrace::GetCurrentPc() { } void StackTrace::FastUnwindStack(uptr pc, uptr bp, - uptr stack_top, uptr stack_bottom) { - CHECK(size == 0 && trace[0] == pc); + uptr stack_top, uptr stack_bottom, + uptr max_depth) { + max_size = max_depth; + if (max_size == 0) { + size = 0; + return; + } + trace[0] = pc; size = 1; uhwptr *frame = (uhwptr *)bp; uhwptr *prev_frame = frame - 1; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index b2e0d6b5f3d..b9ada16d06b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -51,7 +51,8 @@ struct StackTrace { } } - void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom); + void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, + uptr max_depth); void SlowUnwindStack(uptr pc, uptr max_depth); void PopStackFrames(uptr count); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc index 3d352cb97a5..82c4426d8f8 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc @@ -47,16 +47,11 @@ void FastUnwindTest::SetUp() { // Bottom is one slot before the start because FastUnwindStack uses >. fake_bottom = (uptr)&fake_stack[-1]; start_pc = PC(0); - - // This is common setup done by __asan::GetStackTrace(). - trace.size = 0; - trace.max_size = ARRAY_SIZE(fake_stack); - trace.trace[0] = start_pc; } TEST_F(FastUnwindTest, Basic) { trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom); + fake_top, fake_bottom, kStackTraceMax); // Should get all on-stack retaddrs and start_pc. EXPECT_EQ(6U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -70,7 +65,7 @@ TEST_F(FastUnwindTest, FramePointerLoop) { // Make one fp point to itself. fake_stack[4] = (uptr)&fake_stack[4]; trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom); + fake_top, fake_bottom, kStackTraceMax); // Should get all on-stack retaddrs up to the 4th slot and start_pc. EXPECT_EQ(4U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -83,7 +78,7 @@ TEST_F(FastUnwindTest, MisalignedFramePointer) { // Make one fp misaligned. fake_stack[4] += 3; trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom); + fake_top, fake_bottom, kStackTraceMax); // Should get all on-stack retaddrs up to the 4th slot and start_pc. EXPECT_EQ(4U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -92,5 +87,12 @@ TEST_F(FastUnwindTest, MisalignedFramePointer) { } } +TEST_F(FastUnwindTest, OneFrameStackTrace) { + trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], + fake_top, fake_bottom, 1); + EXPECT_EQ(1U, trace.size); + EXPECT_EQ(1U, trace.max_size); + EXPECT_EQ(start_pc, trace.trace[0]); +} } // namespace __sanitizer |

