diff mbox series

[bpf-next,1/2] tools/bpftool: allow substituting custom vmlinux.h for the build

Message ID 20200630004759.521530-1-andriin@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf-next,1/2] tools/bpftool: allow substituting custom vmlinux.h for the build | expand

Commit Message

Andrii Nakryiko June 30, 2020, 12:47 a.m. UTC
In some build contexts (e.g., Travis CI build for outdated kernel), vmlinux.h,
generated from available kernel, doesn't contain all the types necessary for
BPF program compilation. For such set up, the most maintainable way to deal
with this problem is to keep pre-generated (almost up-to-date) vmlinux.h
checked in and use it for compilation purposes. bpftool after that can deal
with kernel missing some of the features in runtime with no problems.

To that effect, allow to specify path to custom vmlinux.h to bpftool's
Makefile with VMLINUX_H variable.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/bpf/bpftool/Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Yonghong Song June 30, 2020, 3:12 a.m. UTC | #1
On 6/29/20 5:47 PM, Andrii Nakryiko wrote:
> In some build contexts (e.g., Travis CI build for outdated kernel), vmlinux.h,
> generated from available kernel, doesn't contain all the types necessary for
> BPF program compilation. For such set up, the most maintainable way to deal
> with this problem is to keep pre-generated (almost up-to-date) vmlinux.h
> checked in and use it for compilation purposes. bpftool after that can deal
> with kernel missing some of the features in runtime with no problems.
> 
> To that effect, allow to specify path to custom vmlinux.h to bpftool's
> Makefile with VMLINUX_H variable.
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Acked-by: Yonghong Song <yhs@fb.com>
Daniel Borkmann June 30, 2020, 2:12 p.m. UTC | #2
On 6/30/20 2:47 AM, Andrii Nakryiko wrote:
> In some build contexts (e.g., Travis CI build for outdated kernel), vmlinux.h,
> generated from available kernel, doesn't contain all the types necessary for
> BPF program compilation. For such set up, the most maintainable way to deal
> with this problem is to keep pre-generated (almost up-to-date) vmlinux.h
> checked in and use it for compilation purposes. bpftool after that can deal
> with kernel missing some of the features in runtime with no problems.
> 
> To that effect, allow to specify path to custom vmlinux.h to bpftool's
> Makefile with VMLINUX_H variable.
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Both applied, thanks!
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 8c6563e56ffc..273da1615503 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -122,20 +122,24 @@  BPFTOOL_BOOTSTRAP := $(if $(OUTPUT),$(OUTPUT)bpftool-bootstrap,./bpftool-bootstr
 BOOTSTRAP_OBJS = $(addprefix $(OUTPUT),main.o common.o json_writer.o gen.o btf.o)
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
 
-VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux)				\
+VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)				\
 		     $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux)	\
 		     ../../../vmlinux					\
 		     /sys/kernel/btf/vmlinux				\
 		     /boot/vmlinux-$(shell uname -r)
-VMLINUX_BTF := $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
+VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
 
-ifneq ($(VMLINUX_BTF),)
+ifneq ($(VMLINUX_BTF)$(VMLINUX_H),)
 ifeq ($(feature-clang-bpf-co-re),1)
 
 BUILD_BPF_SKELS := 1
 
 $(OUTPUT)vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL_BOOTSTRAP)
+ifeq ($(VMLINUX_H),)
 	$(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) btf dump file $< format c > $@
+else
+	$(Q)cp "$(VMLINUX_H)" $@
+endif
 
 $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF)
 	$(QUIET_CLANG)$(CLANG) \