bpfcov icon indicating copy to clipboard operation
bpfcov copied to clipboard

failed to get EHDR from /sys/kernel/btf/vmlinux when compiling examples

Open mtcherni95 opened this issue 3 years ago • 1 comments

Hello! First of all, by having a look at README, this tool looks so cool!

I am following the instructions to compile the examples under examples/src. I generated libBPFCov.so. My bpftool version is v5.4.162. When running make I get:

make: command: Command not found
  MKDIR    vmlinux/
  VMLINUX  vmlinux/vmlinux.h
libbpf: failed to get EHDR from /sys/kernel/btf/vmlinux
Error: failed to load BTF from /sys/kernel/btf/vmlinux: Unknown error -4001
make: *** [Makefile:77: /home/ubuntu/dev/bpfcov/examples/src/.output/vmlinux/vmlinux.h] Error 95
make: *** Deleting file '/home/ubuntu/dev/bpfcov/examples/src/.output/vmlinux/vmlinux.h'

Apart from the Command not found error, looks like I cannot get EHDR from the vm "embedded" btf. My machine is: Linux 5.11.0-1025-aws #27~20.04.1-Ubuntu SMP Fri Jan 7 13:09:56 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Also, I tried to use bpftool with version 5.11.22, however it doesn't have the "skeleton" feature:

bpftool version -j
{"version":"5.11.22","features":{"libbfd":false,"skeletons":false}}

Might be that v5.4.162, does not support skeleton as well. However I do not get such an indication from Makefile. My gut feeling is that the issue is with bpftool version. However, version 5.11.22 looks like the most updated for my OS, and if this one does not work, do you know which version might support skeleton feature? Or maybe, the problem might not be related to bpftool version. Thank you!

mtcherni95 avatar Feb 07 '22 16:02 mtcherni95

Your gut feeling matches mine, too :)

The bpftool you need for compiling the examples' skeletons MUST have the skeletons feature (see link).

Can you try compiling a bpftool with skeletons feature and put it in the examples/tools directory? This way the Makefile would use it rather than symlinking your system one.

I usually compile it myself from kernel sources (see here, and the BUILD_BPF_SKELS in the bpftool Makefile).

Also when running the examples Makefile, I suggest you run it with verbosity on so you can see what's actually executing. Like so: make V=1 ....

Let me know how it goes!

leodido avatar Feb 08 '22 15:02 leodido