Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED()

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

Fixes: ee26dade0e3b ("libbpf: Add support for relocatable bitfields")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211026010831.748682-2-iii@linux.ibm.com

authored by

Ilya Leoshkevich and committed by
Andrii Nakryiko
45f2bebc 124c6003

+1 -1
+1 -1
tools/lib/bpf/bpf_core_read.h
··· 40 40 #define __CORE_RELO(src, field, info) \ 41 41 __builtin_preserve_field_info((src)->field, BPF_FIELD_##info) 42 42 43 - #if __BYTE_ORDER == __LITTLE_ENDIAN 43 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 44 44 #define __CORE_BITFIELD_PROBE_READ(dst, src, fld) \ 45 45 bpf_probe_read_kernel( \ 46 46 (void *)dst, \