[llvm] [BPF] Support Jump Table (PR #149715)

Anton Protopopov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 22 04:04:27 PDT 2025


aspsk wrote:

Ok. With this current patch (and my dev kernel branch) smth like this
```
__label__ l1, l2, l3, l4;
void *jt1[] = {[0]=&&l1, [1]=&&l2};
void *jt2[] = {[0]=&&l3, [1]=&&l4};

...

if (ctx->x % 2)
        goto *jt1[a];
else
        goto *jt2[b];

l1: ret += 1;
l2: ret += 3;
l3: ret += 5;
l4: ret += 7;
```
compiles into two map loads and one `gotox`:
```
# bpftool prog dump x id 42
...
; if (ctx->x % 2)
  10: (67) r3 <<= 3
  11: (18) r4 = 0xffff8881beef5f90
  13: (0f) r4 += r3
  14: (57) r2 &= 1
  15: (15) if r2 == 0x0 goto pc+4
  16: (67) r1 <<= 3
  17: (18) r4 = 0xffff888beefeef10
  19: (0f) r4 += r1
  20: (79) r1 = *(u64 *)(r4 +0)
  21: (0d) gotox r1
...
```
(and it verifies and run properly).

So far all looks good for me to start working on cleaning things up & more examples of computed gotos.

https://github.com/llvm/llvm-project/pull/149715


More information about the llvm-commits mailing list