Skip to content

Commit d9705ed

Browse files
committed
Drop redundant kfunc prototype and dead BTF-info comment
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 64ad7b4 commit d9705ed

1 file changed

Lines changed: 13 additions & 42 deletions

File tree

src/kernel_module_codegen.ml

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,6 @@ let generate_function_prototype func_def =
110110
let params_str = if params = [] then "void" else String.concat ", " params in
111111
sprintf "static %s %s(%s);" return_type func_def.func_name params_str
112112

113-
(** Generate function prototype for kfunc kernel module functions with proper annotations *)
114-
let generate_kfunc_prototype func_def =
115-
let return_type = match get_return_type func_def.func_return_type with
116-
| Some ret_type -> kernelscript_type_to_c_type ret_type
117-
| None -> "void"
118-
in
119-
let params = List.map (fun (param_name, param_type) ->
120-
sprintf "%s %s" (kernelscript_type_to_c_type param_type) param_name
121-
) func_def.func_params in
122-
let params_str = if params = [] then "void" else String.concat ", " params in
123-
sprintf "__bpf_kfunc %s %s(%s);" return_type func_def.func_name params_str
124-
125113
(** Generate statement translation *)
126114
let rec generate_statement_translation stmt =
127115
match stmt.stmt_desc with
@@ -293,20 +281,6 @@ let generate_kfunc_implementation func_def =
293281
let body = String.concat "\n" (List.map generate_statement_translation func_def.func_body) in
294282
sprintf "%s\n{\n%s\n}" signature body
295283

296-
(** Generate BTF information for kfunc *)
297-
let generate_btf_info func_def =
298-
let param_types = List.map (fun (_, param_type) ->
299-
kernelscript_type_to_c_type param_type
300-
) func_def.func_params in
301-
let return_type = match get_return_type func_def.func_return_type with
302-
| Some ret_type -> kernelscript_type_to_c_type ret_type
303-
| None -> "void"
304-
in
305-
sprintf "/* BTF info for %s: %s(%s) */"
306-
func_def.func_name
307-
return_type
308-
(String.concat ", " param_types)
309-
310284
(** Generate complete kernel module *)
311285
let generate_kernel_module context =
312286
let header = sprintf {|/*
@@ -329,15 +303,15 @@ MODULE_VERSION("1.0");
329303

330304
|} context.module_name context.module_name in
331305

332-
(* Generate function prototypes *)
333-
let private_prototypes = String.concat "\n" (List.map generate_function_prototype context.private_functions) in
334-
let kfunc_prototypes = String.concat "\n" (List.map generate_kfunc_prototype context.kfunc_functions) in
335-
let function_prototypes =
336-
if private_prototypes = "" then kfunc_prototypes
337-
else if kfunc_prototypes = "" then private_prototypes
338-
else sprintf "%s\n%s" private_prototypes kfunc_prototypes
306+
(* Forward prototypes for private helpers so kfuncs defined later can call them.
307+
Kfuncs don't need their own prototypes - __bpf_kfunc_start_defs() suppresses
308+
-Wmissing-prototypes, and upstream kfunc modules don't emit them either. *)
309+
let prototypes_section =
310+
if context.private_functions = [] then ""
311+
else sprintf "/* Function prototypes */\n%s\n\n"
312+
(String.concat "\n" (List.map generate_function_prototype context.private_functions))
339313
in
340-
314+
341315
(* Generate private function implementations first (so kfuncs can call them) *)
342316
let private_implementations = String.concat "\n\n" (List.map generate_function_implementation context.private_functions) in
343317

@@ -354,8 +328,6 @@ __bpf_kfunc_start_defs();
354328
__bpf_kfunc_end_defs();
355329
|} (String.concat "\n\n" (List.map generate_kfunc_implementation context.kfunc_functions)) in
356330

357-
let btf_declarations = String.concat "\n" (List.map generate_btf_info context.kfunc_functions) in
358-
359331
let kfunc_btf_ids = String.concat "\n" (List.map (fun func_def ->
360332
sprintf "BTF_ID_FLAGS(func, %s)" func_def.func_name
361333
) context.kfunc_functions) in
@@ -409,12 +381,11 @@ module_exit(%s_exit);
409381
sprintf "%s\n\n%s" private_implementations kfunc_implementations
410382
in
411383

412-
sprintf "%s\n/* Function prototypes */\n%s\n\n%s\n\n%s\n\n%s\n\n%s"
413-
header
414-
function_prototypes
415-
btf_declarations
416-
all_implementations
417-
btf_id_set
384+
sprintf "%s\n%s%s\n\n%s\n\n%s"
385+
header
386+
prototypes_section
387+
all_implementations
388+
btf_id_set
418389
init_function
419390

420391
(** Extract kfunc functions from AST *)

0 commit comments

Comments
 (0)