Skip to content

Commit be1d86d

Browse files
r41k0uclaude
andcommitted
Core: Let a local be initialised from a vmlinux enum constant
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>
1 parent 71fd1d7 commit be1d86d

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎pythonbpf/allocation_pass.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,19 @@ def _allocate_for_name(builder, var_name, rval, local_sym_tab, compilation_conte
324324
"""Allocate memory for variable-to-variable assignment (b = a)."""
325325
source_var = rval.id
326326

327-
# Local first, then a BPF global: the copy takes the source's type either
328-
# way (a c_uint32 global gives a c_uint32 local).
327+
# Same resolution order as every other read of a bare name: local, then
328+
# BPF global, then vmlinux enum constant. A variable source gives the copy
329+
# its type; an enum constant is an immediate with no storage, so the copy
330+
# gets the i64 slot a literal gets.
329331
if source_var in local_sym_tab:
330332
source_symbol = local_sym_tab[source_var]
331333
elif source_var in compilation_context.bpf_globals:
332334
source_symbol = compilation_context.bpf_globals[source_var]
335+
elif VmlinuxHandlerRegistry.handle_name(source_var) is not None:
336+
var = _allocate_with_type(builder, var_name, ir.IntType(64))
337+
local_sym_tab[var_name] = LocalSymbol(var, ir.IntType(64))
338+
logger.info(f"Pre-allocated {var_name} from enum constant {source_var}")
339+
return
333340
else:
334341
logger.error(f"Source variable '{source_var}' not found in symbol table")
335342
return
File renamed without changes.

0 commit comments

Comments
 (0)