[llvm] Fix data race in GSYM converter (PR #225673)

Yuriy Chernyshov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 03:32:25 PDT 2026


https://github.com/georgthegreat created https://github.com/llvm/llvm-project/pull/225673

Found this during https://github.com/yandex/perforator switch to llvm 22.

```
WARNING: ThreadSanitizer: data race (pid=15)
Read of size 8 at 0x7fff520c2f68 by main thread:
  #4 llvm::gsym::OutputAggregator::Report(llvm::StringRef, std::__y1::function<void (llvm::raw_ostream&)>) /-S/contrib/libs/llvm22/include/llvm/DebugInfo/GSYM/OutputAggregator.h:44:5 (race+0x8300fc)
  #5 llvm::gsym::DwarfTransformer::convert(unsigned int, llvm::gsym::OutputAggregator&)::$_0::operator()(llvm::DWARFUnit&) const /-S/perforator/review_15883988/race/DwarfTransformer.cpp:647:13 (race+0x832d51) (BuildId: 04d396fc8733f7b023a1c88367aeee0d88869d6c)
Previous write of size 8 at 0x7fff520c2f68 by thread T3 (mutexes: write M0):
  #5 llvm::gsym::OutputAggregator::Merge(llvm::gsym::OutputAggregator const&) /-S/contrib/libs/llvm22/include/llvm/DebugInfo/GSYM/OutputAggregator.h:71:7 (race+0x840df5)
  #6 llvm::gsym::DwarfTransformer::convert(unsigned int, llvm::gsym::OutputAggregator&)::$_2::operator()() /-S/perforator/review_15883988/race/DwarfTransformer.cpp:706:15 (race+0x840df5)
```

>From 0c1742f383ee4fe8161c839f0b2b51a7787ec6dc Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov <thegeorg at yandex-team.com>
Date: Wed, 23 Sep 2026 13:29:21 +0300
Subject: [PATCH] Fix data race in GSYM converter

Found this during https://github.com/yandex/perforator switch to llvm 22.

```
WARNING: ThreadSanitizer: data race (pid=15)
Read of size 8 at 0x7fff520c2f68 by main thread:
  #4 llvm::gsym::OutputAggregator::Report(llvm::StringRef, std::__y1::function<void (llvm::raw_ostream&)>) /-S/contrib/libs/llvm22/include/llvm/DebugInfo/GSYM/OutputAggregator.h:44:5 (race+0x8300fc)
  #5 llvm::gsym::DwarfTransformer::convert(unsigned int, llvm::gsym::OutputAggregator&)::$_0::operator()(llvm::DWARFUnit&) const /-S/perforator/review_15883988/race/DwarfTransformer.cpp:647:13 (race+0x832d51) (BuildId: 04d396fc8733f7b023a1c88367aeee0d88869d6c)
Previous write of size 8 at 0x7fff520c2f68 by thread T3 (mutexes: write M0):
  #5 llvm::gsym::OutputAggregator::Merge(llvm::gsym::OutputAggregator const&) /-S/contrib/libs/llvm22/include/llvm/DebugInfo/GSYM/OutputAggregator.h:71:7 (race+0x840df5)
  #6 llvm::gsym::DwarfTransformer::convert(unsigned int, llvm::gsym::OutputAggregator&)::$_2::operator()() /-S/perforator/review_15883988/race/DwarfTransformer.cpp:706:15 (race+0x840df5)
```
---
 llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
index 4790cd10269454..b274950f83bf44 100644
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -703,7 +703,11 @@ Error DwarfTransformer::convert(uint32_t NumThreads, OutputAggregator &Out) {
     // Now convert all DWARF to GSYM in a thread pool.
     std::mutex LogMutex;
     for (const auto &CU : DICtx.compile_units()) {
-      DWARFDie Die = getDie(*CU);
+      DWARFDie Die;
+      {
+        std::lock_guard<std::mutex> Guard(LogMutex);
+        Die = getDie(*CU);
+      }
       if (Die) {
         CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(CU.get()));
         pool.async([this, CUI, &LogMutex, &Out, Die]() mutable {



More information about the llvm-commits mailing list