views:

1819

answers:

9

I wonder if someone managed to compile the Linux kernel with some other compiler than gcc. Or if someone have ever tried? Question may seem to be silly or academic, but it arose when I thought about answers to: Are C++ int operations atomic on the mips architecture

It seems that the atomicity of some operations depends not only on the cpu architecture, but also on used compiler. So, I wonder if in Linux world some compiler other than gcc even exists.

+5  A: 

Note that Mr. Torvalds will not be pleased with you asking C++ questions regarding the Linux kernel, which is resolutely C only. I've removed the tag, but left the question untouched.

anon
you are right. I mixed few things in one question :)
oo_olo_oo
haha, this makes it sounds like you are going to report him to "Mr. Torvalds"
amdfan
+7  A: 

Linux explicitly depends on some gcc extensions, so any other compiler must be compatible with the needed extensions, in that case.

This is not a "no", since it's of course not impossible for a separate compiler vendor/developer to track gcc's extensions, just a data point that might help you search.

unwind
+4  A: 

IBM's compiler was able to do it some Linux versions ago, but I'm not sure about now, nor am I sure of how well IBM optimized the kernel as instructed. All I know is, they got it to build.

As Linux is self hosting (with its own libc) and has been developed from the start with gcc (and gcc cross compilers), its sort of silly to use anything else.

I think mainly, playing nice with preprocessor macros and instructed optimizations is the biggest obstacle (not even getting into a departure from gas), as GNU has basically written the book on the above, and extended it. Beyond that, Linux tunes its optimizations to work with gcc, for instance, don't get caught using 'volatile' in the kernel without a damn good reason. Using inline and actually having the compiler agree is another challenge.

Linus is the first one to call GCC an &*#$ hole, which makes for a better compiler.

This is why we have the great GNU/Linux debate.

Tim Post
+6  A: 

There have been some efforts (and patches) to compile an early version of the 2.6 kernel with icc.

Joachim Sauer
More recently, (Feb 25, 2009) http://www.linuxjournal.com/content/linuxdna-supercharges-linux-intel-cc-compiler
Greg Rogers
Intel is really the only one attempting to get the kernel to compile with another compiler.
supercheetah
Dunno I'm pretty sure that I managed to build the kernel with icc (I can't remember if it was 2.6 or 2.4 though)
DrJokepu
+4  A: 

At some point tcc would process and run the linux kernel source. SO that would be a yes, I guess.

::Hat tip to ephemient in the comments.::

dmckee
http://bellard.org/tcc/tccboot.html "TCCBOOT is a boot loader able to compile and boot a Linux kernel directly from its *source code*." Yes, tcc was able build a runnable Linux kernel at some point.
ephemient
@ephemient: I'd never noticed that. Thanks.
dmckee
+2  A: 

Many, many, many years ago, it was actually possible to compile the kernel with g++, and as far as I remember part of the motivation was because C++ had stronger type check, not necessarily to have g++ to produce object files. But as Neil Butterworth have pointed out, Linus is not particular fond of C++, and there is zero chance that this ever will be possible again.

hlovdal
A: 

My non-technical guess: The Linux Kernel can't currently (2009) be compiled with any compiler other than the GNU compiler, gcc.

I say this on the basis that I've heard Richard Stallman, with some conviction, say Linux should be called GNU/Linux because the kernel is "only 1 part of the operating system" and I'm guessing he would not be able to say this if the kernel was non-dependant on GNU (e.g. a tonne of embedded devices run a Linux OS without any GNU software).

As I said, just a guess, let me know if I'm wrong...

Tom
Wrong. :) See other answers.
Arafangion
+3  A: 

The LLVM developers are trying to compile it with clang. The meta-bug on compiling the Linux kernel with clang has more details (the dependency tree for that meta-bug shows how little seems to be left).

CesarB
+3  A: 

Yup. I've done this. http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-October/011711.html

wash