[llvm] r328314 - [DEBUGINFO] Add flag for DWARF2 to use sections as references.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 23 06:35:54 PDT 2018
Author: abataev
Date: Fri Mar 23 06:35:54 2018
New Revision: 328314
URL: http://llvm.org/viewvc/llvm-project?rev=328314&view=rev
Log:
[DEBUGINFO] Add flag for DWARF2 to use sections as references.
Summary:
Some targets does not support labels inside debug sections, but support
references in form `section+offset`. Patch adds initial support
for this.
Reviewers: echristo, probinson, jlebar
Subscribers: llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D43943
Added:
llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=328314&r1=328313&r2=328314&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Fri Mar 23 06:35:54 2018
@@ -270,15 +270,20 @@ void DwarfCompileUnit::addRange(RangeSpa
void DwarfCompileUnit::initStmtList() {
// Define start line table label for each Compile Unit.
- MCSymbol *LineTableStartSym =
- Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
+ MCSymbol *LineTableStartSym;
+ const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
+ if (DD->useSectionsAsReferences()) {
+ LineTableStartSym = TLOF.getDwarfLineSection()->getBeginSymbol();
+ } else {
+ LineTableStartSym =
+ Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
+ }
// DW_AT_stmt_list is a offset of line number information for this
// compile unit in debug_line section. For split dwarf this is
// left in the skeleton CU and so not included.
// The line table entries are not always emitted in assembly, so it
// is not okay to use line_table_start here.
- const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
StmtListValue =
addSectionLabel(getUnitDie(), dwarf::DW_AT_stmt_list, LineTableStartSym,
TLOF.getDwarfLineSection()->getBeginSymbol());
@@ -835,7 +840,7 @@ void DwarfCompileUnit::createAbstractVar
void DwarfCompileUnit::emitHeader(bool UseOffsets) {
// Don't bother labeling the .dwo unit, as its offset isn't used.
- if (!Skeleton) {
+ if (!Skeleton && !DD->useSectionsAsReferences()) {
LabelBegin = Asm->createTempSymbol("cu_begin");
Asm->OutStreamer->EmitLabel(LabelBegin);
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=328314&r1=328313&r2=328314&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Fri Mar 23 06:35:54 2018
@@ -133,6 +133,13 @@ static cl::opt<bool>
cl::desc("Disable emission .debug_ranges section."),
cl::init(false));
+static cl::opt<DefaultOnOff> DwarfSectionsAsReferences(
+ "dwarf-sections-as-references", cl::Hidden,
+ cl::desc("Use sections+offset as references rather than labels."),
+ cl::values(clEnumVal(Default, "Default for platform"),
+ clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
+ cl::init(Default));
+
enum LinkageNameOption {
DefaultLinkageNames,
AllLinkageNames,
@@ -323,6 +330,9 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
UsePubSections = !NoDwarfPubSections;
UseRangesSection = !NoDwarfRangesSection;
+ // Use sections as references.
+ UseSectionsAsReferences = DwarfSectionsAsReferences == Enable;
+
// Work around a GDB bug. GDB doesn't support the standard opcode;
// SCE doesn't support GNU's; LLDB prefers the standard opcode, which
// is defined as of DWARF 3.
@@ -1559,6 +1569,14 @@ void DwarfDebug::emitDebugPubSections()
}
}
+void DwarfDebug::emitSectionReference(const DwarfCompileUnit &CU) {
+ if (useSectionsAsReferences())
+ Asm->EmitDwarfOffset(CU.getSection()->getBeginSymbol(),
+ CU.getDebugSectionOffset());
+ else
+ Asm->emitDwarfSymbolReference(CU.getLabelBegin());
+}
+
void DwarfDebug::emitDebugPubSection(bool GnuStyle, StringRef Name,
DwarfCompileUnit *TheU,
const StringMap<const DIE *> &Globals) {
@@ -1577,7 +1595,7 @@ void DwarfDebug::emitDebugPubSection(boo
Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION);
Asm->OutStreamer->AddComment("Offset of Compilation Unit Info");
- Asm->emitDwarfSymbolReference(TheU->getLabelBegin());
+ emitSectionReference(*TheU);
Asm->OutStreamer->AddComment("Compilation Unit Length");
Asm->EmitInt32(TheU->getLength());
@@ -1876,7 +1894,7 @@ void DwarfDebug::emitDebugARanges() {
Asm->OutStreamer->AddComment("DWARF Arange version number");
Asm->EmitInt16(dwarf::DW_ARANGES_VERSION);
Asm->OutStreamer->AddComment("Offset Into Debug Info Section");
- Asm->emitDwarfSymbolReference(CU->getLabelBegin());
+ emitSectionReference(*CU);
Asm->OutStreamer->AddComment("Address Size (in bytes)");
Asm->EmitInt8(PtrSize);
Asm->OutStreamer->AddComment("Segment Size (in bytes)");
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=328314&r1=328313&r2=328314&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Fri Mar 23 06:35:54 2018
@@ -264,6 +264,10 @@ class DwarfDebug : public DebugHandlerBa
/// Allow emission of .debug_ranges section.
bool UseRangesSection = true;
+ /// True if the sections itself must be used as references and don't create
+ /// temp symbols inside DWARF sections.
+ bool UseSectionsAsReferences = false;
+
/// DWARF5 Experimental Options
/// @{
bool HasDwarfAccelTables;
@@ -448,6 +452,9 @@ class DwarfDebug : public DebugHandlerBa
void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
DenseSet<InlinedVariable> &P);
+ /// Emit the reference to the section.
+ void emitSectionReference(const DwarfCompileUnit &CU);
+
protected:
/// Gather pre-function debug information.
void beginFunctionImpl(const MachineFunction *MF) override;
@@ -513,6 +520,11 @@ public:
/// Returns whether ranges section should be emitted.
bool useRangesSection() const { return UseRangesSection; }
+ /// Returns whether to use sections as labels rather than temp symbols.
+ bool useSectionsAsReferences() const {
+ return UseSectionsAsReferences;
+ }
+
// Experimental DWARF5 features.
/// Returns whether or not to emit tables that dwarf consumers can
Added: llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/sections_as_references.ll?rev=328314&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/sections_as_references.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/sections_as_references.ll Fri Mar 23 06:35:54 2018
@@ -0,0 +1,54 @@
+; RUN: llc -filetype=asm -O0 -mtriple=x86_64-linux-gnu < %s -dwarf-sections-as-references=Enable -dwarf-inlined-strings=Enable -no-dwarf-pub-sections -no-dwarf-ranges-section -dwarf-version 2 -debugger-tune=gdb | FileCheck %s
+
+; CHECK: .file
+
+; CHECK-NOT: .L
+
+; CHECK: .section .debug_abbrev
+; CHECK-NOT: DW_FORM_str{{p|x}}
+; CHECK-NOT: .L
+
+; CHECK: .section .debug_info
+; CHECK-NOT: .L
+; CHECK: .short 2 # DWARF version number
+; CHECK-NOT: .L
+; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section
+; CHECK-NOT: .L
+; CHECK: .long .debug_line # DW_AT_stmt_list
+; CHECK-NOT: .L
+; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section
+; CHECK-NOT: .L
+; CHECK: .long .debug_line # DW_AT_stmt_list
+; CHECK-NOT: .L
+; CHECK: .quad .debug_info+{{[0-9]+}} # DW_AT_type
+; CHECK-NOT: .L
+; CHECK: .byte 0 # End Of Children Mark
+; CHECK-NOT: .L
+
+source_filename = "test/DebugInfo/X86/sections_as_references.ll"
+
+%struct.foo = type { i8 }
+
+ at f = global %struct.foo zeroinitializer, align 1, !dbg !0
+ at g = global %struct.foo zeroinitializer, align 1, !dbg !6
+
+!llvm.dbg.cu = !{!9, !12}
+!llvm.module.flags = !{!14, !15}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "f", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "tu1.cpp", directory: "/dir")
+!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !4, line: 1, size: 8, align: 8, elements: !5, identifier: "_ZTS3foo")
+!4 = !DIFile(filename: "./hdr.h", directory: "/dir")
+!5 = !{}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = !DIGlobalVariable(name: "g", scope: null, file: !8, line: 2, type: !3, isLocal: false, isDefinition: true)
+!8 = !DIFile(filename: "tu2.cpp", directory: "/dir")
+!9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !10, globals: !11, imports: !5)
+!10 = !{!3}
+!11 = !{!0}
+!12 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !8, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !10, globals: !13, imports: !5)
+!13 = !{!6}
+!14 = !{i32 2, !"Dwarf Version", i32 2}
+!15 = !{i32 1, !"Debug Info Version", i32 3}
+
More information about the llvm-commits
mailing list