mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
tools/bpftool: Fix cross-build
The bpftool build first creates an intermediate binary, executed on the host, to generate skeletons required by the final build. When cross-building bpftool for an architecture different from the host, the intermediate binary should be built using the host compiler (gcc) and the final bpftool using the cross compiler (e.g. aarch64-linux-gnu-gcc). Generate the intermediate objects into the bootstrap/ directory using the host toolchain. Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20201110164310.2600671-4-jean-philippe@linaro.org
This commit is contained in:
parent
9e8929fdbb
commit
8859b0da5a
@ -19,24 +19,37 @@ BPF_DIR = $(srctree)/tools/lib/bpf/
|
|||||||
ifneq ($(OUTPUT),)
|
ifneq ($(OUTPUT),)
|
||||||
LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
|
LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
|
||||||
LIBBPF_PATH = $(LIBBPF_OUTPUT)
|
LIBBPF_PATH = $(LIBBPF_OUTPUT)
|
||||||
|
BOOTSTRAP_OUTPUT = $(OUTPUT)/bootstrap/
|
||||||
else
|
else
|
||||||
|
LIBBPF_OUTPUT =
|
||||||
LIBBPF_PATH = $(BPF_DIR)
|
LIBBPF_PATH = $(BPF_DIR)
|
||||||
|
BOOTSTRAP_OUTPUT = $(CURDIR)/bootstrap/
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIBBPF = $(LIBBPF_PATH)libbpf.a
|
LIBBPF = $(LIBBPF_PATH)libbpf.a
|
||||||
|
LIBBPF_BOOTSTRAP_OUTPUT = $(BOOTSTRAP_OUTPUT)libbpf/
|
||||||
|
LIBBPF_BOOTSTRAP = $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a
|
||||||
|
|
||||||
BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
|
BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
|
||||||
|
|
||||||
$(LIBBPF_OUTPUT):
|
$(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT):
|
||||||
$(QUIET_MKDIR)mkdir -p $@
|
$(QUIET_MKDIR)mkdir -p $@
|
||||||
|
|
||||||
$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
|
$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
|
||||||
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
|
||||||
|
|
||||||
|
$(LIBBPF_BOOTSTRAP): FORCE | $(LIBBPF_BOOTSTRAP_OUTPUT)
|
||||||
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_BOOTSTRAP_OUTPUT) \
|
||||||
|
ARCH= CC=$(HOSTCC) LD=$(HOSTLD) $@
|
||||||
|
|
||||||
$(LIBBPF)-clean: $(LIBBPF_OUTPUT)
|
$(LIBBPF)-clean: $(LIBBPF_OUTPUT)
|
||||||
$(call QUIET_CLEAN, libbpf)
|
$(call QUIET_CLEAN, libbpf)
|
||||||
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
|
||||||
|
|
||||||
|
$(LIBBPF_BOOTSTRAP)-clean: $(LIBBPF_BOOTSTRAP_OUTPUT)
|
||||||
|
$(call QUIET_CLEAN, libbpf-bootstrap)
|
||||||
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_BOOTSTRAP_OUTPUT) clean >/dev/null
|
||||||
|
|
||||||
prefix ?= /usr/local
|
prefix ?= /usr/local
|
||||||
bash_compdir ?= /usr/share/bash-completion/completions
|
bash_compdir ?= /usr/share/bash-completion/completions
|
||||||
|
|
||||||
@ -94,6 +107,7 @@ CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
LIBS = $(LIBBPF) -lelf -lz
|
LIBS = $(LIBBPF) -lelf -lz
|
||||||
|
LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
|
||||||
ifeq ($(feature-libcap), 1)
|
ifeq ($(feature-libcap), 1)
|
||||||
CFLAGS += -DUSE_LIBCAP
|
CFLAGS += -DUSE_LIBCAP
|
||||||
LIBS += -lcap
|
LIBS += -lcap
|
||||||
@ -120,9 +134,9 @@ CFLAGS += -DHAVE_LIBBFD_SUPPORT
|
|||||||
SRCS += $(BFD_SRCS)
|
SRCS += $(BFD_SRCS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
BPFTOOL_BOOTSTRAP := $(if $(OUTPUT),$(OUTPUT)bpftool-bootstrap,./bpftool-bootstrap)
|
BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool
|
||||||
|
|
||||||
BOOTSTRAP_OBJS = $(addprefix $(OUTPUT),main.o common.o json_writer.o gen.o btf.o)
|
BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o)
|
||||||
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
|
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
|
||||||
|
|
||||||
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
|
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
|
||||||
@ -169,12 +183,16 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
|
|||||||
|
|
||||||
$(OUTPUT)feature.o: | zdep
|
$(OUTPUT)feature.o: | zdep
|
||||||
|
|
||||||
$(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF)
|
$(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF_BOOTSTRAP)
|
||||||
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTSTRAP_OBJS) $(LIBS)
|
$(QUIET_LINK)$(HOSTCC) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTSTRAP_OBJS) \
|
||||||
|
$(LIBS_BOOTSTRAP)
|
||||||
|
|
||||||
$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
|
$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
|
||||||
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||||
|
|
||||||
|
$(BOOTSTRAP_OUTPUT)%.o: %.c | $(BOOTSTRAP_OUTPUT)
|
||||||
|
$(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $<
|
||||||
|
|
||||||
$(OUTPUT)%.o: %.c
|
$(OUTPUT)%.o: %.c
|
||||||
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
|
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
|
||||||
|
|
||||||
@ -182,11 +200,11 @@ feature-detect-clean:
|
|||||||
$(call QUIET_CLEAN, feature-detect)
|
$(call QUIET_CLEAN, feature-detect)
|
||||||
$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
|
$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
|
||||||
|
|
||||||
clean: $(LIBBPF)-clean feature-detect-clean
|
clean: $(LIBBPF)-clean $(LIBBPF_BOOTSTRAP)-clean feature-detect-clean
|
||||||
$(call QUIET_CLEAN, bpftool)
|
$(call QUIET_CLEAN, bpftool)
|
||||||
$(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
|
$(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
|
||||||
$(Q)$(RM) -- $(BPFTOOL_BOOTSTRAP) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
|
$(Q)$(RM) -- $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
|
||||||
$(Q)$(RM) -r -- $(OUTPUT)libbpf/
|
$(Q)$(RM) -r -- $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT)
|
||||||
$(call QUIET_CLEAN, core-gen)
|
$(call QUIET_CLEAN, core-gen)
|
||||||
$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
|
$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
|
||||||
$(Q)$(RM) -r -- $(OUTPUT)feature/
|
$(Q)$(RM) -r -- $(OUTPUT)feature/
|
||||||
|
Loading…
Reference in New Issue
Block a user