All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] tools/bpftool: Fix cross-build
@ 2021-06-03 17:05 Jean-Philippe Brucker
  2021-06-03 17:50 ` Andrii Nakryiko
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Philippe Brucker @ 2021-06-03 17:05 UTC (permalink / raw)
  To: ast, daniel, andrii
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh, bpf,
	Jean-Philippe Brucker

When the bootstrap and final bpftool have different architectures, we
need to build two distinct disasm.o objects. Add a recipe for the
bootstrap disasm.o

Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/bpf/bpftool/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index d16d289ade7a..d73232be1e99 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -136,7 +136,7 @@ endif
 
 BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool
 
-BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o) $(OUTPUT)disasm.o
+BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o disasm.o)
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
 
 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)				\
@@ -180,6 +180,9 @@ endif
 
 CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_WITHOUT_SKELETONS)
 
+$(BOOTSTRAP_OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
+	$(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $<
+
 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
 	$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
 
-- 
2.31.1


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

* Re: [PATCH bpf-next] tools/bpftool: Fix cross-build
  2021-06-03 17:05 [PATCH bpf-next] tools/bpftool: Fix cross-build Jean-Philippe Brucker
@ 2021-06-03 17:50 ` Andrii Nakryiko
  2021-06-04  7:50   ` Jean-Philippe Brucker
  0 siblings, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2021-06-03 17:50 UTC (permalink / raw)
  To: Jean-Philippe Brucker
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, bpf

On Thu, Jun 3, 2021 at 10:06 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> When the bootstrap and final bpftool have different architectures, we
> need to build two distinct disasm.o objects. Add a recipe for the
> bootstrap disasm.o
>
> Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")

Did this commit break something specifically?

> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
>  tools/bpf/bpftool/Makefile | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index d16d289ade7a..d73232be1e99 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -136,7 +136,7 @@ endif
>
>  BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool
>
> -BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o) $(OUTPUT)disasm.o
> +BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o disasm.o)
>  OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
>
>  VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)                           \
> @@ -180,6 +180,9 @@ endif
>
>  CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_WITHOUT_SKELETONS)
>
> +$(BOOTSTRAP_OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
> +       $(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $<
> +
>  $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c

maybe just do

$(BOOTSTRAP_OUTPUT)disasm.o $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c

?

>         $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
>
> --
> 2.31.1
>

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

* Re: [PATCH bpf-next] tools/bpftool: Fix cross-build
  2021-06-03 17:50 ` Andrii Nakryiko
@ 2021-06-04  7:50   ` Jean-Philippe Brucker
  2021-06-04 17:02     ` Andrii Nakryiko
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Philippe Brucker @ 2021-06-04  7:50 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, bpf

On Thu, Jun 03, 2021 at 10:50:08AM -0700, Andrii Nakryiko wrote:
> On Thu, Jun 3, 2021 at 10:06 AM Jean-Philippe Brucker
> <jean-philippe@linaro.org> wrote:
> >
> > When the bootstrap and final bpftool have different architectures, we
> > need to build two distinct disasm.o objects. Add a recipe for the
> > bootstrap disasm.o
> >
> > Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
> 
> Did this commit break something specifically?

Yes, cross-building bpftool doesn't work anymore, because the bootstrap
bpftool is linked using objects from different architectures:

$ make O=/tmp/bpftool ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/bpf/bpftool/ V=1

  aarch64-linux-gnu-gcc ... -c -MMD -o /tmp/bpftool/disasm.o /home/z/src/linux/kernel/bpf/disasm.c
  gcc ... -c -MMD -o /tmp/bpftool//bootstrap/main.o main.c
  gcc ... -o /tmp/bpftool//bootstrap/bpftool /tmp/bpftool//bootstrap/main.o ... /tmp/bpftool/disasm.o
/usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/bpftool/disasm.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status

The final bpftool is built for arm64, while the bootstrap bpftool,
executed on the host, is built for x86. The problem here is that disasm.o
linked into the bootstrap bpftool is arm64 rather than x86. With my fix we
build two disasm.o, one for the target bpftool in arm64, and one for the
bootstrap bpftool in x86.

> > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > ---
> >  tools/bpf/bpftool/Makefile | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> > index d16d289ade7a..d73232be1e99 100644
> > --- a/tools/bpf/bpftool/Makefile
> > +++ b/tools/bpf/bpftool/Makefile
> > @@ -136,7 +136,7 @@ endif
> >
> >  BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool
> >
> > -BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o) $(OUTPUT)disasm.o
> > +BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o disasm.o)
> >  OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
> >
> >  VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)                           \
> > @@ -180,6 +180,9 @@ endif
> >
> >  CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_WITHOUT_SKELETONS)
> >
> > +$(BOOTSTRAP_OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
> > +       $(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $<
> > +
> >  $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
> 
> maybe just do
> 
> $(BOOTSTRAP_OUTPUT)disasm.o $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c

They need two different recipes. The bootstrap disasm.o needs to be built
with $(HOSTCC) rather than $(CC) (CC=aarch64-linux-gnu-gcc and HOSTCC=gcc)

Thanks,
Jean

> ?
> 
> >         $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
> >
> > --
> > 2.31.1
> >

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

* Re: [PATCH bpf-next] tools/bpftool: Fix cross-build
  2021-06-04  7:50   ` Jean-Philippe Brucker
@ 2021-06-04 17:02     ` Andrii Nakryiko
  0 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2021-06-04 17:02 UTC (permalink / raw)
  To: Jean-Philippe Brucker
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, bpf

On Fri, Jun 4, 2021 at 12:51 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> On Thu, Jun 03, 2021 at 10:50:08AM -0700, Andrii Nakryiko wrote:
> > On Thu, Jun 3, 2021 at 10:06 AM Jean-Philippe Brucker
> > <jean-philippe@linaro.org> wrote:
> > >
> > > When the bootstrap and final bpftool have different architectures, we
> > > need to build two distinct disasm.o objects. Add a recipe for the
> > > bootstrap disasm.o
> > >
> > > Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
> >
> > Did this commit break something specifically?
>
> Yes, cross-building bpftool doesn't work anymore, because the bootstrap
> bpftool is linked using objects from different architectures:
>
> $ make O=/tmp/bpftool ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/bpf/bpftool/ V=1
>
>   aarch64-linux-gnu-gcc ... -c -MMD -o /tmp/bpftool/disasm.o /home/z/src/linux/kernel/bpf/disasm.c
>   gcc ... -c -MMD -o /tmp/bpftool//bootstrap/main.o main.c
>   gcc ... -o /tmp/bpftool//bootstrap/bpftool /tmp/bpftool//bootstrap/main.o ... /tmp/bpftool/disasm.o
> /usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
> /usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
> /usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
> /usr/bin/ld: /tmp/bpftool/disasm.o: error adding symbols: file in wrong format
> collect2: error: ld returned 1 exit status
>
> The final bpftool is built for arm64, while the bootstrap bpftool,
> executed on the host, is built for x86. The problem here is that disasm.o
> linked into the bootstrap bpftool is arm64 rather than x86. With my fix we
> build two disasm.o, one for the target bpftool in arm64, and one for the
> bootstrap bpftool in x86.

Oh, ok, that commit added disasm.o into bootstrap version of bpftool, thanks.

>
> > > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > > ---
> > >  tools/bpf/bpftool/Makefile | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> > > index d16d289ade7a..d73232be1e99 100644
> > > --- a/tools/bpf/bpftool/Makefile
> > > +++ b/tools/bpf/bpftool/Makefile
> > > @@ -136,7 +136,7 @@ endif
> > >
> > >  BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool
> > >
> > > -BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o) $(OUTPUT)disasm.o
> > > +BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o xlated_dumper.o btf_dumper.o disasm.o)
> > >  OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
> > >
> > >  VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux)                           \
> > > @@ -180,6 +180,9 @@ endif
> > >
> > >  CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_WITHOUT_SKELETONS)
> > >
> > > +$(BOOTSTRAP_OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
> > > +       $(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $<
> > > +
> > >  $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
> >
> > maybe just do
> >
> > $(BOOTSTRAP_OUTPUT)disasm.o $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
>
> They need two different recipes. The bootstrap disasm.o needs to be built
> with $(HOSTCC) rather than $(CC) (CC=aarch64-linux-gnu-gcc and HOSTCC=gcc)
>

My bad, missed HOSTCC vs CC in the rule. At a first glance they
appeared to be identical.

Your patch makes sense:

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

> Thanks,
> Jean
>
> > ?
> >
> > >         $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
> > >
> > > --
> > > 2.31.1
> > >

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

end of thread, other threads:[~2021-06-04 17:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 17:05 [PATCH bpf-next] tools/bpftool: Fix cross-build Jean-Philippe Brucker
2021-06-03 17:50 ` Andrii Nakryiko
2021-06-04  7:50   ` Jean-Philippe Brucker
2021-06-04 17:02     ` Andrii Nakryiko

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.