Building the Linux Kernel with LLVM on Oracle Linux 8

January 30, 2024 | 2 minute read
Text Size 100%:

LLVM is commonly used to build the Linux kernel and other operating systems instead of using GCC. Research papers were authored on this subject a number of years ago, which are worth a read:

They utilise LLVM for building the Linux kernel or other operating systems. LLVM is also a prerequisite to use Rust in the Linux kernel.

In this article, we demonstrate the procedure to build the linux kernel with LLVM on an OCI (Oracle Cloud Infrastructure) Oracle Linux 8 instance.

Step 1. Create the instance

In this article, our Oracle Linux 8 instance is an OCI VM.Standard2.16, with 16 OCPUs (32 CPUs) and paravirtualized networking.

Step 2. Setup the environment

Please install the required packages for LLVM.

$ sudo yum install clang lld llvm

Step 3. Download source code

We use linux-6.6 in this article.

$ wget

Step 4. Build and Install

Apply some additional config options and run 32 jobs in parallel during the build (as indicated by -j32). If for instance you had 16 CPUs available, you could specify -j16. We need LLVM=1 to build the linux kernel.

$ tar xvf linux-6.6.tar.xz
$ cd linux-6.6/

$ make LLVM=1 defconfig
$ scripts/config --file ".config" -e CONFIG_X86_X2APIC \
$ make LLVM=1 olddefconfig

$ make LLVM=1 -j32 > /dev/null
$ sudo make LLVM=1 modules_install
$ sudo make LLVM=1 install

Step 5. Configure and Reboot

Increase the loglevel to 7 by editing /etc/default/grub, and re-generate grub. This helps diagnose if any hang/panic events occurred during kernel boot.

You may need sudo su to switch to the root user.

$ cat /etc/default/grub
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 console=tty0 console=ttyS0,115200 rd.luks=0 rd.iscsi.param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 nvme_core.shutdown_timeout=10 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 libiscsi.debug_libiscsi_eh=1 loglevel=7 ip=dhcp,dhcp6 crash_kexec_post_notifiers"

root# grub2-mkconfig > /boot/efi/EFI/redhat/grub.cfg

Set the default boot kernel in grub to linux-6.6.

root# grubby --set-default /boot/vmlinuz-6.6.0
The default is /boot/loader/entries/c568d3603873424f80f6ef62af85b224-6.6.0.conf with index 3 and kernel /boot/vmlinuz-6.6.0

Reboot and check the kernel is now at 6.6:

$ uname -r

In addition, the compiler information in dmesg is for clang.

$ dmesg | grep clang
[    0.000000] Linux version 6.6.0 (opc@test-kernel) (clang version 16.0.6 (Red Hat 16.0.6-2.0.1.module+el8.9.0+90022+019b57b8), LLD 16.0.6) #1 SMP PREEMPT_DYNAMIC Wed Dec 27 02:15:00 GMT 2023


We have demonstrated the procedure to build the Linux kernel 6.6 on OCI and Oracle Linux 8 with LLVM. Developers may use OCI and Oracle Linux 8 for LLVM related development/research projects.

Dongli Zhang

Previous Post

Using systemtap For Tracing libvirt

Shaleen Bathla | 13 min read

Next Post

Oracle Cloud Native Environment 1.8 introduces support for Arm and Kubernetes 1.28

Simon Coter | 3 min read