6

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?

4
  • My first question would be .. "Why is gcc not an option?" I'm not saying that you should not be trying to do what you are doing, in fact its great to see curiosity being indulged. But you are diving into a pool of sharks armed with lasers, so most of us might want to know why.
    – user50049
    Feb 26, 2010 at 4:36
  • 1
    @Tim Post, I want to learn, which problems are there in compiling linux kernel with non-gcc compilers. I work with one experimental compiler and I must to improve its support of gnu extensions, needed to compile linux kernel. Patches from intel (linuxdna) are very interesting for me.
    – osgx
    Feb 26, 2010 at 10:49
  • 1
    the popularity of gcc creature comforts, no matter how much Linus spouts off about gcc developers, is the primary problem for you. I have also up-voted your comment response. Look at simple things like ABS() , and the fact that the kernel has implemented its own version while escaping being bitten by obvious bugs that took years to come to popular light. Linux is not in love with gcc, nor the reverse. They just happen to work well together. Good luck on this :)
    – user50049
    Feb 26, 2010 at 13:35

3 Answers 3

3

An outdatet information: you need to patch the kernel in order to compile using the Intel CC Download Linux kernel patch for Intel® Compiler

See also Is it possible to compile Linux kernel with something other than gcc for further links and information

On of the most recent sources :http://forums.fedoraforum.org/showthread.php?p=1328718

3
  • The 689327 question is a bit outdated too (almost a year). Is there some new information or even a list of non-gcc comiplers for kernel?
    – osgx
    Feb 25, 2010 at 14:09
  • And I want to know any compiler other than gcc, icc, tinycc, which are capable of kernel building.
    – osgx
    Feb 25, 2010 at 14:12
  • llvm with clang is capable of building a linux kernel since this season
    – osgx
    Nov 9, 2010 at 2:47
2

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.

0

In short, you cannot, because the kernel code was written to take advantage of the gcc's compiler semantics...and between the kernel and the compiled code, the relationship is a very strong one, i.e. must be compiled with gcc...Since gcc uses 'ELF' (Embedded Linking Format) object files, the kernel must be built using the object code format. Unless you can hack it up to work with another compiler - it may well compile but may not work, as the compilers under Windows produces PE code, there could be unexpected results, meaning the kernel may not boot at all!

5
  • the are a lot of os and compilers besides windows pe. There are elf compilers in many unixes, there are also a lot of commercial compilers for linux (especailly for embedded platforms). Many compilers work with ELF, and SOME of them support a part of gcc extensions.
    – osgx
    Feb 25, 2010 at 13:44
  • I named 2 compilers, which really was able to compile the kernel at some point in past - Intel CC and Tiny CC. I want to hear here the current state of linux kernel compiling support. E.g. Can "Sun Pro compiler" build the kernel?
    – osgx
    Feb 25, 2010 at 13:47
  • There are many compilers that can produce ELF object code; this is just incorrect. This is not why GCC is required. Feb 25, 2010 at 16:18
  • @Eric: fair enough - your comment is duly noted, the crucial point is that linux was built using gnu toolchain from day 1 ever since...
    – t0mm13b
    Feb 25, 2010 at 16:26
  • tommy, almost entire linux 2.6 branch can be build now with Intel CC. For current kernels the patch for such building is smaller than 100 lines. Also, LLVM tries to build kernel, and patch for it is rather small. Gcc is not the best compiler, even it is not a good compiler (sometimes).
    – osgx
    Feb 26, 2010 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.