diff mbox series

[bpf-next,1/3] selftests/bpf: Fix broken riscv build

Message ID 20201117082638.43675-2-bjorn.topel@gmail.com (mailing list archive)
State New, archived
Headers show
Series [bpf-next,1/3] selftests/bpf: Fix broken riscv build | expand

Commit Message

Björn Töpel Nov. 17, 2020, 8:26 a.m. UTC
The selftests/bpf Makefile includes system include directories from
the host, when building BPF programs. On RISC-V glibc requires that
__riscv_xlen is defined. This is not the case for "clang -target bpf",
which messes up __WORDSIZE (errno.h -> ... -> wordsize.h) and breaks
the build.

By explicitly defining __risc_xlen correctly for riscv, we can
workaround this.

Fixes: 167381f3eac0 ("selftests/bpf: Makefile fix "missing" headers on build with -idirafter")
Signed-off-by: Björn Töpel <bjorn.topel@gmail.com>
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko Nov. 18, 2020, 1:43 a.m. UTC | #1
On Tue, Nov 17, 2020 at 12:28 AM Björn Töpel <bjorn.topel@gmail.com> wrote:
>
> The selftests/bpf Makefile includes system include directories from
> the host, when building BPF programs. On RISC-V glibc requires that
> __riscv_xlen is defined. This is not the case for "clang -target bpf",
> which messes up __WORDSIZE (errno.h -> ... -> wordsize.h) and breaks
> the build.
>
> By explicitly defining __risc_xlen correctly for riscv, we can
> workaround this.
>
> Fixes: 167381f3eac0 ("selftests/bpf: Makefile fix "missing" headers on build with -idirafter")
> Signed-off-by: Björn Töpel <bjorn.topel@gmail.com>
> ---
>  tools/testing/selftests/bpf/Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index c1708ffa6b1c..9d48769ad268 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -219,7 +219,8 @@ $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids  \
>  # build would have failed anyways.
>  define get_sys_includes
>  $(shell $(1) -v -E - </dev/null 2>&1 \
> -       | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
> +       | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
> +       $(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' |sed 's/#define /-D/' | sed 's/ /=/')

just nits: second $(shell ) invocation should be at the same
indentation level as the first one

also '|sed' -> '| sed' ?

Otherwise I have no idea what this does and no way to try it on
RISC-V, but it doesn't break my setup, so I'm fine with it. ;)


>  endef
>
>  # Determine target endianness.
> --
> 2.27.0
>
Björn Töpel Nov. 18, 2020, 6:26 a.m. UTC | #2
On Wed, 18 Nov 2020 at 02:43, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Tue, Nov 17, 2020 at 12:28 AM Björn Töpel <bjorn.topel@gmail.com> wrote:
> >
> > The selftests/bpf Makefile includes system include directories from
> > the host, when building BPF programs. On RISC-V glibc requires that
> > __riscv_xlen is defined. This is not the case for "clang -target bpf",
> > which messes up __WORDSIZE (errno.h -> ... -> wordsize.h) and breaks
> > the build.
> >
> > By explicitly defining __risc_xlen correctly for riscv, we can
> > workaround this.
> >
> > Fixes: 167381f3eac0 ("selftests/bpf: Makefile fix "missing" headers on build with -idirafter")
> > Signed-off-by: Björn Töpel <bjorn.topel@gmail.com>
> > ---
> >  tools/testing/selftests/bpf/Makefile | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index c1708ffa6b1c..9d48769ad268 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -219,7 +219,8 @@ $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids  \
> >  # build would have failed anyways.
> >  define get_sys_includes
> >  $(shell $(1) -v -E - </dev/null 2>&1 \
> > -       | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
> > +       | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
> > +       $(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' |sed 's/#define /-D/' | sed 's/ /=/')
>
> just nits: second $(shell ) invocation should be at the same
> indentation level as the first one
>
> also '|sed' -> '| sed' ?
>
> Otherwise I have no idea what this does and no way to try it on
> RISC-V, but it doesn't break my setup, so I'm fine with it. ;)
>

:-) I'll fix it up in v2.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index c1708ffa6b1c..9d48769ad268 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -219,7 +219,8 @@  $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids	\
 # build would have failed anyways.
 define get_sys_includes
 $(shell $(1) -v -E - </dev/null 2>&1 \
-	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
+	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
+	$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' |sed 's/#define /-D/' | sed 's/ /=/')
 endef
 
 # Determine target endianness.