bpftool BDEPENDs on clang for CO-RE (skeleton) support; it would be nice to have bpf-toolchain as alternative. Reproducible: Always
The CO-RE support is feature-checked here: https://github.com/libbpf/bpftool/blob/main/src/Makefile.feature#L28 Running this should yield: printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo = {};' | clang -g -target bpf -S -o - -x c - | grep BTF_KIND_VAR .long 9 # BTF_KIND_VAR(id = 3) however replacing clang with bpf-unknown-none-gcc and removing the (implicit) "-target bpf" yields nothing (also no error). It seems the comments are missing. printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo = {};' | clang -g -target bpf -S -o - -x c - | grep BTF .section .BTF,"",@progbits .long 1 # BTF_KIND_STRUCT(id = 1) .long 5 # BTF_KIND_INT(id = 2) .long 9 # BTF_KIND_VAR(id = 3) .long 13 # BTF_KIND_DATASEC(id = 4) printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo = {};' | bpf-unknown-none-gcc -g -S -o - -x c - | grep BTF .section ".BTF","",@progbits .section ".BTF.ext","",@progbits
Created attachment 908182 [details] Output by clang
Created attachment 908183 [details] Output by gcc
Diffing the output shows that the relevant elements are there: .long 16777248 # 0x1000020 .long 9 # BTF_KIND_VAR(id = 3) .long 234881024 # 0xe000000 vs. .4byte 0x1000020 .4byte 0x9 .4byte 0xe000000 it's just that the comments are missing, which is what the feature detection checks for.
Tried every debug/output option I could find (including -gbtf), nothing makes a difference. Will engage the bpf list.
https://lore.kernel.org/bpf/8665818f-8a32-3796-1efc-1a9e5d036f18@applied-asynchrony.com/
Via the mentioned bpf mailing list thread Jose E. Marchesi from Oracle gave me the necessary hint that passing -dA will generate annotated assembler output, which makes the feature detection work: printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo = {};' | bpf-unknown-none-gcc -dA -g -S -o - -x c - | grep BTF_KIND_VAR .4byte 0x9 # TYPE 3 BTF_KIND_VAR 'foo' .4byte 0x3 # bts_type: (BTF_KIND_VAR 'foo') After some further Makefile surgery and ignoring some warnings I now get a binary that has CO-RE (skeleton) support: bpftool v7.5.0 using libbpf v1.5 features: libbfd, skeletons \o/ Needs a USE flag and some cleanups, but this is looking promising.
For the meantime, I suggest p.use.forcing USE=clang on the relevant non-bpf-toolchain kw'd arches, so you can proceed.
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=43976a379d0df9a41910594f7aa3803066f19439 commit 43976a379d0df9a41910594f7aa3803066f19439 Author: Holger Hoffstätte <holger@applied-asynchrony.com> AuthorDate: 2024-11-11 16:47:50 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2024-11-11 22:24:12 +0000 dev-util/bpftool: add 7.5.0 with USE=clang to select BPF toolchain We still default to using clang for now, but using the GCC-based sys-devel/bpf-toolchain as alternative should work. Closes: https://bugs.gentoo.org/943113 Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com> Signed-off-by: Sam James <sam@gentoo.org> dev-util/bpftool/Manifest | 1 + dev-util/bpftool/bpftool-7.5.0.ebuild | 137 ++++++++++++++++++++++++++++++++++ dev-util/bpftool/bpftool-9999.ebuild | 24 +++++- dev-util/bpftool/metadata.xml | 1 + 4 files changed, 160 insertions(+), 3 deletions(-)