@@ -1109,72 +1109,39 @@ let generate_declarations_in_source_order ctx _ir_multi_program type_aliases =
11091109(* * Generate standard eBPF includes *)
11101110
11111111let generate_includes ctx ?(program_types =[] ) () =
1112- (* Essential kernel types must come first *)
1113- let base_type_includes = [
1114- " #include <linux/types.h> " ;
1112+ (* Use vmlinux.h which contains all kernel types from BTF *)
1113+ let vmlinux_includes = [
1114+ " #include \" vmlinux.h \" " ;
11151115 ] in
11161116
1117+ (* Only include essential eBPF helpers, vmlinux.h provides all kernel types *)
11171118 let standard_includes = [
1118- " #include <linux/bpf.h>" ;
11191119 " #include <bpf/bpf_helpers.h>" ;
1120- " #include <linux/if_ether.h>" ;
1121- " #include <linux/ip.h>" ;
1122- " #include <linux/in.h>" ;
1123- " #include <linux/if_xdp.h>" ;
11241120 ] in
11251121
1126- (* Get context-specific includes *)
1127- let context_includes = List. fold_left (fun acc prog_type ->
1128- let context_type = match prog_type with
1129- | Ast. Xdp -> Some " xdp"
1130- | Ast. Tc -> Some " tc"
1131- | Ast. Kprobe -> Some " kprobe"
1132- | Ast. Tracepoint -> Some " tracepoint"
1133- | _ -> None
1134- in
1135- match context_type with
1136- | Some ctx_type ->
1137- let includes = Kernelscript_context.Context_codegen. get_context_includes ctx_type in
1138- acc @ includes
1139- | None -> acc
1140- ) [] program_types in
1122+ (* When using vmlinux.h, we don't need context-specific kernel headers *)
1123+ (* vmlinux.h contains all kernel types, so we only need eBPF helpers *)
1124+ let context_includes = [] in (* No additional kernel headers needed with vmlinux.h *)
11411125
11421126 (* Remove duplicates between all include sets *)
1143- let all_base_includes = base_type_includes @ standard_includes in
1127+ let all_base_includes = vmlinux_includes @ standard_includes in
11441128 let unique_context_includes = List. filter (fun inc ->
11451129 not (List. mem inc all_base_includes)) context_includes in
11461130
11471131 (* For kprobe programs, only emit kprobe includes which contain everything needed *)
11481132 let has_kprobe = List. exists (function Ast. Kprobe -> true | _ -> false ) program_types in
11491133 if has_kprobe then (
1150- (* Emit ONLY kprobe includes which contain architecture definition and all needed headers *)
1151- let kprobe_includes = Kernelscript_context.Context_codegen. get_context_includes " kprobe" in
1152- List. iter (emit_line ctx) kprobe_includes;
1153- emit_blank_line ctx;
1154-
1155- (* Add additional standard includes that aren't in kprobe includes *)
1156- let all_additional_includes = [
1157- " #include <linux/types.h>" ;
1158- " #include <linux/bpf.h>" ;
1134+ (* With vmlinux.h, we only need it and eBPF helpers, no additional kernel headers *)
1135+ let vmlinux_and_helpers = [
1136+ " #include \" vmlinux.h\" " ;
11591137 " #include <bpf/bpf_helpers.h>" ;
1160- " #include <linux/if_ether.h>" ;
1161- " #include <linux/ip.h>" ;
1162- " #include <linux/in.h>" ;
1163- " #include <linux/if_xdp.h>" ;
11641138 ] in
1165- let additional_includes = List. filter (fun inc ->
1166- not (List. mem inc kprobe_includes)) all_additional_includes in
1167-
1168- (* Add context-specific includes for non-kprobe programs *)
1169- let filtered_context_includes = List. filter (fun inc ->
1170- not (List. mem inc kprobe_includes) && not (List. mem inc additional_includes)) unique_context_includes in
11711139
1172- List. iter (emit_line ctx) additional_includes;
1173- List. iter (emit_line ctx) filtered_context_includes;
1140+ List. iter (emit_line ctx) vmlinux_and_helpers;
11741141 emit_blank_line ctx
11751142 ) else (
1176- (* For non-kprobe programs, use standard processing *)
1177- let all_includes = standard_includes @ unique_context_includes @ base_type_includes in
1143+ (* For non-kprobe programs, use vmlinux.h and standard processing *)
1144+ let all_includes = vmlinux_includes @ standard_includes @ unique_context_includes in
11781145 List. iter (emit_line ctx) all_includes;
11791146 emit_blank_line ctx;
11801147
0 commit comments