LoginSignup
2
1

More than 3 years have passed since last update.

clangでlinux kernelを自己ビルド

Posted at

clangでlinux kernelを自己ビルドします。やり方は以前書いたgccでビルドするのとほぼ同じです。clangは以前の投稿でインストールしたものを使います。

環境

  • OS: ubuntu 16.04LTS
  • コンパイラ: clang (9.0.0)

準備

clangコマンドが使えるようにPATHを通しておきます。

% export PATH=(somewhere)/bin:$PATH

ソースを取得し、展開、パッチ当てを行います。

% wget https://kojipkgs.fedoraproject.org//packages/kernel/5.4.16/200.fc31/src/kernel-5.4.16-200
.fc31.src.rpm
% mkdir files
% cd files
% rpm2cpio ../kernel-5.4.16-200.fc31.src.rpm |cpio  -id
% tar Jxf  linux-5.4.tar.xz
% cd linux-5.4
% xz -dc ../patch-5.4.16.xz  | patch -p1
% for i in `ls ../*patch`;do;patch -p1 < $i;done

ビルド

.configの雛形を取得し、make oldconfigします。

% cp ../kernel-x86_64-fedora.config .config
% yes "" | make CC=clang oldconfig

ここで、menuconfigを動かしてからビルドします。
「Kernel hacking -> Compile-time checks and compiler options -> Generate BTF typeinfo」のチェックを外します。

% make CC=clang menuconfig
% make -j12 CC=clang deb-pkg LOCALVERSION=-my KDEB_PKGVERSION=1

インストール

% cd ..
% su
# dpkg -i linux-image-5.4.16-my_1_amd64.deb linux-headers-5.4.16-my_1_amd64.deb

おまけ

再起動して新カーネルで起動すると、/var/log/kern.logに以下のような文言を確認できます。

Feb  1 19:08:49 localpc kernel: [    0.000000] Linux version 5.4.16-my (tekito2@my-desktop3) (clang version 9.0.0 (tags/RELEASE_900/final)) #1 SMP Sat Feb 1 18:20:36 JST 2020
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1