diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.h b/compiler-rt/lib/tsan/rtl/tsan_interceptors.h --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.h +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.h @@ -36,10 +36,25 @@ } #endif +ALWAYS_INLINE +ThreadState *cur_thread_init_maybe() { +#if SANITIZER_LINUX && !SANITIZER_ANDROID && defined(__x86_64__) + // On Linux we always have cur_thread initialized + // when we reach any interceptor. The main thread + // is initialized from .preinit_array, and other + // threads are initialized from _setjmp interceptor + // called from within pthread guts. + DCHECK(cur_thread()); + return cur_thread(); +#else + return cur_thread_init(); +#endif +} + } // namespace __tsan #define SCOPED_INTERCEPTOR_RAW(func, ...) \ - ThreadState *thr = cur_thread_init(); \ + ThreadState *thr = cur_thread_init_maybe(); \ const uptr caller_pc = GET_CALLER_PC(); \ ScopedInterceptor si(thr, #func, caller_pc); \ const uptr pc = GET_CURRENT_PC(); \