Index: compiler-rt/lib/xray/xray_profiling.cc =================================================================== --- compiler-rt/lib/xray/xray_profiling.cc +++ compiler-rt/lib/xray/xray_profiling.cc @@ -133,7 +133,7 @@ if (Verbosity()) Report("profiling: No data to flush.\n"); } else { - LogWriter* LW = LogWriter::Open(); + LogWriter *LW = LogWriter::Open(); if (LW == nullptr) { if (Verbosity()) Report("profiling: Failed to flush to file, dropping data.\n"); @@ -227,10 +227,15 @@ // Wait a grace period to allow threads to see that we're finalizing. SleepForMillis(profilingFlags()->grace_period_ms); - // We also want to make sure that the current thread's data is cleaned up, - // if we have any. + // We also want to make sure that the current thread's data is cleaned up, if + // we have any. We need to ensure that the call to postCurrentThreadFCT() is + // guarded by our recursion guard. auto &TLD = getThreadLocalData(); - postCurrentThreadFCT(TLD); + { + RecursionGuard G(ReentranceGuard); + if (G) + postCurrentThreadFCT(TLD); + } // Then we force serialize the log data. profileCollectorService::serialize(); @@ -284,7 +289,13 @@ if (TLD.Allocators == nullptr && TLD.FCT == nullptr) return; - postCurrentThreadFCT(TLD); + { + // If we're somehow executing this while inside a non-reentrant-friendly + // context, we skip attempting to post the current thread's data. + RecursionGuard G(ReentranceGuard); + if (G) + postCurrentThreadFCT(TLD); + } }); // We also need to set up an exit handler, so that we can get the profile