[compiler-rt] r333504 - [asan, myriad] Simplify main thread handling

Walter Lee via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 21:57:29 PDT 2018


Author: waltl
Date: Tue May 29 21:57:29 2018
New Revision: 333504

URL: http://llvm.org/viewvc/llvm-project?rev=333504&view=rev
Log:
[asan, myriad] Simplify main thread handling

On Myriad RTEMS, we don't need to treat the main thread differently.
The existing thread hooks will do the right thing, so get rid of all
the unneeded special logic.

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

Modified:
    compiler-rt/trunk/lib/asan/asan_rtems.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.h

Modified: compiler-rt/trunk/lib/asan/asan_rtems.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtems.cc?rev=333504&r1=333503&r2=333504&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtems.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtems.cc Tue May 29 21:57:29 2018
@@ -72,11 +72,6 @@ void EarlyInit() {
   ResetShadowMemory();
 }
 
-// Main thread information.  Initialized in CreateMainThread() and
-// used by ThreadStartHook().
-static uptr MainThreadSelf;
-static AsanThread *MainThread;
-
 // We can use a plain thread_local variable for TSD.
 static thread_local void *per_thread;
 
@@ -134,18 +129,12 @@ void AsanThread::SetThreadStackAndTls(co
   tls_end_ = options->tls_bottom + options->tls_size;
 }
 
-// Called by __asan::AsanInitInternal (asan_rtl.c).
+// Called by __asan::AsanInitInternal (asan_rtl.c).  Unlike other ports, the
+// main thread on RTEMS does not require special treatment; its AsanThread is
+// already created by the provided hooks.  This function simply looks up and
+// returns the created thread.
 AsanThread *CreateMainThread() {
-  CHECK_NE(__sanitizer::MainThreadStackBase, 0);
-  CHECK_GT(__sanitizer::MainThreadStackSize, 0);
-  AsanThread *t = CreateAsanThread(
-      nullptr, 0, GetThreadSelf(), true,
-      __sanitizer::MainThreadStackBase, __sanitizer::MainThreadStackSize,
-      __sanitizer::MainThreadTlsBase, __sanitizer::MainThreadTlsSize);
-  SetCurrentThread(t);
-  MainThreadSelf = pthread_self();
-  MainThread = t;
-  return t;
+  return GetThreadContextByTidLocked(0)->thread;
 }
 
 // This is called before each thread creation is attempted.  So, in
@@ -179,16 +168,14 @@ static void ThreadCreateHook(void *hook,
   }
 }
 
-// This is called (1) in the newly-created thread before it runs
-// anything else, with the pointer returned by BeforeThreadCreateHook
-// (above).  cf. asan_interceptors.cc:asan_thread_start.  (2) before
-// a thread restart.
+// This is called (1) in the newly-created thread before it runs anything else,
+// with the pointer returned by BeforeThreadCreateHook (above).  (2) before a
+// thread restart.
 static void ThreadStartHook(void *hook, uptr os_id) {
-  if (!hook && !MainThreadSelf)
+  if (!hook)
     return;
 
-  DCHECK(hook || os_id == MainThreadSelf);
-  AsanThread *thread = hook ? static_cast<AsanThread *>(hook) : MainThread;
+  AsanThread *thread = static_cast<AsanThread *>(hook);
   SetCurrentThread(thread);
 
   ThreadStatus status =

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc?rev=333504&r1=333503&r2=333504&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc Tue May 29 21:57:29 2018
@@ -275,14 +275,4 @@ uptr MainThreadTlsBase, MainThreadTlsSiz
 
 } // namespace __sanitizer
 
-extern "C" {
-void __sanitizer_startup_hook(void *stack_base, size_t stack_size,
-                              void *tls_base, size_t tls_size) {
-  __sanitizer::MainThreadStackBase = reinterpret_cast<uintptr_t>(stack_base);
-  __sanitizer::MainThreadStackSize = stack_size;
-  __sanitizer::MainThreadTlsBase = reinterpret_cast<uintptr_t>(tls_base);
-  __sanitizer::MainThreadTlsSize = tls_size;
-}
-}  // extern "C"
-
 #endif  // SANITIZER_RTEMS

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.h?rev=333504&r1=333503&r2=333504&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.h Tue May 29 21:57:29 2018
@@ -17,12 +17,5 @@
 #if SANITIZER_RTEMS
 #include "sanitizer_common.h"
 
-namespace __sanitizer {
-
-extern uptr MainThreadStackBase, MainThreadStackSize;
-extern uptr MainThreadTlsBase, MainThreadTlsSize;
-
-}  // namespace __sanitizer
-
 #endif  // SANITIZER_RTEMS
 #endif  // SANITIZER_RTEMS_H




More information about the llvm-commits mailing list