English 中文(简体)
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?

最佳回答

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.

问题回答

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

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!





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签