[compiler-rt] r197370 - [asan] replace the flag uar_stack_size_log with two flags min_uar_stack_size_log/max_uar_stack_size_log

Kostya Serebryany kcc at google.com
Mon Dec 16 00:42:08 PST 2013


Author: kcc
Date: Mon Dec 16 02:42:08 2013
New Revision: 197370

URL: http://llvm.org/viewvc/llvm-project?rev=197370&view=rev
Log:
[asan] replace the flag uar_stack_size_log with two flags min_uar_stack_size_log/max_uar_stack_size_log

Modified:
    compiler-rt/trunk/lib/asan/asan_fake_stack.cc
    compiler-rt/trunk/lib/asan/asan_flags.h
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/asan_thread.cc
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.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=197370&r1=197369&r2=197370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Mon Dec 16 02:42:08 2013
@@ -49,10 +49,10 @@ FakeStack *FakeStack::Create(uptr stack_
   res->stack_size_log_ = stack_size_log;
   u8 *p = reinterpret_cast<u8 *>(res);
   VReport(1, "T%d: FakeStack created: %p -- %p stack_size_log: %zd; "
-          "noreserve=%d \n",
+          "mmapped %zdK, noreserve=%d \n",
           GetCurrentTidOrInvalid(), p,
           p + FakeStack::RequiredSize(stack_size_log), stack_size_log,
-          flags()->uar_noreserve);
+          size >> 10, flags()->uar_noreserve);
   return res;
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.h?rev=197370&r1=197369&r2=197370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.h (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.h Mon Dec 16 02:42:08 2013
@@ -52,8 +52,9 @@ struct Flags {
   bool mac_ignore_invalid_free;
   // Enables stack-use-after-return checking at run-time.
   bool detect_stack_use_after_return;
-  // The minimal fake stack size log.
-  int uar_stack_size_log;
+  // The minimal and the maximal fake stack size log.
+  int min_uar_stack_size_log;
+  int max_uar_stack_size_log;
   // Use mmap with 'norserve' flag to allocate fake stack.
   bool uar_noreserve;
   // ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=197370&r1=197369&r2=197370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Dec 16 02:42:08 2013
@@ -108,7 +108,8 @@ static void ParseFlagsFromString(Flags *
   ParseFlag(str, &f->mac_ignore_invalid_free, "mac_ignore_invalid_free");
   ParseFlag(str, &f->detect_stack_use_after_return,
             "detect_stack_use_after_return");
-  ParseFlag(str, &f->uar_stack_size_log, "uar_stack_size_log");
+  ParseFlag(str, &f->min_uar_stack_size_log, "min_uar_stack_size_log");
+  ParseFlag(str, &f->max_uar_stack_size_log, "max_uar_stack_size_log");
   ParseFlag(str, &f->uar_noreserve, "uar_noreserve");
   ParseFlag(str, &f->max_malloc_fill_size, "max_malloc_fill_size");
   ParseFlag(str, &f->malloc_fill_byte, "malloc_fill_byte");
@@ -151,7 +152,8 @@ void InitializeFlags(Flags *f, const cha
   f->replace_intrin = true;
   f->mac_ignore_invalid_free = false;
   f->detect_stack_use_after_return = false;  // Also needs the compiler flag.
-  f->uar_stack_size_log = 0;
+  f->min_uar_stack_size_log = 16;  // We can't do smaller anyway.
+  f->max_uar_stack_size_log = 20;  // 1Mb per size class, i.e. ~11Mb per thread.
   f->uar_noreserve = false;
   f->max_malloc_fill_size = 0x1000;  // By default, fill only the first 4K.
   f->malloc_fill_byte = 0xbe;
@@ -459,6 +461,7 @@ void __asan_init() {
   __sanitizer_set_report_path(common_flags()->log_path);
   __asan_option_detect_stack_use_after_return =
       flags()->detect_stack_use_after_return;
+  CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
 
   if (options) {
     VReport(1, "Parsed ASAN_OPTIONS: %s\n", options);

Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=197370&r1=197369&r2=197370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Mon Dec 16 02:42:08 2013
@@ -126,8 +126,11 @@ FakeStack *AsanThread::AsyncSignalSafeLa
       reinterpret_cast<atomic_uintptr_t *>(&fake_stack_), &old_val, 1UL,
       memory_order_relaxed)) {
     uptr stack_size_log = Log2(RoundUpToPowerOfTwo(stack_size));
-    if (flags()->uar_stack_size_log)
-      stack_size_log = static_cast<uptr>(flags()->uar_stack_size_log);
+    CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
+    stack_size_log =
+        Min(stack_size_log, static_cast<uptr>(flags()->max_uar_stack_size_log));
+    stack_size_log =
+        Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
     fake_stack_ = FakeStack::Create(stack_size_log);
     SetTLSFakeStack(fake_stack_);
     return fake_stack_;

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc?rev=197370&r1=197369&r2=197370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc Mon Dec 16 02:42:08 2013
@@ -16,10 +16,10 @@
 // RUN: %clangxx_asan  -DUseThread -O2 %s -o %t && \
 // RUN:   not %t 2>&1 | FileCheck --check-prefix=THREAD %s
 //
-// Test the uar_stack_size_log flag.
+// Test the max_uar_stack_size_log/min_uar_stack_size_log flag.
 //
-// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:uar_stack_size_log=20:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s
-// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:uar_stack_size_log=24:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s
+// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:max_uar_stack_size_log=20:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s
+// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:min_uar_stack_size_log=24:max_uar_stack_size_log=28:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s
 
 #include <stdio.h>
 #include <pthread.h>





More information about the llvm-commits mailing list