* [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs
@ 2022-11-19 17:18 Björn Töpel
2022-11-21 10:45 ` Anders Roxell
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Björn Töpel @ 2022-11-19 17:18 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev
Cc: Björn Töpel, Lina Wang, linux-kselftest, Anders Roxell
From: Björn Töpel <bjorn@rivosinc.com>
The selftests/net does not have proper cross-compilation support, and
does not properly state libbpf as a dependency. Mimic/copy the BPF
build from selftests/bpf, which has the nice side-effect that libbpf
is built as well.
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
Now that BPF builds are starting to show up in more places
(selftests/net, and soon selftests/hid), maybe it would be cleaner to
move parts of the BPF builds to lib.mk?
Björn
---
tools/testing/selftests/net/bpf/Makefile | 45 +++++++++++++++++++++---
1 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/bpf/Makefile b/tools/testing/selftests/net/bpf/Makefile
index 8ccaf8732eb2..a26cb94354f6 100644
--- a/tools/testing/selftests/net/bpf/Makefile
+++ b/tools/testing/selftests/net/bpf/Makefile
@@ -1,14 +1,51 @@
# SPDX-License-Identifier: GPL-2.0
CLANG ?= clang
+SCRATCH_DIR := $(OUTPUT)/tools
+BUILD_DIR := $(SCRATCH_DIR)/build
+BPFDIR := $(abspath ../../../lib/bpf)
+APIDIR := $(abspath ../../../include/uapi)
+
CCINCLUDE += -I../../bpf
-CCINCLUDE += -I../../../../lib
CCINCLUDE += -I../../../../../usr/include/
+CCINCLUDE += -I$(SCRATCH_DIR)/include
+
+BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
+
+MAKE_DIRS := $(BUILD_DIR)/libbpf
+$(MAKE_DIRS):
+ mkdir -p $@
TEST_CUSTOM_PROGS = $(OUTPUT)/bpf/nat6to4.o
all: $(TEST_CUSTOM_PROGS)
-$(OUTPUT)/%.o: %.c
- $(CLANG) -O2 -target bpf -c $< $(CCINCLUDE) -o $@
+# Get Clang's default includes on this system, as opposed to those seen by
+# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
+#
+# Use '-idirafter': Don't interfere with include mechanics except where the
+# build would have failed anyways.
+define get_sys_includes
+$(shell $(1) $(2) -v -E - </dev/null 2>&1 \
+ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
+$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
+endef
+
+ifneq ($(CROSS_COMPILE),)
+CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
+endif
+
+CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
+
+$(TEST_CUSTOM_PROGS): $(BPFOBJ)
+ $(CLANG) -O2 -target bpf -c $(@:.o=.c) $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
+
+$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
+ $(APIDIR)/linux/bpf.h \
+ | $(BUILD_DIR)/libbpf
+ $(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
+ EXTRA_CFLAGS='-g -O0' \
+ DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
+
+EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR)
-EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)
base-commit: 8bd8dcc5e47f0f9dc40187c3b8b42d992181eee1
--
2.37.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs
2022-11-19 17:18 [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs Björn Töpel
@ 2022-11-21 10:45 ` Anders Roxell
2022-11-21 16:48 ` Björn Töpel
2022-11-22 12:54 ` Paolo Abeni
2022-11-22 13:00 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: Anders Roxell @ 2022-11-21 10:45 UTC (permalink / raw)
To: Björn Töpel
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, Björn Töpel, Lina Wang, linux-kselftest
On Sat, 19 Nov 2022 at 18:19, Björn Töpel <bjorn@kernel.org> wrote:
>
> From: Björn Töpel <bjorn@rivosinc.com>
>
> The selftests/net does not have proper cross-compilation support, and
> does not properly state libbpf as a dependency. Mimic/copy the BPF
> build from selftests/bpf, which has the nice side-effect that libbpf
> is built as well.
>
> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
> ---
> Now that BPF builds are starting to show up in more places
> (selftests/net, and soon selftests/hid), maybe it would be cleaner to
> move parts of the BPF builds to lib.mk?
Yes, since its in tc-testing too.
Maybe thats what we should do already now?
Cheers,
Anders
>
> Björn
> ---
> tools/testing/selftests/net/bpf/Makefile | 45 +++++++++++++++++++++---
> 1 file changed, 41 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/net/bpf/Makefile b/tools/testing/selftests/net/bpf/Makefile
> index 8ccaf8732eb2..a26cb94354f6 100644
> --- a/tools/testing/selftests/net/bpf/Makefile
> +++ b/tools/testing/selftests/net/bpf/Makefile
> @@ -1,14 +1,51 @@
> # SPDX-License-Identifier: GPL-2.0
>
> CLANG ?= clang
> +SCRATCH_DIR := $(OUTPUT)/tools
> +BUILD_DIR := $(SCRATCH_DIR)/build
> +BPFDIR := $(abspath ../../../lib/bpf)
> +APIDIR := $(abspath ../../../include/uapi)
> +
> CCINCLUDE += -I../../bpf
> -CCINCLUDE += -I../../../../lib
> CCINCLUDE += -I../../../../../usr/include/
> +CCINCLUDE += -I$(SCRATCH_DIR)/include
> +
> +BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
> +
> +MAKE_DIRS := $(BUILD_DIR)/libbpf
> +$(MAKE_DIRS):
> + mkdir -p $@
>
> TEST_CUSTOM_PROGS = $(OUTPUT)/bpf/nat6to4.o
> all: $(TEST_CUSTOM_PROGS)
>
> -$(OUTPUT)/%.o: %.c
> - $(CLANG) -O2 -target bpf -c $< $(CCINCLUDE) -o $@
> +# Get Clang's default includes on this system, as opposed to those seen by
> +# '-target bpf'. This fixes "missing" files on some architectures/distros,
> +# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
> +#
> +# Use '-idirafter': Don't interfere with include mechanics except where the
> +# build would have failed anyways.
> +define get_sys_includes
> +$(shell $(1) $(2) -v -E - </dev/null 2>&1 \
> + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
> +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
> +endef
> +
> +ifneq ($(CROSS_COMPILE),)
> +CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
> +endif
> +
> +CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
> +
> +$(TEST_CUSTOM_PROGS): $(BPFOBJ)
> + $(CLANG) -O2 -target bpf -c $(@:.o=.c) $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
> +
> +$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
> + $(APIDIR)/linux/bpf.h \
> + | $(BUILD_DIR)/libbpf
> + $(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
> + EXTRA_CFLAGS='-g -O0' \
> + DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
> +
> +EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR)
>
> -EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)
>
> base-commit: 8bd8dcc5e47f0f9dc40187c3b8b42d992181eee1
> --
> 2.37.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs
2022-11-21 10:45 ` Anders Roxell
@ 2022-11-21 16:48 ` Björn Töpel
2022-11-22 7:47 ` Anders Roxell
0 siblings, 1 reply; 6+ messages in thread
From: Björn Töpel @ 2022-11-21 16:48 UTC (permalink / raw)
To: Anders Roxell
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, Björn Töpel, Lina Wang, linux-kselftest
Anders Roxell <anders.roxell@linaro.org> writes:
> On Sat, 19 Nov 2022 at 18:19, Björn Töpel <bjorn@kernel.org> wrote:
[...]
>> Now that BPF builds are starting to show up in more places
>> (selftests/net, and soon selftests/hid), maybe it would be cleaner to
>> move parts of the BPF builds to lib.mk?
>
> Yes, since its in tc-testing too.
> Maybe thats what we should do already now?
Ok, so there's three BPF builds, in addition to selftests/bpf. Do you
suggest moving (cross-compiled) libbpf builds (for bpf_helpers_defs.h
generation) and some kind of clang BPF build-rule to lib.mk? Or would
you like more things there, like resolve_btfids?
I guess this patch could go in regardless, and fix the build *now*, and
do a lib.mk thing as a follow-up?
Björn
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs
2022-11-21 16:48 ` Björn Töpel
@ 2022-11-22 7:47 ` Anders Roxell
0 siblings, 0 replies; 6+ messages in thread
From: Anders Roxell @ 2022-11-22 7:47 UTC (permalink / raw)
To: Björn Töpel
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, Björn Töpel, Lina Wang, linux-kselftest
On Mon, 21 Nov 2022 at 17:48, Björn Töpel <bjorn@kernel.org> wrote:
>
> Anders Roxell <anders.roxell@linaro.org> writes:
>
> > On Sat, 19 Nov 2022 at 18:19, Björn Töpel <bjorn@kernel.org> wrote:
> [...]
> >> Now that BPF builds are starting to show up in more places
> >> (selftests/net, and soon selftests/hid), maybe it would be cleaner to
> >> move parts of the BPF builds to lib.mk?
> >
> > Yes, since its in tc-testing too.
> > Maybe thats what we should do already now?
>
> Ok, so there's three BPF builds, in addition to selftests/bpf. Do you
> suggest moving (cross-compiled) libbpf builds (for bpf_helpers_defs.h
> generation) and some kind of clang BPF build-rule to lib.mk?
Maybe start with moving the libbpf builds, for build_helpers_defs.h generation,
and 'define get_sys_includes' into the lib.mk ?
> Or would
> you like more things there, like resolve_btfids?
>
> I guess this patch could go in regardless, and fix the build *now*, and
> do a lib.mk thing as a follow-up?
Make sense.
Reviewed-by: Anders Roxell <anders.roxell@linaro.org>
Cheers,
Anders
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs
2022-11-19 17:18 [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs Björn Töpel
2022-11-21 10:45 ` Anders Roxell
@ 2022-11-22 12:54 ` Paolo Abeni
2022-11-22 13:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 6+ messages in thread
From: Paolo Abeni @ 2022-11-22 12:54 UTC (permalink / raw)
To: Björn Töpel, David S. Miller, Eric Dumazet,
Jakub Kicinski, netdev
Cc: Björn Töpel, Lina Wang, linux-kselftest, Anders Roxell
On Sat, 2022-11-19 at 18:18 +0100, Björn Töpel wrote:
> From: Björn Töpel <bjorn@rivosinc.com>
>
> The selftests/net does not have proper cross-compilation support, and
> does not properly state libbpf as a dependency. Mimic/copy the BPF
> build from selftests/bpf, which has the nice side-effect that libbpf
> is built as well.
>
> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
> ---
> Now that BPF builds are starting to show up in more places
> (selftests/net, and soon selftests/hid), maybe it would be cleaner to
> move parts of the BPF builds to lib.mk?
+1 on such follow-up ;)
Thanks!
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs
2022-11-19 17:18 [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs Björn Töpel
2022-11-21 10:45 ` Anders Roxell
2022-11-22 12:54 ` Paolo Abeni
@ 2022-11-22 13:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-22 13:00 UTC (permalink / raw)
To: =?utf-8?b?QmrDtnJuIFTDtnBlbCA8Ympvcm5Aa2VybmVsLm9yZz4=?=
Cc: davem, edumazet, kuba, pabeni, netdev, bjorn, lina.wang,
linux-kselftest, anders.roxell
Hello:
This patch was applied to netdev/net-next.git (master)
by Paolo Abeni <pabeni@redhat.com>:
On Sat, 19 Nov 2022 18:18:41 +0100 you wrote:
> From: Björn Töpel <bjorn@rivosinc.com>
>
> The selftests/net does not have proper cross-compilation support, and
> does not properly state libbpf as a dependency. Mimic/copy the BPF
> build from selftests/bpf, which has the nice side-effect that libbpf
> is built as well.
>
> [...]
Here is the summary with links:
- [net-next] selftests: net: Add cross-compilation support for BPF programs
https://git.kernel.org/netdev/net-next/c/837a3d66d698
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-11-22 13:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19 17:18 [PATCH net-next] selftests: net: Add cross-compilation support for BPF programs Björn Töpel
2022-11-21 10:45 ` Anders Roxell
2022-11-21 16:48 ` Björn Töpel
2022-11-22 7:47 ` Anders Roxell
2022-11-22 12:54 ` Paolo Abeni
2022-11-22 13:00 ` patchwork-bot+netdevbpf
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).