Skip to content

Commit 571fa24

Browse files
kkdwivedianakryiko
authored andcommitted
samples: bpf: Fix vmlinux.h generation for XDP samples
Generate vmlinux.h only from the in-tree vmlinux, and remove enum declarations that would cause a build failure in case of version mismatches. There are now two options when building the samples: 1. Compile the kernel to use in-tree vmlinux for vmlinux.h 2. Override VMLINUX_BTF for samples using something like this: make VMLINUX_BTF=/sys/kernel/btf/vmlinux -C samples/bpf This change was tested with relative builds, e.g. cases like: * make O=build -C samples/bpf * make KBUILD_OUTPUT=build -C samples/bpf * make -C samples/bpf * cd samples/bpf && make When a suitable VMLINUX_BTF is not found, the following message is printed: /home/kkd/src/linux/samples/bpf/Makefile:333: *** Cannot find a vmlinux for VMLINUX_BTF at any of " ./vmlinux", build the kernel or set VMLINUX_BTF variable. Stop. Fixes: 384b6b3 (samples: bpf: Add vmlinux.h generation support) Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Toke Høiland-Jørgensen <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 4ccb9f0 commit 571fa24

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

samples/bpf/Makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,24 +322,23 @@ $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
322322

323323
-include $(BPF_SAMPLES_PATH)/Makefile.target
324324

325-
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
326-
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
327-
../../../../vmlinux \
328-
/sys/kernel/btf/vmlinux \
329-
/boot/vmlinux-$(shell uname -r)
325+
VMLINUX_BTF_PATHS ?= $(abspath $(if $(O),$(O)/vmlinux)) \
326+
$(abspath $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux)) \
327+
$(abspath ./vmlinux)
330328
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
331329

332-
ifeq ($(VMLINUX_BTF),)
333-
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
334-
endif
335-
336330
$(obj)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL)
337331
ifeq ($(VMLINUX_H),)
338332
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
339333
else
340334
$(Q)cp "$(VMLINUX_H)" $@
341335
endif
342336

337+
ifeq ($(VMLINUX_BTF),)
338+
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)",\
339+
build the kernel or set VMLINUX_BTF variable)
340+
endif
341+
343342
clean-files += vmlinux.h
344343

345344
# Get Clang's default includes on this system, as opposed to those seen by

samples/bpf/xdp_redirect_map_multi.bpf.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
#include "xdp_sample.bpf.h"
66
#include "xdp_sample_shared.h"
77

8-
enum {
9-
BPF_F_BROADCAST = (1ULL << 3),
10-
BPF_F_EXCLUDE_INGRESS = (1ULL << 4),
11-
};
12-
138
struct {
149
__uint(type, BPF_MAP_TYPE_DEVMAP_HASH);
1510
__uint(key_size, sizeof(int));

0 commit comments

Comments
 (0)