Skip to content

Commit a1fe2ed

Browse files
change to 64 bit pointers. May be an issue. revert this commit if issues arise
1 parent 93285db commit a1fe2ed

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

pythonbpf/codegen.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def finalize_module(original_str):
3939

4040
def bpf_passthrough_gen(module):
4141
i32_ty = ir.IntType(32)
42-
ptr_ty = ir.PointerType(ir.IntType(8))
42+
ptr_ty = ir.PointerType(ir.IntType(64))
4343
fnty = ir.FunctionType(ptr_ty, [i32_ty, ptr_ty])
4444

4545
# Declare the intrinsic
@@ -158,7 +158,6 @@ def compile_to_ir(filename: str, output: str, loglevel=logging.INFO):
158158
module.add_named_metadata("llvm.ident", [f"PythonBPF {VERSION}"])
159159

160160
module_string: str = finalize_module(str(module))
161-
module_string += '\ndeclare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) "nocallback" "nofree" "nosync" "nounwind" "willreturn" "memory(none)"'
162161

163162
logger.info(f"IR written to {output}")
164163
with open(output, "w") as f:

pythonbpf/functions/functions_pass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def process_bpf_chunk(func_node, module, return_type, map_sym_tab, structs_sym_t
402402
func.linkage = "dso_local"
403403
func.attributes.add("nounwind")
404404
func.attributes.add("noinline")
405-
func.attributes.add("optnone")
405+
# func.attributes.add("optnone")
406406

407407
if func_node.args.args:
408408
# Only look at the first argument for now

pythonbpf/vmlinux_parser/vmlinux_exports_handler.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def handle_vmlinux_struct_field(
8686
globvar_ir, field_data = self.get_field_type(
8787
python_type.__name__, field_name
8888
)
89-
builder.function.args[0].type = ir.PointerType(ir.IntType(8))
89+
builder.function.args[0].type = ir.PointerType(ir.IntType(64))
9090
print(builder.function.args[0])
9191
field_ptr = self.load_ctx_field(builder, builder.function.args[0], globvar_ir)
9292
print(field_ptr)
@@ -113,18 +113,18 @@ def load_ctx_field(builder, ctx_arg, offset_global):
113113
offset = builder.load(offset_global)
114114

115115
# Ensure ctx_arg is treated as i8* (byte pointer)
116-
i8_type = ir.IntType(8)
117-
i8_ptr_type = ir.PointerType(i8_type)
116+
# i8_type = ir.IntType(8)
117+
i8_ptr_type = ir.PointerType()
118118

119119
# Cast ctx_arg to i8* if it isn't already
120-
if str(ctx_arg.type) != str(i8_ptr_type):
121-
ctx_i8_ptr = builder.bitcast(ctx_arg, i8_ptr_type)
122-
else:
123-
ctx_i8_ptr = ctx_arg
120+
# if str(ctx_arg.type) != str(i8_ptr_type):
121+
# ctx_i8_ptr = builder.bitcast(ctx_arg, i8_ptr_type)
122+
# else:
123+
# ctx_i8_ptr = ctx_arg
124124

125125
# GEP with explicit type - this is the key fix
126126
field_ptr = builder.gep(
127-
ctx_i8_ptr,
127+
ctx_arg,
128128
[offset],
129129
inbounds=False,
130130
)
@@ -138,19 +138,20 @@ def load_ctx_field(builder, ctx_arg, offset_global):
138138
raise KeyError
139139
except (KeyError, AttributeError):
140140
passthrough_type = ir.FunctionType(
141-
i8_ptr_type,
142-
[ir.IntType(32), i8_ptr_type]
141+
ir.PointerType(),
142+
[ir.IntType(32), ir.PointerType()],
143143
)
144144
passthrough_fn = ir.Function(
145145
module,
146146
passthrough_type,
147-
name='llvm.bpf.passthrough.p0.p0'
147+
name='llvm.bpf.passthrough.p0.p0',
148148
)
149149

150150
# Call passthrough to satisfy BPF verifier
151151
verified_ptr = builder.call(
152152
passthrough_fn,
153153
[ir.Constant(ir.IntType(32), 0), field_ptr],
154+
tail=True
154155
)
155156

156157
# Bitcast to i64* (assuming field is 64-bit, adjust if needed)

0 commit comments

Comments
 (0)