Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 943113 - dev-util/bpftool: support CO-RE via sys-devel/bpf-toolchain
Summary: dev-util/bpftool: support CO-RE via sys-devel/bpf-toolchain
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Holger Hoffstätte
URL:
Whiteboard:
Keywords: PullRequest
Depends on: 938169
Blocks:
  Show dependency tree
 
Reported: 2024-11-09 10:00 UTC by Holger Hoffstätte
Modified: 2024-11-11 22:25 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Output by clang (out.clang,9.20 KB, text/plain)
2024-11-09 10:14 UTC, Holger Hoffstätte
Details
Output by gcc (out.gcc,837 bytes, text/plain)
2024-11-09 10:15 UTC, Holger Hoffstätte
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Holger Hoffstätte 2024-11-09 10:00:26 UTC
bpftool BDEPENDs on clang for CO-RE (skeleton) support; it would be nice to have bpf-toolchain as alternative.


Reproducible: Always
Comment 1 Holger Hoffstätte 2024-11-09 10:09:42 UTC
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
Comment 2 Holger Hoffstätte 2024-11-09 10:14:57 UTC
Created attachment 908182 [details]
Output by clang
Comment 3 Holger Hoffstätte 2024-11-09 10:15:20 UTC
Created attachment 908183 [details]
Output by gcc
Comment 4 Holger Hoffstätte 2024-11-09 10:24:46 UTC
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.
Comment 5 Holger Hoffstätte 2024-11-09 11:16:24 UTC
Tried every debug/output option I could find (including -gbtf), nothing makes a difference. Will engage the bpf list.
Comment 7 Holger Hoffstätte 2024-11-09 19:12:40 UTC
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.
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-11-11 17:45:13 UTC
For the meantime, I suggest p.use.forcing USE=clang on the relevant non-bpf-toolchain kw'd arches, so you can proceed.
Comment 9 Larry the Git Cow gentoo-dev 2024-11-11 22:25:42 UTC
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(-)