On 10/25/21 3:12 PM, Ilya Leoshkevich wrote:
__BYTE_ORDER is supposed to be defined by a libc, and __BYTE_ORDER__ - by a compiler. bpf_core_read.h checks __BYTE_ORDER == __LITTLE_ENDIAN, which is true if neither are defined, leading to incorrect behavior on big-endian hosts if libc headers are not included, which is often the case. Instead of changing just this particular location, replace all occurrences of __BYTE_ORDER with __BYTE_ORDER__ in libbpf code for consistency.
ACK, that is definitely broken as is - we had similar issue back then with the bpf_{htons,ntohs}() helpers, details: 78a5a93c1eeb ("bpf, tests: fix endianness selection"). The bpf_core_read.h change I would split out as a separate commit along with a proper Fixes tag so it could potentially be cherry-picked easier (since the remainder in here is a cleanup for consistency and not used out of the BPF prog where this issue exists).
Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx> --- tools/lib/bpf/bpf_core_read.h | 2 +- tools/lib/bpf/btf.c | 4 ++-- tools/lib/bpf/btf_dump.c | 8 ++++---- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/linker.c | 12 ++++++------ tools/lib/bpf/relo_core.c | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-)
Thanks, Daniel