[llvm] [BPF] Support Jump Table (PR #149715)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 10:29:50 PDT 2025
eddyz87 wrote:
The following example is not handled:
```c++
int bar(int a) {
__label__ l1, l2;
void * volatile tgt;
int ret = 0;
if (a)
tgt = &&l1;
else
tgt = &&l2;
goto *tgt;
l1: ret += 1;
l2: ret += 2;
return ret;
}
```
Currently the following code is produced:
```
$ (use-my-llvm ; clang -O2 -S -o - --target=bpf jt-vars.c )
.file "jt-vars.c"
.text
.globl bar # -- Begin function bar
.p2align 3
.type bar, at function
bar: # @bar
# %bb.0: # %entry
r2 = .Ltmp0 ll
if w1 == 0 goto LBB0_2
# %bb.1: # %entry
r2 = .Ltmp1 ll
LBB0_2: # %entry
*(u64 *)(r10 - 8) = r2
r1 = *(u64 *)(r10 - 8)
gotox r1
.Ltmp1: # Block address taken
LBB0_3: # %l1
w0 = 3
goto LBB0_5
.Ltmp0: # Block address taken
LBB0_4: # %l2
w0 = 2
LBB0_5: # %.split
exit
.Lfunc_end0:
.size bar, .Lfunc_end0-bar
# -- End function
.addrsig
```
As discussed previously, `r2 = .Ltmp0 ll` should be converted to an access to a single element jump table. Otherwise kernel won't be able to adjust `.Ltmp0` properly in `verifier.c:do_misc_fixups`.
https://github.com/llvm/llvm-project/pull/149715
More information about the llvm-commits
mailing list