[asan] Initialize fake stack during thread init
authorWalter Lee <waltl@google.com>
Thu, 10 May 2018 20:09:03 +0000 (20:09 +0000)
committerWalter Lee <waltl@google.com>
Thu, 10 May 2018 20:09:03 +0000 (20:09 +0000)
If detect-stack-use-after-return is on, initialize fake stack during
AsanThread::Init(), rather than lazily.  This is required on Myriad.
From kcc: "There used to be a reason why this was done lazily, but I
don't remember if we still have that reason."  Tested on x86.

Differential Revision: https://reviews.llvm.org/D46626

llvm-svn: 332033

compiler-rt/lib/asan/asan_thread.cc
compiler-rt/lib/asan/asan_thread.h

index 4a8779f..b6ca1df 100644 (file)
@@ -221,13 +221,15 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
 void AsanThread::Init(const InitOptions *options) {
   next_stack_top_ = next_stack_bottom_ = 0;
   atomic_store(&stack_switching_, false, memory_order_release);
-  fake_stack_ = nullptr;  // Will be initialized lazily if needed.
   CHECK_EQ(this->stack_size(), 0U);
   SetThreadStackAndTls(options);
   CHECK_GT(this->stack_size(), 0U);
   CHECK(AddrIsInMem(stack_bottom_));
   CHECK(AddrIsInMem(stack_top_ - 1));
   ClearShadowForThreadStackAndTLS();
+  fake_stack_ = nullptr;
+  if (__asan_option_detect_stack_use_after_return)
+    AsyncSignalSafeLazyInitFakeStack();
   int local = 0;
   VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(),
           (void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_,
index 6609192..a3052ec 100644 (file)
@@ -117,8 +117,6 @@ class AsanThread {
       return nullptr;
     if (atomic_load(&stack_switching_, memory_order_relaxed))
       return nullptr;
-    if (!has_fake_stack())
-      return AsyncSignalSafeLazyInitFakeStack();
     return fake_stack_;
   }