Print section start labels when first switching to the section.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 11 Mar 2015 00:51:37 +0000 (00:51 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 11 Mar 2015 00:51:37 +0000 (00:51 +0000)
This is less brittle and avoids polluting the start of the file with every
debug section.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231898 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
lib/MC/MCStreamer.cpp
test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll
test/DebugInfo/AArch64/struct_by_value.ll
test/DebugInfo/PowerPC/tls-fission.ll
test/DebugInfo/X86/dbg-i128-const.ll
test/DebugInfo/X86/header.ll [new file with mode: 0644]
test/DebugInfo/X86/stmt-list.ll
test/DebugInfo/X86/tls.ll
test/DebugInfo/array.ll
test/MC/ELF/gen-dwarf.s

index 85f807808b3ed2ff21f69284feaef47411a5947e..8d14781871b640dd73eeee30f1cd6f1421ebde6d 100644 (file)
@@ -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);
index df967d58151c2655db262030076affa2c7d6e1df..6e462bf06d05c0e252860bc3213ecf798bd031cf 100644 (file)
@@ -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);
 
index d5277ffbd10c4769bc05c60e14cb1cb34eceab8b..63b0bf2c80f81cafc0edb826255c32cb3026c4cf 100644 (file)
@@ -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);
   }
 }
index b4742b6c5aab26df9cb54f46789a9bdc486f473c..442c0cc80e1c4a6426f3ec4a75fcf8e265a994b7 100644 (file)
@@ -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
  
index 5d6aa6c4d2e8cd17bc7eae64bb27927374d1316a..7fcab2bdde319354cac222138ab5207ff5f1f940 100644 (file)
@@ -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
index d6dd62cfccc64f581e713c995d9bf0c28d72507d..74674858a508e0c8a1c6adc26dce56b0e513ceff 100644 (file)
@@ -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
index ee428511e16d9f0084ff02fe470a9c5a04d2b7e7..d172f01b64adf1b627fd42d108ddbf657e494cdd 100644 (file)
@@ -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 (file)
index 0000000..263f9ec
--- /dev/null
@@ -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    "<stdin>"
+; 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)
index cbc10ebb467f4d59be7c20c75ce145e9091c562e..7cad3fc7ee326ddad88b857aee0f0587bc9277fd 100644 (file)
@@ -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:
index 57497b5ce1afe6faa23ee6b80682fd07c7232d4f..d43a173485c282ac5b54a1833795659149132e00 100644 (file)
@@ -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
index 634a17d0925ec298694c2397ecf36f98522e996e..119ffd301ff34eec1f74f1f51a57dd30cddf4630 100644 (file)
@@ -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
index 7f0c0594ce95de5761aec87bc3378241bf931ec9..5c90bf724b9700d5f2a47604e3e3259120623ef2 100644 (file)
@@ -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.