summaryrefslogtreecommitdiffstatshomepage
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/16/index.md42
1 files changed, 42 insertions, 0 deletions
diff --git a/content/16/index.md b/content/16/index.md
new file mode 100644
index 0000000..2cb12b3
--- /dev/null
+++ b/content/16/index.md
@@ -0,0 +1,42 @@
++++
+date = 2022-02-05T19:29:44+01:00
+title = "Building the Linux kernel with clang and full LTO"
+
+[taxonomies]
+tags = ["experiments"]
++++
+
+My main desktop PC tracks the latest LTS [release](https://kernel.org/) of the
+Linux kernel which very recently switched to the 5.15 line. Along with neat new
+features like the
+[NTSF3 driver](https://lore.kernel.org/all/aa4aa155-b9b2-9099-b7a2-349d8d9d8fbd@paragon-software.com/)
+it also includes experimental support for
+[Link Time Optimization](https://llvm.org/docs/LinkTimeOptimization.html)
+through LLVM's
+[`clang` compiler](https://clang.llvm.org/).
+
+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](https://lld.llvm.org/), 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](https://bugs.gentoo.org/show_bug.cgi?id=814194) which should soon be
+[fixed upstream](https://github.com/openzfs/zfs/pull/13046). 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.