Skip to content

[SOL] Debug sections relocations #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
17 changes: 17 additions & 0 deletions lld/ELF/Arch/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ RelExpr BPF::getRelExpr(RelType type, const Symbol &s,
switch (type) {
case R_BPF_64_32:
return R_PC;
case R_BPF_64_ABS32:
case R_BPF_64_NODYLD32:
case R_BPF_64_ABS64:
case R_BPF_64_64:
return R_ABS;
default:
Expand All @@ -68,6 +71,12 @@ void BPF::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
write32le(loc + 4, ((val - 8) / 8) & 0xFFFFFFFF);
break;
}
case R_BPF_64_ABS32:
case R_BPF_64_NODYLD32: {
// Relocation used by .BTF.ext and DWARF
write32le(loc, val & 0xFFFFFFFF);
break;
}
case R_BPF_64_64: {
// Relocation of a lddw instruction
// 64 bit address is divided into the imm of this and the following
Expand All @@ -76,6 +85,14 @@ void BPF::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
write32le(loc + 8 + 4, val >> 32);
break;
}
case R_BPF_64_ABS64: {
// The relocation type is used for normal 64-bit data. The
// actual to-be-relocated data is stored at r_offset and the
// read/write data bitsize is 64 (8 bytes). The relocation can
// be resolved with the symbol value plus implicit addend.
write64le(loc, val);
break;
}
default:
error(getErrorLocation(loc) + "unrecognized reloc " + toString(rel.type));
}
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,12 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
return;

unsigned Type = TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);

unsigned Flags = FixupSection.getFlags();
// Change R_BPF_64_64 relocations in .debug_* sections to R_BPF_64_ABS64
if (Ctx.getTargetTriple().isBPF() && !(Flags & ELF::SHF_ALLOC) && (Type==ELF::R_BPF_64_64))
Type = ELF::R_BPF_64_ABS64;

const auto *Parent = cast<MCSectionELF>(Fragment->getParent());
// Emiting relocation with sybmol for CG Profile to help with --cg-profile.
bool RelocateWithSymbol =
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,
BPFMCAsmInfo *MAI =
static_cast<BPFMCAsmInfo *>(const_cast<MCAsmInfo *>(AsmInfo.get()));
MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS());
bool IsSolana = TT.getArch() == Triple::sbf || FS.contains("solana");
MAI->setSupportsDebugInformation(!IsSolana);
MAI->setSupportsDebugInformation(true);
}

namespace {
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
if ((Flags & ELF::SHF_ALLOC) && (Flags & ELF::SHF_WRITE))
return ELF::R_BPF_64_NODYLD32;
}
// .debug_* sections
if (!(Flags & ELF::SHF_ALLOC))
return ELF::R_BPF_64_ABS32;
}
}
return isSolana ? ELF::R_BPF_64_32 : ELF::R_BPF_64_ABS32;
Expand Down