samples: bpf: Fix vmlinux.h generation for XDP samples
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Tue, 28 Sep 2021 05:46:08 +0000 (11:16 +0530)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 29 Sep 2021 00:21:35 +0000 (17:21 -0700)
commit571fa247ab411f3233eeaaf837c6e646a513b9f8
tree338b25807575e4387e3cfd7cb15763bd11452e61
parent4ccb9f03fee7b20484187ba7e25a7b9b79fe63d5
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: 384b6b3bbf0d (samples: bpf: Add vmlinux.h generation support)
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210928054608.1799021-1-memxor@gmail.com
samples/bpf/Makefile
samples/bpf/xdp_redirect_map_multi.bpf.c