Re: [PATCH bpf-next v3 1/3] bpftool: Skip non-autoload programs when generating light skeletons

From: Andrii Nakryiko

Date: Mon Sep 21 2026 - 17:30:59 EST


On Thu, Sep 17, 2026 at 9:09 PM Thiébaud Weksteen <tweek@xxxxxxxxxx> wrote:
>
> When generating a light skeleton (bpftool gen skeleton -L),
> bpf_object__load() skips loading programs marked as non-autoload (e.g.
> SEC("?...")), so the generated loader program only records and populates
> file descriptors for autoloaded programs.
>
> Previously, bpftool emitted struct bpf_prog_desc fields, link fields,
> and attach/detach/destroy functions for all programs in the BPF object,
> causing the loader program to store subsequent program FDs into
> incorrect skeleton struct fields when non-autoload programs were
> present.
>
> Furthermore, bpf_object__load() can update a program's autoload status
> during preparation (e.g. for struct_ops programs when resolving kernel
> BTF members or adjusting autoload based on map autocreate settings).
> Move bpf_object__gen_loader() and bpf_object__load() out of gen_trace()
> into do_skeleton() before counting programs and emitting struct fields so
> that struct field declarations and attach/detach/destroy functions all
> observe the final post-load autoload state.
>
> Skip programs with !bpf_program__autoload(prog) when counting programs
> and generating progs/links struct fields as well as attach, detach, and
> destroy functions for light skeletons.

This seems like error prone behavior to me. Wouldn't it be better to
hard fail if the BPF object has non-autoloaded BPF programs instead,
as clearly it's not meant to be used with a light skeleton that
doesn't support such programs? So why not emit a meaningful error and
exit?

Or I don't know, let's teach light skeleton how to support
non-loadable programs maybe, not sure what that would take, but worth
considering to bridge the gap?


pw-bot: cr

>
> Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
> Signed-off-by: Thiébaud Weksteen <tweek@xxxxxxxxxx>
> ---
> v2 -> v3:
> - Move comment from gen_trace() to do_skeleton()
> - Add comment to do_skeleton() why the loader is called early
> v1 -> v2:
> - Move bpf_object__gen_loader() and bpf_object__load() out of gen_trace()
>
> .../bpf/bpftool/Documentation/bpftool-gen.rst | 4 +-
> tools/bpf/bpftool/gen.c | 76 ++++++++++++-------
> 2 files changed, 52 insertions(+), 28 deletions(-)
>

[...]