@@ -185,6 +185,7 @@ namespace bolt {
185185class DIEStreamer : public DwarfStreamer {
186186 DIEBuilder *DIEBldr;
187187 DWARFRewriter &Rewriter;
188+ GDBIndex &GDBIndexSection;
188189
189190private:
190191 // / Emit the compilation unit header for \p Unit in the debug_info
@@ -247,7 +248,7 @@ class DIEStreamer : public DwarfStreamer {
247248 const uint64_t TypeSignature = cast<DWARFTypeUnit>(Unit).getTypeHash ();
248249 DIE *TypeDIE = DIEBldr->getTypeDIE (Unit);
249250 const DIEBuilder::DWARFUnitInfo &UI = DIEBldr->getUnitInfoByDwarfUnit (Unit);
250- Rewriter .addGDBTypeUnitEntry (
251+ GDBIndexSection .addGDBTypeUnitEntry (
251252 {UI.UnitOffset , TypeSignature, TypeDIE->getOffset ()});
252253 if (Unit.getVersion () < 5 ) {
253254 // Switch the section to .debug_types section.
@@ -279,11 +280,12 @@ class DIEStreamer : public DwarfStreamer {
279280
280281public:
281282 DIEStreamer (DIEBuilder *DIEBldr, DWARFRewriter &Rewriter,
283+ GDBIndex &GDBIndexSection,
282284 DWARFLinkerBase::OutputFileType OutFileType,
283285 raw_pwrite_stream &OutFile,
284286 DWARFLinkerBase::MessageHandlerTy Warning)
285287 : DwarfStreamer(OutFileType, OutFile, Warning), DIEBldr(DIEBldr),
286- Rewriter (Rewriter){};
288+ Rewriter (Rewriter), GDBIndexSection(GDBIndexSection) {};
287289
288290 using DwarfStreamer::emitCompileUnitHeader;
289291
@@ -326,12 +328,11 @@ static cl::opt<bool> KeepARanges(
326328 " keep or generate .debug_aranges section if .gdb_index is written" ),
327329 cl::Hidden, cl::cat(BoltCategory));
328330
329- static cl::opt<bool >
330- DeterministicDebugInfo (" deterministic-debuginfo" ,
331- cl::desc (" disables parallel execution of tasks that may produce "
332- " nondeterministic debug info" ),
333- cl::init(true ),
334- cl::cat(BoltCategory));
331+ static cl::opt<bool > DeterministicDebugInfo (
332+ " deterministic-debuginfo" ,
333+ cl::desc (" disables parallel execution of tasks that may produce "
334+ " nondeterministic debug info" ),
335+ cl::init(true ), cl::cat(BoltCategory));
335336
336337static cl::opt<std::string> DwarfOutputPath (
337338 " dwarf-output-path" ,
@@ -460,10 +461,11 @@ static std::optional<uint64_t> getAsAddress(const DWARFUnit &DU,
460461static std::unique_ptr<DIEStreamer>
461462createDIEStreamer (const Triple &TheTriple, raw_pwrite_stream &OutFile,
462463 StringRef Swift5ReflectionSegmentName, DIEBuilder &DIEBldr,
463- DWARFRewriter &Rewriter) {
464+ DWARFRewriter &Rewriter, GDBIndex &GDBIndexSection ) {
464465
465466 std::unique_ptr<DIEStreamer> Streamer = std::make_unique<DIEStreamer>(
466- &DIEBldr, Rewriter, DWARFLinkerBase::OutputFileType::Object, OutFile,
467+ &DIEBldr, Rewriter, GDBIndexSection,
468+ DWARFLinkerBase::OutputFileType::Object, OutFile,
467469 [&](const Twine &Warning, StringRef Context, const DWARFDie *) {});
468470 Error Err = Streamer->init (TheTriple, Swift5ReflectionSegmentName);
469471 if (Err)
@@ -484,13 +486,12 @@ emitUnit(DIEBuilder &DIEBldr, DIEStreamer &Streamer, DWARFUnit &Unit) {
484486 return {U.UnitOffset , U.UnitLength , TypeHash};
485487}
486488
487- static void emitDWOBuilder (const std::string &DWOName,
488- DIEBuilder &DWODIEBuilder, DWARFRewriter &Rewriter,
489- DWARFUnit &SplitCU, DWARFUnit &CU,
490- DWARFRewriter::DWPState &State,
491- DebugLocWriter &LocWriter,
492- DebugStrOffsetsWriter &StrOffstsWriter,
493- DebugStrWriter &StrWriter) {
489+ static void
490+ emitDWOBuilder (const std::string &DWOName, DIEBuilder &DWODIEBuilder,
491+ DWARFRewriter &Rewriter, DWARFUnit &SplitCU, DWARFUnit &CU,
492+ DWARFRewriter::DWPState &State, DebugLocWriter &LocWriter,
493+ DebugStrOffsetsWriter &StrOffstsWriter,
494+ DebugStrWriter &StrWriter, GDBIndex &GDBIndexSection) {
494495 // Populate debug_info and debug_abbrev for current dwo into StringRef.
495496 DWODIEBuilder.generateAbbrevs ();
496497 DWODIEBuilder.finish ();
@@ -500,8 +501,9 @@ static void emitDWOBuilder(const std::string &DWOName,
500501 std::make_shared<raw_svector_ostream>(OutBuffer);
501502 const object::ObjectFile *File = SplitCU.getContext ().getDWARFObj ().getFile ();
502503 auto TheTriple = std::make_unique<Triple>(File->makeTriple ());
503- std::unique_ptr<DIEStreamer> Streamer = createDIEStreamer (
504- *TheTriple, *ObjOS, " DwoStreamerInitAug2" , DWODIEBuilder, Rewriter);
504+ std::unique_ptr<DIEStreamer> Streamer =
505+ createDIEStreamer (*TheTriple, *ObjOS, " DwoStreamerInitAug2" ,
506+ DWODIEBuilder, Rewriter, GDBIndexSection);
505507 DWARFRewriter::UnitMetaVectorType TUMetaVector;
506508 DWARFRewriter::UnitMeta CUMI = {0 , 0 , 0 };
507509 if (SplitCU.getContext ().getMaxDWOVersion () >= 5 ) {
@@ -652,6 +654,7 @@ void DWARFRewriter::updateDebugInfo() {
652654
653655 DWARF5AcceleratorTable DebugNamesTable (opts::CreateDebugNames, BC,
654656 *StrWriter);
657+ GDBIndex GDBIndexSection (BC);
655658 DWPState State;
656659 if (opts::WriteDWP)
657660 initDWPState (State);
@@ -704,7 +707,8 @@ void DWARFRewriter::updateDebugInfo() {
704707 TempRangesSectionWriter->finalizeSection ();
705708
706709 emitDWOBuilder (DWOName, DWODIEBuilder, *this , **SplitCU, *Unit, State,
707- DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter);
710+ DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
711+ GDBIndexSection);
708712 }
709713
710714 if (Unit->getVersion () >= 5 ) {
@@ -729,9 +733,10 @@ void DWARFRewriter::updateDebugInfo() {
729733 std::make_unique<raw_svector_ostream>(OutBuffer);
730734 const object::ObjectFile *File = BC.DwCtx ->getDWARFObj ().getFile ();
731735 auto TheTriple = std::make_unique<Triple>(File->makeTriple ());
732- std::unique_ptr<DIEStreamer> Streamer =
733- createDIEStreamer (*TheTriple, *ObjOS, " TypeStreamer" , DIEBlder, *this );
734- CUOffsetMap OffsetMap = finalizeTypeSections (DIEBlder, *Streamer);
736+ std::unique_ptr<DIEStreamer> Streamer = createDIEStreamer (
737+ *TheTriple, *ObjOS, " TypeStreamer" , DIEBlder, *this , GDBIndexSection);
738+ CUOffsetMap OffsetMap =
739+ finalizeTypeSections (DIEBlder, *Streamer, GDBIndexSection);
735740
736741 const bool SingleThreadedMode =
737742 opts::NoThreads || opts::DeterministicDebugInfo;
@@ -761,7 +766,8 @@ void DWARFRewriter::updateDebugInfo() {
761766
762767 finalizeDebugSections (DIEBlder, DebugNamesTable, *Streamer, *ObjOS,
763768 OffsetMap);
764- updateGdbIndexSection (OffsetMap, CUIndex);
769+ GDBIndexSection.updateGdbIndexSection (OffsetMap, CUIndex,
770+ *ARangesSectionWriter);
765771}
766772
767773void DWARFRewriter::updateUnitDebugInfo (
@@ -1429,7 +1435,8 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) {
14291435}
14301436
14311437CUOffsetMap DWARFRewriter::finalizeTypeSections (DIEBuilder &DIEBlder,
1432- DIEStreamer &Streamer) {
1438+ DIEStreamer &Streamer,
1439+ GDBIndex &GDBIndexSection) {
14331440 // update TypeUnit DW_AT_stmt_list with new .debug_line information.
14341441 auto updateLineTable = [&](const DWARFUnit &Unit) -> void {
14351442 DIE *UnitDIE = DIEBlder.getUnitDIEbyUnit (Unit);
@@ -1449,8 +1456,8 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
14491456 std::make_shared<raw_svector_ostream>(OutBuffer);
14501457 const object::ObjectFile *File = BC.DwCtx ->getDWARFObj ().getFile ();
14511458 auto TheTriple = std::make_unique<Triple>(File->makeTriple ());
1452- std::unique_ptr<DIEStreamer> TypeStreamer =
1453- createDIEStreamer ( *TheTriple, *ObjOS, " TypeStreamer" , DIEBlder, *this );
1459+ std::unique_ptr<DIEStreamer> TypeStreamer = createDIEStreamer (
1460+ *TheTriple, *ObjOS, " TypeStreamer" , DIEBlder, *this , GDBIndexSection );
14541461
14551462 // generate debug_info and CUMap
14561463 CUOffsetMap CUMap;
0 commit comments