[compiler-rt] r178747 - [sanitizer] while doing fast unwinding make sure that the frame pointer is aligned; fix lint

Kostya Serebryany kcc at google.com
Wed Apr 3 23:52:40 PDT 2013


Author: kcc
Date: Thu Apr  4 01:52:40 2013
New Revision: 178747

URL: http://llvm.org/viewvc/llvm-project?rev=178747&view=rev
Log:
[sanitizer] while doing fast unwinding make sure that the frame pointer is aligned; fix lint

Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=178747&r1=178746&r2=178747&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Apr  4 01:52:40 2013
@@ -826,7 +826,7 @@ INTERCEPTOR(int, getrusage, int who, voi
 
 INTERCEPTOR(int, sigaction, int signum, const void *act, void *oldact) {
   ENSURE_MSAN_INITED();
-  // TODO: check that *act is unpoisoned.
+  // FIXME: check that *act is unpoisoned.
   // That requires intercepting all of sigemptyset, sigfillset, etc.
   int res = REAL(sigaction)(signum, act, oldact);
   if (res == 0) {

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=178747&r1=178746&r2=178747&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Thu Apr  4 01:52:40 2013
@@ -137,6 +137,7 @@ void StackTrace::FastUnwindStack(uptr pc
   while (frame > prev_frame &&
          frame < (uhwptr *)stack_top - 2 &&
          frame > (uhwptr *)stack_bottom &&
+         IsAligned((uptr)frame, sizeof(*frame)) &&
          size < max_size) {
     uhwptr pc1 = frame[1];
     if (pc1 != pc) {

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc?rev=178747&r1=178746&r2=178747&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc Thu Apr  4 01:52:40 2013
@@ -28,12 +28,16 @@ class FastUnwindTest : public ::testing:
   StackTrace trace;
 };
 
+static uptr PC(uptr idx) {
+  return (1<<20) + idx;
+}
+
 void FastUnwindTest::SetUp() {
   // Fill an array of pointers with fake fp+retaddr pairs.  Frame pointers have
   // even indices.
   for (uptr i = 0; i+1 < ARRAY_SIZE(fake_stack); i += 2) {
     fake_stack[i] = (uptr)&fake_stack[i+2];  // fp
-    fake_stack[i+1] = i+1; // retaddr
+    fake_stack[i+1] = PC(i + 1); // retaddr
   }
   // Mark the last fp as zero to terminate the stack trace.
   fake_stack[RoundDownTo(ARRAY_SIZE(fake_stack) - 1, 2)] = 0;
@@ -42,7 +46,7 @@ void FastUnwindTest::SetUp() {
   fake_top = (uptr)&fake_stack[ARRAY_SIZE(fake_stack) + 2];
   // Bottom is one slot before the start because FastUnwindStack uses >.
   fake_bottom = (uptr)&fake_stack[-1];
-  start_pc = 0;
+  start_pc = PC(0);
 
   // This is common setup done by __asan::GetStackTrace().
   trace.size = 0;
@@ -57,7 +61,7 @@ TEST_F(FastUnwindTest, Basic) {
   EXPECT_EQ(6U, trace.size);
   EXPECT_EQ(start_pc, trace.trace[0]);
   for (uptr i = 1; i <= 5; i++) {
-    EXPECT_EQ(i*2 - 1, trace.trace[i]);
+    EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
   }
 }
 
@@ -71,8 +75,22 @@ TEST_F(FastUnwindTest, FramePointerLoop)
   EXPECT_EQ(4U, trace.size);
   EXPECT_EQ(start_pc, trace.trace[0]);
   for (uptr i = 1; i <= 3; i++) {
-    EXPECT_EQ(i*2 - 1, trace.trace[i]);
+    EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
   }
 }
 
+TEST_F(FastUnwindTest, MisalignedFramePointer) {
+  // Make one fp misaligned.
+  fake_stack[4] += 3;
+  trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0],
+                        fake_top, fake_bottom);
+  // 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]);
+  for (uptr i = 1; i < 4U; i++) {
+    EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
+  }
+}
+
+
 }  // namespace __sanitizer





More information about the llvm-commits mailing list