The Linux kernel on dragon wings – Compiling the Kernel with LLVM/clang – Jan-Simon Möller

LLVM is a libraries for building tools for manipulating code. It includes a compiler, clang. clang is faster than gcc (note that clang still uses GNU binutils, so linking doesn’t change). Code generation is roughly as good as gcc.

First step in supporting the kernel is that the static analysis can run on the kernel source code. This currently works (after some fixes to the checker). There are still some false positives (things that don’t apply to the kernel), e.g. because of C library.

LLVMLinux project tries to compile the kernel with clang, and fix (and upstream) issues either on the kernel or on the clang side. On the kernel side, it’s usually things that are wrong that just happen to work with gcc – LLVM is much more strict about things.

Remaining issues:

  • Variable-length arrays in structures: a gcc extension that is evil so clang will not support it. It is used in the crypto part of the kernel, which is particularly bad because it is copied over into all kinds of other subsystems and drivers.
  • Weak aliases and section attributes. Weak aliases are used for the module init etc. functions. gcc inherits all the section attributes, while clang doesn’t, so something needs to be changed.
  • Inline assembly: clang’s integrated assembler was broken for a while.

Currently no patches for LLVM, only kernel patches are outstanding. has the build environment that patches the kernel and builds it with clang.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s