31 changes: 23 additions & 8 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,16 @@ 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.
if (AccelTables != AccelTableKind::Default)
return AccelTables;

// Accelerator tables with type units are currently not supported.
if (GenerateTypeUnits)
if (GenerateTypeUnits &&
(DwarfVersion < 5 || HasSplitDwarf || !TT.isOSBinFormatELF()))
return AccelTableKind::None;

// Accelerator tables get emitted if targetting DWARF v5 or LLDB. DWARF v5
Expand All @@ -325,6 +327,9 @@ static AccelTableKind computeAccelTableKind(unsigned DwarfVersion,
: AccelTableKind::Dwarf;
return AccelTableKind::None;
}
void DwarfDebug::addTypeUnit(std::unique_ptr<DwarfTypeUnit> U) {
InfoHolder.addTypeUnit(std::move(U));
}

DwarfDebug::DwarfDebug(AsmPrinter *A)
: DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
Expand Down Expand Up @@ -400,8 +405,9 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
A->TM.getTargetTriple().isOSBinFormatWasm()) &&
GenerateDwarfTypeUnits;

TheAccelTableKind = computeAccelTableKind(
DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple());
TheAccelTableKind =
computeAccelTableKind(DwarfVersion, GenerateTypeUnits, HasSplitDwarf,
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
Expand Down Expand Up @@ -2394,7 +2400,7 @@ void DwarfDebug::emitAccelDebugNames() {
if (getUnits().empty())
return;

emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits());
emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits(), getTypeUnits());
}

// Emit visible names into a hashed accelerator table section.
Expand Down Expand Up @@ -3499,7 +3505,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
// Types referencing entries in the address table cannot be placed in type
// units.
if (AddrPool.hasBeenUsed()) {

AccelTypeUntsDebugNames.clear();
// Remove all the types built while building this type.
// This is pessimistic as some of these types might not be dependent on
// the type that used an address.
Expand All @@ -3514,11 +3520,15 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
return;
}

// If the type wasn't dependent on fission addresses, finish adding the type
// and all its dependent types.
for (auto &TU : TypeUnitsToAdd) {
InfoHolder.computeSizeAndOffsetsForUnit(TU.first.get());
InfoHolder.emitUnit(TU.first.get(), useSplitDwarf());
if (getDwarfVersion() >= 5 &&
getAccelTableKind() == AccelTableKind::Dwarf) {
addTypeUnit(std::move(TU.first));
AccelDebugNames.addEntries(AccelTypeUntsDebugNames);
AccelTypeUntsDebugNames.clear();
}
}
}
CU.addDIETypeSignature(RefDie, Signature);
Expand Down Expand Up @@ -3548,7 +3558,12 @@ void DwarfDebug::addAccelNameImpl(const DICompileUnit &CU,
AppleAccel.addName(Ref, Die);
break;
case AccelTableKind::Dwarf:
AccelDebugNames.addName(Ref, Die);
// The type unit can be discarded, so need to add references to final
// acceleration table once we know it's complete and we emit it.
if (TypeUnitsUnderConstruction.empty())
AccelDebugNames.addName(Ref, Die);
else
AccelTypeUntsDebugNames.addName(Ref, Die);
break;
case AccelTableKind::Default:
llvm_unreachable("Default should have already been resolved.");
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class DwarfDebug : public DebugHandlerBase {

/// Accelerator tables.
AccelTable<DWARF5AccelTableData> AccelDebugNames;
AccelTable<DWARF5AccelTableData> AccelTypeUntsDebugNames;
AccelTable<AppleAccelTableOffsetData> AccelNames;
AccelTable<AppleAccelTableOffsetData> AccelObjC;
AccelTable<AppleAccelTableOffsetData> AccelNamespace;
Expand All @@ -515,6 +516,13 @@ class DwarfDebug : public DebugHandlerBase {
return InfoHolder.getUnits();
}

/// Returns Type Units constructed for this module.
const SmallVectorImpl<std::unique_ptr<DwarfTypeUnit>> &getTypeUnits() {
return InfoHolder.getTypeUnits();
}

void addTypeUnit(std::unique_ptr<DwarfTypeUnit> U);

using InlinedEntity = DbgValueHistoryMap::InlinedEntity;

void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
Expand Down Expand Up @@ -780,6 +788,9 @@ class DwarfDebug : public DebugHandlerBase {
/// Returns what kind (if any) of accelerator tables to emit.
AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }

/// Seet TheAccelTableKind
void setTheAccelTableKind(AccelTableKind K) { TheAccelTableKind = K; };

bool useAppleExtensionAttributes() const {
return HasAppleExtensionAttributes;
}
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ void DwarfFile::addUnit(std::unique_ptr<DwarfCompileUnit> U) {
CUs.push_back(std::move(U));
}

void DwarfFile::addTypeUnit(std::unique_ptr<DwarfTypeUnit> U) {
TUs.push_back(std::move(U));
}

// Emit the various dwarf units to the unit section USection with
// the abbreviations going into ASection.
void DwarfFile::emitUnits(bool UseOffsets) {
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DbgLabel;
class DINode;
class DILocalScope;
class DwarfCompileUnit;
class DwarfTypeUnit;
class DwarfUnit;
class LexicalScope;
class MCSection;
Expand Down Expand Up @@ -59,6 +60,9 @@ class DwarfFile {
// A pointer to all units in the section.
SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;

// A pointer to all type units in the section.
SmallVector<std::unique_ptr<DwarfTypeUnit>, 1> TUs;

DwarfStringPool StrPool;

// List of range lists for a given compile unit, separate from the ranges for
Expand Down Expand Up @@ -103,6 +107,11 @@ class DwarfFile {
return CUs;
}

/// Returns type units that were constructed.
const SmallVectorImpl<std::unique_ptr<DwarfTypeUnit>> &getTypeUnits() {
return TUs;
}

std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
SmallVector<RangeSpan, 2> R);

Expand All @@ -124,6 +133,11 @@ class DwarfFile {
/// Add a unit to the list of CUs.
void addUnit(std::unique_ptr<DwarfCompileUnit> U);

/// Add a unit to the list of TUs.
/// Preserves type unit so that memory is not released before DWARF5
/// accelerator table is created.
void addTypeUnit(std::unique_ptr<DwarfTypeUnit> U);

/// Emit all of the units to the section listed with the given
/// abbreviation section.
void emitUnits(bool UseOffsets);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,10 @@ void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) {
}

void DwarfTypeUnit::emitHeader(bool UseOffsets) {
if (!DD->useSplitDwarf()) {
LabelBegin = Asm->createTempSymbol("tu_begin");
Asm->OutStreamer->emitLabel(LabelBegin);
}
DwarfUnit::emitCommonHeader(UseOffsets,
DD->useSplitDwarf() ? dwarf::DW_UT_split_type
: dwarf::DW_UT_type);
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class DwarfTypeUnit final : public DwarfUnit {
DwarfCompileUnit &CU;
MCDwarfDwoLineTable *SplitLineTable;
bool UsedLineTable = false;
/// The start of the type unit within .debug_nfo section.
MCSymbol *LabelBegin = nullptr;

unsigned getOrCreateSourceID(const DIFile *File) override;
void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override;
Expand All @@ -372,6 +374,8 @@ class DwarfTypeUnit final : public DwarfUnit {
DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable = nullptr);

void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
/// Returns Type Signature.
uint64_t getTypeSignature() const { return TypeSignature; }
void setType(const DIE *Ty) { this->Ty = Ty; }

/// Emit the header for this unit, not including the initial length field.
Expand All @@ -385,6 +389,11 @@ class DwarfTypeUnit final : public DwarfUnit {
void addGlobalType(const DIType *Ty, const DIE &Die,
const DIScope *Context) override;
DwarfCompileUnit &getCU() override { return CU; }
/// Get the the symbol for start of the section for this type unit.
MCSymbol *getLabelBegin() const {
assert(LabelBegin && "LabelBegin is not initialized");
return LabelBegin;
}
};
} // end llvm namespace
#endif
13 changes: 11 additions & 2 deletions llvm/lib/DWARFLinker/DWARFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,19 @@ void DwarfStreamer::emitDebugNames(
}

Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
dwarf::Form Form = DIEInteger::BestForm(/*IsSigned*/ false,
(uint64_t)UniqueIdToCuMap.size() - 1);
/// llvm-dwarfutil doesn't support type units + .debug_names right now anyway,
/// so just keeping current behavior.
emitDWARF5AccelTable(
Asm.get(), Table, CompUnits,
[&UniqueIdToCuMap](const DWARF5AccelTableStaticData &Entry) {
return UniqueIdToCuMap[Entry.getCUIndex()];
[&UniqueIdToCuMap, &Form](const DWARF5AccelTableStaticData &Entry)
-> GetIndexForEntryReturnType {
GetIndexForEntryReturnType Index = std::nullopt;
if (UniqueIdToCuMap.size() > 1)
Index = {UniqueIdToCuMap[Entry.getCUIndex()],
{dwarf::DW_IDX_compile_unit, Form}};
return Index;
});
}

Expand Down
18 changes: 14 additions & 4 deletions llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,20 @@ void DwarfEmitterImpl::emitDebugNames(
return;

Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
emitDWARF5AccelTable(Asm.get(), Table, CUOffsets,
[&CUidToIdx](const DWARF5AccelTableStaticData &Entry) {
return CUidToIdx[Entry.getCUIndex()];
});
dwarf::Form Form =
DIEInteger::BestForm(/*IsSigned*/ false, (uint64_t)CUidToIdx.size() - 1);
/// DWARFLinker doesn't support type units + .debug_names right now anyway,
/// so just keeping current behavior.
emitDWARF5AccelTable(
Asm.get(), Table, CUOffsets,
[&CUidToIdx, &Form](const DWARF5AccelTableStaticData &Entry)
-> GetIndexForEntryReturnType {
GetIndexForEntryReturnType Index = std::nullopt;
if (CUidToIdx.size() > 1)
Index = {CUidToIdx[Entry.getCUIndex()],
{dwarf::DW_IDX_compile_unit, Form}};
return Index;
});
}

void DwarfEmitterImpl::emitAppleNamespaces(
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ std::optional<uint64_t> DWARFDebugNames::Entry::getCUOffset() const {
}

void DWARFDebugNames::Entry::dump(ScopedPrinter &W) const {
W.printHex("Abbrev", Abbr->Code);
DictScope AbbrevScope(W, ("Abbrev: 0x" + Twine::utohexstr(Abbr->Code)).str());
W.startLine() << formatv("Tag: {0}\n", Abbr->Tag);
assert(Abbr->Attributes.size() == Values.size());
for (auto Tuple : zip_first(Abbr->Attributes, Values)) {
Expand Down
1 change: 0 additions & 1 deletion llvm/test/DebugInfo/X86/accel-tables-dwarf5.ll
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
; RUN: | llvm-readobj --sections - | FileCheck --check-prefix=DEBUG_NAMES %s

; NONE-NOT: apple_names
; NONE-NOT: debug_names

; DEBUG_NAMES-NOT: apple_names
; DEBUG_NAMES: debug_names
Expand Down
22 changes: 12 additions & 10 deletions llvm/test/DebugInfo/X86/debug-names-dwarf64.ll
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
; CHECK-NEXT: CU[0]: 0x00000000
; CHECK-NEXT: ]
; CHECK-NEXT: Abbreviations [
; CHECK-NEXT: Abbreviation 0x34 {
; CHECK-NEXT: Tag: DW_TAG_variable
; CHECK-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: Abbreviation 0x24 {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_variable
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: ]
Expand All @@ -40,9 +40,10 @@
; CHECK-NEXT: Hash: 0xB888030
; CHECK-NEXT: String: {{.+}} "int"
; CHECK-NEXT: Entry @ {{.+}} {
; CHECK-NEXT: Abbrev: 0x24
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_die_offset: [[TYPEDIE]]
; CHECK-NEXT: Abbrev: [[ABBREV]] {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_die_offset: [[TYPEDIE]]
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
Expand All @@ -51,9 +52,10 @@
; CHECK-NEXT: Hash: 0xB887389
; CHECK-NEXT: String: {{.+}} "foo"
; CHECK-NEXT: Entry @ {{.+}} {
; CHECK-NEXT: Abbrev: 0x34
; CHECK-NEXT: Tag: DW_TAG_variable
; CHECK-NEXT: DW_IDX_die_offset: [[VARDIE]]
; CHECK-NEXT: Abbrev: [[ABBREV1]] {
; CHECK-NEXT: Tag: DW_TAG_variable
; CHECK-NEXT: DW_IDX_die_offset: [[VARDIE]]
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
Expand Down
168 changes: 168 additions & 0 deletions llvm/test/DebugInfo/X86/debug-names-types-monolithic.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
; This checks that .debug_names can be generated with monolithic -fdebug-type-sections.

; 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

; CHECK: .debug_info contents:
; CHECK: DW_TAG_type_unit
; CHECK-NEXT: DW_AT_language (DW_LANG_C_plus_plus_14)
; CHECK-NEXT: DW_AT_stmt_list (0x00000000)
; CHECK-NEXT: DW_AT_str_offsets_base (0x00000008)
; CHECK: DW_TAG_structure_type
; CHECK-NEXT: DW_AT_calling_convention (DW_CC_pass_by_value)
; CHECK-NEXT: DW_AT_name ("Foo")
; CHECK-NEXT: DW_AT_byte_size (0x08)
; CHECK-NEXT: DW_AT_decl_file ("/typeSmall/main.cpp")
; CHECK-NEXT: DW_AT_decl_line (1)
; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name ("c1")
; CHECK-NEXT: DW_AT_type (0x00000033 "char *")
; CHECK-NEXT: DW_AT_decl_file ("/typeSmall/main.cpp")
; CHECK-NEXT: DW_AT_decl_line (2)
; CHECK-NEXT: DW_AT_data_member_location (0x00)
; CHECK: DW_TAG_pointer_type
; CHECK-NEXT: DW_AT_type (0x00000038 "char")
; CHECK: DW_TAG_base_type
; CHECK-NEXT: DW_AT_name ("char")
; CHECK-NEXT: DW_AT_encoding (DW_ATE_signed_char)
; CHECK-NEXT: DW_AT_byte_size (0x01)
; CHECK: .debug_names contents:
; CHECK: Compilation Unit offsets [
; CHECK-NEXT: CU[0]: 0x00000000
; CHECK-NEXT: ]
; CHECK-NEXT: Local Type Unit offsets [
; CHECK-NEXT: LocalTU[0]: 0x00000000
; CHECK-NEXT: ]
; CHECK: Abbreviations [
; CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_structure_type
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: Abbreviation [[ABBREV3:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_structure_type
; CHECK-NEXT: DW_IDX_type_unit: DW_FORM_data1
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: Abbreviation [[ABBREV2:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_subprogram
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: Abbreviation [[ABBREV4:0x[0-9a-f]*]] {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_type_unit: DW_FORM_data1
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
; CHECK-NEXT: }
; CHECK-NEXT: ]
; CHECK-NEXT: Bucket 0 [
; CHECK-NEXT: Name 1 {
; CHECK-NEXT: Hash: 0xB888030
; CHECK-NEXT: String: {{.+}} "int"
; CHECK-NEXT: Entry @ {{.+}} {
; CHECK-NEXT: Abbrev: [[ABBREV]] {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_die_offset: 0x0000003e
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
; CHECK-NEXT: Bucket 1 [
; CHECK-NEXT: Name 2 {
; CHECK-NEXT: Hash: 0xB887389
; CHECK-NEXT: String: {{.+}} "Foo"
; CHECK-NEXT: Entry @ {{.+}} {
; CHECK-NEXT: Abbrev: [[ABBREV3]] {
; CHECK-NEXT: Tag: DW_TAG_structure_type
; CHECK-NEXT: DW_IDX_type_unit: 0x00
; CHECK-NEXT: DW_IDX_die_offset: 0x00000023
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: Entry @ 0xaa {
; CHECK-NEXT: Abbrev: [[ABBREV1]] {
; CHECK-NEXT: Tag: DW_TAG_structure_type
; CHECK-NEXT: DW_IDX_die_offset: 0x00000042
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
; CHECK-NEXT: Bucket 2 [
; CHECK-NEXT: Name 3 {
; CHECK-NEXT: Hash: 0x7C9A7F6A
; CHECK-NEXT: String: {{.+}} "main"
; CHECK-NEXT: Entry @ {{.+}} {
; CHECK-NEXT: Abbrev: [[ABBREV2]] {
; CHECK-NEXT: Tag: DW_TAG_subprogram
; CHECK-NEXT: DW_IDX_die_offset: 0x00000023
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
; CHECK-NEXT: Bucket 3 [
; CHECK-NEXT: Name 4 {
; CHECK-NEXT: Hash: 0x7C952063
; CHECK-NEXT: String: {{.+}} "char"
; CHECK-NEXT: Entry @ {{.+}} {
; CHECK-NEXT: Abbrev: [[ABBREV4]] {
; CHECK-NEXT: Tag: DW_TAG_base_type
; CHECK-NEXT: DW_IDX_type_unit: 0x00
; CHECK-NEXT: DW_IDX_die_offset: 0x00000038
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
; CHECK-NEXT: }


; ModuleID = 'main.cpp'
source_filename = "main.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Foo = type { ptr }

; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
define dso_local noundef i32 @main() #0 !dbg !10 {
entry:
%retval = alloca i32, align 4
%f = alloca %struct.Foo, align 8
store i32 0, ptr %retval, align 4
call void @llvm.dbg.declare(metadata ptr %f, metadata !15, metadata !DIExpression()), !dbg !21
ret i32 0, !dbg !22
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
!llvm.ident = !{!9}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
!1 = !DIFile(filename: "main.cpp", directory: "/typeSmall", checksumkind: CSK_MD5, checksum: "e5b402e9dbafe24c7adbb087d1f03549")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!5 = !{i32 8, !"PIC Level", i32 2}
!6 = !{i32 7, !"PIE Level", i32 2}
!7 = !{i32 7, !"uwtable", i32 2}
!8 = !{i32 7, !"frame-pointer", i32 2}
!9 = !{!"clang version 18.0.0"}
!10 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
!11 = !DISubroutineType(types: !12)
!12 = !{!13}
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!14 = !{}
!15 = !DILocalVariable(name: "f", scope: !10, file: !1, line: 5, type: !16)
!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS3Foo")
!17 = !{!18}
!18 = !DIDerivedType(tag: DW_TAG_member, name: "c1", scope: !16, file: !1, line: 2, baseType: !19, size: 64)
!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
!20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!21 = !DILocation(line: 5, column: 6, scope: !10)
!22 = !DILocation(line: 6, column: 2, scope: !10)
57 changes: 57 additions & 0 deletions llvm/test/DebugInfo/X86/debug-names-types-split.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; This checks that .debug_names is not generated with split-dwarf + -fdebug-type-sections.

; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj -split-dwarf-file=mainTypes.dwo --split-dwarf-output=mainTypes.dwo %s -o %t
; RUN: llvm-readelf --sections %t | FileCheck %s

; CHECK-NOT: .debug_names

; ModuleID = 'main.cpp'
source_filename = "main.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Foo = type { ptr }

; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
define dso_local noundef i32 @main() #0 !dbg !10 {
entry:
%retval = alloca i32, align 4
%f = alloca %struct.Foo, align 8
store i32 0, ptr %retval, align 4
call void @llvm.dbg.declare(metadata ptr %f, metadata !15, metadata !DIExpression()), !dbg !21
ret i32 0, !dbg !22
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
!llvm.ident = !{!9}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0 (ssh://git.vip.facebook.com/data/gitrepos/osmeta/external/llvm-project 680deb27e25976d9b74ad7b48ec5cb96be0e44b6)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "main.dwo", emissionKind: FullDebug, splitDebugInlining: false)
!1 = !DIFile(filename: "main.cpp", directory: "/home/ayermolo/local/tasks/T138552329/typeSmallSplit", checksumkind: CSK_MD5, checksum: "e5b402e9dbafe24c7adbb087d1f03549")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!5 = !{i32 8, !"PIC Level", i32 2}
!6 = !{i32 7, !"PIE Level", i32 2}
!7 = !{i32 7, !"uwtable", i32 2}
!8 = !{i32 7, !"frame-pointer", i32 2}
!9 = !{!"clang version 18.0.0 (ssh://git.vip.facebook.com/data/gitrepos/osmeta/external/llvm-project 680deb27e25976d9b74ad7b48ec5cb96be0e44b6)"}
!10 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
!11 = !DISubroutineType(types: !12)
!12 = !{!13}
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!14 = !{}
!15 = !DILocalVariable(name: "f", scope: !10, file: !1, line: 5, type: !16)
!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS3Foo")
!17 = !{!18}
!18 = !DIDerivedType(tag: DW_TAG_member, name: "c1", scope: !16, file: !1, line: 2, baseType: !19, size: 64)
!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
!20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!21 = !DILocation(line: 5, column: 6, scope: !10)
!22 = !DILocation(line: 6, column: 2, scope: !10)
36 changes: 20 additions & 16 deletions llvm/test/DebugInfo/X86/dwarfdump-debug-names.s
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
# CHECK-NEXT: CU[0]: 0x00000000
# CHECK-NEXT: ]
# CHECK-NEXT: Abbreviations [
# CHECK-NEXT: Abbreviation 0x2e {
# CHECK-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] {
# CHECK-NEXT: Tag: DW_TAG_subprogram
# CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
# CHECK-NEXT: }
Expand All @@ -164,18 +164,20 @@
# CHECK-NEXT: Hash: 0xB887389
# CHECK-NEXT: String: 0x00000000 "foo"
# CHECK-NEXT: Entry @ 0x4f {
# CHECK-NEXT: Abbrev: 0x2E
# CHECK-NEXT: Tag: DW_TAG_subprogram
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: Abbrev: [[ABBREV]]
# CHECK-NEXT: Tag: DW_TAG_subprogram
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: Name 2 {
# CHECK-NEXT: Hash: 0xB5063D0B
# CHECK-NEXT: String: 0x00000004 "_Z3foov"
# CHECK-NEXT: Entry @ 0x58 {
# CHECK-NEXT: Abbrev: 0x2E
# CHECK-NEXT: Tag: DW_TAG_subprogram
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: Abbrev: [[ABBREV]]
# CHECK-NEXT: Tag: DW_TAG_subprogram
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: ]
Expand All @@ -197,7 +199,7 @@
# CHECK-NEXT: CU[0]: 0x00000002
# CHECK-NEXT: ]
# CHECK-NEXT: Abbreviations [
# CHECK-NEXT: Abbreviation 0x34 {
# CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] {
# CHECK-NEXT: Tag: DW_TAG_variable
# CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
# CHECK-NEXT: }
Expand All @@ -207,9 +209,10 @@
# CHECK-NEXT: Hash: 0xB8860BA
# CHECK-NEXT: String: 0x0000000c "bar"
# CHECK-NEXT: Entry @ 0xa3 {
# CHECK-NEXT: Abbrev: 0x34
# CHECK-NEXT: Tag: DW_TAG_variable
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: Abbrev: [[ABBREV1]]
# CHECK-NEXT: Tag: DW_TAG_variable
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: ]
Expand Down Expand Up @@ -237,7 +240,7 @@
# CHECK-NEXT: ForeignTU[0]: 0xffffff00ffffffff
# CHECK-NEXT: ]
# CHECK-NEXT: Abbreviations [
# CHECK-NEXT: Abbreviation 0x1 {
# CHECK-NEXT: Abbreviation [[ABBREV2:0x[0-9a-f]*]] {
# CHECK-NEXT: Tag: DW_TAG_base_type
# CHECK-NEXT: DW_IDX_type_unit: DW_FORM_data4
# CHECK-NEXT: DW_IDX_type_hash: DW_FORM_data8
Expand All @@ -248,10 +251,11 @@
# CHECK-NEXT: Hash: 0xB887389
# CHECK-NEXT: String: 0x00000000 "foo"
# CHECK-NEXT: Entry @ 0x111 {
# CHECK-NEXT: Abbrev: 0x1
# CHECK-NEXT: Tag: DW_TAG_base_type
# CHECK-NEXT: DW_IDX_type_unit: 0x00000001
# CHECK-NEXT: DW_IDX_type_hash: 0x0000ff03ffffffff
# CHECK-NEXT: Abbrev: [[ABBREV2]]
# CHECK-NEXT: Tag: DW_TAG_base_type
# CHECK-NEXT: DW_IDX_type_unit: 0x00000001
# CHECK-NEXT: DW_IDX_type_hash: 0x0000ff03ffffffff
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: ]
Expand Down
18 changes: 9 additions & 9 deletions llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ RUN: dsymutil -accelerator=Apple -oso-prepend-path=%p/../Inputs %p/../Inputs/acc
RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON
RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON

RUN: dsymutil --linker llvm -accelerator=Dwarf -oso-prepend-path=%p/../Inputs \
RUN: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM
RUN: dsymutil --linker llvm -accelerator=Apple -oso-prepend-path=%p/../Inputs \
RUN: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM

RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON
RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON
RUN2: dsymutil --linker llvm -accelerator=Dwarf -oso-prepend-path=%p/../Inputs \
RUN2: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM
RUN2: dsymutil --linker llvm -accelerator=Apple -oso-prepend-path=%p/../Inputs \
RUN2: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM
RUN2: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON
RUN2: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON

COMMON: .debug_info contents
COMMON: {{.*}}DW_TAG_namespace
Expand All @@ -29,8 +28,9 @@ DWARF-NEXT: Hash: {{.*}}
DWARF-NEXT: String: {{.*}} "C"
DWARF-NEXT: Entry {{.*}} {
DWARF-NEXT: Abbrev: {{.*}}
DWARF-NEXT: Tag: DW_TAG_namespace
DWARF-NEXT: DW_IDX_die_offset: [[NAMESPACE]]
DWARF-NEXT: Tag: DW_TAG_namespace
DWARF-NEXT: DW_IDX_die_offset: [[NAMESPACE]]
DWARF-NEXT: }
DWARF-NEXT: }
DWARF-NEXT: Entry {{.*}} {
DWARF-NEXT: Abbrev: {{.*}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CHECK:.debug_abbrev contents:
CHECK-NEXT: Abbrev table for offset: 0x00000000

CHECK: .debug_info contents:
CHECK: 0x00000000: Compile Unit: length = 0x0000004a, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08
CHECK: 0x00000000: Compile Unit: length = 0x0000004a, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08
CHECK: DW_AT_producer [DW_FORM_strx] (indexed (00000000) string = "Apple clang version 14.0.3 (clang-1403.0.22.14.1)")
CHECK: DW_AT_name [DW_FORM_strx] (indexed (00000001) string = "a.cpp")
CHECK: DW_AT_LLVM_sysroot [DW_FORM_strx] (indexed (00000002) string = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
Expand All @@ -59,12 +59,12 @@ CHECK-NEXT: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x[[
CHECK: DW_AT_linkage_name [DW_FORM_strx] (indexed (00000005) string = "_Z4foo2i")
CHECK: DW_AT_name [DW_FORM_strx] (indexed (00000006) string = "foo2")
CHECK: 0x0000003c: DW_TAG_formal_parameter [3] (0x0000002c)
CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOCLIST_OFFSET:[0-9a-f]+]]:
CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOCLIST_OFFSET:[0-9a-f]+]]:
CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START:]], 0x[[#%.16x,LOCLIST_PAIR_END:]]): [[LOCLIST_EXPR:.*]]
CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START2:]], 0x[[#%.16x,LOCLIST_PAIR_END2:]]): [[LOCLIST_EXPR2:.*]])
CHECK: DW_AT_name [DW_FORM_strx] (indexed (00000007) string = "a")

CHECK: 0x0000004e: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x00{{00|5a}}, addr_size = 0x08
CHECK: 0x0000004e: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x00{{00|5a}}, addr_size = 0x08
CHECK: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000001] = "Apple clang version 14.0.3 (clang-1403.0.22.14.1)")
CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000e0] = "b.cpp")
CHECK: DW_AT_LLVM_sysroot [DW_FORM_strp] ( .debug_str[0x00000039] = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
Expand All @@ -79,7 +79,7 @@ CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x[[#%.16x,LOC_LOWPC
CHECK: DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000e6] = "_Z3bari")
CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000ee] = "bar")
CHECK: 0x0000009d: DW_TAG_formal_parameter {{.*}} (0x00000080)
CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]:
CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]:
CHECK-NEXT: [0x[[#%.16x,LOC_PAIR_START:]], 0x[[#%.16x,LOC_PAIR_END:]]): [[LOC_EXPR:.*]]
CHECK-NEXT: [0x[[#%.16x,LOC_PAIR_START2:]], 0x[[#%.16x,LOC_PAIR_END2:]]): [[LOC_EXPR2:.*]])
CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000f2] = "x")
Expand All @@ -91,7 +91,7 @@ CHECK-NEXT: (0x[[#sub(LOC_PAIR_START2,LOC_LOWPC)]], 0x[[#sub(LOC_PAIR

CHECK: .debug_loclists contents:
CHECK-NEXT: 0x00000000: locations list header: length = 0x00000018, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
CHECK-NEXT: 0x[[LOCLIST_OFFSET]]:
CHECK-NEXT: 0x[[LOCLIST_OFFSET]]:
CHECK-NEXT: DW_LLE_base_addressx (0x0000000000000000)
CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END,LOCLIST_LOWPC)]])
CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START2,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END2,LOCLIST_LOWPC)]])
Expand Down Expand Up @@ -205,14 +205,14 @@ CHECK-NEXT: 0x00000028: 000000dc "int"
CHECK: .debug_names contents:
CHECK-NEXT: Name Index @ 0x0 {
CHECK-NEXT: Header {
CHECK-NEXT: Length: 0xBC
CHECK-NEXT: Length: 0xC4
CHECK-NEXT: Format: DWARF32
CHECK-NEXT: Version: 5
CHECK-NEXT: CU count: 2
CHECK-NEXT: Local TU count: 0
CHECK-NEXT: Foreign TU count: 0
CHECK-NEXT: Bucket count: 5
CHECK-NEXT: Name count: 5
CHECK-NEXT: Abbreviations table size: 0x11
CHECK-NEXT: Abbreviations table size: 0x13
CHECK-NEXT: Augmentation: 'LLVM0700'
CHECK-NEXT: }
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# CHECK: Name 1 {
# CHECK-NEXT: String: 0x00000000 "foo"
# CHECK-NEXT: Entry @ 0x37 {
# CHECK-NEXT: Abbrev: 0x2E
# CHECK-NEXT: Abbrev: 0x2e
# CHECK-NEXT: Tag: DW_TAG_subprogram
# CHECK-NEXT: DW_IDX_die_offset: 0x00000001
# CHECK-NEXT: }
Expand Down