From: Jiri Olsa <olsajiri@gmail.com>
To: Viktor Malik <vmalik@redhat.com>
Cc: bpf@vger.kernel.org, Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Mykola Lysenko <mykolal@fb.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>
Subject: Re: [PATCH bpf-next v2 1/3] selftests/bpf: Allow building with extra flags
Date: Mon, 21 Oct 2024 09:30:49 +0200 [thread overview]
Message-ID: <ZxYDKXBv3GR6QFAG@krava> (raw)
In-Reply-To: <e2ec5f8c7ee79e18161a359dfa19f80a90fdc3fc.1729233447.git.vmalik@redhat.com>
On Fri, Oct 18, 2024 at 08:48:59AM +0200, Viktor Malik wrote:
> In order to specify extra compilation or linking flags to BPF selftests,
> it is possible to set EXTRA_CFLAGS and EXTRA_LDFLAGS from the command
> line. The problem is that they are not propagated to sub-make calls
> (runqslower, bpftool, libbpf) and in the better case are not applied, in
> the worse case cause the entire build fail.
>
> Propagate EXTRA_CFLAGS and EXTRA_LDFLAGS to the sub-makes.
>
> This, for instance, allows to build selftests as PIE with
>
> $ make EXTRA_CFLAGS='-fPIE' EXTRA_LDFLAGS='-pie'
>
> Without this change, the command would fail because libbpf.a would not
> be built with -fPIE and other PIE binaries would not link against it.
>
> The only problem is that we have to explicitly provide empty
> EXTRA_CFLAGS='' and EXTRA_LDFLAGS='' to the builds of kernel modules
> (bpf_testmod and bpf_test_no_cfi) as we don't want to build modules with
> flags used for userspace (the above example would fail as kernel doesn't
> support PIE).
>
> Signed-off-by: Viktor Malik <vmalik@redhat.com>
> Tested-by: Eduard Zingerman <eddyz87@gmail.com>
lgtm
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> tools/testing/selftests/bpf/Makefile | 26 +++++++++++++++++---------
> 1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 28a76baa854d..1fc7c38e56b5 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -294,13 +294,17 @@ $(OUTPUT)/sign-file: ../../../../scripts/sign-file.c
> $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
> $(call msg,MOD,,$@)
> $(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation
> - $(Q)$(MAKE) $(submake_extras) RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) -C bpf_testmod
> + $(Q)$(MAKE) $(submake_extras) -C bpf_testmod \
> + RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) \
> + EXTRA_CFLAGS='' EXTRA_LDFLAGS=''
> $(Q)cp bpf_testmod/bpf_testmod.ko $@
>
> $(OUTPUT)/bpf_test_no_cfi.ko: $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard bpf_test_no_cfi/Makefile bpf_test_no_cfi/*.[ch])
> $(call msg,MOD,,$@)
> $(Q)$(RM) bpf_test_no_cfi/bpf_test_no_cfi.ko # force re-compilation
> - $(Q)$(MAKE) $(submake_extras) RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) -C bpf_test_no_cfi
> + $(Q)$(MAKE) $(submake_extras) -C bpf_test_no_cfi \
> + RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) \
> + EXTRA_CFLAGS='' EXTRA_LDFLAGS=''
> $(Q)cp bpf_test_no_cfi/bpf_test_no_cfi.ko $@
>
> DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool
> @@ -319,8 +323,8 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT)
> BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \
> BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf/ \
> BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) \
> - EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS)' \
> - EXTRA_LDFLAGS='$(SAN_LDFLAGS)' && \
> + EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS) $(EXTRA_CFLAGS)' \
> + EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' && \
> cp $(RUNQSLOWER_OUTPUT)runqslower $@
>
> TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL)
> @@ -354,7 +358,8 @@ $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
> $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool
> $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
> ARCH= CROSS_COMPILE= CC="$(HOSTCC)" LD="$(HOSTLD)" \
> - EXTRA_CFLAGS='-g $(OPT_FLAGS)' \
> + EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
> + EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \
> OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \
> LIBBPF_OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \
> LIBBPF_DESTDIR=$(HOST_SCRATCH_DIR)/ \
> @@ -365,7 +370,8 @@ $(CROSS_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
> $(BPFOBJ) | $(BUILD_DIR)/bpftool
> $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
> ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) \
> - EXTRA_CFLAGS='-g $(OPT_FLAGS)' \
> + EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
> + EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \
> OUTPUT=$(BUILD_DIR)/bpftool/ \
> LIBBPF_OUTPUT=$(BUILD_DIR)/libbpf/ \
> LIBBPF_DESTDIR=$(SCRATCH_DIR)/ \
> @@ -388,8 +394,8 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
> $(APIDIR)/linux/bpf.h \
> | $(BUILD_DIR)/libbpf
> $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
> - EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS)' \
> - EXTRA_LDFLAGS='$(SAN_LDFLAGS)' \
> + EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS) $(EXTRA_CFLAGS)' \
> + EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \
> DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
>
> ifneq ($(BPFOBJ),$(HOST_BPFOBJ))
> @@ -397,7 +403,9 @@ $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
> $(APIDIR)/linux/bpf.h \
> | $(HOST_BUILD_DIR)/libbpf
> $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \
> - EXTRA_CFLAGS='-g $(OPT_FLAGS)' ARCH= CROSS_COMPILE= \
> + ARCH= CROSS_COMPILE= \
> + EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
> + EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \
> OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \
> CC="$(HOSTCC)" LD="$(HOSTLD)" \
> DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers
> --
> 2.47.0
>
next prev parent reply other threads:[~2024-10-21 7:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 6:48 [PATCH bpf-next v2 0/3] selftests/bpf: Improve building with extra Viktor Malik
2024-10-18 6:48 ` [PATCH bpf-next v2 1/3] selftests/bpf: Allow building with extra flags Viktor Malik
2024-10-21 7:30 ` Jiri Olsa [this message]
2024-10-18 6:49 ` [PATCH bpf-next v2 2/3] bpftool: Prevent setting duplicate _GNU_SOURCE in Makefile Viktor Malik
2024-10-18 9:17 ` Quentin Monnet
2024-10-21 7:27 ` Jiri Olsa
2024-10-18 6:49 ` [PATCH bpf-next v2 3/3] selftests/bpf: Disable warnings on unused flags for Clang builds Viktor Malik
2024-10-20 17:24 ` Jiri Olsa
2024-10-21 6:20 ` Viktor Malik
2024-10-21 7:26 ` Jiri Olsa
2024-10-22 0:00 ` [PATCH bpf-next v2 0/3] selftests/bpf: Improve building with extra patchwork-bot+netdevbpf
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=ZxYDKXBv3GR6QFAG@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=justinstitt@google.com \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=morbo@google.com \
--cc=mykolal@fb.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=vmalik@redhat.com \
--cc=yonghong.song@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox