The LLVMLinux Project

I’d like to announce the LLVMLinux project. This project aims to fully build the Linux kernel using Clang/LLVM on the various architectures supported by the Linux kernel. The project consolidates the work of the lll-project, the PAX team, and Mark Charlebois’ work on the ARM kernel.

http://llvm.linuxfoundation.org

The hope is that this project will help reduce duplicate work, as well as concentrate, and accelerate efforts around this subject matter in order to allow Linux Kernel developers, and system integrators to have the choice of a Clang compiled Linux kernel. The goal is for this project to be a testing/proving ground for these updates and to get patches that make this possible upstream to their respective projects (Clang/LLVM and the Linux Kernel).

Currently the work is centred around the ARM, x86 and x86_64 architectures but contributions to support other architectures are welcome. Patches accepted!

The Linux Kernel has some issues with being compiled with Clang; these are issues which the LLVMLinux project is attempting to fix in the Linux Kernel code base and pushed upstream:

  • The use of variable length arrays in structs (VLAIS)
  • Kbuild support for Clang (currently Kbuild is gcc specific)
  • Use of explicit register variables
  • Extra __refdata annotations needed to overcome segment reference errors
  • EXPORT_SYMBOL of inline functions

However, there are some things in Clang/LLVM which also need to be addressed in order to make a Clang compiled Linux Kernel possible. Amongst other things these are:

  • The Linux kernel currently uses compiler flags which are unsupported in Clang:
  • -fdelete-null-pointer-checks
  • –fno-inline-functions-called-once
  • –Wno-unused-but-set-variable vs –Wno-unused-variable (GCC 4.6)
  • –mabi=aapcs-linux (Bug 11326)
  • Clang also reports errors for redefinitions of posix functions used in Linux kernel. It should be possible to suppress this.

The LLVMLinux project is certainly following and hope to contribute to issues listed in the LLVM Meta bug 4068.

But let me finish by thanking you all for the LLVM project and Clang toolchain. They are truly an awesome accomplishment.

Behan

Hi Behan,

However, there are some things in Clang/LLVM which also need to be addressed in
order to make a Clang compiled Linux Kernel possible. Amongst other things these
are:

* The Linux kernel currently uses compiler flags which are unsupported in Clang:
   * -fdelete-null-pointer-checks

I think this may be easy to fix by exploiting the fact that LLVM only thinks
that dereferencing a null pointer *in the default address space* is wrong.
LLVM considers reading and writing to null pointers in non-default address
spaces to be perfectly fine. Thus when clang sees -fdelete-null-pointer-checks
it could put every pointer in some special address space and Bob's your uncle.

Best wishes, Duncan.

Hi all!

For LLVMLinux on i586/x86_64 the current status can be summarized by:

Thanks to the excellent work on patches by the PaX team and Bryce Lelbach
(lll-project) and their contributions to the LLVMLinux project we can
successfully build a v3.3 kernel which boots to console and desktop on x86.

Their patches are included in the LLVMLinux project repository.

The following issues still need resolution (of course patches welcome :wink: ):

* The x86 portion of LLVMLinux is currently based upon kernel v3.3 - the
  patches need to be split and rebased to HEAD so that the buildbot is able to
  detect breakages early and also improve contributions to upstream projects.

* Module unloading fails/impossible. (Check required. Also on ARM)

  - Module loading is fine (even binary blobs!).

Issues specific to x86 related to LLVM/Clang are:

* Macro support (WIP in upstream LLVM/Clang -
                 PaX-Team/Andy Zhang/Rafael Espindola)

* code16gcc support - low-level bootup code
  (would need own backend, 16bit code currently unsupported)

* Lateron: take care of optimizations (e.g. missing -ffixed-REG,
  -fcall-used-REG, -fcall-saved-REG ; we require
  CONFIG_ARCH_HWEIGHT_CFLAGS to be off atm)

To get an "ordinary" system working with network, firewall, drivers we need
these issues resolved.

Contributions appreciated and patches welcome !

Best regards,
Jan-Simon Möller