Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/MC/MCSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
return OS;
}

bool isRangeRelaxable(const MCSymbol *Begin, const MCSymbol *End);

} // end namespace llvm

#endif // LLVM_MC_MCSYMBOL_H
64 changes: 39 additions & 25 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3291,14 +3291,12 @@ static MCSymbol *emitLoclistsTableHeader(AsmPrinter *Asm,
}

template <typename Ranges, typename PayloadEmitter>
static void emitRangeList(
DwarfDebug &DD, AsmPrinter *Asm, MCSymbol *Sym, const Ranges &R,
const DwarfCompileUnit &CU, unsigned BaseAddressx, unsigned OffsetPair,
unsigned StartxLength, unsigned EndOfList,
StringRef (*StringifyEnum)(unsigned),
bool ShouldUseBaseAddress,
PayloadEmitter EmitPayload) {

static void
emitRangeList(DwarfDebug &DD, AsmPrinter *Asm, MCSymbol *Sym, const Ranges &R,
const DwarfCompileUnit &CU, unsigned BaseAddressx,
unsigned OffsetPair, unsigned StartxLength, unsigned StartxEndx,
unsigned EndOfList, StringRef (*StringifyEnum)(unsigned),
bool ShouldUseBaseAddress, PayloadEmitter EmitPayload) {
auto Size = Asm->MAI->getCodePointerSize();
bool UseDwarf5 = DD.getDwarfVersion() >= 5;

Expand All @@ -3317,7 +3315,8 @@ static void emitRangeList(
bool BaseIsSet = false;
for (const auto &P : SectionRanges) {
auto *Base = CUBase;
if ((Asm->TM.getTargetTriple().isNVPTX() && DD.tuneForGDB())) {
if ((Asm->TM.getTargetTriple().isNVPTX() && DD.tuneForGDB()) ||
(DD.useSplitDwarf() && UseDwarf5 && P.first->isLinkerRelaxable())) {
// PTX does not support subtracting labels from the code section in the
// debug_loc section. To work around this, the NVPTX backend needs the
// compile unit to have no low_pc in order to have a zero base_address
Expand Down Expand Up @@ -3373,12 +3372,27 @@ static void emitRangeList(
Asm->emitLabelDifference(End, Base, Size);
}
} else if (UseDwarf5) {
Asm->OutStreamer->AddComment(StringifyEnum(StartxLength));
Asm->emitInt8(StartxLength);
Asm->OutStreamer->AddComment(" start index");
Asm->emitULEB128(DD.getAddressPool().getIndex(Begin));
Asm->OutStreamer->AddComment(" length");
Asm->emitLabelDifferenceAsULEB128(End, Begin);
// NOTE: We can't use absoluteSymbolDiff here instead of
// isRangeRelaxable. While isRangeRelaxable only checks that the offset
// between labels won't change at link time (which is exactly what we
// need), absoluteSymbolDiff also requires that the offset remain
// unchanged at assembly time, imposing a much stricter condition.
// Consequently, this would lead to less optimal debug info emission.
if (DD.useSplitDwarf() && llvm::isRangeRelaxable(Begin, End)) {
Asm->OutStreamer->AddComment(StringifyEnum(StartxEndx));
Asm->emitInt8(StartxEndx);
Asm->OutStreamer->AddComment(" start index");
Asm->emitULEB128(DD.getAddressPool().getIndex(Begin));
Asm->OutStreamer->AddComment(" end index");
Asm->emitULEB128(DD.getAddressPool().getIndex(End));
} else {
Asm->OutStreamer->AddComment(StringifyEnum(StartxLength));
Asm->emitInt8(StartxLength);
Asm->OutStreamer->AddComment(" start index");
Asm->emitULEB128(DD.getAddressPool().getIndex(Begin));
Asm->OutStreamer->AddComment(" length");
Asm->emitLabelDifferenceAsULEB128(End, Begin);
}
} else {
Asm->OutStreamer->emitSymbolValue(Begin, Size);
Asm->OutStreamer->emitSymbolValue(End, Size);
Expand All @@ -3399,14 +3413,14 @@ static void emitRangeList(

// Handles emission of both debug_loclist / debug_loclist.dwo
static void emitLocList(DwarfDebug &DD, AsmPrinter *Asm, const DebugLocStream::List &List) {
emitRangeList(DD, Asm, List.Label, DD.getDebugLocs().getEntries(List),
*List.CU, dwarf::DW_LLE_base_addressx,
dwarf::DW_LLE_offset_pair, dwarf::DW_LLE_startx_length,
dwarf::DW_LLE_end_of_list, llvm::dwarf::LocListEncodingString,
/* ShouldUseBaseAddress */ true,
[&](const DebugLocStream::Entry &E) {
DD.emitDebugLocEntryLocation(E, List.CU);
});
emitRangeList(
DD, Asm, List.Label, DD.getDebugLocs().getEntries(List), *List.CU,
dwarf::DW_LLE_base_addressx, dwarf::DW_LLE_offset_pair,
dwarf::DW_LLE_startx_length, dwarf::DW_LLE_startx_endx,
dwarf::DW_LLE_end_of_list, llvm::dwarf::LocListEncodingString,
/* ShouldUseBaseAddress */ true, [&](const DebugLocStream::Entry &E) {
DD.emitDebugLocEntryLocation(E, List.CU);
});
}

void DwarfDebug::emitDebugLocImpl(MCSection *Sec) {
Expand Down Expand Up @@ -3628,8 +3642,8 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
const RangeSpanList &List) {
emitRangeList(DD, Asm, List.Label, List.Ranges, *List.CU,
dwarf::DW_RLE_base_addressx, dwarf::DW_RLE_offset_pair,
dwarf::DW_RLE_startx_length, dwarf::DW_RLE_end_of_list,
llvm::dwarf::RangeListEncodingString,
dwarf::DW_RLE_startx_length, dwarf::DW_RLE_startx_endx,
dwarf::DW_RLE_end_of_list, llvm::dwarf::RangeListEncodingString,
List.CU->getCUNode()->getRangesBaseAddress() ||
DD.getDwarfVersion() >= 5,
[](auto) {});
Expand Down
20 changes: 17 additions & 3 deletions llvm/lib/MC/MCSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,21 @@ void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void MCSymbol::dump() const {
dbgs() << *this;
}
LLVM_DUMP_METHOD void MCSymbol::dump() const { dbgs() << *this; }
#endif

// Determine whether the offset between two labels can change at link time.
// Currently, this function is used only in DWARF info emission logic, where it
// helps generate more optimal debug info when the offset between labels is
// constant at link time.
bool llvm::isRangeRelaxable(const MCSymbol *Begin, const MCSymbol *End) {
assert(Begin && "Range without a begin symbol?");
assert(End && "Range without an end symbol?");
for (const auto *Fragment = Begin->getFragment();
Fragment != End->getFragment(); Fragment = Fragment->getNext()) {
assert(Fragment);
if (Fragment->isLinkerRelaxable())
return true;
}
return false;
}
Loading