On Thu, Oct 01, 2026 at 10:52:13PM +0000, Jay Wang wrote:
> With CONFIG_DEBUG_INFO_BTF=m, which the next patch makes possible, the
> vmlinux BTF is not part of vmlinux: scripts/Makefile.vmlinux strips .BTF
> from it, and only vmlinux.unstripped, from which vmlinux is made, keeps
> it.  The tools and samples that generate vmlinux.h from a kernel build
> tree take the first vmlinux they find, so after an =m build they would
> pick one without BTF and fail, e.g. the bpftool skeletons when bpftool is
> built from the kernel tree right after the kernel.
> 
> Look for vmlinux.unstripped before vmlinux in each of these lists.  Every
> kernel build produces it, and with =y it carries the same BTF as vmlinux,
> so nothing changes there.  perf filters the candidates for a .BTF
> section, but its unanchored grep also matches .BTF_ids and .BTF.link,
> which vmlinux keeps with =m; match the section name exactly.
> 
> Signed-off-by: Jay Wang <[email protected]>
> ---
>  samples/bpf/Makefile                       | 6 +++++-
>  samples/hid/Makefile                       | 6 +++++-
>  tools/bpf/bpftool/Makefile                 | 6 +++++-
>  tools/perf/bpf_skel.mak                    | 8 ++++++--
>  tools/sched_ext/Makefile                   | 6 +++++-
>  tools/testing/selftests/bpf/Makefile       | 6 +++++-
>  tools/testing/selftests/hid/Makefile       | 6 +++++-
>  tools/testing/selftests/sched_ext/Makefile | 6 +++++-
>  8 files changed, 41 insertions(+), 9 deletions(-)
> 
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index c28e65046986..fb5cd2d5b6f8 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -305,8 +305,12 @@ $(obj)/$(TRACE_HELPERS): TPROGS_CFLAGS := 
> $(TPROGS_CFLAGS) -D__must_check=
>  
>  -include $(BPF_SAMPLES_PATH)/Makefile.target
>  
> -VMLINUX_BTF_PATHS ?= $(abspath $(if $(O),$(O)/vmlinux))                      
>         \
> +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF
> +VMLINUX_BTF_PATHS ?= $(abspath $(if $(O),$(O)/vmlinux.unstripped))           
> \
> +                  $(abspath $(if $(O),$(O)/vmlinux))                         
> \
> +                  $(abspath $(if 
> $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped))      \
>                    $(abspath $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux)) 
> \
> +                  $(abspath $(objtree)/vmlinux.unstripped)                   
> \
>                    $(abspath $(objtree)/vmlinux)

(out-of-scope for the concrete patch)

I am surprised that of these multi-ambiguous path list.  It looks to me
as if samples/bpf/ and samples/hid/ are always built via Kbuild, thus
there is proper management of variables like O, KBUILD_OUTPUT and
objtree already.  I'd expect 

                     $(abspath $(objtree)/vmlinux.unstripped)                   
\
                     $(abspath $(objtree)/vmlinux)

to be enough here.  But I may be missing something.


Kind regards,
Nicolas

Reply via email to