Kernel 5.5.4 build fail for BPF-selftests with latest LLVM

From: Jesper Dangaard Brouer
Date: Wed Feb 19 2020 - 07:30:33 EST


Hi Andrii,

Downloaded tarball for kernel release 5.5.4, and I cannot compile
tools/testing/selftests/bpf/ with latest LLVM release version 9.

Looking closer at the build error messages, I can see that this is
caused by using LLVM features that (I assume) will be avail in release
10. I find it very strange that we can release a kernel that have build
dependencies on a unreleased version of LLVM.

I'm willing to help out, such that we can do either version or feature
detection, to either skip compiling specific test programs or at least
give users a proper warning of they are using a too "old" LLVM version.


I love the new LLVM BTF features, but we cannot break users/CI-systems
that wants to run the BPF-selftests.

--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer

http://releases.llvm.org/download.html

Compile error message:
unknown builtin '__builtin_preserve_field_info'

Full:

make -C /home/jbrouer/build/linux-5.5.4/tools/lib/bpf OUTPUT=/home/jbrouer/build/linux-5.5.4/tools/testing/selftests/bpf/
make[1]: Entering directory '/home/jbrouer/build/linux-5.5.4/tools/lib/bpf'
make[1]: Leaving directory '/home/jbrouer/build/linux-5.5.4/tools/lib/bpf'
(clang -I. -I/home/jbrouer/build/linux-5.5.4/tools/testing/selftests/bpf -g -D__TARGET_ARCH_x86 -mlittle-endian -I. -I./include/uapi -I/home/jbrouer/build/linux-5.5.4/tools/include/uapi -I/home/jbrouer/build/linux-5.5.4/tools/lib/bpf -I/home/jbrouer/build/linux-5.5.4/tools/testing/selftests/usr/include -idirafter /usr/local/include -idirafter /usr/lib64/clang/9.0.0/include -idirafter /usr/include -Wno-compare-distinct-pointer-types -O2 -target bpf -emit-llvm -c progs/test_core_reloc_bitfields_probed.c -o - || echo "BPF obj compilation failed") | llc -mattr=dwarfris -march=bpf -mcpu=probe -mattr=+alu32 -filetype=obj -o /home/jbrouer/build/linux-5.5.4/tools/testing/selftests/bpf/test_core_reloc_bitfields_probed.o
progs/test_core_reloc_bitfields_probed.c:47:13: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->ub1 = BPF_CORE_READ_BITFIELD_PROBED(in, ub1);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
progs/test_core_reloc_bitfields_probed.c:48:13: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->ub2 = BPF_CORE_READ_BITFIELD_PROBED(in, ub2);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
progs/test_core_reloc_bitfields_probed.c:49:13: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->ub7 = BPF_CORE_READ_BITFIELD_PROBED(in, ub7);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
progs/test_core_reloc_bitfields_probed.c:50:13: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->sb4 = BPF_CORE_READ_BITFIELD_PROBED(in, sb4);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
progs/test_core_reloc_bitfields_probed.c:51:14: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->sb20 = BPF_CORE_READ_BITFIELD_PROBED(in, sb20);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
progs/test_core_reloc_bitfields_probed.c:52:13: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->u32 = BPF_CORE_READ_BITFIELD_PROBED(in, u32);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
progs/test_core_reloc_bitfields_probed.c:53:13: error: use of unknown builtin '__builtin_preserve_field_info' [-Wimplicit-function-declaration]
out->s32 = BPF_CORE_READ_BITFIELD_PROBED(in, s32);
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:52:2: note: expanded from macro 'BPF_CORE_READ_BITFIELD_PROBED'
__CORE_BITFIELD_PROBE_READ(&val, s, field); \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:28:10: note: expanded from macro '__CORE_BITFIELD_PROBE_READ'
__CORE_RELO(src, fld, BYTE_SIZE), \
^
/home/jbrouer/build/linux-5.5.4/tools/lib/bpf/bpf_core_read.h:23:2: note: expanded from macro '__CORE_RELO'
__builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
^
7 errors generated.
llc: error: llc: <stdin>:1:1: error: expected top-level entity
BPF obj compilation failed
^
make: *** [Makefile:281: /home/jbrouer/build/linux-5.5.4/tools/testing/selftests/bpf/test_core_reloc_bitfields_probed.o] Error 1