Re: [PATCH bpf-next 2/2] bpftool: Reject non-autoload programs for light skeletons

From: Thiébaud Weksteen

Date: Tue Sep 08 2026 - 00:58:19 EST


On Tue, Sep 8, 2026 at 1:24 AM Quentin Monnet <qmo@xxxxxxxxxx> wrote:
>
> 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 <tweek@xxxxxxxxxx>
> > ---
> > 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".

Thanks for the review. I agree, I'm not sure how I missed that one.

>
>
> > + }
>
>
> 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.

Ack. I'll send a new patch to skip over these programs instead, as
suggested by Leon in the other patch ("selftests/bpf: Move verifier
failure tests out of test_global_percpu_data"). Thanks.