linuxlinux-kernelclangllvm

compiling linux kernel with non-gcc


Linux kernel is written for compiling with gcc and uses a lot of small and ugly gcc-hacks. Which compilers can compile linux kernel except gcc?

The one, which can, is the Intel Compiler. What minimal version of it is needed for kernel compiling?

There also was a Tiny C compiler, but it was able to compile only reduced and specially edited version of the kernel.

Is there other compilers capable of building kernel?


Solution

  • There is ongoing process of committing LLVMLinux patches into vanilla kernel (2013-2014).

    The LLVMLinux is project by The Linux Foundation: http://llvm.linuxfoundation.org/ to enable vanilla kernel to be built with LLVM. Lot of patches are prepared by Behan Webster, who is LLVMLinux project lead.

    There is LWN article about the project from May 2013 https://lwn.net/Articles/549203/ "LFCS: The LLVMLinux project"

    Current status of LLVMLinux project is tracked at page http://llvm.linuxfoundation.org/index.php/Bugs#Linux_Kernel_Issues

    Things (basically gcc-isms) already eliminated from kernel: * Expicit Registers Variables (non-C99) * VLAIS (non C99-compliant undocumented GCC feature "Variable length arrays in structs") like struct S { int array[N];} or even struct S { int array[N]; int array_usb_gadget[M]; } where N and M are non-constant function argument * Nested Functions (Ada feature ported into C by GCC/Gnat developers; not allowed in C99) * Some gcc/gas magic like special segments, or macro

    Things to be done: * Usage of __builtin_constant_p builtin to implement scary magic like BUILD_BUG_ON(!__builtin_constant_p(offset));

    The good news about LLVMLinux are that after its patches kernel not only becomes buildable with LLVM+clang, but also easier to build by other non-GCC compilers, because the project kills much not C99 code like VLAIS, created by usb gadget author, by netfilter hackers, and by crypto subsystem hackers; also nested functions are killed.