Skip to content

Commit 08106ce

Browse files
committed
[SOL] re-enable debug info and add R_BPF_64_{ABS64, ABS32, NODYLD32} relocations to lld
Co-Authored-By: Richard Patel <[email protected]> [SOL] emit R_BPF_64_{ABS64, ABS32} for .debug_* sections
1 parent 7afcca5 commit 08106ce

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

lld/ELF/Arch/BPF.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ RelExpr BPF::getRelExpr(RelType type, const Symbol &s,
4545
switch (type) {
4646
case R_BPF_64_32:
4747
return R_PC;
48+
case R_BPF_64_ABS32:
49+
case R_BPF_64_NODYLD32:
50+
case R_BPF_64_ABS64:
4851
case R_BPF_64_64:
4952
return R_ABS;
5053
default:
@@ -68,6 +71,12 @@ void BPF::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
6871
write32le(loc + 4, ((val - 8) / 8) & 0xFFFFFFFF);
6972
break;
7073
}
74+
case R_BPF_64_ABS32:
75+
case R_BPF_64_NODYLD32: {
76+
// Relocation used by .BTF.ext and DWARF
77+
write32le(loc, val & 0xFFFFFFFF);
78+
break;
79+
}
7180
case R_BPF_64_64: {
7281
// Relocation of a lddw instruction
7382
// 64 bit address is divided into the imm of this and the following
@@ -76,6 +85,14 @@ void BPF::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
7685
write32le(loc + 8 + 4, val >> 32);
7786
break;
7887
}
88+
case R_BPF_64_ABS64: {
89+
// The relocation type is used for normal 64-bit data. The
90+
// actual to-be-relocated data is stored at r_offset and the
91+
// read/write data bitsize is 64 (8 bytes). The relocation can
92+
// be resolved with the symbol value plus implicit addend.
93+
write64le(loc, val);
94+
break;
95+
}
7996
default:
8097
error(getErrorLocation(loc) + "unrecognized reloc " + toString(rel.type));
8198
}

llvm/lib/MC/ELFObjectWriter.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,12 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
14551455
return;
14561456

14571457
unsigned Type = TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
1458+
1459+
unsigned Flags = FixupSection.getFlags();
1460+
// Change R_BPF_64_64 relocations in .debug_* sections to R_BPF_64_ABS64
1461+
if (Ctx.getTargetTriple().isBPF() && !(Flags & ELF::SHF_ALLOC) && (Type==ELF::R_BPF_64_64))
1462+
Type = ELF::R_BPF_64_ABS64;
1463+
14581464
const auto *Parent = cast<MCSectionELF>(Fragment->getParent());
14591465
// Emiting relocation with sybmol for CG Profile to help with --cg-profile.
14601466
bool RelocateWithSymbol =

llvm/lib/Target/BPF/BPFTargetMachine.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,
8383
BPFMCAsmInfo *MAI =
8484
static_cast<BPFMCAsmInfo *>(const_cast<MCAsmInfo *>(AsmInfo.get()));
8585
MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS());
86-
bool IsSolana = TT.getArch() == Triple::sbf || FS.contains("solana");
87-
MAI->setSupportsDebugInformation(!IsSolana);
86+
MAI->setSupportsDebugInformation(true);
8887
}
8988

9089
namespace {

llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
9292
if ((Flags & ELF::SHF_ALLOC) && (Flags & ELF::SHF_WRITE))
9393
return ELF::R_BPF_64_NODYLD32;
9494
}
95+
// .debug_* sections
96+
if (!(Flags & ELF::SHF_ALLOC))
97+
return ELF::R_BPF_64_ABS32;
9598
}
9699
}
97100
return isSolana ? ELF::R_BPF_64_32 : ELF::R_BPF_64_ABS32;

0 commit comments

Comments
 (0)