From: Victor Leschuk Date: Wed, 1 Aug 2018 05:48:06 +0000 (+0000) Subject: [DWARF] Basic support for producing DWARFv5 .debug_addr section X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=64e0c56717628333554be781d70d5fe45d5b9b0b;p=platform%2Fupstream%2Fllvm.git [DWARF] Basic support for producing DWARFv5 .debug_addr section This revision implements support for generating DWARFv5 .debug_addr section. The implementation is pretty straight-forward: we just check the dwarf version and emit section header if needed. Reviewers: aprantl, dblaikie, probinson Reviewed by: dblaikie Differential Revision: https://reviews.llvm.org/D50005 llvm-svn: 338487 --- diff --git a/llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp b/llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp index 4a226527..c8305ad 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp @@ -24,8 +24,26 @@ unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) { return IterBool.first->second.Number; } + +void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) { + static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize(); + Asm.OutStreamer->SwitchSection(Section); + + uint64_t Length = sizeof(uint16_t) // version + + sizeof(uint8_t) // address_size + + sizeof(uint8_t) // segment_selector_size + + AddrSize * Pool.size(); // entries + Asm.emitInt32(Length); // TODO: Support DWARF64 format. + Asm.emitInt16(Asm.getDwarfVersion()); + Asm.emitInt8(AddrSize); + Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size. +} + // Emit addresses into the section given. void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) { + if (Asm.getDwarfVersion() >= 5) + emitHeader(Asm, AddrSection); + if (Pool.empty()) return; diff --git a/llvm/lib/CodeGen/AsmPrinter/AddressPool.h b/llvm/lib/CodeGen/AsmPrinter/AddressPool.h index 5350006..d5008fa 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AddressPool.h +++ b/llvm/lib/CodeGen/AsmPrinter/AddressPool.h @@ -50,6 +50,9 @@ public: bool hasBeenUsed() const { return HasBeenUsed; } void resetUsedFlag() { HasBeenUsed = false; } + +private: + void emitHeader(AsmPrinter &Asm, MCSection *Section); }; } // end namespace llvm diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index e5a457e..0af408ae 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -886,8 +886,7 @@ void DwarfDebug::endModule() { emitDebugInfoDWO(); emitDebugAbbrevDWO(); emitDebugLineDWO(); - // Emit DWO addresses. - AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection()); + emitDebugAddr(); } // Emit info into the dwarf accelerator table sections. @@ -2297,6 +2296,12 @@ void DwarfDebug::emitDebugStrDWO() { OffSec, /* UseRelativeOffsets = */ false); } +// Emit DWO addresses. +void DwarfDebug::emitDebugAddr() { + assert(useSplitDwarf() && "No split dwarf?"); + AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection()); +} + MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) { if (!useSplitDwarf()) return nullptr; diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 0c7be5d..abf2e43 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -447,6 +447,9 @@ class DwarfDebug : public DebugHandlerBase { /// Emit the debug str dwo section. void emitDebugStrDWO(); + /// Emit DWO addresses. + void emitDebugAddr(); + /// Flags to let the linker know we have emitted new style pubnames. Only /// emit it here if we don't have a skeleton CU for split dwarf. void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const; diff --git a/llvm/test/DebugInfo/X86/debug_addr.ll b/llvm/test/DebugInfo/X86/debug_addr.ll new file mode 100644 index 0000000..cf6b241 --- /dev/null +++ b/llvm/test/DebugInfo/X86/debug_addr.ll @@ -0,0 +1,79 @@ +; RUN: llc -split-dwarf-file=test.dwo -dwarf-version=4 %s -mtriple=i386-unknown-linux-gnu -filetype=obj -o - | \ +; RUN: llvm-dwarfdump -v - | FileCheck %s -check-prefix=DWARF4 + +; RUN: llc -split-dwarf-file=test.dwo -dwarf-version=5 %s -mtriple=i386-unknown-linux-gnu -filetype=obj -o - | \ +; RUN: llvm-dwarfdump -v - | FileCheck %s -check-prefix=DWARF5 + +; Source: +; void foo() { +; } +; +; void bar() { +; } + +; DWARF4: .debug_info contents: +; DWARF4: Compile Unit:{{.*}}version = 0x0004 +; DWARF4-NOT: Compile Unit +; DWARF4: DW_TAG_compile_unit +; DWARF4-NOT: DW_TAG_{{.*}} +; DWARF4: DW_AT_GNU_dwo_name{{.*}}test.dwo +; DWARF4: DW_AT_GNU_addr_base{{.*}}0x00000000 +; DWARF4: .debug_addr contents: +; DWARF4-NEXT: 0x00000000: Addr Section: length = 0x00000000, version = 0x0004, addr_size = 0x04, seg_size = 0x00 +; DWARF4-NEXT: Addrs: [ +; DWARF4-NEXT: 0x00000000 +; DWARF4-NEXT: 0x00000010 +; DWARF4-NEXT: ] + +; DWARF5: .debug_info contents: +; DWARF5: Compile Unit:{{.*}}version = 0x0005 +; DWARF5-NOT: Compile Unit +; DWARF5: DW_TAG_compile_unit +; DWARF5-NOT: DW_TAG_{{.*}} +; DWARF5: DW_AT_GNU_dwo_name{{.*}}test.dwo +; DWARF5: DW_AT_GNU_addr_base{{.*}}0x00000000 +; DWARF5: .debug_addr contents: +; DWARF5-NEXT: 0x00000000: Addr Section: length = 0x0000000c, version = 0x0005, addr_size = 0x04, seg_size = 0x00 +; DWARF5-NEXT: Addrs: [ +; DWARF5-NEXT: 0x00000000 +; DWARF5-NEXT: 0x00000010 +; DWARF5-NEXT: ] + +; ModuleID = './test.c' +source_filename = "./test.c" +target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" +target triple = "i386-unknown-linux-gnu" + +; Function Attrs: noinline nounwind optnone +define void @foo() #0 !dbg !8 { +entry: + ret void, !dbg !12 +} + +; Function Attrs: noinline nounwind optnone +define void @bar() #0 !dbg !13 { +entry: + ret void, !dbg !14 +} + +attributes #0 = { noinline nounwind optnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.1", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "test.c", directory: "/tmp") +!2 = !{} +!3 = !{i32 1, !"NumRegisterParameters", i32 0} +!4 = !{i32 2, !"Dwarf Version", i32 5} +!5 = !{i32 2, !"Debug Info Version", i32 3} +!6 = !{i32 1, !"wchar_size", i32 4} +!7 = !{!"clang version 6.0.1"} +!8 = distinct !DISubprogram(name: "foo", scope: !9, file: !9, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0) +!9 = !DIFile(filename: "./test.c", directory: "/tmp") +!10 = !DISubroutineType(types: !11) +!11 = !{null} +!12 = !DILocation(line: 2, column: 3, scope: !8) +!13 = distinct !DISubprogram(name: "bar", scope: !9, file: !9, line: 5, type: !10, isLocal: false, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !0) +!14 = !DILocation(line: 6, column: 3, scope: !13)