bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds
@ 2020-08-27 15:36 Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions Jean-Philippe Brucker
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker

A few fixes for cross-building bpftool and runqslower, to build for
example an arm64 bpftool on a x86 host machine and run it on an embedded
platform. Also fix out-of-tree build, allowing for example to use the
same source tree for different target architectures.

Patch 1 factors the HOST variables definitions. Patches 2 and 3 fix the
bpftool build and patches 4-6 fix the runqslower build. I also have some
fixes for the BPF selftests build which I'll send later.

Jean-Philippe Brucker (6):
  tools: Factor HOSTCC, HOSTLD, HOSTAR definitions
  tools/bpftool: Force clean of out-of-tree build
  tools/bpftool: Fix cross-build
  tools/runqslower: Use Makefile.include
  tools/runqslower: Enable out-of-tree build
  tools/runqslower: Build bpftool using HOSTCC

 tools/bpf/bpftool/Makefile        | 38 +++++++++++++----
 tools/bpf/resolve_btfids/Makefile |  9 ----
 tools/bpf/runqslower/Makefile     | 68 ++++++++++++++++++-------------
 tools/build/Makefile              |  4 --
 tools/objtool/Makefile            |  9 ----
 tools/perf/Makefile.perf          |  4 --
 tools/power/acpi/Makefile.config  |  1 -
 tools/scripts/Makefile.include    | 10 +++++
 8 files changed, 78 insertions(+), 65 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
@ 2020-08-27 15:36 ` Jean-Philippe Brucker
  2020-08-27 17:44   ` Rafael J. Wysocki
  2020-08-27 18:35   ` Jiri Olsa
  2020-08-27 15:36 ` [PATCH bpf-next 2/6] tools/bpftool: Force clean of out-of-tree build Jean-Philippe Brucker
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker, Josh Poimboeuf, Peter Zijlstra,
	Ingo Molnar, Arnaldo Carvalho de Melo, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Robert Moore,
	Erik Kaneda, Rafael J. Wysocki, Len Brown, linux-acpi, devel

Several Makefiles in tools/ need to define the host toolchain variables.
Move their definition to tools/scripts/Makefile.include

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Robert Moore <robert.moore@intel.com>
Cc: Erik Kaneda <erik.kaneda@intel.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: devel@acpica.org
---
 tools/bpf/resolve_btfids/Makefile |  9 ---------
 tools/build/Makefile              |  4 ----
 tools/objtool/Makefile            |  9 ---------
 tools/perf/Makefile.perf          |  4 ----
 tools/power/acpi/Makefile.config  |  1 -
 tools/scripts/Makefile.include    | 10 ++++++++++
 6 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index a88cd4426398..b06935578a96 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -17,15 +17,6 @@ else
 endif
 
 # always use the host compiler
-ifneq ($(LLVM),)
-HOSTAR  ?= llvm-ar
-HOSTCC  ?= clang
-HOSTLD  ?= ld.lld
-else
-HOSTAR  ?= ar
-HOSTCC  ?= gcc
-HOSTLD  ?= ld
-endif
 AR       = $(HOSTAR)
 CC       = $(HOSTCC)
 LD       = $(HOSTLD)
diff --git a/tools/build/Makefile b/tools/build/Makefile
index 727050c40f09..8a55378e8b7c 100644
--- a/tools/build/Makefile
+++ b/tools/build/Makefile
@@ -15,10 +15,6 @@ endef
 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
 $(call allow-override,LD,$(CROSS_COMPILE)ld)
 
-HOSTCC ?= gcc
-HOSTLD ?= ld
-HOSTAR ?= ar
-
 export HOSTCC HOSTLD HOSTAR
 
 ifeq ($(V),1)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 7770edcda3a0..b7cb4f26ccde 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -3,15 +3,6 @@ include ../scripts/Makefile.include
 include ../scripts/Makefile.arch
 
 # always use the host compiler
-ifneq ($(LLVM),)
-HOSTAR	?= llvm-ar
-HOSTCC	?= clang
-HOSTLD	?= ld.lld
-else
-HOSTAR	?= ar
-HOSTCC	?= gcc
-HOSTLD	?= ld
-endif
 AR	 = $(HOSTAR)
 CC	 = $(HOSTCC)
 LD	 = $(HOSTLD)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 6031167939ae..43e90334a54e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -175,10 +175,6 @@ endef
 
 LD += $(EXTRA_LDFLAGS)
 
-HOSTCC  ?= gcc
-HOSTLD  ?= ld
-HOSTAR  ?= ar
-
 PKG_CONFIG = $(CROSS_COMPILE)pkg-config
 LLVM_CONFIG ?= llvm-config
 
diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config
index 54a2857c2510..331f6d30f472 100644
--- a/tools/power/acpi/Makefile.config
+++ b/tools/power/acpi/Makefile.config
@@ -54,7 +54,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM}
 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
 CROSS_COMPILE ?= $(CROSS)
 LD = $(CC)
-HOSTCC = gcc
 
 # check if compiler option is supported
 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index a7974638561c..1358e89cdf7d 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -59,6 +59,16 @@ $(call allow-override,LD,$(CROSS_COMPILE)ld)
 $(call allow-override,CXX,$(CROSS_COMPILE)g++)
 $(call allow-override,STRIP,$(CROSS_COMPILE)strip)
 
+ifneq ($(LLVM),)
+HOSTAR  ?= llvm-ar
+HOSTCC  ?= clang
+HOSTLD  ?= ld.lld
+else
+HOSTAR  ?= ar
+HOSTCC  ?= gcc
+HOSTLD  ?= ld
+endif
+
 ifeq ($(CC_NO_CLANG), 1)
 EXTRA_WARNINGS += -Wstrict-aliasing=3
 endif
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bpf-next 2/6] tools/bpftool: Force clean of out-of-tree build
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions Jean-Philippe Brucker
@ 2020-08-27 15:36 ` Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 3/6] tools/bpftool: Fix cross-build Jean-Philippe Brucker
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker

Cleaning a partial build can fail if the output directory for libbpf
wasn't created:

$ make -C tools/bpf/bpftool O=/tmp/bpf clean
/bin/sh: line 0: cd: /tmp/bpf/libbpf/: No such file or directory
tools/scripts/Makefile.include:17: *** output directory "/tmp/bpf/libbpf/" does not exist.  Stop.
make: *** [Makefile:36: /tmp/bpf/libbpf/libbpf.a-clean] Error 2

As a result make never gets around to clearing the leftover objects. Add
the libbpf output directory as clean dependency to ensure clean always
succeeds (similarly to the "descend" macro). The directory is later
removed by the clean recipe.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/bpf/bpftool/Makefile | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 8462690a039b..26a0006f329d 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -27,11 +27,13 @@ LIBBPF = $(LIBBPF_PATH)libbpf.a
 
 BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
 
-$(LIBBPF): FORCE
-	$(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
+$(LIBBPF_OUTPUT):
+	$(QUIET_MKDIR)mkdir -p $@
+
+$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
 	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
 
-$(LIBBPF)-clean:
+$(LIBBPF)-clean: $(LIBBPF_OUTPUT)
 	$(call QUIET_CLEAN, libbpf)
 	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bpf-next 3/6] tools/bpftool: Fix cross-build
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 2/6] tools/bpftool: Force clean of out-of-tree build Jean-Philippe Brucker
@ 2020-08-27 15:36 ` Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 4/6] tools/runqslower: Use Makefile.include Jean-Philippe Brucker
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker

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>
---
 tools/bpf/bpftool/Makefile | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 26a0006f329d..383489b5173a 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -19,24 +19,36 @@ BPF_DIR = $(srctree)/tools/lib/bpf/
 ifneq ($(OUTPUT),)
   LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
   LIBBPF_PATH = $(LIBBPF_OUTPUT)
+  BOOTSTRAP_OUTPUT = $(OUTPUT)/bootstrap/
 else
   LIBBPF_PATH = $(BPF_DIR)
+  BOOTSTRAP_OUTPUT = $(CURDIR)/bootstrap/
 endif
 
 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)
 
-$(LIBBPF_OUTPUT):
+$(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT):
 	$(QUIET_MKDIR)mkdir -p $@
 
 $(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
 	$(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)
 	$(call QUIET_CLEAN, libbpf)
 	$(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
 bash_compdir ?= /usr/share/bash-completion/completions
 
@@ -94,6 +106,7 @@ CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
 endif
 
 LIBS = $(LIBBPF) -lelf -lz
+LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
 ifeq ($(feature-libcap), 1)
 CFLAGS += -DUSE_LIBCAP
 LIBS += -lcap
@@ -120,9 +133,9 @@ CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
 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
 
 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)				\
@@ -169,20 +182,25 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
 
 $(OUTPUT)feature.o: | zdep
 
-$(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF)
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTSTRAP_OBJS) $(LIBS)
+$(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF_BOOTSTRAP)
+	$(QUIET_LINK)$(HOSTCC) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTSTRAP_OBJS) \
+		$(LIBS_BOOTSTRAP)
 
 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
 
+$(BOOTSTRAP_OUTPUT)%.o: %.c | $(BOOTSTRAP_OUTPUT)
+	$(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $<
+
 $(OUTPUT)%.o: %.c
 	$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
 
-clean: $(LIBBPF)-clean
+clean: $(LIBBPF)-clean $(LIBBPF_BOOTSTRAP)-clean
 	$(call QUIET_CLEAN, bpftool)
 	$(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 -- $(BOOTSTRAP_OUTPUT)
 	$(call QUIET_CLEAN, core-gen)
 	$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
 	$(Q)$(RM) -r -- $(OUTPUT)feature/
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bpf-next 4/6] tools/runqslower: Use Makefile.include
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
                   ` (2 preceding siblings ...)
  2020-08-27 15:36 ` [PATCH bpf-next 3/6] tools/bpftool: Fix cross-build Jean-Philippe Brucker
@ 2020-08-27 15:36 ` Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 5/6] tools/runqslower: Enable out-of-tree build Jean-Philippe Brucker
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker

Makefile.include defines variables such as OUTPUT and CC for out-of-tree
build and cross-build. Include it into the runqslower Makefile and use
its $(QUIET*) helpers.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/bpf/runqslower/Makefile | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile
index fb1337d69868..bcc4a7396713 100644
--- a/tools/bpf/runqslower/Makefile
+++ b/tools/bpf/runqslower/Makefile
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+include ../../scripts/Makefile.include
+
 OUTPUT := .output
 CLANG ?= clang
 LLC ?= llc
@@ -21,10 +23,8 @@ VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword			       \
 abs_out := $(abspath $(OUTPUT))
 ifeq ($(V),1)
 Q =
-msg =
 else
 Q = @
-msg = @printf '  %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
 MAKEFLAGS += --no-print-directory
 submake_extras := feature_display=0
 endif
@@ -37,12 +37,11 @@ all: runqslower
 runqslower: $(OUTPUT)/runqslower
 
 clean:
-	$(call msg,CLEAN)
+	$(call QUIET_CLEAN, runqslower)
 	$(Q)rm -rf $(OUTPUT) runqslower
 
 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
-	$(call msg,BINARY,$@)
-	$(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
+	$(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
 
 $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
 			$(OUTPUT)/runqslower.bpf.o
@@ -50,31 +49,26 @@ $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
 $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h
 
 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
-	$(call msg,GEN-SKEL,$@)
-	$(Q)$(BPFTOOL) gen skeleton $< > $@
+	$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
 
 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
-	$(call msg,BPF,$@)
-	$(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES)			      \
+	$(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES)		      \
 		 -c $(filter %.c,$^) -o $@ &&				      \
 	$(LLVM_STRIP) -g $@
 
 $(OUTPUT)/%.o: %.c | $(OUTPUT)
-	$(call msg,CC,$@)
-	$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
+	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
 
 $(OUTPUT):
-	$(call msg,MKDIR,$@)
-	$(Q)mkdir -p $(OUTPUT)
+	$(QUIET_MKDIR)mkdir -p $(OUTPUT)
 
 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
-	$(call msg,GEN,$@)
 	$(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
 		echo "Couldn't find kernel BTF; set VMLINUX_BTF to"	       \
 			"specify its location." >&2;			       \
 		exit 1;\
 	fi
-	$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
+	$(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
 
 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
 	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)			       \
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bpf-next 5/6] tools/runqslower: Enable out-of-tree build
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
                   ` (3 preceding siblings ...)
  2020-08-27 15:36 ` [PATCH bpf-next 4/6] tools/runqslower: Use Makefile.include Jean-Philippe Brucker
@ 2020-08-27 15:36 ` Jean-Philippe Brucker
  2020-08-27 15:36 ` [PATCH bpf-next 6/6] tools/runqslower: Build bpftool using HOSTCC Jean-Philippe Brucker
  2020-08-31 20:23 ` [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Daniel Borkmann
  6 siblings, 0 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker

Enable out-of-tree build for runqslower. Only set OUTPUT=.output if it
wasn't already set by the user.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/bpf/runqslower/Makefile | 45 +++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile
index bcc4a7396713..861f4dcde960 100644
--- a/tools/bpf/runqslower/Makefile
+++ b/tools/bpf/runqslower/Makefile
@@ -1,15 +1,20 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 include ../../scripts/Makefile.include
 
-OUTPUT := .output
+ifeq ($(OUTPUT),)
+  OUTPUT = $(abspath .output)/
+endif
+
 CLANG ?= clang
 LLC ?= llc
 LLVM_STRIP ?= llvm-strip
-DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
+BPFTOOL_OUTPUT := $(OUTPUT)bpftool/
+DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bpftool
 BPFTOOL ?= $(DEFAULT_BPFTOOL)
 LIBBPF_SRC := $(abspath ../../lib/bpf)
-BPFOBJ := $(OUTPUT)/libbpf.a
-BPF_INCLUDE := $(OUTPUT)
+BPFOBJ_OUTPUT := $(OUTPUT)libbpf/
+BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a
+BPF_INCLUDE := $(BPFOBJ_OUTPUT)
 INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib)        \
        -I$(abspath ../../include/uapi)
 CFLAGS := -g -Wall
@@ -20,7 +25,6 @@ VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL)
 VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword			       \
 					  $(wildcard $(VMLINUX_BTF_PATHS))))
 
-abs_out := $(abspath $(OUTPUT))
 ifeq ($(V),1)
 Q =
 else
@@ -36,9 +40,13 @@ all: runqslower
 
 runqslower: $(OUTPUT)/runqslower
 
-clean:
+clean: $(DEFAULT_BPFTOOL)-clean $(BPFOBJ)-clean
 	$(call QUIET_CLEAN, runqslower)
-	$(Q)rm -rf $(OUTPUT) runqslower
+	$(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
+	$(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
+	$(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
+	$(Q)$(RM) $(OUTPUT)runqslower
+	$(Q)$(RM) -r .output
 
 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
@@ -59,8 +67,8 @@ $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
 $(OUTPUT)/%.o: %.c | $(OUTPUT)
 	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
 
-$(OUTPUT):
-	$(QUIET_MKDIR)mkdir -p $(OUTPUT)
+$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
+	$(QUIET_MKDIR)mkdir -p $@
 
 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
 	$(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
@@ -70,10 +78,17 @@ $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
 	fi
 	$(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
 
-$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
-	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)			       \
-		    OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
+$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
+	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) $@
+
+$(BPFOBJ)-clean: $(BPFOBJ_OUTPUT)
+	$(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) clean
 
-$(DEFAULT_BPFTOOL):
-	$(Q)$(MAKE) $(submake_extras) -C ../bpftool			      \
-		    prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install
+$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
+	$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT)
+
+$(DEFAULT_BPFTOOL)-clean: $(BPFTOOL_OUTPUT)
+ifeq ($(DEFAULT_BPFTOOL),$(BPFTOOL))
+	$(call QUIET_CLEAN,bpftool)
+	$(Q)$(MAKE) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) clean
+endif
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bpf-next 6/6] tools/runqslower: Build bpftool using HOSTCC
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
                   ` (4 preceding siblings ...)
  2020-08-27 15:36 ` [PATCH bpf-next 5/6] tools/runqslower: Enable out-of-tree build Jean-Philippe Brucker
@ 2020-08-27 15:36 ` Jean-Philippe Brucker
  2020-08-31 20:23 ` [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Daniel Borkmann
  6 siblings, 0 replies; 10+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-27 15:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Jean-Philippe Brucker

When cross building runqslower for an other architecture, the
intermediate bpftool used to generate a skeleton must be built using the
host toolchain. Pass HOSTCC and HOSTLD, defined in Makefile.include, to
the bpftool Makefile.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/bpf/runqslower/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile
index 861f4dcde960..fa5c18b70dd0 100644
--- a/tools/bpf/runqslower/Makefile
+++ b/tools/bpf/runqslower/Makefile
@@ -85,7 +85,8 @@ $(BPFOBJ)-clean: $(BPFOBJ_OUTPUT)
 	$(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) clean
 
 $(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
-	$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT)
+	$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT)   \
+		    CC=$(HOSTCC) LD=$(HOSTLD)
 
 $(DEFAULT_BPFTOOL)-clean: $(BPFTOOL_OUTPUT)
 ifeq ($(DEFAULT_BPFTOOL),$(BPFTOOL))
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions
  2020-08-27 15:36 ` [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions Jean-Philippe Brucker
@ 2020-08-27 17:44   ` Rafael J. Wysocki
  2020-08-27 18:35   ` Jiri Olsa
  1 sibling, 0 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2020-08-27 17:44 UTC (permalink / raw)
  To: Jean-Philippe Brucker, ast, daniel
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, Josh Poimboeuf, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Robert Moore, Erik Kaneda, Len Brown,
	linux-acpi, devel

On 8/27/2020 5:36 PM, Jean-Philippe Brucker wrote:
> Several Makefiles in tools/ need to define the host toolchain variables.
> Move their definition to tools/scripts/Makefile.include
>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
> Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Robert Moore <robert.moore@intel.com>
> Cc: Erik Kaneda <erik.kaneda@intel.com>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: devel@acpica.org

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

for the ACPI part.


> ---
>   tools/bpf/resolve_btfids/Makefile |  9 ---------
>   tools/build/Makefile              |  4 ----
>   tools/objtool/Makefile            |  9 ---------
>   tools/perf/Makefile.perf          |  4 ----
>   tools/power/acpi/Makefile.config  |  1 -
>   tools/scripts/Makefile.include    | 10 ++++++++++
>   6 files changed, 10 insertions(+), 27 deletions(-)
>
> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> index a88cd4426398..b06935578a96 100644
> --- a/tools/bpf/resolve_btfids/Makefile
> +++ b/tools/bpf/resolve_btfids/Makefile
> @@ -17,15 +17,6 @@ else
>   endif
>   
>   # always use the host compiler
> -ifneq ($(LLVM),)
> -HOSTAR  ?= llvm-ar
> -HOSTCC  ?= clang
> -HOSTLD  ?= ld.lld
> -else
> -HOSTAR  ?= ar
> -HOSTCC  ?= gcc
> -HOSTLD  ?= ld
> -endif
>   AR       = $(HOSTAR)
>   CC       = $(HOSTCC)
>   LD       = $(HOSTLD)
> diff --git a/tools/build/Makefile b/tools/build/Makefile
> index 727050c40f09..8a55378e8b7c 100644
> --- a/tools/build/Makefile
> +++ b/tools/build/Makefile
> @@ -15,10 +15,6 @@ endef
>   $(call allow-override,CC,$(CROSS_COMPILE)gcc)
>   $(call allow-override,LD,$(CROSS_COMPILE)ld)
>   
> -HOSTCC ?= gcc
> -HOSTLD ?= ld
> -HOSTAR ?= ar
> -
>   export HOSTCC HOSTLD HOSTAR
>   
>   ifeq ($(V),1)
> diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
> index 7770edcda3a0..b7cb4f26ccde 100644
> --- a/tools/objtool/Makefile
> +++ b/tools/objtool/Makefile
> @@ -3,15 +3,6 @@ include ../scripts/Makefile.include
>   include ../scripts/Makefile.arch
>   
>   # always use the host compiler
> -ifneq ($(LLVM),)
> -HOSTAR	?= llvm-ar
> -HOSTCC	?= clang
> -HOSTLD	?= ld.lld
> -else
> -HOSTAR	?= ar
> -HOSTCC	?= gcc
> -HOSTLD	?= ld
> -endif
>   AR	 = $(HOSTAR)
>   CC	 = $(HOSTCC)
>   LD	 = $(HOSTLD)
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 6031167939ae..43e90334a54e 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -175,10 +175,6 @@ endef
>   
>   LD += $(EXTRA_LDFLAGS)
>   
> -HOSTCC  ?= gcc
> -HOSTLD  ?= ld
> -HOSTAR  ?= ar
> -
>   PKG_CONFIG = $(CROSS_COMPILE)pkg-config
>   LLVM_CONFIG ?= llvm-config
>   
> diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config
> index 54a2857c2510..331f6d30f472 100644
> --- a/tools/power/acpi/Makefile.config
> +++ b/tools/power/acpi/Makefile.config
> @@ -54,7 +54,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM}
>   CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
>   CROSS_COMPILE ?= $(CROSS)
>   LD = $(CC)
> -HOSTCC = gcc
>   
>   # check if compiler option is supported
>   cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
> diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
> index a7974638561c..1358e89cdf7d 100644
> --- a/tools/scripts/Makefile.include
> +++ b/tools/scripts/Makefile.include
> @@ -59,6 +59,16 @@ $(call allow-override,LD,$(CROSS_COMPILE)ld)
>   $(call allow-override,CXX,$(CROSS_COMPILE)g++)
>   $(call allow-override,STRIP,$(CROSS_COMPILE)strip)
>   
> +ifneq ($(LLVM),)
> +HOSTAR  ?= llvm-ar
> +HOSTCC  ?= clang
> +HOSTLD  ?= ld.lld
> +else
> +HOSTAR  ?= ar
> +HOSTCC  ?= gcc
> +HOSTLD  ?= ld
> +endif
> +
>   ifeq ($(CC_NO_CLANG), 1)
>   EXTRA_WARNINGS += -Wstrict-aliasing=3
>   endif



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions
  2020-08-27 15:36 ` [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions Jean-Philippe Brucker
  2020-08-27 17:44   ` Rafael J. Wysocki
@ 2020-08-27 18:35   ` Jiri Olsa
  1 sibling, 0 replies; 10+ messages in thread
From: Jiri Olsa @ 2020-08-27 18:35 UTC (permalink / raw)
  To: Jean-Philippe Brucker
  Cc: ast, daniel, bpf, kafai, songliubraving, yhs, andriin,
	john.fastabend, kpsingh, Josh Poimboeuf, Peter Zijlstra,
	Ingo Molnar, Arnaldo Carvalho de Melo, Mark Rutland,
	Alexander Shishkin, Namhyung Kim, Robert Moore, Erik Kaneda,
	Rafael J. Wysocki, Len Brown, linux-acpi, devel

On Thu, Aug 27, 2020 at 05:36:25PM +0200, Jean-Philippe Brucker wrote:
> Several Makefiles in tools/ need to define the host toolchain variables.
> Move their definition to tools/scripts/Makefile.include
> 
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>

for perf and resolve_btfids

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds
  2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
                   ` (5 preceding siblings ...)
  2020-08-27 15:36 ` [PATCH bpf-next 6/6] tools/runqslower: Build bpftool using HOSTCC Jean-Philippe Brucker
@ 2020-08-31 20:23 ` Daniel Borkmann
  6 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2020-08-31 20:23 UTC (permalink / raw)
  To: Jean-Philippe Brucker, ast
  Cc: bpf, kafai, songliubraving, yhs, andriin, john.fastabend, kpsingh

On 8/27/20 5:36 PM, Jean-Philippe Brucker wrote:
> A few fixes for cross-building bpftool and runqslower, to build for
> example an arm64 bpftool on a x86 host machine and run it on an embedded
> platform. Also fix out-of-tree build, allowing for example to use the
> same source tree for different target architectures.
> 
> Patch 1 factors the HOST variables definitions. Patches 2 and 3 fix the
> bpftool build and patches 4-6 fix the runqslower build. I also have some
> fixes for the BPF selftests build which I'll send later.
> 
> Jean-Philippe Brucker (6):
>    tools: Factor HOSTCC, HOSTLD, HOSTAR definitions
>    tools/bpftool: Force clean of out-of-tree build
>    tools/bpftool: Fix cross-build
>    tools/runqslower: Use Makefile.include
>    tools/runqslower: Enable out-of-tree build
>    tools/runqslower: Build bpftool using HOSTCC
> 
>   tools/bpf/bpftool/Makefile        | 38 +++++++++++++----
>   tools/bpf/resolve_btfids/Makefile |  9 ----
>   tools/bpf/runqslower/Makefile     | 68 ++++++++++++++++++-------------
>   tools/build/Makefile              |  4 --
>   tools/objtool/Makefile            |  9 ----
>   tools/perf/Makefile.perf          |  4 --
>   tools/power/acpi/Makefile.config  |  1 -
>   tools/scripts/Makefile.include    | 10 +++++
>   8 files changed, 78 insertions(+), 65 deletions(-)

Looks like this doesn't apply cleanly and thus needs a rebase. Pls submit a
v2, thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-08-31 20:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 15:36 [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Jean-Philippe Brucker
2020-08-27 15:36 ` [PATCH bpf-next 1/6] tools: Factor HOSTCC, HOSTLD, HOSTAR definitions Jean-Philippe Brucker
2020-08-27 17:44   ` Rafael J. Wysocki
2020-08-27 18:35   ` Jiri Olsa
2020-08-27 15:36 ` [PATCH bpf-next 2/6] tools/bpftool: Force clean of out-of-tree build Jean-Philippe Brucker
2020-08-27 15:36 ` [PATCH bpf-next 3/6] tools/bpftool: Fix cross-build Jean-Philippe Brucker
2020-08-27 15:36 ` [PATCH bpf-next 4/6] tools/runqslower: Use Makefile.include Jean-Philippe Brucker
2020-08-27 15:36 ` [PATCH bpf-next 5/6] tools/runqslower: Enable out-of-tree build Jean-Philippe Brucker
2020-08-27 15:36 ` [PATCH bpf-next 6/6] tools/runqslower: Build bpftool using HOSTCC Jean-Philippe Brucker
2020-08-31 20:23 ` [PATCH bpf-next 0/6] tools/bpftool: Fix cross and out-of-tree builds Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).