[PATCH] D102712: BPF: Add more relocation kinds

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 18 12:36:56 PDT 2021


yonghong-song created this revision.
yonghong-song added a reviewer: ast.
Herald added a subscriber: hiraditya.
yonghong-song requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, BPF only contains three relocations:

  R_BPF_NONE   for no relocation
  R_BPF_64_64  for LD_imm64 and normal 64-bit data relocation
  R_BPF_64_32  for call insn and normal 32-bit data relocation

Also .BTF and .BTF.ext sections contain symbols in allocated
program and data sections. These two sections reserved 32bit
space to hold the offset relative to the symbol's section.
LLVM JIT tries to resolve these symbols with an actual 64bit
address and it won't work since we only have 32bit space.
So we used R_BPF_NONE for such relocations.

This all works fine until when we try to do linking of
multiple objects.

  . R_BPF_64_64 handling of LD_imm64 vs. normal 64-bit data
    is different, so target->relocate() needs more context
    to do a correct job.
  . The same for R_BPF_64_32.
  . Since relocations in .BTF and .BTF.ext are set to none,
    they will not be relocated properly.

This patch intends to address this issue by adding additional
relocation kinds:

  R_BPF_64_LD64     for LD_imm64 relocation
  R_BPF_64_PC32     for call insn relocation
  R_BPF_64_ALLOC32  for .BTF and .BTF.ext style relocations.

R_BPF_64_64 and R_BPF_64_32 are used for 64- and 32-bit data
relocations. The elfutils already used them for dwarf.

  https://sourceware.org/git/?p=elfutils.git;a=blob;f=backends/bpf_reloc.def

This patch does not change that. So elfutils does not 
need change even with this patch.

I also removed handling of FK_SecRel_4 Fixup Kind as it seems
there is no bpf insn which could trigger this fixup kind.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102712

Files:
  llvm/include/llvm/BinaryFormat/ELFRelocs/BPF.def
  llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
  llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
  llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
  llvm/test/CodeGen/BPF/reloc-2.ll
  llvm/test/CodeGen/BPF/reloc-btf-2.ll
  llvm/test/CodeGen/BPF/reloc-btf.ll
  llvm/test/MC/BPF/insn-unit.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102712.346245.patch
Type: text/x-patch
Size: 7637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/601d3f30/attachment-0001.bin>


More information about the llvm-commits mailing list