diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp @@ -138,6 +138,8 @@ creation_stack_id = CurrentStackId(args->thr, args->pc); } +extern "C" void __tsan_stack_initialization() {} + struct OnStartedArgs { ThreadState *thr; uptr stk_addr; @@ -173,9 +175,15 @@ #endif #if !SANITIZER_GO + // Don't imitate stack/TLS writes for the main thread, + // because its initialization is synchronized with all + // subsequent threads anyway. if (tid != kMainTid) { - if (stk_addr && stk_size) - MemoryRangeImitateWrite(thr, /*pc=*/1, stk_addr, stk_size); + if (stk_addr && stk_size) { + const uptr pc = StackTrace::GetNextInstructionPc( + reinterpret_cast(__tsan_stack_initialization)); + MemoryRangeImitateWrite(thr, pc, stk_addr, stk_size); + } if (tls_addr && tls_size) ImitateTlsWrite(thr, tls_addr, tls_size);