From e16f6c637258a26ae88dc18495e5f119b6f1f255 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 10 Dec 2018 22:44:48 +0000 Subject: [PATCH] debuginfo: Use symbol difference for CU length to simplify assembly reading/editing Mucking about simplifying a test case ( https://reviews.llvm.org/D55261 ) I stumbled across something I've hit before - that LLVM's (GCC's does too, FWIW) assembly output includes a hardcode length for a DWARF unit in its header. Instead we could emit a label difference - making the assembly easier to read/edit (though potentially at a slight (I haven't tried to observe it) performance cost of delaying/sinking the length computation into the MC layer). Reviewers: JDevlieghere, probinson, ABataev Differential Revision: https://reviews.llvm.org/D55281 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348806 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfFile.cpp | 2 ++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 13 ++++++++++++- lib/CodeGen/AsmPrinter/DwarfUnit.h | 2 ++ test/DebugInfo/X86/sections_as_references.ll | 11 +++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfFile.cpp b/lib/CodeGen/AsmPrinter/DwarfFile.cpp index 4e410bb49be..094c654943d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfFile.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfFile.cpp @@ -46,6 +46,8 @@ void DwarfFile::emitUnit(DwarfUnit *TheU, bool UseOffsets) { TheU->emitHeader(UseOffsets); Asm->emitDwarfDIE(Die); + + Asm->OutStreamer->EmitLabel(TheU->getEndLabel()); } // Compute the size and offset for each DIE. diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 2053395808f..90b91180c80 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -38,6 +38,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" #include #include #include @@ -1553,7 +1554,17 @@ DIE *DwarfUnit::getOrCreateStaticMemberDIE(const DIDerivedType *DT) { void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) { // Emit size of content not including length itself Asm->OutStreamer->AddComment("Length of Unit"); - Asm->emitInt32(getHeaderSize() + getUnitDie().getSize()); + StringRef Prefix = isDwoUnit() ? "debug_info_dwo_" : "debug_info_"; + MCSymbol *BeginLabel = Asm->createTempSymbol(Prefix + "start"); + EndLabel = Asm->createTempSymbol(Prefix + "end"); + + // Use a label difference for the convenience of legible/easily modified + // assembly - except on NVPTX where label differences aren't supported. + if (Asm->TM.getTargetTriple().isNVPTX()) + Asm->emitInt32(getHeaderSize() + getUnitDie().getSize()); + else + Asm->EmitLabelDifference(EndLabel, BeginLabel, 4); + Asm->OutStreamer->EmitLabel(BeginLabel); Asm->OutStreamer->AddComment("DWARF version number"); unsigned Version = DD->getDwarfVersion(); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 860d1653184..ec67c4b1cda 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -48,6 +48,7 @@ protected: /// Target of Dwarf emission. AsmPrinter *Asm; + MCSymbol *EndLabel; // Holders for some common dwarf information. DwarfDebug *DD; @@ -82,6 +83,7 @@ protected: public: // Accessors. AsmPrinter* getAsmPrinter() const { return Asm; } + MCSymbol *getEndLabel() const { return EndLabel; } uint16_t getLanguage() const { return CUNode->getSourceLanguage(); } const DICompileUnit *getCUNode() const { return CUNode; } diff --git a/test/DebugInfo/X86/sections_as_references.ll b/test/DebugInfo/X86/sections_as_references.ll index 0268b506003..bb2b0282d1f 100644 --- a/test/DebugInfo/X86/sections_as_references.ll +++ b/test/DebugInfo/X86/sections_as_references.ll @@ -9,13 +9,19 @@ ; CHECK-NOT: .L ; CHECK: .section .debug_info -; CHECK-NOT: .L -; CHECK: .short 2 # DWARF version number +; CHECK-NEXT: .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit +; CHECK-NEXT: .Ldebug_info_start0: +; CHECK-NEXT: .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: .Ldebug_info_end0: +; CHECK-NOT: .L +; CHECK: .long .Ldebug_info_end1-.Ldebug_info_start1 # Length of Unit +; CHECK-NEXT: .Ldebug_info_start1: +; CHECK-NOT: .L ; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section ; CHECK-NOT: .L ; CHECK: .long .debug_line # DW_AT_stmt_list @@ -23,6 +29,7 @@ ; CHECK: .quad .debug_info+{{[0-9]+}} # DW_AT_type ; CHECK-NOT: .L ; CHECK: .byte 0 # End Of Children Mark +; CHECK-NEXT: .Ldebug_info_end1: ; CHECK-NOT: .L source_filename = "test/DebugInfo/X86/sections_as_references.ll" -- 2.11.0