All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: bpf <bpf@vger.kernel.org>, Shuah Khan <shuah@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf-next 1/5] selftests/bpf: Enable cross-building
Date: Tue, 12 Jan 2021 12:57:14 -0800	[thread overview]
Message-ID: <CAEf4BzadNOciqNMO_r9i3sVTQWHVQ4m=Yuqx5zaMdvxMS+gJ=A@mail.gmail.com> (raw)
In-Reply-To: <20210112135959.649075-2-jean-philippe@linaro.org>

On Tue, Jan 12, 2021 at 6:01 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> Build bpftool and resolve_btfids using the host toolchain when
> cross-compiling, since they are executed during build to generate the
> selftests. Add a host build directory in order to build both host and
> target version of libbpf. Build host tools using $(HOSTCC) defined in
> Makefile.include.
>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---

Makes sense.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  tools/testing/selftests/bpf/Makefile | 43 ++++++++++++++++++++++------
>  1 file changed, 34 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index c51df6b91bef..1d85565883ea 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
>  include ../../../../scripts/Kbuild.include
>  include ../../../scripts/Makefile.arch
> +include ../../../scripts/Makefile.include
>
>  CXX ?= $(CROSS_COMPILE)g++
>
> @@ -113,7 +114,20 @@ SCRATCH_DIR := $(OUTPUT)/tools
>  BUILD_DIR := $(SCRATCH_DIR)/build
>  INCLUDE_DIR := $(SCRATCH_DIR)/include
>  BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
> -RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids
> +ifneq ($(CROSS_COMPILE),)
> +HOST_BUILD_DIR         := $(BUILD_DIR)/host
> +HOST_SCRATCH_DIR       := $(OUTPUT)/host-tools
> +else
> +HOST_BUILD_DIR         := $(BUILD_DIR)
> +HOST_SCRATCH_DIR       := $(SCRATCH_DIR)
> +endif
> +HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a
> +RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids
> +
> +# sort removes libbpf duplicates when not cross-building
> +MAKE_DIRS := $(sort $(BUILD_DIR)/libbpf $(HOST_BUILD_DIR)/libbpf              \
> +              $(HOST_BUILD_DIR)/bpftool $(HOST_BUILD_DIR)/resolve_btfids      \
> +              $(INCLUDE_DIR))
>
>  VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)                           \
>                      $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux)    \
> @@ -157,7 +171,7 @@ $(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
>         $(call msg,CC,,$@)
>         $(Q)$(CC) -c $(CFLAGS) -o $@ $<
>
> -DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool
> +DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool
>
>  $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
>         $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower     \
> @@ -182,10 +196,11 @@ $(OUTPUT)/test_sysctl: cgroup_helpers.c
>
>  BPFTOOL ?= $(DEFAULT_BPFTOOL)
>  $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)    \
> -                   $(BPFOBJ) | $(BUILD_DIR)/bpftool
> +                   $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool
>         $(Q)$(MAKE) $(submake_extras)  -C $(BPFTOOLDIR)                        \
> -                   OUTPUT=$(BUILD_DIR)/bpftool/                               \
> -                   prefix= DESTDIR=$(SCRATCH_DIR)/ install
> +                   CC=$(HOSTCC) LD=$(HOSTLD)                                  \
> +                   OUTPUT=$(HOST_BUILD_DIR)/bpftool/                          \
> +                   prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install
>         $(Q)mkdir -p $(BUILD_DIR)/bpftool/Documentation
>         $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras)           \
>                     -C $(BPFTOOLDIR)/Documentation                             \
> @@ -198,7 +213,16 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)                \
>         $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
>                     DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
>
> -$(BUILD_DIR)/libbpf $(BUILD_DIR)/bpftool $(BUILD_DIR)/resolve_btfids $(INCLUDE_DIR):
> +ifneq ($(BPFOBJ),$(HOST_BPFOBJ))
> +$(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)                \
> +          ../../../include/uapi/linux/bpf.h                                   \
> +          | $(INCLUDE_DIR) $(HOST_BUILD_DIR)/libbpf
> +       $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR)                             \
> +               OUTPUT=$(HOST_BUILD_DIR)/libbpf/ CC=$(HOSTCC) LD=$(HOSTLD)     \
> +                   DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers
> +endif
> +
> +$(MAKE_DIRS):
>         $(call msg,MKDIR,,$@)
>         $(Q)mkdir -p $@
>

nit: I'd just put this rule right next to MAKE_DIRS definition


> @@ -211,7 +235,7 @@ else
>         $(Q)cp "$(VMLINUX_H)" $@
>  endif
>
> -$(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids     \
> +$(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids   \
>                        $(TOOLSDIR)/bpf/resolve_btfids/main.c    \
>                        $(TOOLSDIR)/lib/rbtree.c                 \
>                        $(TOOLSDIR)/lib/zalloc.c                 \
> @@ -219,7 +243,8 @@ $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids  \
>                        $(TOOLSDIR)/lib/ctype.c                  \
>                        $(TOOLSDIR)/lib/str_error_r.c
>         $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
> -               OUTPUT=$(BUILD_DIR)/resolve_btfids/ BPFOBJ=$(BPFOBJ)
> +               CC=$(HOSTCC) LD=$(HOSTLD) AR=$(HOSTAR) \
> +               OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ)
>
>  # Get Clang's default includes on this system, as opposed to those seen by
>  # '-target bpf'. This fixes "missing" files on some architectures/distros,
> @@ -450,7 +475,7 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
>         $(call msg,BINARY,,$@)
>         $(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
>
> -EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR)                     \
> +EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \
>         prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
>         feature                                                         \
>         $(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc bpf_testmod.ko)
> --
> 2.30.0
>

  reply	other threads:[~2021-01-12 21:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12 13:59 [PATCH bpf-next 0/5] selftests/bpf: Some build fixes Jean-Philippe Brucker
2021-01-12 13:59 ` [PATCH bpf-next 1/5] selftests/bpf: Enable cross-building Jean-Philippe Brucker
2021-01-12 20:57   ` Andrii Nakryiko [this message]
2021-01-12 13:59 ` [PATCH bpf-next 2/5] selftests/bpf: Fix out-of-tree build Jean-Philippe Brucker
2021-01-12 20:57   ` Andrii Nakryiko
2021-01-12 13:59 ` [PATCH bpf-next 3/5] selftests/bpf: Move generated test files to $(TEST_GEN_FILES) Jean-Philippe Brucker
2021-01-12 13:59 ` [PATCH bpf-next 4/5] selftests/bpf: Fix installation of urandom_read Jean-Philippe Brucker
2021-01-12 20:57   ` Andrii Nakryiko
2021-01-12 14:00 ` [PATCH bpf-next 5/5] selftests/bpf: Install btf_dump test cases Jean-Philippe Brucker
2021-01-12 20:55   ` Andrii Nakryiko
2021-01-13  9:59     ` Jean-Philippe Brucker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEf4BzadNOciqNMO_r9i3sVTQWHVQ4m=Yuqx5zaMdvxMS+gJ=A@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jean-philippe@linaro.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.