title: Linux BTF: bpftool: Failed to get EHDR from /sys/kernel/btf/vmlinux
body: <p>I am trying to start with BPF CO:RE Development.
  Using Ubuntu 20.04 LTS in a VM, I needed to recompile the kernel and install pahole (from apt install dwarves) so that BTF is enabled (I set CONFIG_DEBUG_FS=y and CONFIG_DEBUG_INFO_BTF=y).</p>
  <p>So my setup is:</p>
  <ul>
  <li>Ubuntu 20.04</li>
  <li>Kernel 5.4.0-90-generic</li>
  <li>bpftool --version: /usr/lib/linux-tools/5.4.0-90-generic/bpftool v5.4.148</li>
  </ul>
  <p>/sys/kernel/btf/vmlinux exists and can be read out with cat.</p>
  <p>But bpftool shows the following error:</p>
  <pre><code>$ sudo bpftool btf dump file /sys/kernel/btf/vmlinux format c
  
  libbpf: failed to get EHDR from /sys/kernel/btf/vmlinux
  Error: failed to load BTF from /sys/kernel/btf/vmlinux: Unknown error -4001
  </code></pre>
  <p>From <a href="https://github.com/libbpf/libbpf/blob/master/src/libbpf.h" rel="nofollow noreferrer">https://github.com/libbpf/libbpf/blob/master/src/libbpf.h</a>
  it looks like it is <em>LIBBPF_ERRNO__FORMAT, /* BPF object format invalid */</em>
  but I can not find out what's wrong.</p>
  <p>Does anybody know where the mistake might be?</p>
  <p>Thanks in advance!</p>
  <p>EDIT: Added bpftool version</p>