libbpf-bootstrap: [Android] Failed to find valid kernel BTF

Device: Android 13 AOSP for x86_64, all necessary flags are enabled during kernel build, including CONFIG_DEBUG_INFO_BTF

bpftool version: not sure, provided by xmake-repo libbpf: 432a4348579e0049af45c6712a2c1430f607b086

> file /sys/kernel/btf/vmlinux
/sys/kernel/btf/vmlinux : data

Steps:

git clone --recurse-submodules https://github.com/libbpf/libbpf-bootstrap
...
xmake f -p android -a x86_64 -c --require-bpftool=y
xmake -y

all compiles successfully.

minimal works on the devices. bootstrap fails:

libbpf: failed to find valid kernel BTF
libbpf: Error loading vmlinux BTF: -3
libbpf: failed to load object 'bootstrap_bpf'
libbpf: failed to load BPF skeleton 'bootstrap_bpf': -3
Failed to load and verify BPF skeleton

My guess is that the problem is related to maps since minimal doesn’t contain any and it works.

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I also encountered this problem when I updated the libbpfv1.0.0 used on my Android device to the latest version a few days ago. I found that the permission check was modified in this commit: https://github.com/libbpf/libbpf/commit/9da0dcb62149ab0a6c5711813d77a844ec6f393b However, the “AT_EACCESS” flag is not supported on Android devices. Relevant instructions can be found in the AOSP source code: https://android.googlesource.com/platform/bionic/+/refs/heads/android13-release/libc/bionic/faccessat.cpp#50 Therefore, if you want to use BTF on Android devices, you can try to modify the libbpf source code and change the “AT_EACCESS” flag to 0, or you can use the pre-commit version of libbpf that modified the permission check.

If you have /sys/kernel/btf/vmlinux and libbpf still complains about “failed to find valid kernel BTF”, then one of two things: either your application doesn’t have permissions to open that file, or it has BTF that your version of libbpf doesn’t understand (e.g., it’s using some new BTF features that older libbpf doesn’t know how to parse). There is a slight chance that /sys/kernel/btf/vmlinux is just corrupted, you should be able to validate somewhat by dumping it using bpftool:

bpftool btf dump file /sys/kernel/btf/vmlinux

I don’t have an android environment to run and test it, you can run xmake -rvD to check the full compilation flags.

Is there a way to specify btftool version when fetching from xmake?

you need add version to https://github.com/xmake-io/xmake-repo/blob/f97b2f979f870b51ca1ef7a306fe1458625d1448/packages/l/linux-tools/xmake.lua#L13

then add version in https://github.com/libbpf/libbpf-bootstrap/blob/6aa0c77287e2c6152f679013a2cf94a2d0314f72/examples/c/xmake.lua#L46

add_requires("linux-tool 5.16.9", ...)