Skip to contentSkip to conversation

docs/bpf: add llvm_reloc.rst to explain llvm bpf relocations

PATCH Applied Yonghong Song 3 participants 3 messages May 26, 2021 – May 28, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 docs/bpf: add llvm_reloc.rst to explain llvm bpf relocations

LLVM upstream commit https://reviews.llvm.org/D102712
made some changes to bpf relocations to make them llvm linker lld friendly. The scope of existing relocations R_BPF_64_{64,32} is narrowed and new relocations R_BPF_64_{ABS32,ABS64,NODYLD32} are introduced.

Let us add some documentation about llvm bpf relocations so people can understand how to resolve them properly in their respective tools.

Cc John Fastabend <[email protected]>
Cc Lorenz Bauer <[email protected]>
---
 Documentation/bpf/index.rst            |   1 +
 Documentation/bpf/llvm_reloc.rst       | 240 +++++++++++++++++++++++++
 tools/testing/selftests/bpf/README.rst |  19 ++
 3 files changed, 260 insertions(+)
 create mode 100644 Documentation/bpf/llvm_reloc.rst

Changelogs:
v2 -> v3:
- change "SECTION" to "STT_SECTION" (macro name in the elf.h header file) to describe corresponding symbol table type.
- change "IA" to "A" to represent "Addend".
v1 -> v2:
- add an example to illustrate how relocations related to base section and symbol table and what is "Implicit Addend"
- clarify why we use 32bit read/write for R_BPF_64_64 (ld_imm64) relocations.

Documentation/bpf/index.rst +1 -0
index a702f67dd45f..93e8cf12a6d4 100644
@@ -84,6 +84,7 @@ Other
    :maxdepth: 1
 
    ringbuf
+   llvm_reloc
 
 .. Links:
 .. _networking-filter: ../networking/filter.rst
Documentation/bpf/llvm_reloc.rst new file +240 -0

240 lines not on this page · raw message

tools/testing/selftests/bpf/README.rst +19 -0
index 3353778c30f8..8deec1ca9150 100644
@@ -202,3 +202,22 @@ generate valid BTF information for weak variables. Please make sure you use
 Clang that contains the fix.
 
 __ https://reviews.llvm.org/D100362
+
+Clang relocation changes
+========================
+
+Clang 13 patch `clang reloc patch`_  made some changes on relocations such
+that existing relocation types are broken into more types and
+each new type corresponds to only one way to resolve relocation.
+See `kernel llvm reloc`_ for more explanation and some examples.
+Using clang 13 to compile old libbpf which has static linker support,
+there will be a compilation failure::
+
+  libbpf: ELF relo #0 in section #6 has unexpected type 2 in .../bpf_tcp_nogpl.o
+
+Here, ``type 2`` refers to new relocation type ``R_BPF_64_ABS64``.
+To fix this issue, user newer libbpf.
+
+.. Links
+.. _clang reloc patch: https://reviews.llvm.org/D102712
+.. _kernel llvm reloc: /Documentation/bpf/llvm_reloc.rst
Signature · 1 line
2.30.2
Acked-by on v3 1/1
#1 lore raw
Quoted 15 lines · Yonghong Song

LLVM upstream commit https://reviews.llvm.org/D102712
made some changes to bpf relocations to make them llvm linker lld friendly. The scope of existing relocations R_BPF_64_{64,32} is narrowed and new relocations R_BPF_64_{ABS32,ABS64,NODYLD32} are introduced.

Let us add some documentation about llvm bpf relocations so people can understand how to resolve them properly in their respective tools.

Cc John Fastabend <[email protected]>
Cc Lorenz Bauer <[email protected]>

---

[...]

Quoted 23 lines

__ https://reviews.llvm.org/D100362

tools/testing/selftests/bpf/README.rst +19 -0
+
+Clang relocation changes
+========================
+
+Clang 13 patch `clang reloc patch`_  made some changes on relocations such
+that existing relocation types are broken into more types and
+each new type corresponds to only one way to resolve relocation.
+See `kernel llvm reloc`_ for more explanation and some examples.
+Using clang 13 to compile old libbpf which has static linker support,
+there will be a compilation failure::
+
+  libbpf: ELF relo #0 in section #6 has unexpected type 2 in .../bpf_tcp_nogpl.o
+
+Here, ``type 2`` refers to new relocation type ``R_BPF_64_ABS64``.
+To fix this issue, user newer libbpf.
+
+.. Links
+.. _clang reloc patch: https://reviews.llvm.org/D102712
+.. _kernel llvm reloc: /Documentation/bpf/llvm_reloc.rst
Signature · 1 line
2.30.2

LGTM.

#2 lore raw
In reply to Yonghong Song
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 8 lines · On Wed, 26 May 2021 08:24:57 -0700 you wrote:

LLVM upstream commit https://reviews.llvm.org/D102712
made some changes to bpf relocations to make them llvm linker lld friendly. The scope of existing relocations R_BPF_64_{64,32} is narrowed and new relocations R_BPF_64_{ABS32,ABS64,NODYLD32} are introduced.

[...]

Here is the summary with links:
- [bpf-next,v3] docs/bpf: add llvm_reloc.rst to explain llvm bpf relocations

    https://git.kernel.org/bpf/bpf-next/c/fc8c262e0eb5

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html