[llvm] [BPF] Support Jump Table (PR #149715)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 22 15:55:13 PDT 2025
eddyz87 wrote:
> > > R_BPF_64_NODYLD32
> >
> >
> > Even I forgot that it is for R_BPF_64_NODYLD32. I is related to dynamic linking and initially for .BTF and .BTF.ext sections. I will take a look again about what it is and what we should do about it.
> > The original commit:
> > commit [6a2ea84](https://github.com/llvm/llvm-project/commit/6a2ea84600ba4bd3b2733bd8f08f5115eb32164b) Author: Yonghong Song [yhs at fb.com](mailto:yhs at fb.com) Date: Tue May 18 08:35:59 2021 -0700
> > ```
> > BPF: Add more relocation kinds
> > ```
>
> Okay, I checked the above commit. R_BPF_64_NODYLD32 is mostly for linker when lld tries to merge different progs. Unfortunately this is never materialized. So you can treat R_BPF_64_NODYLD32 as a normal R_BPF_64_ABS32 (data) relocation.
I think relocations can be made to go away if table content would be implemented as instruction offsets, computed as difference between label and section start. The piece of code I posted [here](https://github.com/llvm/llvm-project/pull/149715#issuecomment-3097615612) generated the following assembly:
```
.section .jumptables,"", at progbits
.L0_0_set_7 = ((LBB0_7-.LBPF.JX.0.0)>>3)-1
.L0_0_set_2 = ((LBB0_2-.LBPF.JX.0.0)>>3)-1
.L0_0_set_8 = ((LBB0_8-.LBPF.JX.0.0)>>3)-1
.L0_0_set_9 = ((LBB0_9-.LBPF.JX.0.0)>>3)-1
.L0_0_set_10 = ((LBB0_10-.LBPF.JX.0.0)>>3)-1
BPF.JT.0.0:
.long .L0_0_set_7
.long .L0_0_set_2
.long .L0_0_set_2
.long .L0_0_set_2
...
```
And there were no relocations for ".jumptables":
```
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .strtab STRTAB 0000000000000000 000320 000065 00 0 0 1
[ 2] .text PROGBITS 0000000000000000 000040 0000f0 00 AX 0 0 8
[ 3] .rel.text REL 0000000000000000 0002f0 000030 10 I 6 2 8
[ 4] .jumptables PROGBITS 0000000000000000 000130 000130 00 0 0 1
[ 5] .llvm_addrsig LLVM_ADDRSIG 0000000000000000 000320 000000 00 E 6 0 1
[ 6] .symtab SYMTAB 0000000000000000 000260 000090 18 1 2 8
```
Do we need these relocations to simplify linking by libbpf?
https://github.com/llvm/llvm-project/pull/149715
More information about the llvm-commits
mailing list