ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

asm: allow negative constants for builtin function calls

Open lmb opened this issue 4 months ago • 1 comments

The work to encode a platform into various constant types made it so that decoding a call to a builtin helper with a negative value fails with

decoding instructions for section <sectionname>:
offset <offset>: invalid constant 0xffffffff

for a BPF instruction of "call -1". This is because we can't represent -1 as a tagged platform constant.

Allow negative constants by not transforming them into a platform constant at all. Adjust the platform tag size so that we never generate a platform constant with the high bit set. This avoids confusing it with a negative number when reinterpreting it as a signed number and ensures that trying to marshal such an instruction gives an error.

Fixes: https://github.com/cilium/ebpf/issues/1797

lmb avatar Jun 19 '25 15:06 lmb