From 9c1e56a84d5618e74662d98c0416a74e5a7ab31d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 18 Mar 2014 01:17:26 +0000 Subject: [PATCH] DebugInfo: Implement debug_line.dwo for file names used in type units during -gsplit-dwarf This removes an attribute (and more importantly, a relocation) from skeleton type units and removes some unnecessary file names from the debug_line section that remains in the .o (and linked executable) file. There's still a few places we could shave off some more space here: * use compilation dir of the underlying compilation unit (since all the type units share that compilation dir - though this would be more complicated in LTO cases where they don't (keep a map of compilation dir->line table header?)) * Remove some of the unnecessary header fields from the line table since they're not needed in this situation (about 12 bytes per table). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204099 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 14 +++++++++++--- lib/CodeGen/AsmPrinter/DwarfDebug.h | 8 ++++++++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 16 +++++++++++++--- lib/CodeGen/AsmPrinter/DwarfUnit.h | 16 ++++++++++++---- test/DebugInfo/X86/generate-odr-hash.ll | 19 +++++++++++++------ 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 77765e12f81..ab03753227d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1060,6 +1060,7 @@ void DwarfDebug::endModule() { emitDebugStrDWO(); emitDebugInfoDWO(); emitDebugAbbrevDWO(); + emitDebugLineDWO(); // Emit DWO addresses. InfoHolder.emitAddresses(Asm->getObjFileLowering().getDwarfAddrSection()); } @@ -2658,7 +2659,6 @@ DwarfTypeUnit *DwarfDebug::constructSkeletonTU(DwarfTypeUnit *TU) { NewTU->setType(NULL); NewTU->initSection( Asm->getObjFileLowering().getDwarfTypesSection(TU->getTypeSignature())); - CU.applyStmtList(*Die); initSkeletonUnit(TU, Die, NewTU); return NewTU; @@ -2680,6 +2680,13 @@ void DwarfDebug::emitDebugAbbrevDWO() { InfoHolder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection()); } +void DwarfDebug::emitDebugLineDWO() { + assert(useSplitDwarf() && "No split dwarf?"); + Asm->OutStreamer.SwitchSection( + Asm->getObjFileLowering().getDwarfLineDWOSection()); + Asm->OutStreamer.EmitLabel(SplitTypeUnitFileTable.Emit(&Asm->OutStreamer).second); +} + // Emit the .debug_str.dwo section for separated dwarf. This contains the // string section and is identical in format to traditional .debug_str // sections. @@ -2708,8 +2715,9 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU, } DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit); - DwarfTypeUnit *NewTU = new DwarfTypeUnit(InfoHolder.getUnits().size(), - UnitDie, CU, Asm, this, &InfoHolder); + DwarfTypeUnit *NewTU = new DwarfTypeUnit( + InfoHolder.getUnits().size(), UnitDie, CU, Asm, this, &InfoHolder, + useSplitDwarf() ? &SplitTypeUnitFileTable : nullptr); TU = NewTU; InfoHolder.addUnit(NewTU); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 71ff75d640a..4756509d094 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -27,6 +27,7 @@ #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DebugLoc.h" #include "llvm/MC/MachineLocation.h" +#include "llvm/MC/MCDwarf.h" #include "llvm/Support/Allocator.h" namespace llvm { @@ -486,6 +487,10 @@ class DwarfDebug : public AsmPrinterHandler { // Holder for the skeleton information. DwarfFile SkeletonHolder; + // Store file names for type units under fission in a line table header that + // will be emitted into debug_line.dwo. + MCDwarfLineTableHeader SplitTypeUnitFileTable; + void addScopeVariable(LexicalScope *LS, DbgVariable *Var); const SmallVectorImpl &getUnits() { @@ -621,6 +626,9 @@ class DwarfDebug : public AsmPrinterHandler { /// \brief Emit the debug abbrev dwo section. void emitDebugAbbrevDWO(); + /// \brief Emit the debug line dwo section. + void emitDebugLineDWO(); + /// \brief Emit the debug str dwo section. void emitDebugStrDWO(); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 9b7e38f9bd4..2a74d0552fe 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -56,8 +56,13 @@ DwarfCompileUnit::DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, } DwarfTypeUnit::DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, - AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU) - : DwarfUnit(UID, D, CU.getCUNode(), A, DW, DWU), CU(CU) {} + AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, + MCDwarfLineTableHeader *SplitLineTable) + : DwarfUnit(UID, D, CU.getCUNode(), A, DW, DWU), CU(CU), + SplitLineTable(SplitLineTable) { + if (SplitLineTable) + addSectionOffset(UnitDie.get(), dwarf::DW_AT_stmt_list, 0); +} /// ~Unit - Destructor for compile unit. DwarfUnit::~DwarfUnit() { @@ -307,6 +312,11 @@ unsigned DwarfCompileUnit::getOrCreateSourceID(StringRef FileName, StringRef Dir Asm->OutStreamer.hasRawTextSupport() ? 0 : getUniqueID()); } +unsigned DwarfTypeUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) { + return SplitLineTable ? SplitLineTable->getFile(DirName, FileName) + : getCU().getOrCreateSourceID(FileName, DirName); +} + /// addOpAddress - Add a dwarf op address data and value using the /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index. /// @@ -394,7 +404,7 @@ void DwarfUnit::addSourceLine(DIE *Die, unsigned Line, StringRef File, if (Line == 0) return; - unsigned FileID = getCU().getOrCreateSourceID(File, Directory); + unsigned FileID = getOrCreateSourceID(File, Directory); assert(FileID && "Invalid file id"); addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); addUInt(Die, dwarf::DW_AT_decl_line, None, Line); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 705c95bf28a..68954dc5548 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -23,6 +23,7 @@ #include "llvm/IR/DebugInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCSection.h" +#include "llvm/MC/MCDwarf.h" namespace llvm { @@ -511,6 +512,10 @@ protected: /// getOrCreateStaticMemberDIE - Create new static data member DIE. DIE *getOrCreateStaticMemberDIE(DIDerivedType DT); + /// Look up the source ID with the given directory and source file names. If + /// none currently exists, create a new ID and insert it in the line table. + virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0; + private: /// constructTypeDIE - Construct basic type die from DIBasicType. void constructTypeDIE(DIE &Buffer, DIBasicType BTy); @@ -603,9 +608,7 @@ public: DwarfCompileUnit &getCU() override { return *this; } - /// Look up the source ID with the given directory and source file names. If - /// none currently exists, create a new ID and insert it in the line table. - unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName); + unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override; }; class DwarfTypeUnit : public DwarfUnit { @@ -613,10 +616,12 @@ private: uint64_t TypeSignature; const DIE *Ty; DwarfCompileUnit &CU; + MCDwarfLineTableHeader *SplitLineTable; public: DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, AsmPrinter *A, - DwarfDebug *DW, DwarfFile *DWU); + DwarfDebug *DW, DwarfFile *DWU, + MCDwarfLineTableHeader *SplitLineTable = nullptr); void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } uint64_t getTypeSignature() const { return TypeSignature; } @@ -631,6 +636,9 @@ public: } void initSection(const MCSection *Section); DwarfCompileUnit &getCU() override { return CU; } + +protected: + unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override; }; } // end llvm namespace #endif diff --git a/test/DebugInfo/X86/generate-odr-hash.ll b/test/DebugInfo/X86/generate-odr-hash.ll index 64a428e2d52..e01863d76c3 100644 --- a/test/DebugInfo/X86/generate-odr-hash.ll +++ b/test/DebugInfo/X86/generate-odr-hash.ll @@ -76,9 +76,9 @@ ; FISSION-NOT: type_signature ; FISSION-LABEL: type_signature = 0x1d02f3be30cc5688 ; FISSION: DW_TAG_type_unit -; FISSION: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000) -; FISSION: DW_AT_GNU_dwo_name{{.*}}"bar.dwo" -; FISSION: DW_AT_comp_dir{{.*}}"/tmp/dbginfo" +; FISSION-NEXT: DW_AT_GNU_dwo_name{{.*}}"bar.dwo" +; FISSION-NEXT: DW_AT_GNU_addr_base +; FISSION-NEXT: DW_AT_comp_dir{{.*}}"/tmp/dbginfo" ; FISSION-NOT: type_signature ; FISSION-LABEL: type_signature = 0xb04af47397402e77 ; FISSION-NOT: type_signature @@ -120,8 +120,7 @@ ; CHECK-NOT: type_signature ; CHECK-LABEL: type_signature = 0xe94f6d3843e62d6b ; CHECK: DW_TAG_type_unit -; SINGLE: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000) -; FISSION-NOT: DW_AT_stmt_list +; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000) ; CHECK-NOT: NULL ; CHECK-NOT: DW_AT_GNU_odr_signature ; CHECK: DW_TAG_structure_type @@ -136,9 +135,17 @@ ; CHECK-LABEL: .debug_line contents: ; CHECK: Line table prologue ; CHECK-NOT: file_names[ -; CHECK: file_names{{.*}} bar.h +; SINGLE: file_names{{.*}} bar.h ; CHECK: file_names{{.*}} bar.cpp ; CHECK-NOT: file_names[ + +; CHECK-LABEL: .debug_line.dwo contents: +; FISSION: Line table prologue +; FISSION-NOT: file_names[ +; FISSION: file_names{{.*}} bar.h +; FISSION: file_names{{.*}} bar.cpp +; FISSION-NOT: file_names[ + ; CHECK-LABEL: .debug_str contents: ; Use the unit size as a rough hash/identifier for the unit we're dealing with