[asan] increase the stack size limit to 256M (yes, that happens); also CHECK that the stack size is less than that on a non-main thread

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157249 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc
index fb2e21d..7fa59d8 100644
--- a/lib/asan/asan_linux.cc
+++ b/lib/asan/asan_linux.cc
@@ -39,6 +39,8 @@
 
 namespace __asan {
 
+const size_t kMaxThreadStackSize = 256 * (1 << 20);  // 256M
+
 void *AsanDoesNotSupportStaticLinkage() {
   // This will fail to link with -static.
   return &_DYNAMIC;  // defined in link.h
@@ -294,6 +296,9 @@
     size_t stacksize = rl.rlim_cur;
     if (stacksize > end - prev_end)
       stacksize = end - prev_end;
+    // When running with unlimited stack size, we still want to set some limit.
+    // The unlimited stack size is caused by 'ulimit -s unlimited'.
+    // Also, for some reason, GNU make spawns subrocesses with unlimited stack.
     if (stacksize > kMaxThreadStackSize)
       stacksize = kMaxThreadStackSize;
     stack_top_ = end;
@@ -310,12 +315,7 @@
 
   stack_top_ = (uintptr_t)stackaddr + stacksize;
   stack_bottom_ = (uintptr_t)stackaddr;
-  // When running with unlimited stack size, we still want to set some limit.
-  // The unlimited stack size is caused by 'ulimit -s unlimited'.
-  // Also, for some reason, GNU make spawns subrocesses with unlimited stack.
-  if (stacksize > kMaxThreadStackSize) {
-    stack_bottom_ = stack_top_ - kMaxThreadStackSize;
-  }
+  CHECK(stacksize < kMaxThreadStackSize);  // Sanity check.
   CHECK(AddrIsInStack((uintptr_t)&attr));
 }
 
diff --git a/lib/asan/asan_thread.h b/lib/asan/asan_thread.h
index 09607d9..200d306 100644
--- a/lib/asan/asan_thread.h
+++ b/lib/asan/asan_thread.h
@@ -21,8 +21,6 @@
 
 namespace __asan {
 
-const size_t kMaxThreadStackSize = 16 * (1 << 20);  // 16M
-
 class AsanThread;
 
 // These objects are created for every thread and are never deleted,