Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -253,6 +253,7 @@ SmallVector< std::pair, const DICompositeType *>, 1> TypeUnitsUnderConstruction; + SmallVector, 1> TypeUnitsToEmit; /// Whether to use the GNU TLS opcode (instead of the standard opcode). bool UseGNUTLSOpcode; @@ -350,6 +351,10 @@ /// Emit the debug info section. void emitDebugInfo(); + /// Emit the debug type units. They might go various places, depending on + /// the DWARF version and whether we're doing split DWARF. + void emitDebugTypes(); + /// Emit the abbreviation section. void emitAbbreviations(); Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -841,6 +841,9 @@ AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection()); } + // Emit the type units, whereever they are supposed to go. + emitDebugTypes(); + // Emit info into the dwarf accelerator table sections. switch (getAccelTableKind()) { case AccelTableKind::Apple: @@ -1445,6 +1448,12 @@ Holder.emitUnits(/* UseOffsets */ false); } +// Emit the type units. +void DwarfDebug::emitDebugTypes() { + for (auto &TU : TypeUnitsToEmit) + InfoHolder.emitUnit(TU.get(), useSplitDwarf()); +} + // Emit the abbreviation section. void DwarfDebug::emitAbbreviations() { DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder; @@ -2261,7 +2270,7 @@ // and all its dependent types. for (auto &TU : TypeUnitsToAdd) { InfoHolder.computeSizeAndOffsetsForUnit(TU.first.get()); - InfoHolder.emitUnit(TU.first.get(), useSplitDwarf()); + TypeUnitsToEmit.emplace_back(std::move(TU.first)); } } CU.addDIETypeSignature(RefDie, Signature);