mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
Every read of a bare name resolves local, then BPF global, then vmlinux enum constant, except the allocation pass's variable-to-variable path, which stopped after the globals and rejected `act = XDP_PASS` with "source variable not found", while `act = XDP_PASS + 0` compiled through the binop path. The error text pointed the wrong way: it is the target that needs a stack slot, and the pass could not type it. An enum constant is an immediate with no storage of its own, so the target gets the i64 slot a literal gets, and the constant is folded at the store. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
23 lines
515 B
Python
23 lines
515 B
Python
from vmlinux import XDP_PASS
|
|
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
|
|
import logging
|
|
from ctypes import c_int64, c_void_p
|
|
|
|
|
|
@bpf
|
|
@section("kprobe/blk_mq_start_request")
|
|
def example(ctx: c_void_p) -> c_int64:
|
|
d = XDP_PASS # This gives an error, but
|
|
e = XDP_PASS + 0 # this does not
|
|
print(f"test1 {e} test2 {d}")
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile_to_ir("assignment_handling.py", "assignment_handling.ll", loglevel=logging.INFO)
|