bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* selftests/bpf - Error: failed to open BPF object file: Endian mismatch
@ 2021-04-02  7:48 Christophe Leroy
  2021-04-02  8:02 ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Leroy @ 2021-04-02  7:48 UTC (permalink / raw)
  To: bpf, iii

Hello,

I'm having hard time cross-building bpf selftests on an x86 for a powerpc target.

[root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool gen skeleton 
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o > 
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h
libbpf: elf: endianness mismatch in atomic_bounds.
Error: failed to open BPF object file: Endian mismatch

[root@PC-server-ldb bpf]# file atomic_bounds.o
atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped

Seems like the just-built host bpftool doesn't take into account target's endianness.

I see the patch https://github.com/torvalds/linux/commit/313e7f6f ("selftest/bpf: Use -m{little, 
big}-endian for clang") in bpf selftest to enable cross-compilation, but it seems it is not enough.

What should I do to get bpftool work with the target's endianness ?

Thanks
Christophe

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

* Re: selftests/bpf - Error: failed to open BPF object file: Endian mismatch
  2021-04-02  7:48 selftests/bpf - Error: failed to open BPF object file: Endian mismatch Christophe Leroy
@ 2021-04-02  8:02 ` Christophe Leroy
  2021-04-03 16:01   ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Leroy @ 2021-04-02  8:02 UTC (permalink / raw)
  To: bpf, iii, Jean-Philippe Brucker



Le 02/04/2021 à 09:48, Christophe Leroy a écrit :
> Hello,
> 
> I'm having hard time cross-building bpf selftests on an x86 for a powerpc target.
> 
> [root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1
> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool gen skeleton 
> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o > 
> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h
> libbpf: elf: endianness mismatch in atomic_bounds.
> Error: failed to open BPF object file: Endian mismatch
> 
> [root@PC-server-ldb bpf]# file atomic_bounds.o
> atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped
> 
> Seems like the just-built host bpftool doesn't take into account target's endianness.
> 
> I see the patch https://github.com/torvalds/linux/commit/313e7f6f ("selftest/bpf: Use -m{little, 
> big}-endian for clang") in bpf selftest to enable cross-compilation, but it seems it is not enough.
> 
> What should I do to get bpftool work with the target's endianness ?
> 

I also see https://github.com/torvalds/linux/commit/8859b0da ("tools/bpftool: Fix cross-build") but 
that commit doesn't seem to address endianness difference between the host and the target.

Christophe

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

* Re: selftests/bpf - Error: failed to open BPF object file: Endian mismatch
  2021-04-02  8:02 ` Christophe Leroy
@ 2021-04-03 16:01   ` Andrii Nakryiko
  0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2021-04-03 16:01 UTC (permalink / raw)
  To: Christophe Leroy; +Cc: bpf, Ilya Leoshkevich, Jean-Philippe Brucker

On Fri, Apr 2, 2021 at 1:02 AM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 02/04/2021 à 09:48, Christophe Leroy a écrit :
> > Hello,
> >
> > I'm having hard time cross-building bpf selftests on an x86 for a powerpc target.
> >
> > [root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1
> > /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool gen skeleton
> > /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o >
> > /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h
> > libbpf: elf: endianness mismatch in atomic_bounds.
> > Error: failed to open BPF object file: Endian mismatch
> >
> > [root@PC-server-ldb bpf]# file atomic_bounds.o
> > atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped
> >
> > Seems like the just-built host bpftool doesn't take into account target's endianness.
> >
> > I see the patch https://github.com/torvalds/linux/commit/313e7f6f ("selftest/bpf: Use -m{little,
> > big}-endian for clang") in bpf selftest to enable cross-compilation, but it seems it is not enough.
> >
> > What should I do to get bpftool work with the target's endianness ?
> >

bpftool is using bpf_object__open() from libbpf to discover all
information (maps, progs, etc) from the given BPF object file. This is
needed to generate BPF skeleton.

But libbpf itself doesn't support opening BPF object files with
non-native endianness. We solved that problem for BTF specifically to
allow cross-compiling kernel (to let pahole -J generate BTF for an
endianness different from the host endianness), but libbpf was never
taught to work with non-native endianness of loaded ELF file.

And solving this for ELF processing in libbpf is a messier problem
than for BTF itself, so I don't know if I'd like to support such use
case at all.

>
> I also see https://github.com/torvalds/linux/commit/8859b0da ("tools/bpftool: Fix cross-build") but
> that commit doesn't seem to address endianness difference between the host and the target.
>
> Christophe

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02  7:48 selftests/bpf - Error: failed to open BPF object file: Endian mismatch Christophe Leroy
2021-04-02  8:02 ` Christophe Leroy
2021-04-03 16:01   ` Andrii Nakryiko

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).