[compiler-rt] r179292 - [asan] improve the UAR reporting (try harder to find the correct frame), try to make the test more stable

Kostya Serebryany kcc at google.com
Thu Apr 11 08:35:41 PDT 2013


Author: kcc
Date: Thu Apr 11 10:35:40 2013
New Revision: 179292

URL: http://llvm.org/viewvc/llvm-project?rev=179292&view=rev
Log:
[asan] improve the UAR reporting (try harder to find the correct frame), try to make the test more stable

Modified:
    compiler-rt/trunk/lib/asan/asan_fake_stack.cc
    compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc

Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.cc?rev=179292&r1=179291&r2=179292&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Thu Apr 11 10:35:40 2013
@@ -30,24 +30,26 @@ bool FakeStack::AddrIsInSizeClass(uptr a
 }
 
 uptr FakeStack::AddrIsInFakeStack(uptr addr) {
-  for (uptr i = 0; i < kNumberOfSizeClasses; i++) {
-    if (AddrIsInSizeClass(addr, i)) return allocated_size_classes_[i];
+  for (uptr size_class = 0; size_class < kNumberOfSizeClasses; size_class++) {
+    if (!AddrIsInSizeClass(addr, size_class)) continue;
+    uptr size_class_first_ptr = allocated_size_classes_[size_class];
+    uptr size = ClassSize(size_class);
+    CHECK_LE(size_class_first_ptr, addr);
+    CHECK_GT(size_class_first_ptr + ClassMmapSize(size_class), addr);
+    return size_class_first_ptr + ((addr - size_class_first_ptr) / size) * size;
   }
   return 0;
 }
 
 // We may want to compute this during compilation.
-inline uptr FakeStack::ComputeSizeClass(uptr alloc_size) {
+ALWAYS_INLINE uptr FakeStack::ComputeSizeClass(uptr alloc_size) {
   uptr rounded_size = RoundUpToPowerOfTwo(alloc_size);
   uptr log = Log2(rounded_size);
-  CHECK(alloc_size <= (1UL << log));
-  if (!(alloc_size > (1UL << (log-1)))) {
-    Printf("alloc_size %zu log %zu\n", alloc_size, log);
-  }
-  CHECK(alloc_size > (1UL << (log-1)));
+  CHECK_LE(alloc_size, (1UL << log));
+  CHECK_GT(alloc_size, (1UL << (log-1)));
   uptr res = log < kMinStackFrameSizeLog ? 0 : log - kMinStackFrameSizeLog;
-  CHECK(res < kNumberOfSizeClasses);
-  CHECK(ClassSize(res) >= rounded_size);
+  CHECK_LT(res, kNumberOfSizeClasses);
+  CHECK_GE(ClassSize(res), rounded_size);
   return res;
 }
 
@@ -115,7 +117,7 @@ void FakeStack::AllocateOneSizeClass(upt
   allocated_size_classes_[size_class] = new_mem;
 }
 
-uptr FakeStack::AllocateStack(uptr size, uptr real_stack) {
+ALWAYS_INLINE uptr FakeStack::AllocateStack(uptr size, uptr real_stack) {
   if (!alive_) return real_stack;
   CHECK(size <= kMaxStackMallocSize && size > 1);
   uptr size_class = ComputeSizeClass(size);
@@ -137,7 +139,7 @@ uptr FakeStack::AllocateStack(uptr size,
   return ptr;
 }
 
-void FakeStack::DeallocateFrame(FakeFrame *fake_frame) {
+ALWAYS_INLINE void FakeStack::DeallocateFrame(FakeFrame *fake_frame) {
   CHECK(alive_);
   uptr size = fake_frame->size_minus_one + 1;
   uptr size_class = ComputeSizeClass(size);
@@ -148,7 +150,7 @@ void FakeStack::DeallocateFrame(FakeFram
   size_classes_[size_class].FifoPush(fake_frame);
 }
 
-void FakeStack::OnFree(uptr ptr, uptr size, uptr real_stack) {
+ALWAYS_INLINE void FakeStack::OnFree(uptr ptr, uptr size, uptr real_stack) {
   FakeFrame *fake_frame = (FakeFrame*)ptr;
   CHECK_EQ(fake_frame->magic, kRetiredStackFrameMagic);
   CHECK_NE(fake_frame->descr, 0);

Modified: compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc?rev=179292&r1=179291&r2=179292&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc Thu Apr 11 10:35:40 2013
@@ -10,7 +10,7 @@
 #include <stdlib.h>
 
 __attribute__((noinline))
-inline char *pretend_to_do_something(char *x) {
+char *pretend_to_do_something(char *x) {
   __asm__ __volatile__("" : : "r" (x) : "memory");
   return x;
 }
@@ -26,19 +26,18 @@ __attribute__((noinline))
 void RecuriveFunctionWithStackFrame(int depth) {
   if (depth <= 0) return;
   char x[1024];
-  memset(x, 0, sizeof(x));
+  x[0] = depth;
   pretend_to_do_something(x);
   RecuriveFunctionWithStackFrame(depth - 1);
-  memset(x, 0, sizeof(x));
 }
 
 int main(int argc, char **argv) {
-  char *stale_stack = LeakStack();
   int n_iter = argc >= 2 ? atoi(argv[1]) : 1000;
-  int depth  = argc >= 3 ? atoi(argv[2]) : 1000;
-  for (int i = 0; i < n_iter; i++) {
+  int depth  = argc >= 3 ? atoi(argv[2]) : 500;
+  for (int i = 0; i < n_iter; i++)
     RecuriveFunctionWithStackFrame(depth);
-  }
+  char *stale_stack = LeakStack();
+  RecuriveFunctionWithStackFrame(10);
   stale_stack[100]++;
   // CHECK: ERROR: AddressSanitizer: stack-use-after-return on address
   // CHECK: is located in stack of thread T0 at offset 132 in frame





More information about the llvm-commits mailing list