Index: llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp +++ llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp @@ -180,6 +180,15 @@ #endif }; +/// The struct represents a compile unit reference to be emitted by +/// Dwarf5AccelTableWriter. It either contains LabelBegin of the CU and a zero +/// offset or BeginSymbol of the debug info section and the offset in the +/// section if a distinct label is not defined. +struct CUReference { + MCSymbol *Label; + uint64_t Offset; +}; + /// Class responsible for emitting a DWARF v5 Accelerator Table. The only /// public function is emit(), which performs the actual emission. /// @@ -214,7 +223,7 @@ Header Header; DenseMap> Abbreviations; - ArrayRef CompUnits; + ArrayRef CompUnits; llvm::function_ref getCUIndexForEntry; MCSymbol *ContributionEnd = nullptr; MCSymbol *AbbrevStart = Asm->createTempSymbol("names_abbrev_start"); @@ -236,7 +245,7 @@ public: Dwarf5AccelTableWriter( AsmPrinter *Asm, const AccelTableBase &Contents, - ArrayRef CompUnits, + ArrayRef CompUnits, llvm::function_ref GetCUIndexForEntry); void emit(); @@ -420,7 +429,10 @@ void Dwarf5AccelTableWriter::emitCUList() const { for (const auto &CU : enumerate(CompUnits)) { Asm->OutStreamer->AddComment("Compilation unit " + Twine(CU.index())); - Asm->emitDwarfSymbolReference(CU.value()); + if (CU.value().Offset) + Asm->emitDwarfOffset(CU.value().Label, CU.value().Offset); + else + Asm->emitDwarfSymbolReference(CU.value().Label); } } @@ -509,7 +521,7 @@ template Dwarf5AccelTableWriter::Dwarf5AccelTableWriter( AsmPrinter *Asm, const AccelTableBase &Contents, - ArrayRef CompUnits, + ArrayRef CompUnits, llvm::function_ref getCUIndexForEntry) : AccelTableWriter(Asm, Contents, false), Header(CompUnits.size(), Contents.getBucketCount(), @@ -546,7 +558,7 @@ void llvm::emitDWARF5AccelTable( AsmPrinter *Asm, AccelTable &Contents, const DwarfDebug &DD, ArrayRef> CUs) { - std::vector CompUnits; + std::vector CompUnits; SmallVector CUIndex(CUs.size()); int Count = 0; for (const auto &CU : enumerate(CUs)) { @@ -557,7 +569,11 @@ assert(CU.index() == CU.value()->getUniqueID()); const DwarfCompileUnit *MainCU = DD.useSplitDwarf() ? CU.value()->getSkeleton() : CU.value().get(); - CompUnits.push_back(MainCU->getLabelBegin()); + if (DD.useSectionsAsReferences()) + CompUnits.push_back({MainCU->getSection()->getBeginSymbol(), + MainCU->getDebugSectionOffset()}); + else + CompUnits.push_back({MainCU->getLabelBegin(), 0}); } if (CompUnits.empty()) @@ -582,7 +598,11 @@ llvm::function_ref getCUIndexForEntry) { Contents.finalize(Asm, "names"); - Dwarf5AccelTableWriter(Asm, Contents, CUs, + std::vector CompUnits; + CompUnits.reserve(CUs.size()); + for (auto *Label : CUs) + CompUnits.push_back({Label, 0}); + Dwarf5AccelTableWriter(Asm, Contents, CompUnits, getCUIndexForEntry) .emit(); } Index: llvm/test/DebugInfo/X86/sections-as-references-dwarf5-accel-tables.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/sections-as-references-dwarf5-accel-tables.ll @@ -0,0 +1,29 @@ +; Test that DWARFv5 accelerator tables can be emitted when +; -dwarf-sections-as-references=Enable is specified. + +; RUN: llc -filetype=asm -mtriple=x86_64-linux-gnu -accel-tables=Dwarf \ +; RUN: -dwarf-sections-as-references=Enable < %s | FileCheck %s + +; CHECK: .section .debug_names, +; CHECK-NOT: .section +; CHECK: .long .debug_info # Compilation unit 0 +; CHECK-NEXT: .long .debug_info+[[#]] # Compilation unit 1 + +%struct.foo = type { i8 } + +@f = global %struct.foo zeroinitializer, align 1, !dbg !0 + +!llvm.dbg.cu = !{!6, !7} +!llvm.module.flags = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = !DIGlobalVariable(name: "f", scope: null, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true) +!2 = !DIFile(filename: "tu.h", directory: "/dir") +!3 = !DIFile(filename: "tu.cpp", directory: "/dir") +!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !2, line: 1, size: 8, align: 8, elements: !5, identifier: "_ZTS3foo") +!5 = !{} +!6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !8, imports: !5) +!7 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, globals: !9, imports: !5) +!8 = !{!4} +!9 = !{!0} +!10 = !{i32 1, !"Debug Info Version", i32 3}