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) VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) diff --git a/samples/hid/Makefile b/samples/hid/Makefile index db5a077c77fc..84566fbe4a5b 100644 --- a/samples/hid/Makefile +++ b/samples/hid/Makefile @@ -162,8 +162,12 @@ $(obj)/hid_surface_dial.o: $(obj)/hid_surface_dial.skel.h -include $(HID_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) VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index b0f7168e7943..0e25bffd0d72 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -236,8 +236,12 @@ $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o $(OBJS): $(LIBBPF) $(LIBBPF_INTERNAL_HDRS) -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux.unstripped) \ + $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../vmlinux.unstripped \ ../../../vmlinux \ /sys/kernel/btf/vmlinux \ /boot/vmlinux-$(shell uname -r) diff --git a/tools/perf/bpf_skel.mak b/tools/perf/bpf_skel.mak index f2559de39f96..01b07dd77692 100644 --- a/tools/perf/bpf_skel.mak +++ b/tools/perf/bpf_skel.mak @@ -44,8 +44,12 @@ $(BPFTOOL): $(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool OUTPUT=$(SKEL_TOOL_TMP_OUT)/ bootstrap # Paths to search for a kernel to generate vmlinux.h from. -VMLINUX_BTF_ELF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF +VMLINUX_BTF_ELF_PATHS ?= $(if $(O),$(O)/vmlinux.unstripped) \ + $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../vmlinux.unstripped \ ../../vmlinux \ /boot/vmlinux-$(shell uname -r) @@ -56,7 +60,7 @@ VMLINUX_BTF_BTF_PATHS ?= /sys/kernel/btf/vmlinux VMLINUX_BTF_ELF_ABSPATHS ?= $(abspath $(wildcard $(VMLINUX_BTF_ELF_PATHS))) VMLINUX_BTF_PATHS ?= $(shell for file in $(VMLINUX_BTF_ELF_ABSPATHS); \ do \ - if [ -f $$file ] && ($(READELF) -S "$$file" | grep -q .BTF); \ + if [ -f $$file ] && ($(READELF) -SW "$$file" | grep -q "[[:space:]]\.BTF[[:space:]]"); \ then \ echo "$$file"; \ fi; \ diff --git a/tools/sched_ext/Makefile b/tools/sched_ext/Makefile index 21554f089692..cf6842904934 100644 --- a/tools/sched_ext/Makefile +++ b/tools/sched_ext/Makefile @@ -73,8 +73,12 @@ HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids DEFAULT_BPFTOOL := $(HOST_OUTPUT_DIR)/sbin/bpftool -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux.unstripped) \ + $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../vmlinux.unstripped \ ../../vmlinux \ /sys/kernel/btf/vmlinux \ /boot/vmlinux-$(shell uname -r) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index afa589a27b15..e6a841e03219 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -140,8 +140,12 @@ endif # Some utility functions use LLVM libraries $(OUTPUT)/jit_disasm_helpers.o: CFLAGS += $(LLVM_CFLAGS) -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux.unstripped) \ + $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../../vmlinux.unstripped \ ../../../../vmlinux \ /sys/kernel/btf/vmlinux \ /boot/vmlinux-$(shell uname -r) diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile index 2f423de83147..8b85382be254 100644 --- a/tools/testing/selftests/hid/Makefile +++ b/tools/testing/selftests/hid/Makefile @@ -81,8 +81,12 @@ endif HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux.unstripped) \ + $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../../vmlinux.unstripped \ ../../../../vmlinux \ /sys/kernel/btf/vmlinux \ /boot/vmlinux-$(shell uname -r) diff --git a/tools/testing/selftests/sched_ext/Makefile b/tools/testing/selftests/sched_ext/Makefile index 3cfe90e0f34f..f9a911c5ce33 100644 --- a/tools/testing/selftests/sched_ext/Makefile +++ b/tools/testing/selftests/sched_ext/Makefile @@ -37,8 +37,12 @@ HOST_LIBBPF_OUTPUT := $(OBJ_DIR)/host/libbpf/ HOST_LIBBPF_DESTDIR := $(OUTPUT_DIR)/host/ HOST_DESTDIR := $(OUTPUT_DIR)/host/ -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +# With CONFIG_DEBUG_INFO_BTF=m only vmlinux.unstripped has the BTF +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux.unstripped) \ + $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux.unstripped) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../../vmlinux.unstripped \ ../../../../vmlinux \ /sys/kernel/btf/vmlinux \ /boot/vmlinux-$(shell uname -r) -- 2.47.3
