[clang] [llvm] [dwarf] make dwarf fission compatible with RISCV relaxations (PR #164128)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 20 09:54:47 PDT 2025
================
@@ -3290,34 +3275,70 @@ static MCSymbol *emitLoclistsTableHeader(AsmPrinter *Asm,
return TableEnd;
}
-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) {
+namespace {
+
+struct DebugLocSpanList {
+ MCSymbol *Label;
+ const DwarfCompileUnit *CU;
+ llvm::ArrayRef<llvm::DebugLocStream::Entry> Ranges;
+};
+
+template <typename DWARFSpanList> struct DwarfRangeListTraits {};
+
+template <> struct DwarfRangeListTraits<DebugLocSpanList> {
+ static constexpr unsigned BaseAddressx = dwarf::DW_LLE_base_addressx;
+ static constexpr unsigned OffsetPair = dwarf::DW_LLE_offset_pair;
+ static constexpr unsigned StartxLength = dwarf::DW_LLE_startx_length;
+ static constexpr unsigned StartxEndx = dwarf::DW_LLE_startx_endx;
+ static constexpr unsigned EndOfList = dwarf::DW_LLE_end_of_list;
+
+ static StringRef StringifyRangeKind(unsigned Encoding) {
+ return llvm::dwarf::LocListEncodingString(Encoding);
+ }
+};
+
+template <> struct DwarfRangeListTraits<RangeSpanList> {
+ static constexpr unsigned BaseAddressx = dwarf::DW_RLE_base_addressx;
+ static constexpr unsigned OffsetPair = dwarf::DW_RLE_offset_pair;
+ static constexpr unsigned StartxLength = dwarf::DW_RLE_startx_length;
+ static constexpr unsigned StartxEndx = dwarf::DW_RLE_startx_endx;
+ static constexpr unsigned EndOfList = dwarf::DW_RLE_end_of_list;
+
+ static StringRef StringifyRangeKind(unsigned Encoding) {
+ return llvm::dwarf::RangeListEncodingString(Encoding);
+ }
+};
+
+} // namespace
+
+template <
+ typename Ranges, typename PayloadEmitter,
+ std::enable_if_t<DwarfRangeListTraits<Ranges>::BaseAddressx, bool> = true>
+static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm, const Ranges &R,
+ bool ShouldUseBaseAddress,
+ PayloadEmitter EmitPayload) {
auto Size = Asm->MAI->getCodePointerSize();
bool UseDwarf5 = DD.getDwarfVersion() >= 5;
// Emit our symbol so we can find the beginning of the range.
- Asm->OutStreamer->emitLabel(Sym);
+ Asm->OutStreamer->emitLabel(R.Label);
// Gather all the ranges that apply to the same section so they can share
// a base address entry.
- SmallMapVector<const MCSection *, std::vector<decltype(&*R.begin())>, 16>
+ SmallMapVector<const MCSection *, std::vector<decltype(&*R.Ranges.begin())>,
+ 16>
SectionRanges;
- for (const auto &Range : R)
+ for (const auto &Range : R.Ranges)
SectionRanges[&Range.Begin->getSection()].push_back(&Range);
- const MCSymbol *CUBase = CU.getBaseAddress();
+ const MCSymbol *CUBase = R.CU->getBaseAddress();
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() && P.first->isLinkerRelaxable())) {
----------------
dwblaikie wrote:
Might be worth separating these two changes too - one for DWARFv4 and one for DWARFv5?
https://github.com/llvm/llvm-project/pull/164128
More information about the llvm-commits
mailing list