Index: compiler-rt/lib/asan/asan_rtems.cc =================================================================== --- compiler-rt/lib/asan/asan_rtems.cc +++ compiler-rt/lib/asan/asan_rtems.cc @@ -72,11 +72,6 @@ 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 @@ 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 @@ } } -// 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(hook) : MainThread; + AsanThread *thread = static_cast(hook); SetCurrentThread(thread); ThreadStatus status = Index: compiler-rt/lib/sanitizer_common/sanitizer_rtems.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_rtems.h +++ compiler-rt/lib/sanitizer_common/sanitizer_rtems.h @@ -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 Index: compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc +++ compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc @@ -275,14 +275,4 @@ } // 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(stack_base); - __sanitizer::MainThreadStackSize = stack_size; - __sanitizer::MainThreadTlsBase = reinterpret_cast(tls_base); - __sanitizer::MainThreadTlsSize = tls_size; -} -} // extern "C" - #endif // SANITIZER_RTEMS