Self-build linux kernel with clang

Self-build the linux kernel with clang. The method is written before It is almost the same as building with gcc. clang uses the one that was installed in the previous post.

environment

Preparation

Keep it in your PATH so that you can use the clang command.

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

Get the source, deploy and patch it.

% 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

Build

Get the .config template and make oldconfig.

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

Now, run menuconfig and then build. Uncheck "Kernel hacking-> Compile-time checks and compiler options-> Generate BTF type info".

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

Installation

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

bonus

After rebooting and booting with the new kernel, you will see the following wording in /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

Recommended Posts

Self-build linux kernel with clang
Get the latest Linux kernel version with Arch Linux
About Linux kernel parameters
Kernel Method with Python
Linux (Lubuntu) with OneMix3S
Check Linux kernel version
Linux kernel release 5.x (3/4)
Linux kernel build time
linux with termux app
Linux kernel release 5.x (4/4)
Linux kernel release 5.x (1/4)
Kernel regression with Numpy only
Linux Kernel Build for DE10nano
Play around with Linux partitions
What is the Linux kernel?
Deep Kernel Learning with Pyro
Linux fastest learning with AWS
Use WDC-433SU2M2 with Manjaro Linux
[LINUX kernel rebuild] Version upgrade (4.18.0 → 5.8.8)
Prepare pipenv environment with amazon Linux 2
Linux kernel memory model related documentation
Linux kernel, its 29-year history report
[Linux] OS recovery with restore command
Try the Linux kernel lockdown mechanism
[Linux] [kernel module] Create kthread in kernel module
Play around with Linux partitions ~ Continued ~
linux (kernel) source analysis: system call call
Using Kali Linux Gui with WSL2
Use a custom kernel with WSL2
Operate Linux Network Namespace with Go