diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 85f807808b3..8d14781871b 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -241,14 +241,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) // Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h. DwarfDebug::~DwarfDebug() { } -// Switch to the specified MCSection and emit an assembler -// temporary label to it if SymbolStem is specified. -static void emitSectionSym(AsmPrinter *Asm, const MCSection *Section) { - Asm->OutStreamer.SwitchSection(Section); - MCSymbol *TmpSym = Section->getBeginSymbol(); - Asm->OutStreamer.EmitLabel(TmpSym); -} - static bool isObjCClass(StringRef Name) { return Name.startswith("+") || Name.startswith("-"); } @@ -449,9 +441,6 @@ void DwarfDebug::beginModule() { return; TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); - // Emit initial sections so we can reference labels later. - emitSectionLabels(); - SingleCU = CU_Nodes->getNumOperands() == 1; for (MDNode *N : CU_Nodes->operands()) { @@ -619,14 +608,13 @@ void DwarfDebug::finalizeModuleInfo() { // Emit all Dwarf sections that should come after the content. void DwarfDebug::endModule() { - const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); assert(CurFn == nullptr); assert(CurMI == nullptr); // If we aren't actually generating debug info (check beginModule - // conditionalized on !DisableDebugInfoPrinting and the presence of the // llvm.dbg.cu metadata node) - if (!TLOF.getDwarfInfoSection()->getBeginSymbol()->isInSection()) + if (!MMI->hasDebugInfo()) return; // Finalize the debug info for the module. @@ -640,12 +628,12 @@ void DwarfDebug::endModule() { // Emit info into a debug loc section. emitDebugLoc(); - // Emit all the DIEs into a debug info section. - emitDebugInfo(); - // Corresponding abbreviations into a abbrev section. emitAbbreviations(); + // Emit all the DIEs into a debug info section. + emitDebugInfo(); + // Emit info into a debug aranges section. if (GenerateARangeSection) emitDebugARanges(); @@ -1299,31 +1287,6 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S, // Emit Methods //===----------------------------------------------------------------------===// -// Emit initial Dwarf sections with a label at the start of each one. -void DwarfDebug::emitSectionLabels() { - const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); - - // Dwarf sections base addresses. - emitSectionSym(Asm, TLOF.getDwarfInfoSection()); - if (useSplitDwarf()) { - emitSectionSym(Asm, TLOF.getDwarfInfoDWOSection()); - emitSectionSym(Asm, TLOF.getDwarfTypesDWOSection()); - } - emitSectionSym(Asm, TLOF.getDwarfAbbrevSection()); - if (useSplitDwarf()) - emitSectionSym(Asm, TLOF.getDwarfAbbrevDWOSection()); - - emitSectionSym(Asm, TLOF.getDwarfLineSection()); - emitSectionSym(Asm, TLOF.getDwarfStrSection()); - if (useSplitDwarf()) { - emitSectionSym(Asm, TLOF.getDwarfStrDWOSection()); - emitSectionSym(Asm, TLOF.getDwarfAddrSection()); - emitSectionSym(Asm, TLOF.getDwarfLocDWOSection()); - } else - emitSectionSym(Asm, TLOF.getDwarfLocSection()); - emitSectionSym(Asm, TLOF.getDwarfRangesSection()); -} - // Emit the debug info section. void DwarfDebug::emitDebugInfo() { DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder; @@ -1364,7 +1327,7 @@ void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { void DwarfDebug::emitAccel(DwarfAccelTable &Accel, const MCSection *Section, StringRef TableName) { Accel.FinalizeTable(Asm, TableName); - emitSectionSym(Asm, Section); + Asm->OutStreamer.SwitchSection(Section); // Emit the full data. Accel.emit(Asm, Section->getBeginSymbol(), this); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index df967d58151..6e462bf06d0 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -339,9 +339,6 @@ class DwarfDebug : public AsmPrinterHandler { /// \brief Construct a DIE for this abstract scope. void constructAbstractSubprogramScopeDIE(LexicalScope *Scope); - /// \brief Emit initial Dwarf sections with a label at the start of each one. - void emitSectionLabels(); - /// \brief Compute the size and offset of a DIE given an incoming Offset. unsigned computeSizeAndOffset(DIE *Die, unsigned Offset); diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index d5277ffbd10..63b0bf2c80f 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCObjectWriter.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCWin64EH.h" #include "llvm/Support/ErrorHandling.h" @@ -670,5 +671,8 @@ void MCStreamer::SwitchSection(const MCSection *Section, if (MCSectionSubPair(Section, Subsection) != curSection) { SectionStack.back().first = MCSectionSubPair(Section, Subsection); ChangeSection(Section, Subsection); + MCSymbol *Sym = Section->getBeginSymbol(); + if (Sym && !Sym->isInSection()) + EmitLabel(Sym); } } diff --git a/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll b/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll index b4742b6c5aa..442c0cc80e1 100644 --- a/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll +++ b/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll @@ -1,6 +1,7 @@ ; RUN: %llc_dwarf -O2 %s -o - | FileCheck %s ; Check struct X for dead variable xyz from inlined function foo. +; CHECK: .Lsection_info ; CHECK: DW_TAG_structure_type ; CHECK-NEXT: info_string diff --git a/test/DebugInfo/AArch64/struct_by_value.ll b/test/DebugInfo/AArch64/struct_by_value.ll index 5d6aa6c4d2e..7fcab2bdde3 100644 --- a/test/DebugInfo/AArch64/struct_by_value.ll +++ b/test/DebugInfo/AArch64/struct_by_value.ll @@ -1,6 +1,7 @@ ; A by-value struct is a register-indirect value (breg). ; RUN: llc %s -filetype=asm -o - | FileCheck %s +; CHECK: Lsection_info: ; CHECK: DW_AT_location ; CHECK-NEXT: .byte 112 ; 112 = 0x70 = DW_OP_breg0 diff --git a/test/DebugInfo/PowerPC/tls-fission.ll b/test/DebugInfo/PowerPC/tls-fission.ll index d6dd62cfccc..74674858a50 100644 --- a/test/DebugInfo/PowerPC/tls-fission.ll +++ b/test/DebugInfo/PowerPC/tls-fission.ll @@ -14,6 +14,7 @@ ; CHECK-NEXT: .byte 224 ; check that the expected TLS address description is the first thing in the debug_addr section ; CHECK: debug_addr +; CHECK-NEXT: .Laddr_sec: ; CHECK-NEXT: .quad tls@dtprel+32768 @tls = thread_local global i32 0, align 4 diff --git a/test/DebugInfo/X86/dbg-i128-const.ll b/test/DebugInfo/X86/dbg-i128-const.ll index ee428511e16..d172f01b64a 100644 --- a/test/DebugInfo/X86/dbg-i128-const.ll +++ b/test/DebugInfo/X86/dbg-i128-const.ll @@ -1,5 +1,6 @@ ; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s +; CHECK: .section .debug_info ; CHECK: DW_AT_const_value ; CHECK-NEXT: 42 diff --git a/test/DebugInfo/X86/header.ll b/test/DebugInfo/X86/header.ll new file mode 100644 index 00000000000..263f9ec923c --- /dev/null +++ b/test/DebugInfo/X86/header.ll @@ -0,0 +1,29 @@ +; RUN: llc -mtriple x86_64-pc-linux < %s | FileCheck %s + +; Test that we don't pollute the start of the file with debug sections + +; CHECK: .text +; CHECK-NEXT: .file "" +; CHECK-NEXT: .globl f +; CHECK-NEXT: .align 16, 0x90 +; CHECK-NEXT: .type f,@function +; CHECK-NEXT: f: # @f + +; CHECK: .section .debug_str + +define void @f() { + ret void, !dbg !9 +} +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!7, !8} + +!0 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "foo", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2) +!1 = !MDFile(filename: "/foo/test.c", directory: "/foo") +!2 = !{} +!3 = !{!4} +!4 = !MDSubprogram(name: "f", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, function: void ()* @f, variables: !2) +!5 = !MDSubroutineType(types: !6) +!6 = !{null} +!7 = !{i32 2, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !MDLocation(line: 1, column: 15, scope: !4) diff --git a/test/DebugInfo/X86/stmt-list.ll b/test/DebugInfo/X86/stmt-list.ll index cbc10ebb467..7cad3fc7ee3 100644 --- a/test/DebugInfo/X86/stmt-list.ll +++ b/test/DebugInfo/X86/stmt-list.ll @@ -1,9 +1,10 @@ ; RUN: llc -mtriple x86_64-pc-linux-gnu < %s | FileCheck %s +; CHECK: .long .Lline_table_start0 # DW_AT_stmt_list + ; CHECK: .section .debug_line,"",@progbits ; CHECK-NEXT: .Lsection_line: - -; CHECK: .long .Lline_table_start0 # DW_AT_stmt_list +; CHECK-NEXT: .Lline_table_start0: define void @f() { entry: diff --git a/test/DebugInfo/X86/tls.ll b/test/DebugInfo/X86/tls.ll index 57497b5ce1a..d43a173485c 100644 --- a/test/DebugInfo/X86/tls.ll +++ b/test/DebugInfo/X86/tls.ll @@ -68,6 +68,7 @@ ; check that the expected TLS address description is the first thing in the debug_addr section ; FISSION: .section .debug_addr +; FISSION: addr_sec: ; FISSION-NEXT: .quad tls@DTPOFF ; FISSION-NEXT: .quad glbl ; FISSION-NOT: .quad glbl diff --git a/test/DebugInfo/array.ll b/test/DebugInfo/array.ll index 634a17d0925..119ffd301ff 100644 --- a/test/DebugInfo/array.ll +++ b/test/DebugInfo/array.ll @@ -25,6 +25,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone !7 = distinct !MDLexicalBlock(line: 3, column: 12, file: !14, scope: !0) !8 = !MDCompositeType(tag: DW_TAG_array_type, align: 32, file: !14, scope: !2, baseType: !5, elements: !9) !9 = !{!10} +;CHECK: section_info: ;CHECK: DW_TAG_subrange_type ;CHECK-NEXT: DW_AT_type ;CHECK-NOT: DW_AT_lower_bound diff --git a/test/MC/ELF/gen-dwarf.s b/test/MC/ELF/gen-dwarf.s index 7f0c0594ce9..5c90bf724b9 100644 --- a/test/MC/ELF/gen-dwarf.s +++ b/test/MC/ELF/gen-dwarf.s @@ -34,6 +34,7 @@ foo: // ASM: .section .debug_info // ASM: .section .debug_abbrev +// ASM-NEXT: .Lsection_abbrev: // ASM-NEXT: [[ABBREV_LABEL:.Ltmp[0-9]+]] // Second instance of the section has the CU @@ -48,6 +49,7 @@ foo: // ASM-NEXT: .long [[LINE_LABEL:.L[a-z0-9]+]] // ASM: .section .debug_line +// ASM-NEXT:.Lsection_line: // ASM-NEXT: [[LINE_LABEL]] // DWARF1: Dwarf version 1 is not supported.