Recently the GCD tests started failing because of the invalid size of
FakeStack on the worker threads.
This patch moves the AsanThread initialization into a separate
procedure that's called when AsanThread objects are called for worker
threads.
Patch by glider@google.com



git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@146752 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc
index af4d95e..43e8c00 100644
--- a/lib/asan/asan_mac.cc
+++ b/lib/asan/asan_mac.cc
@@ -106,6 +106,7 @@
     t = (AsanThread*)asan_malloc(sizeof(AsanThread), &stack);
     new(t) AsanThread(context->parent_tid,
                       /*start_routine*/NULL, /*arg*/NULL, &stack);
+    t->Init();
     asanThreadRegistry().SetCurrent(t);
   }
   // Call the original dispatcher for the block.
diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc
index 27fa2fe..a71ad8d 100644
--- a/lib/asan/asan_thread.cc
+++ b/lib/asan/asan_thread.cc
@@ -51,7 +51,7 @@
   real_memset((void*)shadow_bot, 0, shadow_top - shadow_bot);
 }
 
-void *AsanThread::ThreadStart() {
+void AsanThread::Init() {
   SetThreadStackTopAndBottom();
   fake_stack_.Init(stack_size());
   if (FLAG_v >= 1) {
@@ -65,6 +65,10 @@
   CHECK(AddrIsInMem(stack_top_));
 
   ClearShadowForThreadStack();
+}
+
+void *AsanThread::ThreadStart() {
+  Init();
 
   if (!start_routine_) {
     // start_routine_ == NULL if we're on the main thread or on one of the
diff --git a/lib/asan/asan_thread.h b/lib/asan/asan_thread.h
index 2e68b0d..c382c85 100644
--- a/lib/asan/asan_thread.h
+++ b/lib/asan/asan_thread.h
@@ -66,6 +66,7 @@
              void *arg, AsanStackTrace *stack);
   ~AsanThread();
 
+  void Init();  // Should be called from the thread itself.
   void *ThreadStart();
 
   uintptr_t stack_top() { return stack_top_; }