[all-commits] [llvm/llvm-project] 6a2ea8: BPF: Add more relocation kinds

yonghong-song via All-commits all-commits at lists.llvm.org
Tue May 25 08:20:37 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6a2ea84600ba4bd3b2733bd8f08f5115eb32164b
      https://github.com/llvm/llvm-project/commit/6a2ea84600ba4bd3b2733bd8f08f5115eb32164b
  Author: Yonghong Song <yhs at fb.com>
  Date:   2021-05-25 (Tue, 25 May 2021)

  Changed paths:
    M llvm/include/llvm/BinaryFormat/ELFRelocs/BPF.def
    M llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
    M llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
    M llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
    A llvm/test/CodeGen/BPF/reloc-2.ll
    A llvm/test/CodeGen/BPF/reloc-3.ll
    M llvm/test/CodeGen/BPF/reloc-btf-2.ll
    M llvm/test/CodeGen/BPF/reloc-btf.ll
    M llvm/test/CodeGen/BPF/reloc.ll
    A llvm/test/ExecutionEngine/RuntimeDyld/BPF/abs64-relocation.s
    A llvm/test/ExecutionEngine/RuntimeDyld/BPF/lit.local.cfg
    A llvm/test/ExecutionEngine/RuntimeDyld/BPF/nodyld32-64-relocations.s

  Log Message:
  -----------
  BPF: Add more relocation kinds

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.
When LLVM JIT is used, the LLVM ExecutionEngine RuntimeDyld
may attempt to resolve relocations for .BTF and .BTF.ext,
which we want to prevent. 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 lld target->relocate() needs more context
    to do a correct job.
  . The same for R_BPF_64_32. More context is needed for
    lld target->relocate() to differentiate call insn vs.
    normal 32-bit data relocation.
  . Since relocations in .BTF and .BTF.ext are set to R_BPF_NONE,
    they will not be relocated properly when multiple .BTF/.BTF.ext
    sections are merged by lld.

This patch intends to address this issue by adding additional
relocation kinds:
  R_BPF_64_ABS64     for normal 64-bit data relocation
  R_BPF_64_ABS32     for normal 32-bit data relocation
  R_BPF_64_NODYLD32  for .BTF and .BTF.ext style relocations.
The old R_BPF_64_{64,32} semantics:
  R_BPF_64_64        for LD_imm64 relocation
  R_BPF_64_32        for call insn relocation

The existing R_BPF_64_64/R_BPF_64_32 mapping to numeric values
is maintained. They are the most common use cases for
bpf programs and we want to maintain backward compatibility
as much as possible.

ExecutionEngine RuntimeDyld BPF relocations are adjusted as well.
R_BPF_64_{ABS64,ABS32} relocations will be resolved properly and
other relocations will be ignored.
Two tests are added for RuntimeDyld. Not handling R_BPF_64_NODYLD32 in
RuntimeDyldELF.cpp will result in "Relocation type not implemented yet!"
fatal error.

FK_SecRel_4 usages in BPFAsmBackend.cpp and BPFELFObjectWriter.cpp
are removed as they are not triggered in BPF backend.
BPF backend used FK_SecRel_8 for LD_imm64 instruction operands.

Differential Revision: https://reviews.llvm.org/D102712




More information about the All-commits mailing list