]> git.feebdaed.xyz Git - 0xmirror/ebpf.git/commit
asm: allow negative constants for builtin function calls
authorLorenz Bauer <lmb@isovalent.com>
Tue, 24 Jun 2025 08:17:45 +0000 (09:17 +0100)
committerLorenz Bauer <lmb@users.noreply.github.com>
Tue, 24 Jun 2025 11:03:47 +0000 (12:03 +0100)
commitdab673cc3076f2e4011b18b8fceb87efac7d2bd8
tree76ec1a42039fc5a2bf8e4b2b5fee885b31669969
parent9958a4f58fb4e533201e0a76d6d82eeeaa91434b
asm: allow negative constants for builtin function calls

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
Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
asm/instruction.go
asm/instruction_test.go
internal/platform/constants.go
internal/platform/constants_test.go