You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: We probably need cpu v5 or other flags to enable this feature.
We can add it later when necessary.
- Generate all jump tables in a single section named .jumptables.
- Represent each jump table as a symbol:
- value points to an offset within .jumptables;
- size encodes jump table size in bytes.
- Indirect jump is a gotox instruction:
- dst register is an index within the table;
- accompanied by a R_BPF_64_64 relocation pointing to a jump table
symbol.
clang -S:
.LJTI0_0:
.reloc 0, FK_SecRel_8, .BPF.JT.0.0
gotox r1
goto LBB0_2
LBB0_4:
...
.section .jumptables,"",@progbits
.L0_0_set_4 = ((LBB0_4-.LBPF.JX.0.0)>>3)-1
.L0_0_set_2 = ((LBB0_2-.LBPF.JX.0.0)>>3)-1
...
.BPF.JT.0.0:
.long .L0_0_set_4
.long .L0_0_set_2
...
llvm-readelf -r --sections --symbols:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...
[ 4] .jumptables PROGBITS 0000000000000000 000118 000100 00 0 0 1
...
Relocation section '.rel.text' at offset 0x2a8 contains 2 entries:
Offset Info Type Symbol's Value Symbol's Name
0000000000000010 0000000300000001 R_BPF_64_64 0000000000000000 .BPF.JT.0.0
...
Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
...
2: 0000000000000000 112 FUNC GLOBAL DEFAULT 2 foo
3: 0000000000000000 128 NOTYPE GLOBAL DEFAULT 4 .BPF.JT.0.0
...
llvm-objdump -Sdr:
0000000000000000 <foo>:
...
2: gotox r1
0000000000000010: R_BPF_64_64 .BPF.JT.0.0
An option -bpf-min-jump-table-entries is implemented to control the minimum
number of entries to use a jump table on BPF. The default value 4, but it
can be changed with the following clang option
clang ... -mllvm -bpf-min-jump-table-entries=6
where the number of jump table cases needs to be >= 6 in order to
use jump table.
0 commit comments