Linux 4.18 eBPF编译环境搭建

Posted:   December 25, 2021

Edited:   December 25, 2021

Status:   Completed

Tags :   eBPF

Categories :   eBPF

Were equations, pictures or diagrams not properly rendered, please refresh the page. If the problem persists, you can contact me.

背景:

本文主要解决centos7 4.18内核系统eBPF编译环境搭建

流程:

1.内核升级

关于如何在centos7安装4.18内核,这个网上有大把教程,不再赘述

2.编译套件升级

centos7 默认clang llvm版本较低,不识别-target=bpf命令,因此需要对clang进行升级

GCC升级
编译llvm,需要gcc至少为 5.1版本,centos默认安装的是 gcc 4.8.5。
yum install centos-release-scl 
yum install devtoolset-7 
当前登陆session生效 
scl enable devtoolset-7 
bash source /opt/rh/devtoolset-7/enable
echo "source /opt/rh/devtoolset-7/enable" >> ~/.bash_profile 
source /opt/rh/devtoolset-7/enable
安装cmake
https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0.tar.gz
tar -zxvf cmake-3.14.0.tar.gz
cd cmake-3.14.0
./bootstrap
make
make install
安装clang9 这个步骤非常耗时 预计3+小时
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout origin/release/9.x
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" -G "Unix Makefiles" ../llvm
make
make install

3.libbpf库

安装libelf zlib yum install -y elfutils-libelf-devel 安装libbpf

git clone https://github.com/libbpf/libbpf
cd libbpf/src
make
make install

至此,环境搭建完成,愉快的Coding

Comments


Be the first one to comment on this page!
You can use extended GitHub flavored markdown in your comment. Commenting FAQs & Guidelines