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
This commit is contained in:
David Blaikie 2014-03-18 01:17:26 +00:00
parent cdbfefbfed
commit 9c1e56a84d
5 changed files with 57 additions and 16 deletions

View File

@ -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);

View File

@ -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<DwarfUnit *> &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();

View File

@ -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);

View File

@ -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

View File

@ -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