[llvm] r231898 - Print section start labels when first switching to the section.

Rafael Espindola rafael.espindola at gmail.com
Tue Mar 10 17:51:38 PDT 2015


Author: rafael
Date: Tue Mar 10 19:51:37 2015
New Revision: 231898

URL: http://llvm.org/viewvc/llvm-project?rev=231898&view=rev
Log:
Print section start labels when first switching to the section.

This is less brittle and avoids polluting the start of the file with every
debug section.

Added:
    llvm/trunk/test/DebugInfo/X86/header.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/MC/MCStreamer.cpp
    llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll
    llvm/trunk/test/DebugInfo/AArch64/struct_by_value.ll
    llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll
    llvm/trunk/test/DebugInfo/X86/dbg-i128-const.ll
    llvm/trunk/test/DebugInfo/X86/stmt-list.ll
    llvm/trunk/test/DebugInfo/X86/tls.ll
    llvm/trunk/test/DebugInfo/array.ll
    llvm/trunk/test/MC/ELF/gen-dwarf.s

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Mar 10 19:51:37 2015
@@ -241,14 +241,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
 // 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(unsign
 // 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(uns
 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);

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Mar 10 19:51:37 2015
@@ -339,9 +339,6 @@ class DwarfDebug : public AsmPrinterHand
   /// \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);
 

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Tue Mar 10 19:51:37 2015
@@ -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 MCS
   if (MCSectionSubPair(Section, Subsection) != curSection) {
     SectionStack.back().first = MCSectionSubPair(Section, Subsection);
     ChangeSection(Section, Subsection);
+    MCSymbol *Sym = Section->getBeginSymbol();
+    if (Sym && !Sym->isInSection())
+      EmitLabel(Sym);
   }
 }

Modified: llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll (original)
+++ llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll Tue Mar 10 19:51:37 2015
@@ -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
  

Modified: llvm/trunk/test/DebugInfo/AArch64/struct_by_value.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/AArch64/struct_by_value.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/AArch64/struct_by_value.ll (original)
+++ llvm/trunk/test/DebugInfo/AArch64/struct_by_value.ll Tue Mar 10 19:51:37 2015
@@ -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

Modified: llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll (original)
+++ llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll Tue Mar 10 19:51:37 2015
@@ -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 at dtprel+32768
 
 @tls = thread_local global i32 0, align 4

Modified: llvm/trunk/test/DebugInfo/X86/dbg-i128-const.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-i128-const.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dbg-i128-const.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/dbg-i128-const.ll Tue Mar 10 19:51:37 2015
@@ -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
 

Added: llvm/trunk/test/DebugInfo/X86/header.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/header.ll?rev=231898&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/header.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/header.ll Tue Mar 10 19:51:37 2015
@@ -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, at 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)

Modified: llvm/trunk/test/DebugInfo/X86/stmt-list.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/stmt-list.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/stmt-list.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/stmt-list.ll Tue Mar 10 19:51:37 2015
@@ -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,"", at progbits
 ; CHECK-NEXT: .Lsection_line:
-
-; CHECK:      .long   .Lline_table_start0          # DW_AT_stmt_list
+; CHECK-NEXT: .Lline_table_start0:
 
 define void @f() {
 entry:

Modified: llvm/trunk/test/DebugInfo/X86/tls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/tls.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/tls.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/tls.ll Tue Mar 10 19:51:37 2015
@@ -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 at DTPOFF
 ; FISSION-NEXT: .quad  glbl
 ; FISSION-NOT: .quad  glbl

Modified: llvm/trunk/test/DebugInfo/array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/array.ll?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/array.ll (original)
+++ llvm/trunk/test/DebugInfo/array.ll Tue Mar 10 19:51:37 2015
@@ -25,6 +25,7 @@ declare void @llvm.dbg.declare(metadata,
 !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

Modified: llvm/trunk/test/MC/ELF/gen-dwarf.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/gen-dwarf.s?rev=231898&r1=231897&r2=231898&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/gen-dwarf.s (original)
+++ llvm/trunk/test/MC/ELF/gen-dwarf.s Tue Mar 10 19:51:37 2015
@@ -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.





More information about the llvm-commits mailing list