zunzuncito

My main desktop PC tracks the latest LTS release of the Linux kernel which very recently switched to the 5.15 line. Along with neat new features like the NTFS3 driver it also includes experimental support for Link Time Optimization through LLVM’s clang compiler.

I’m not really one to shy away from weird experiments, so I decided to run a full LTO kernel for a while. If you have a recent version of clang and the lld linker, building one is as easy as toggling CONFIG_LTO_CLANG_FULL and exporting the right flags to make:

make CC=clang LLVM=1 menuconfig
	# CONFIG_LTO_CLANG_FULL=y
make CC=clang LLVM=1

Subsequent steps are the same as with a normal build:

sudo make install
sudo make modules_install

Keep in mind, however, that any out-of-tree modules such as ZFS must also be built with clang. Here I ran into this bug which should soon be fixed upstream. For now I backported that fix locally to ZFS 2.1.2 and am building it like so:

sudo CC=clang LLVM=1 emerge zfs-kmod

Build times and memory usage when building are increased dramatically with full LTO. Optimizing vmlinux.o alone allocates about 3 to 4 GiB of memory. If you rely a lot on incremental builds, thin LTO might be the better option here.