On 04/09/2026 04:19, Thiébaud Weksteen wrote:
> When generating a light skeleton (bpftool gen skeleton -L), there is no
> libbpf runtime object or bpf_program__set_autoload() API available to
> enable/disable the autoloading of programs. If a BPF program in the
> object has autoload disabled (e.g. via SEC("?...")), bpf_object__load()
> silently skips loading it. bpftool still generates struct bpf_prog_desc
> fields and attach functions in the light skeleton header, leaving
> skel->progs.<name>.prog_fd uninitialized (0).
>
> Explicitly reject non-autoloaded programs when use_loader is true with
> an error message, preventing the generation of broken light skeleton
> headers.
>
> Signed-off-by: Thiébaud Weksteen <[email protected]>
> ---
> tools/bpf/bpftool/gen.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index a50540ef6521..1583150241c8 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -1340,6 +1340,12 @@ static int do_skeleton(int argc, char **argv)
> }
> bpf_object__for_each_program(prog, obj) {
> prog_cnt++;
> +
> + if (use_loader && !bpf_program__autoload(prog)) {
> + p_err("program '%s' is marked as non-autoload, which is
> not supported for light skeletons",
> + bpf_program__name(prog));
> + return -1;
Sashiko is correct, at this stage of the function, rather than returning
directly, you'd need to "goto out".
> + }
Thank you. Maybe consider adding a word about autoload/non-autoload in
"bpftool gen" man page? My concern is that users who are not familiar
with the notion will struggle to understand the error message.
Quentin