bpftool icon indicating copy to clipboard operation
bpftool copied to clipboard

Skeletons: Support cross-compiling towards architectures with different endianness

Open qmonnet opened this issue 2 years ago • 1 comments

TL;DR: When cross-compiling, host little-endian bootstrap bpftool cannot open a big-endian ELF to generate a skeleton from it and build target big-endian bpftool.

Long version: Currently, bpftool's Makefile compiles the skeleton-related programs (skeletons/*.bpf.c) without paying attention to the target architecture. When cross-compiling, say on a host with LE for a target with BE, this leads to runtime failure on "bpftool prog show", because bpftool cannot load the LE bytecode on the BE target machine. This is Christophe's output here.

So the first fix is to make the Makefile aware of the target endianness somehow, and to build this ELF with target endianness. But this is not enough, because when (host) boostrap bpftool opens the ELF to generate the skeleton from it before building the final (target) bpftool binary, then bpf_object__check_endianness() in libbpf refuses to open the ELF if endianness is not the same as on the host as seen here.

The way I see it, we'd need to make sure libbpf can work with ELFs of a different endianness -- assuming that's doable -- and to pass it an option to tell whether LE or BE is expected for a given ELF. Which in turn would require bootstrap bpftool to be aware of the target endianness.

https://lore.kernel.org/bpf/[email protected]/

qmonnet avatar Mar 06 '23 16:03 qmonnet

Cc @chantra, just FYI - this is the issue that we discussed earlier today.

qmonnet avatar Nov 15 '23 03:11 qmonnet

https://lore.kernel.org/bpf/[email protected]/t/#u

qmonnet avatar Aug 22 '24 13:08 qmonnet

That patch series was merged with my latest revision. Hopefully the years of cross-endian trauma can now begin to heal... 🤕

Looking forward to the next libbpf 1.5.0 and bpftool 7.5.0 releases! 🙌

guidosarducci avatar Oct 14 '24 07:10 guidosarducci