1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

DebugInfo: Use address pool forms in debug_rnglists

Save no relocations by reusing addresses from the address pool.

llvm-svn: 344836
This commit is contained in:
David Blaikie 2018-10-20 07:36:39 +00:00
parent a79c8f8708
commit 1edc4789b6
11 changed files with 140 additions and 121 deletions

View File

@ -415,6 +415,7 @@ void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
case dwarf::DW_FORM_ref_udata:
case dwarf::DW_FORM_strx:
case dwarf::DW_FORM_addrx:
case dwarf::DW_FORM_rnglistx:
case dwarf::DW_FORM_udata:
Asm->EmitULEB128(Integer);
return;
@ -442,6 +443,7 @@ unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
case dwarf::DW_FORM_ref_udata:
case dwarf::DW_FORM_strx:
case dwarf::DW_FORM_addrx:
case dwarf::DW_FORM_rnglistx:
case dwarf::DW_FORM_udata:
return getULEB128Size(Integer);
case dwarf::DW_FORM_sdata:

View File

@ -424,24 +424,30 @@ void DwarfCompileUnit::addScopeRangeList(DIE &ScopeDIE,
? TLOF.getDwarfRnglistsSection()->getBeginSymbol()
: TLOF.getDwarfRangesSection()->getBeginSymbol();
RangeSpanList List(Asm->createTempSymbol("debug_ranges"), std::move(Range));
HasRangeLists = true;
// Add the range list to the set of ranges to be emitted.
auto IndexAndList =
(DD->getDwarfVersion() < 5 && Skeleton ? Skeleton->DU : DU)
->addRange((Skeleton ? Skeleton->BaseAddress : BaseAddress),
std::move(Range));
uint32_t Index = IndexAndList.first;
auto &List = *IndexAndList.second;
// Under fission, ranges are specified by constant offsets relative to the
// CU's DW_AT_GNU_ranges_base.
// FIXME: For DWARF v5, do not generate the DW_AT_ranges attribute under
// fission until we support the forms using the .debug_addr section
// (DW_RLE_startx_endx etc.).
if (isDwoUnit()) {
if (DD->getDwarfVersion() < 5)
addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
RangeSectionSym);
} else {
if (isDwoUnit())
addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
RangeSectionSym);
else if (DD->getDwarfVersion() >= 5)
addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_rnglistx, Index);
else
addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
RangeSectionSym);
}
// Add the range list to the set of ranges to be emitted.
(Skeleton ? Skeleton : this)->CURangeLists.push_back(std::move(List));
}
void DwarfCompileUnit::attachRangesOrLowHighPC(

View File

@ -44,6 +44,7 @@ class MDNode;
class DwarfCompileUnit final : public DwarfUnit {
/// A numeric ID unique among all CUs in the module
unsigned UniqueID;
bool HasRangeLists = false;
/// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding
/// the need to search for it in applyStmtList.
@ -69,10 +70,6 @@ class DwarfCompileUnit final : public DwarfUnit {
/// GlobalTypes - A map of globally visible types for this unit.
StringMap<const DIE *> GlobalTypes;
// List of range lists for a given compile unit, separate from the ranges for
// the CU itself.
SmallVector<RangeSpanList, 1> CURangeLists;
// List of ranges for a given compile unit.
SmallVector<RangeSpan, 2> CURanges;
@ -108,6 +105,7 @@ public:
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A,
DwarfDebug *DW, DwarfFile *DWU);
bool hasRangeLists() const { return HasRangeLists; }
unsigned getUniqueID() const { return UniqueID; }
DwarfCompileUnit *getSkeleton() const {
@ -299,11 +297,6 @@ public:
void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie);
/// getRangeLists - Get the vector of range lists.
const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
return (Skeleton ? Skeleton : this)->CURangeLists;
}
/// getRanges - Get the list of ranges for this unit.
const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
SmallVector<RangeSpan, 2> takeRanges() { return std::move(CURanges); }

View File

@ -728,9 +728,13 @@ void DwarfDebug::beginModule() {
// Create the symbol that designates the start of the DWARF v5 range list
// table. It is located past the header and before the offsets table.
if (getDwarfVersion() >= 5)
if (getDwarfVersion() >= 5) {
(useSplitDwarf() ? SkeletonHolder : InfoHolder)
.setRnglistsTableBaseSym(Asm->createTempSymbol("rnglists_table_base"));
if (useSplitDwarf())
InfoHolder.setRnglistsTableBaseSym(
Asm->createTempSymbol("rnglists_dwo_table_base"));
}
// Create the symbol that points to the first entry following the debug
// address table (.debug_addr) header.
@ -852,7 +856,7 @@ void DwarfDebug::finalizeModuleInfo() {
dwarf::DW_FORM_data8, ID);
}
if (getDwarfVersion() < 5 && !SkCU->getRangeLists().empty()) {
if (getDwarfVersion() < 5 && !SkeletonHolder.getRangeLists().empty()) {
const MCSymbol *Sym = TLOF.getDwarfRangesSection()->getBeginSymbol();
SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_ranges_base,
Sym, Sym);
@ -884,8 +888,7 @@ void DwarfDebug::finalizeModuleInfo() {
U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges());
}
if (getDwarfVersion() >= 5 && !useSplitDwarf() &&
!U.getRangeLists().empty())
if (getDwarfVersion() >= 5 && U.hasRangeLists())
U.addRnglistsBase();
auto *CUNode = cast<DICompileUnit>(P.first);
@ -2134,10 +2137,10 @@ void DwarfDebug::emitDebugARanges() {
}
/// Emit a single range list. We handle both DWARF v5 and earlier.
static void emitRangeList(AsmPrinter *Asm, DwarfCompileUnit *CU,
static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
const RangeSpanList &List) {
auto DwarfVersion = CU->getDwarfVersion();
auto DwarfVersion = DD.getDwarfVersion();
// Emit our symbol so we can find the beginning of the range.
Asm->OutStreamer->EmitLabel(List.getSym());
// Gather all the ranges that apply to the same section so they can share
@ -2149,7 +2152,7 @@ static void emitRangeList(AsmPrinter *Asm, DwarfCompileUnit *CU,
for (const RangeSpan &Range : List.getRanges())
SectionRanges[&Range.getStart()->getSection()].push_back(&Range);
auto *CUBase = CU->getBaseAddress();
const MCSymbol *CUBase = List.getBaseAddress();
bool BaseIsSet = false;
for (const auto &P : SectionRanges) {
// Don't bother with a base address entry if there's only one range in
@ -2166,12 +2169,15 @@ static void emitRangeList(AsmPrinter *Asm, DwarfCompileUnit *CU,
// the lowest address/range in this object.
Base = P.second.front()->getStart();
if (DwarfVersion >= 5) {
Asm->OutStreamer->AddComment("DW_RLE_base_address");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_base_address, 1);
} else
Asm->OutStreamer->AddComment("DW_RLE_base_addressx");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_base_addressx, 1);
Asm->OutStreamer->AddComment(" base address index");
Asm->EmitULEB128(DD.getAddressPool().getIndex(Base));
} else {
Asm->OutStreamer->EmitIntValue(-1, Size);
Asm->OutStreamer->AddComment(" base address");
Asm->OutStreamer->EmitSymbolValue(Base, Size);
Asm->OutStreamer->AddComment(" base address");
Asm->OutStreamer->EmitSymbolValue(Base, Size);
}
} else if (BaseIsSet && DwarfVersion < 5) {
BaseIsSet = false;
assert(!Base);
@ -2198,10 +2204,10 @@ static void emitRangeList(AsmPrinter *Asm, DwarfCompileUnit *CU,
Asm->EmitLabelDifference(End, Base, Size);
}
} else if (DwarfVersion >= 5) {
Asm->OutStreamer->AddComment("DW_RLE_start_length");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_start_length, 1);
Asm->OutStreamer->AddComment(" start");
Asm->OutStreamer->EmitSymbolValue(Begin, Size);
Asm->OutStreamer->AddComment("DW_RLE_startx_length");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_startx_length, 1);
Asm->OutStreamer->AddComment(" start index");
Asm->EmitULEB128(DD.getAddressPool().getIndex(Begin));
Asm->OutStreamer->AddComment(" length");
Asm->EmitLabelDifferenceAsULEB128(End, Begin);
} else {
@ -2223,85 +2229,72 @@ static void emitRangeList(AsmPrinter *Asm, DwarfCompileUnit *CU,
// Emit the header of a DWARF 5 range list table. Returns the symbol that
// designates the end of the table for the caller to emit when the table is
// complete.
static MCSymbol *emitRnglistsTableHeader(AsmPrinter *Asm, DwarfFile &Holder) {
static MCSymbol *emitRnglistsTableHeader(AsmPrinter *Asm,
const DwarfFile &Holder) {
// The length is described by a starting label right after the length field
// and an end label.
MCSymbol *TableStart = Asm->createTempSymbol("debug_rnglist_table_start");
MCSymbol *TableEnd = Asm->createTempSymbol("debug_rnglist_table_end");
// Build the range table header, which starts with the length field.
Asm->OutStreamer->AddComment("Length");
Asm->EmitLabelDifference(TableEnd, TableStart, 4);
Asm->OutStreamer->EmitLabel(TableStart);
// Version number (DWARF v5 and later).
Asm->OutStreamer->AddComment("Version");
Asm->emitInt16(Asm->OutStreamer->getContext().getDwarfVersion());
// Address size.
Asm->OutStreamer->AddComment("Address size");
Asm->emitInt8(Asm->MAI->getCodePointerSize());
// Segment selector size.
Asm->OutStreamer->AddComment("Segment selector size");
Asm->emitInt8(0);
MCSymbol *RnglistTableBaseSym = Holder.getRnglistsTableBaseSym();
MCSymbol *RnglistsTableBaseSym = Holder.getRnglistsTableBaseSym();
// FIXME: Generate the offsets table and use DW_FORM_rnglistx with the
// DW_AT_ranges attribute. Until then set the number of offsets to 0.
Asm->emitInt32(0);
Asm->OutStreamer->EmitLabel(RnglistTableBaseSym);
Asm->OutStreamer->AddComment("Offset entry count");
Asm->emitInt32(Holder.getRangeLists().size());
Asm->OutStreamer->EmitLabel(RnglistsTableBaseSym);
for (const RangeSpanList &List : Holder.getRangeLists())
Asm->EmitLabelDifference(List.getSym(), RnglistsTableBaseSym, 4);
return TableEnd;
}
void emitDebugRangesImpl(DwarfDebug &DD, AsmPrinter *Asm,
const DwarfFile &Holder, MCSymbol *TableEnd) {
for (const RangeSpanList &List : Holder.getRangeLists())
emitRangeList(DD, Asm, List);
if (TableEnd)
Asm->OutStreamer->EmitLabel(TableEnd);
}
/// Emit address ranges into the .debug_ranges section or into the DWARF v5
/// .debug_rnglists section.
void DwarfDebug::emitDebugRanges() {
if (CUMap.empty())
return;
auto NoRangesPresent = [this]() {
return llvm::all_of(
CUMap, [](const decltype(CUMap)::value_type &Pair) {
return Pair.second->getRangeLists().empty();
});
};
const auto &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
if (llvm::all_of(CUMap, [](const decltype(CUMap)::value_type &Pair) {
return Pair.second->getCUNode()->isDebugDirectivesOnly();
})) {
assert(NoRangesPresent() && "No debug ranges expected.");
if (Holder.getRangeLists().empty())
return;
}
if (!useRangesSection()) {
assert(NoRangesPresent() && "No debug ranges expected.");
return;
}
if (NoRangesPresent())
return;
assert(useRangesSection());
assert(llvm::none_of(CUMap, [](const decltype(CUMap)::value_type &Pair) {
return Pair.second->getCUNode()->isDebugDirectivesOnly();
}));
// Start the dwarf ranges section.
MCSymbol *TableEnd = nullptr;
if (getDwarfVersion() >= 5) {
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfRnglistsSection());
TableEnd = emitRnglistsTableHeader(Asm, useSplitDwarf() ? SkeletonHolder
: InfoHolder);
TableEnd = emitRnglistsTableHeader(Asm, Holder);
} else
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfRangesSection());
// Grab the specific ranges for the compile units in the module.
for (const auto &I : CUMap) {
DwarfCompileUnit *TheCU = I.second;
if (TheCU->getCUNode()->isDebugDirectivesOnly())
continue;
if (auto *Skel = TheCU->getSkeleton())
TheCU = Skel;
// Iterate over the misc ranges for the compile units in the module.
for (const RangeSpanList &List : TheCU->getRangeLists())
emitRangeList(Asm, TheCU, List);
}
if (TableEnd)
Asm->OutStreamer->EmitLabel(TableEnd);
emitDebugRangesImpl(*this, Asm, Holder, TableEnd);
}
void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) {

View File

@ -490,9 +490,7 @@ class DwarfDebug : public DebugHandlerBase {
/// Emit address ranges into a debug ranges section.
void emitDebugRanges();
/// Emit range lists into a DWARF v5 debug rnglists section.
void emitDebugRnglists();
void emitDebugRangesDWO();
/// Emit macros into a debug macinfo section.
void emitDebugMacinfo();

View File

@ -109,3 +109,11 @@ void DwarfFile::addScopeLabel(LexicalScope *LS, DbgLabel *Label) {
SmallVectorImpl<DbgLabel *> &Labels = ScopeLabels[LS];
Labels.push_back(Label);
}
std::pair<uint32_t, RangeSpanList *>
DwarfFile::addRange(const MCSymbol *&CUBaseAddress,
SmallVector<RangeSpan, 2> R) {
CURangeLists.push_back(RangeSpanList(Asm->createTempSymbol("debug_ranges"),
CUBaseAddress, std::move(R)));
return std::make_pair(CURangeLists.size() - 1, &CURangeLists.back());
}

View File

@ -32,6 +32,37 @@ class DwarfUnit;
class LexicalScope;
class MCSection;
// Data structure to hold a range for range lists.
class RangeSpan {
public:
RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
const MCSymbol *getStart() const { return Start; }
const MCSymbol *getEnd() const { return End; }
void setEnd(const MCSymbol *E) { End = E; }
private:
const MCSymbol *Start, *End;
};
class RangeSpanList {
private:
// Index for locating within the debug_range section this particular span.
MCSymbol *RangeSym;
const MCSymbol **CUBaseAddress;
// List of ranges.
SmallVector<RangeSpan, 2> Ranges;
public:
RangeSpanList(MCSymbol *Sym, const MCSymbol *&CUBaseAddress,
SmallVector<RangeSpan, 2> Ranges)
: RangeSym(Sym), CUBaseAddress(&CUBaseAddress),
Ranges(std::move(Ranges)) {}
MCSymbol *getSym() const { return RangeSym; }
const MCSymbol *&getBaseAddress() const { return *CUBaseAddress; }
const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
void addRange(RangeSpan Range) { Ranges.push_back(Range); }
};
class DwarfFile {
// Target of Dwarf emission, used for sizing of abbreviations.
AsmPrinter *Asm;
@ -46,6 +77,10 @@ class DwarfFile {
DwarfStringPool StrPool;
// List of range lists for a given compile unit, separate from the ranges for
// the CU itself.
SmallVector<RangeSpanList, 1> CURangeLists;
/// DWARF v5: The symbol that designates the start of the contribution to
/// the string offsets table. The contribution is shared by all units.
MCSymbol *StringOffsetsStartSym = nullptr;
@ -84,6 +119,14 @@ public:
return CUs;
}
std::pair<uint32_t, RangeSpanList *> addRange(const MCSymbol *&CUBaseAddress,
SmallVector<RangeSpan, 2> R);
/// getRangeLists - Get the vector of range lists.
const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
return CURangeLists;
}
/// Compute the size and offset of a DIE given an incoming Offset.
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);

View File

@ -35,33 +35,6 @@ class ConstantFP;
class DbgVariable;
class DwarfCompileUnit;
// Data structure to hold a range for range lists.
class RangeSpan {
public:
RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
const MCSymbol *getStart() const { return Start; }
const MCSymbol *getEnd() const { return End; }
void setEnd(const MCSymbol *E) { End = E; }
private:
const MCSymbol *Start, *End;
};
class RangeSpanList {
private:
// Index for locating within the debug_range section this particular span.
MCSymbol *RangeSym;
// List of ranges.
SmallVector<RangeSpan, 2> Ranges;
public:
RangeSpanList(MCSymbol *Sym, SmallVector<RangeSpan, 2> Ranges)
: RangeSym(Sym), Ranges(std::move(Ranges)) {}
MCSymbol *getSym() const { return RangeSym; }
const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
void addRange(RangeSpan Range) { Ranges.push_back(Range); }
};
//===----------------------------------------------------------------------===//
/// This dwarf writer support class manages information associated with a
/// source file.

View File

@ -56,11 +56,14 @@
; V5RNGLISTS-NOT: DW_TAG
; V5RNGLISTS: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000c)
; V5RNGLISTS: .debug_rnglists contents:
; V5RNGLISTS-NEXT: 0x00000000: range list header: length = 0x00000015, version = 0x0005,
; V5RNGLISTS-SAME: addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
; V5RNGLISTS-NEXT: 0x00000000: range list header: length = 0x00000019, version = 0x0005,
; V5RNGLISTS-SAME: addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000001
; V5RNGLISTS-NEXT: offsets: [
; V5RNGLISTS-NEXT: => 0x00000010
; V5RNGLISTS-NEXT: ]
; V5RNGLISTS-NEXT: ranges:
; V5RNGLISTS-NEXT: 0x0000000c: [DW_RLE_offset_pair]:
; V5RNGLISTS-NEXT: 0x0000000f: [DW_RLE_offset_pair]:
; V5RNGLISTS-NEXT: 0x00000010: [DW_RLE_offset_pair]:
; V5RNGLISTS-NEXT: 0x00000013: [DW_RLE_offset_pair]:
; V5RNGLISTS: 0x{{[0-9a-f]+}}: [DW_RLE_end_of_list]
; From the code:

View File

@ -38,22 +38,22 @@
; COMMON-NEXT: .quad 0
; DWARF5: {{^.Ldebug_ranges0}}
; DWARF5-NEXT: # DW_RLE_start_length
; DWARF5-NEXT: .quad .Lfunc_begin0 # start
; DWARF5-NEXT: # DW_RLE_startx_length
; DWARF5-NEXT: .byte 0 # start index
; DWARF5-NEXT: .uleb128 .Lfunc_end0-.Lfunc_begin0 # length
; DWARF5-NEXT: # DW_RLE_base_address
; DWARF5-NEXT: .quad .Lfunc_begin1 # base address
; DWARF5-NEXT: # DW_RLE_base_addressx
; DWARF5-NEXT: .byte 1 # base address index
; DWARF5-NEXT: # DW_RLE_offset_pair
; DWARF5-NEXT: .uleb128 .Lfunc_begin1-.Lfunc_begin1 # starting offset
; DWARF5-NEXT: .uleb128 .Lfunc_end1-.Lfunc_begin1 # ending offset
; DWARF5-NEXT: # DW_RLE_offset_pair
; DWARF5-NEXT: .uleb128 .Lfunc_begin3-.Lfunc_begin1 # starting offset
; DWARF5-NEXT: .uleb128 .Lfunc_end3-.Lfunc_begin1 # ending offset
; DWARF5-NEXT: # DW_RLE_start_length
; DWARF5-NEXT: .quad .Lfunc_begin4 # start
; DWARF5-NEXT: # DW_RLE_startx_length
; DWARF5-NEXT: .byte 3 # start index
; DWARF5-NEXT: .uleb128 .Lfunc_end4-.Lfunc_begin4 # length
; DWARF5-NEXT: # DW_RLE_start_length
; DWARF5-NEXT: .quad .Lfunc_begin5 # start
; DWARF5-NEXT: # DW_RLE_startx_length
; DWARF5-NEXT: .byte 4 # start index
; DWARF5-NEXT: .uleb128 .Lfunc_end5-.Lfunc_begin5 # length
; DWARF5-NEXT: # DW_RLE_end_of_list

View File

@ -16,8 +16,8 @@
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000c)
; CHECK: .debug_rnglists contents:
; CHECK: 0x00000000: range list header: length = 0x0000001d, version = 0x0005,
; CHECK-SAME: addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
; CHECK: 0x00000000: range list header: length = 0x00000013, version = 0x0005,
; CHECK-SAME: addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000001
; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @f1() section "text.foo" !dbg !7 {