Build linux kernel with ebpf enabled
I try to deploy my dev env and I experienced some pitfalls. I want to share this. If this can save people’s time, that will be my happiness. And this is my first blog about ebpf. This will be a good start.
Prerequisits
-
Install latest version pahole or just build it from source Make sure pahole lib in the LD_LIBARY_PATH:
`export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH` Without this set, I just faild to compile the kernel with error: `FAILED: load BTF from vmlinux: No such file or directory` -
Install llvm sets. Again it should be the latest versioin. I just referred the kernel doc. But there is an error when to compile the test cases of bpf:
"stdbool.h file not found."I found it is because the head files are not in place. Even I push the binary in the PATH. The header files should be in the place. And I figure it out install with:
$ git clone https://github.com/llvm/llvm-project.git
$ mkdir -p llvm-project/llvm/build
$ cd llvm-project/llvm/build
$ cmake .. -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DLLVM_ENABLE_PROJECTS="clang; lld" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BUILD_RUNTIME=OF
$ make -j8 && make install
Then all the biaries as well as header files will be in the right place.
Compile your own kernel with bpf enabled
Of course you need to clone linux code When to compile new kernel, you need a config file. I assume you got a relative new kernel, just copy your config file from /boot to linux repo as name .config. And you need to rename the new kernel in Makefile.
-
with “CONFIG_DEBUG_INFO_NONE=n”
This is config will disable all the debug info config which bpf requres.
-
Enable epbf config.(Pleae search keywords you will find more in linux config file.)
-
build the linux kernel then.
-
restart linux and select the proper kernel
Voila! Just enjoy your bpf world~