[llvm] [RFC][BOLT] Add a new parallel DWARF processing(2/2) (PR #197859)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 00:46:51 PDT 2026


================
@@ -610,45 +718,146 @@ getDWONameMap(DWARFContext &DwCtx) {
   }
   return DWOIDToNameMap;
 }
-void DWARFRewriter::updateDebugInfo() {
-  ErrorOr<BinarySection &> DebugInfo = BC.getUniqueSectionByName(".debug_info");
-  if (!DebugInfo)
+
+void DWARFRewriter::finalizeSkeletonAndStrSection(
+    DIEBuilder &PartDIEBlder, DWARFUnit &CU,
+    const std::unordered_map<uint64_t, std::string> &DWOToNameMap) {
+  const std::optional<uint64_t> DWOId = CU.getDWOId();
+  std::optional<DWARFUnit *> DWOCU = DWOId ? BC.getDWOCU(*DWOId) : std::nullopt;
+  const bool HasSplitCU = DWOCU && *DWOCU != nullptr;
+  const unsigned Version = CU.getVersion();
+
+  if (HasSplitCU) {
+    auto It = DWOToNameMap.find(*DWOId);
+    if (It != DWOToNameMap.end()) {
+      PartDIEBlder.updateDWONameCompDir(*StrOffstsWriter, *StrWriter, CU,
+                                        opts::DwarfOutputPath,
+                                        StringRef(It->second));
+      if (Version >= 5 && StrOffstsWriter->isStrOffsetsSectionModified())
+        StrOffstsWriter->finalizeSection(CU, PartDIEBlder);
+    }
+    //  split CU were just finalized above when the
+    // .debug_str_offsets section was modified;
     return;
+  }
 
-  ARangesSectionWriter = std::make_unique<DebugARangesSectionWriter>();
-  StrWriter = std::make_unique<DebugStrWriter>(*BC.DwCtx, false);
-  StrOffstsWriter = std::make_unique<DebugStrOffsetsWriter>(BC);
+  if (Version >= 5)
+    StrOffstsWriter->finalizeSection(CU, PartDIEBlder);
+}
 
-  /// Stores and serializes information that will be put into the
-  /// .debug_addr DWARF section.
-  std::unique_ptr<DebugAddrWriter> FinalAddrWriter;
+/// Merge: compute per-CU loclist/legacy-loc bases and in the
+/// same loop apply DWARF5 rnglists/loclists base fixups and legacy
+/// .debug_loc base fixups.
+void DWARFRewriter::mergePerBucketLocsAndRanges(
+    DIEBuilder &PartDIEBlder, BucketLocalWriter &LocalWriters,
+    const std::unordered_map<uint64_t, std::string> &DWOToNameMap,
+    BucketLocAccumOffset &Accum) {
+  const auto &Processed = PartDIEBlder.getProcessedCUs();
+  std::vector<DWARFUnit *> SortedCUs;
+  SortedCUs.assign(Processed.begin(), Processed.end());
+  // Ensure deterministic output by sorting CUs in section offset order.
+  llvm::sort(SortedCUs, [](const DWARFUnit *A, const DWARFUnit *B) {
+    return A->getOffset() < B->getOffset();
+  });
+
+  for (DWARFUnit *CU : SortedCUs) {
+    // record CUs order to make loc/loclist order correct
+    Accum.LocListCUOrder.push_back(CU->getOffset());
+    finalizeSkeletonAndStrSection(PartDIEBlder, *CU, DWOToNameMap);
----------------
Jinjie-Huang wrote:

Why is stringoffset updated during the LocsAndRanges merge process? This seems a bit misleading. `DWOToNameMapWe` will not be needed if we could move this out?

https://github.com/llvm/llvm-project/pull/197859


More information about the llvm-commits mailing list