1

I have to execute eBPF on linux kernel that don't support BTF (linux 4.X).

I have to access kernel structures in eBPF frequently.
Without vmlinux.h, I have to get memory offset of each struct element. It will cost great efforts.

Could I use vmlinux.h header file in eBPF program?

1 Answer 1

1

Could I use vmlinux.h header file in eBPF program?

Yes. vmlinux.h is essentially the translated version of the BTF that normally ships with newer kernels. You can generate BTF for kernels that don't ship with it normally using a tool called pahole. The BTFHub project also includes a load of pre-generated BTF files for most commonly used distros, you might be able to use one of these.

Once you have a BTF blob for the kernel you can generate the vmlinux.h from it using the following command:

$ bpftool btf dump file {path to file} format c > vmlinux.h

That having said, you can also use a vmlinux.h based on a kernel that ships it and use CO:RE to recalculate the correct offset. The same BTFhub blobs can also be used by loaders to substitute if a target doesn't ship with a vmlinux. This is the original purpose of the project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.