Skip to content

Commit 384b6b3

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
samples: bpf: Add vmlinux.h generation support
Also, take this opportunity to depend on in-tree bpftool, so that we can use static linking support in subsequent commits for XDP samples BPF helper object. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20210821002010.845777-13-memxor@gmail.com
1 parent af93d58 commit 384b6b3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎samples/bpf/Makefile‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ $(LIBBPF): FORCE
276276
$(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \
277277
LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O=
278278

279+
BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
280+
BPFTOOL := $(BPFTOOLDIR)/bpftool
281+
$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)
282+
$(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../
283+
279284
$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
280285
$(call filechk,offsets,__SYSCALL_NRS_H__)
281286

@@ -313,6 +318,26 @@ $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
313318

314319
-include $(BPF_SAMPLES_PATH)/Makefile.target
315320

321+
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
322+
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
323+
../../../../vmlinux \
324+
/sys/kernel/btf/vmlinux \
325+
/boot/vmlinux-$(shell uname -r)
326+
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
327+
328+
ifeq ($(VMLINUX_BTF),)
329+
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
330+
endif
331+
332+
$(obj)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL)
333+
ifeq ($(VMLINUX_H),)
334+
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
335+
else
336+
$(Q)cp "$(VMLINUX_H)" $@
337+
endif
338+
339+
clean-files += vmlinux.h
340+
316341
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
317342
# But, there is no easy way to fix it, so just exclude it since it is
318343
# useless for BPF samples.

0 commit comments

Comments
 (0)