Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpftool: Install libbpf headers for the bootstrap version, too

We recently changed bpftool's Makefile to make it install libbpf's
headers locally instead of pulling them from the source directory of the
library. Although bpftool needs two versions of libbpf, a "regular" one
and a "bootstrap" version, we would only install headers for the regular
libbpf build. Given that this build always occurs before the bootstrap
build when building bpftool, this is enough to ensure that the bootstrap
bpftool will have access to the headers exported through the regular
libbpf build.

However, this did not account for the case when we only want the
bootstrap version of bpftool, through the "bootstrap" target. For
example, perf needs the bootstrap version only, to generate BPF
skeletons. In that case, when are the headers installed? For some time,
the issue has been masked, because we had a step (the installation of
headers internal to libbpf) which would depend on the regular build of
libbpf and hence trigger the export of the headers, just for the sake of
creating a directory. But this changed with commit 8b6c46241c77
("bpftool: Remove Makefile dep. on $(LIBBPF) for
$(LIBBPF_INTERNAL_HDRS)"), where we cleaned up that stage and removed
the dependency on the regular libbpf build. As a result, when we only
want the bootstrap bpftool version, the regular libbpf is no longer
built. The bootstrap libbpf version is built, but headers are not
exported, and the bootstrap bpftool build fails because of the missing
headers.

To fix this, we also install the library headers for the bootstrap
version of libbpf, to use them for the bootstrap bpftool and for
generating the skeletons.

Fixes: f012ade10b34 ("bpftool: Install libbpf headers instead of including the dir")
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/bpf/20211105015813.6171-1-quentin@isovalent.com

authored by

Quentin Monnet and committed by
Daniel Borkmann
e41ac202 a38bc45a

+22 -10
+22 -10
tools/bpf/bpftool/Makefile
··· 22 22 _OUTPUT := $(CURDIR) 23 23 endif 24 24 BOOTSTRAP_OUTPUT := $(_OUTPUT)/bootstrap/ 25 + 25 26 LIBBPF_OUTPUT := $(_OUTPUT)/libbpf/ 26 27 LIBBPF_DESTDIR := $(LIBBPF_OUTPUT) 27 28 LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)/include 28 29 LIBBPF_HDRS_DIR := $(LIBBPF_INCLUDE)/bpf 30 + LIBBPF := $(LIBBPF_OUTPUT)libbpf.a 29 31 30 - LIBBPF = $(LIBBPF_OUTPUT)libbpf.a 31 - LIBBPF_BOOTSTRAP_OUTPUT = $(BOOTSTRAP_OUTPUT)libbpf/ 32 - LIBBPF_BOOTSTRAP = $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a 32 + LIBBPF_BOOTSTRAP_OUTPUT := $(BOOTSTRAP_OUTPUT)libbpf/ 33 + LIBBPF_BOOTSTRAP_DESTDIR := $(LIBBPF_BOOTSTRAP_OUTPUT) 34 + LIBBPF_BOOTSTRAP_INCLUDE := $(LIBBPF_BOOTSTRAP_DESTDIR)/include 35 + LIBBPF_BOOTSTRAP_HDRS_DIR := $(LIBBPF_BOOTSTRAP_INCLUDE)/bpf 36 + LIBBPF_BOOTSTRAP := $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a 33 37 34 38 # We need to copy hashmap.h and nlattr.h which is not otherwise exported by 35 39 # libbpf, but still required by bpftool. 36 40 LIBBPF_INTERNAL_HDRS := $(addprefix $(LIBBPF_HDRS_DIR)/,hashmap.h nlattr.h) 41 + LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hashmap.h) 37 42 38 43 ifeq ($(BPFTOOL_VERSION),) 39 44 BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion) 40 45 endif 41 46 42 - $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR): 47 + $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR) $(LIBBPF_BOOTSTRAP_HDRS_DIR): 43 48 $(QUIET_MKDIR)mkdir -p $@ 44 49 45 50 $(LIBBPF): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_OUTPUT) ··· 57 52 58 53 $(LIBBPF_BOOTSTRAP): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_BOOTSTRAP_OUTPUT) 59 54 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_BOOTSTRAP_OUTPUT) \ 60 - ARCH= CC=$(HOSTCC) LD=$(HOSTLD) $@ 55 + DESTDIR=$(LIBBPF_BOOTSTRAP_DESTDIR) prefix= \ 56 + ARCH= CC=$(HOSTCC) LD=$(HOSTLD) $@ install_headers 57 + 58 + $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BOOTSTRAP_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_BOOTSTRAP_HDRS_DIR) 59 + $(call QUIET_INSTALL, $@) 60 + $(Q)install -m 644 -t $(LIBBPF_BOOTSTRAP_HDRS_DIR) $< 61 61 62 62 $(LIBBPF)-clean: FORCE | $(LIBBPF_OUTPUT) 63 63 $(call QUIET_CLEAN, libbpf) ··· 182 172 $(Q)cp "$(VMLINUX_H)" $@ 183 173 endif 184 174 185 - $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF) 175 + $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF_BOOTSTRAP) 186 176 $(QUIET_CLANG)$(CLANG) \ 187 177 -I$(if $(OUTPUT),$(OUTPUT),.) \ 188 178 -I$(srctree)/tools/include/uapi/ \ 189 - -I$(LIBBPF_INCLUDE) \ 179 + -I$(LIBBPF_BOOTSTRAP_INCLUDE) \ 190 180 -g -O2 -Wall -target bpf -c $< -o $@ && $(LLVM_STRIP) -g $@ 191 181 192 182 $(OUTPUT)%.skel.h: $(OUTPUT)%.bpf.o $(BPFTOOL_BOOTSTRAP) ··· 219 209 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) 220 210 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) 221 211 222 - $(BOOTSTRAP_OUTPUT)%.o: %.c $(LIBBPF_INTERNAL_HDRS) | $(BOOTSTRAP_OUTPUT) 223 - $(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $< 212 + $(BOOTSTRAP_OUTPUT)%.o: %.c $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS) | $(BOOTSTRAP_OUTPUT) 213 + $(QUIET_CC)$(HOSTCC) \ 214 + $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),$(CFLAGS)) \ 215 + -c -MMD -o $@ $< 224 216 225 217 $(OUTPUT)%.o: %.c 226 218 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $< ··· 269 257 FORCE: 270 258 271 259 .SECONDARY: 272 - .PHONY: all FORCE clean install-bin install uninstall 260 + .PHONY: all FORCE bootstrap clean install-bin install uninstall 273 261 .PHONY: doc doc-clean doc-install doc-uninstall 274 262 .DEFAULT_GOAL := all