@@ -36,6 +36,23 @@ def finalize_module(original_str):
3636 replacement = r'\1 "btf_ama"'
3737 return re .sub (pattern , replacement , original_str )
3838
39+ def bpf_passthrough_gen (module ):
40+ i32_ty = ir .IntType (32 )
41+ ptr_ty = ir .PointerType (ir .IntType (8 ))
42+ fnty = ir .FunctionType (ptr_ty , [i32_ty , ptr_ty ])
43+
44+ # Declare the intrinsic
45+ passthrough = ir .Function (module , fnty , "llvm.bpf.passthrough.p0.p0" )
46+
47+ # Set function attributes
48+ # TODO: the ones commented are supposed to be there but cannot be added due to llvmlite limitations at the moment
49+ # passthrough.attributes.add("nofree")
50+ # passthrough.attributes.add("nosync")
51+ passthrough .attributes .add ("nounwind" )
52+ # passthrough.attributes.add("memory(none)")
53+
54+ return passthrough
55+
3956
4057def find_bpf_chunks (tree ):
4158 """Find all functions decorated with @bpf in the AST."""
@@ -57,6 +74,8 @@ def processor(source_code, filename, module):
5774 for func_node in bpf_chunks :
5875 logger .info (f"Found BPF function/struct: { func_node .name } " )
5976
77+ bpf_passthrough_gen (module )
78+
6079 vmlinux_symtab = vmlinux_proc (tree , module )
6180 if vmlinux_symtab :
6281 handler = VmlinuxHandler .initialize (vmlinux_symtab )
0 commit comments