用clang编译Linux内核
安装clang
For convenience there is an automatic installation script available that installs LLVM for you.
To install the latest stable version:
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
To install a specific version of LLVM:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh <version number>
To install all apt.llvm.org packages at once:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh <version number> all
# or
sudo ./llvm.sh all
比如安装14:
sudo ./llvm.sh 14 all
安装完毕后,可以使用update-alternatives配置一下:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-10 50 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-10 --slave /usr/bin/clang-cpp clang-cpp /usr/bin/clang-cpp-10
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 100 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-14 --slave /usr/bin/clang-cpp clang-cpp /usr/bin/clang-cpp-14
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 200 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-17 --slave /usr/bin/clang-cpp clang-cpp /usr/bin/clang-cpp-17
编译内核
比如按照前面的步骤按照了clang,版本是17,那么可以使用下面的命令编译:
make LLVM=-17
本文来自博客园,作者:dolinux,未经同意,禁止转载