diff --git a/llvm/include/llvm/CodeGen/AccelTable.h b/llvm/include/llvm/CodeGen/AccelTable.h index 6a69a01a8c786..0f35fd3514fae 100644 --- a/llvm/include/llvm/CodeGen/AccelTable.h +++ b/llvm/include/llvm/CodeGen/AccelTable.h @@ -297,15 +297,15 @@ class DWARF5AccelTableData : public AccelTableData { }; struct TypeUnitMetaInfo { - // Symbol for start of the TU section. - MCSymbol *Label; + // Symbol for start of the TU section or signature if this is SplitDwarf. + std::variant LabelOrSignature; // Unique ID of Type Unit. unsigned UniqueID; }; using TUVectorTy = SmallVector; class DWARF5AccelTable : public AccelTable { // Symbols to start of all the TU sections that were generated. - TUVectorTy TUSymbols; + TUVectorTy TUSymbolsOrHashes; public: struct UnitIndexAndEncoding { @@ -313,9 +313,11 @@ class DWARF5AccelTable : public AccelTable { DWARF5AccelTableData::AttributeEncoding Endoding; }; /// Returns type units that were constructed. - const TUVectorTy &getTypeUnitsSymbols() { return TUSymbols; } + const TUVectorTy &getTypeUnitsSymbols() { return TUSymbolsOrHashes; } /// Add a type unit start symbol. void addTypeUnitSymbol(DwarfTypeUnit &U); + /// Add a type unit Signature. + void addTypeUnitSignature(DwarfTypeUnit &U); /// Convert DIE entries to explicit offset. /// Needs to be called after DIE offsets are computed. void convertDieToOffset() { diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp index 60c54687c9666..d6f487c18b030 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp @@ -201,9 +201,11 @@ class Dwarf5AccelTableWriter : public AccelTableWriter { char AugmentationString[8] = {'L', 'L', 'V', 'M', '0', '7', '0', '0'}; Header(uint32_t CompUnitCount, uint32_t LocalTypeUnitCount, - uint32_t BucketCount, uint32_t NameCount) + uint32_t ForeignTypeUnitCount, uint32_t BucketCount, + uint32_t NameCount) : CompUnitCount(CompUnitCount), LocalTypeUnitCount(LocalTypeUnitCount), - BucketCount(BucketCount), NameCount(NameCount) {} + ForeignTypeUnitCount(ForeignTypeUnitCount), BucketCount(BucketCount), + NameCount(NameCount) {} void emit(Dwarf5AccelTableWriter &Ctx); }; @@ -220,6 +222,8 @@ class Dwarf5AccelTableWriter : public AccelTableWriter { MCSymbol *AbbrevStart = Asm->createTempSymbol("names_abbrev_start"); MCSymbol *AbbrevEnd = Asm->createTempSymbol("names_abbrev_end"); MCSymbol *EntryPool = Asm->createTempSymbol("names_entries"); + // Indicates if this module is built with Split Dwarf enabled. + bool IsSplitDwarf = false; void populateAbbrevsMap(); @@ -238,7 +242,8 @@ class Dwarf5AccelTableWriter : public AccelTableWriter { ArrayRef> TypeUnits, llvm::function_ref< std::optional(const DataT &)> - getIndexForEntry); + getIndexForEntry, + bool IsSplitDwarf); void emit(); }; @@ -450,6 +455,8 @@ void Dwarf5AccelTableWriter::emitTUList() const { Asm->OutStreamer->AddComment("Type unit " + Twine(TU.index())); if (std::holds_alternative(TU.value())) Asm->emitDwarfSymbolReference(std::get(TU.value())); + else if (IsSplitDwarf) + Asm->emitInt64(std::get(TU.value())); else Asm->emitDwarfLengthOrOffset(std::get(TU.value())); } @@ -551,12 +558,15 @@ Dwarf5AccelTableWriter::Dwarf5AccelTableWriter( ArrayRef> TypeUnits, llvm::function_ref< std::optional(const DataT &)> - getIndexForEntry) + getIndexForEntry, + bool IsSplitDwarf) : AccelTableWriter(Asm, Contents, false), - Header(CompUnits.size(), TypeUnits.size(), Contents.getBucketCount(), + Header(CompUnits.size(), IsSplitDwarf ? 0 : TypeUnits.size(), + IsSplitDwarf ? TypeUnits.size() : 0, Contents.getBucketCount(), Contents.getUniqueNameCount()), CompUnits(CompUnits), TypeUnits(TypeUnits), - getIndexForEntry(std::move(getIndexForEntry)) { + getIndexForEntry(std::move(getIndexForEntry)), + IsSplitDwarf(IsSplitDwarf) { populateAbbrevsMap(); } @@ -608,7 +618,10 @@ void llvm::emitDWARF5AccelTable( for (const auto &TU : TUSymbols) { TUIndex[TU.UniqueID] = TUCount++; - TypeUnits.push_back(TU.Label); + if (DD.useSplitDwarf()) + TypeUnits.push_back(std::get(TU.LabelOrSignature)); + else + TypeUnits.push_back(std::get(TU.LabelOrSignature)); } if (CompUnits.empty()) @@ -633,12 +646,17 @@ void llvm::emitDWARF5AccelTable( return {{CUIndex[Entry.getUnitID()], {dwarf::DW_IDX_compile_unit, CUIndexForm}}}; return std::nullopt; - }) + }, + DD.useSplitDwarf()) .emit(); } void DWARF5AccelTable::addTypeUnitSymbol(DwarfTypeUnit &U) { - TUSymbols.push_back({U.getLabelBegin(), U.getUniqueID()}); + TUSymbolsOrHashes.push_back({U.getLabelBegin(), U.getUniqueID()}); +} + +void DWARF5AccelTable::addTypeUnitSignature(DwarfTypeUnit &U) { + TUSymbolsOrHashes.push_back({U.getTypeSignature(), U.getUniqueID()}); } void llvm::emitDWARF5AccelTable( @@ -650,7 +668,7 @@ void llvm::emitDWARF5AccelTable( std::vector> TypeUnits; Contents.finalize(Asm, "names"); Dwarf5AccelTableWriter(Asm, Contents, CUs, TypeUnits, - getIndexForEntry) + getIndexForEntry, false) .emit(); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index f311931a41aa5..ab29020bf1d7b 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -305,7 +305,6 @@ void Loc::MMI::addFrameIndexExpr(const DIExpression *Expr, int FI) { static AccelTableKind computeAccelTableKind(unsigned DwarfVersion, bool GenerateTypeUnits, - bool HasSplitDwarf, DebuggerKind Tuning, const Triple &TT) { // Honor an explicit request. @@ -314,8 +313,7 @@ static AccelTableKind computeAccelTableKind(unsigned DwarfVersion, // Generating DWARF5 acceleration table. // Currently Split dwarf and non ELF format is not supported. - if (GenerateTypeUnits && - (DwarfVersion < 5 || HasSplitDwarf || !TT.isOSBinFormatELF())) + if (GenerateTypeUnits && (DwarfVersion < 5 || !TT.isOSBinFormatELF())) return AccelTableKind::None; // Accelerator tables get emitted if targetting DWARF v5 or LLDB. DWARF v5 @@ -403,9 +401,8 @@ DwarfDebug::DwarfDebug(AsmPrinter *A) A->TM.getTargetTriple().isOSBinFormatWasm()) && GenerateDwarfTypeUnits; - TheAccelTableKind = - computeAccelTableKind(DwarfVersion, GenerateTypeUnits, HasSplitDwarf, - DebuggerTuning, A->TM.getTargetTriple()); + TheAccelTableKind = computeAccelTableKind( + DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple()); // Work around a GDB bug. GDB doesn't support the standard opcode; // SCE doesn't support GNU's; LLDB prefers the standard opcode, which @@ -3532,8 +3529,12 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU, InfoHolder.computeSizeAndOffsetsForUnit(TU.first.get()); InfoHolder.emitUnit(TU.first.get(), useSplitDwarf()); if (getDwarfVersion() >= 5 && - getAccelTableKind() == AccelTableKind::Dwarf) - AccelDebugNames.addTypeUnitSymbol(*TU.first); + getAccelTableKind() == AccelTableKind::Dwarf) { + if (useSplitDwarf()) + AccelDebugNames.addTypeUnitSignature(*TU.first); + else + AccelDebugNames.addTypeUnitSymbol(*TU.first); + } } AccelTypeUnitsDebugNames.convertDieToOffset(); AccelDebugNames.addTypeEntries(AccelTypeUnitsDebugNames); diff --git a/llvm/test/DebugInfo/X86/debug-names-types.ll b/llvm/test/DebugInfo/X86/debug-names-types.ll index fc23e604b3863..d32691305d1c1 100644 --- a/llvm/test/DebugInfo/X86/debug-names-types.ll +++ b/llvm/test/DebugInfo/X86/debug-names-types.ll @@ -1,15 +1,10 @@ ; UNSUPPORTED: system-windows -; This checks that .debug_names can be generated with monolithic -fdebug-type-sections, and does not generate when split-dwarf is enabled. +; This checks that .debug_names can be generated with monolithic, and split-dwarf, when -fdebug-type-sections is enabled. ; Generated with: clang++ main.cpp -g2 -gdwarf-5 -gpubnames -fdebug-types-section ; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj %s -o %t ; RUN: llvm-dwarfdump -debug-info -debug-names %t | FileCheck %s -; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj -split-dwarf-file=%t.mainTypes.dwo --split-dwarf-output=%t.mainTypes.dwo %s -o %t -; RUN: llvm-readelf --sections %t | FileCheck %s --check-prefixes=CHECK-SPLIT - -; CHECK-SPLIT-NOT: .debug_names - ; CHECK: .debug_info contents: ; CHECK: DW_TAG_type_unit ; CHECK-NEXT: DW_AT_language (DW_LANG_C_plus_plus_14) @@ -117,6 +112,99 @@ ; CHECK-NEXT: ] ; CHECK-NEXT: } +; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj -split-dwarf-file=%t.mainTypes.dwo --split-dwarf-output=%t.mainTypes.dwo %s -o %t +; RUN: llvm-dwarfdump -debug-names %t | FileCheck %s --check-prefixes=CHECK-SPLIT + +; CHECK-SPLIT: .debug_names contents +; CHECK-SPLIT: Foreign TU count: 1 +; CHECK-SPLIT-NEXT: Bucket count: 4 +; CHECK-SPLIT-NEXT: Name count: 4 +; CHECK-SPLIT-NEXT: Abbreviations table size: 0x28 +; CHECK-SPLIT-NEXT: Augmentation: 'LLVM0700' +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: Compilation Unit offsets [ +; CHECK-SPLIT-NEXT: CU[0]: 0x00000000 +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: Foreign Type Unit signatures [ +; CHECK-SPLIT-NEXT: ForeignTU[0]: 0x675d23e4f33235f2 +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: Abbreviations [ +; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] { +; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] { +; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type +; CHECK-SPLIT-NEXT: DW_IDX_type_unit: DW_FORM_data1 +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV2:0x[0-9a-f]*]] { +; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV3:0x[0-9a-f]*]] { +; CHECK-SPLIT-NEXT: Tag: DW_TAG_subprogram +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV4:0x[0-9a-f]*]] { +; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type +; CHECK-SPLIT-NEXT: DW_IDX_type_unit: DW_FORM_data1 +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: Bucket 0 [ +; CHECK-SPLIT-NEXT: Name 1 { +; CHECK-SPLIT-NEXT: Hash: 0xB888030 +; CHECK-SPLIT-NEXT: String: {{.+}} "int" +; CHECK-SPLIT-NEXT: Entry @ {{.+}} { +; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV2]] +; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000035 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: Bucket 1 [ +; CHECK-SPLIT-NEXT: Name 2 { +; CHECK-SPLIT-NEXT: Hash: 0xB887389 +; CHECK-SPLIT-NEXT: String: {{.+}} "Foo" +; CHECK-SPLIT-NEXT: Entry @ {{.+}} { +; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV1]] +; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type +; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00 +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x0000001f +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: Entry @ 0xae { +; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV]] +; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000039 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: Bucket 2 [ +; CHECK-SPLIT-NEXT: Name 3 { +; CHECK-SPLIT-NEXT: Hash: 0x7C9A7F6A +; CHECK-SPLIT-NEXT: String: {{.+}} "main" +; CHECK-SPLIT-NEXT: Entry @ {{.+}} { +; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV3]] +; CHECK-SPLIT-NEXT: Tag: DW_TAG_subprogram +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x0000001a +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: Bucket 3 [ +; CHECK-SPLIT-NEXT: Name 4 { +; CHECK-SPLIT-NEXT: Hash: 0x7C952063 +; CHECK-SPLIT-NEXT: String: {{.+}} "char" +; CHECK-SPLIT-NEXT: Entry @ {{.+}} { +; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV4]] +; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type +; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00 +; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000034 +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: } +; CHECK-SPLIT-NEXT: ] +; CHECK-SPLIT-NEXT: } + ; ModuleID = 'main.cpp' source_filename = "main.cpp"