23

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.

Community
  • 1
  • 1
oo_olo_oo
  • 2,815
  • 5
  • 28
  • 25
  • I wonder if some soft written for some cpu architecture can stop working correctly when is compiled with different compiler (most probably yes, so I wanted to know how big the probability is that some other than gcc compiler will be ever used for Linux). – oo_olo_oo Mar 27 '09 at 11:41
  • clang specific: https://unix.stackexchange.com/questions/17972/is-there-a-linux-distro-compiled-with-clang-llvm – Ciro Santilli OurBigBook.com Sep 22 '17 at 06:52

10 Answers10

13

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
  • 391,730
  • 64
  • 469
  • 606
  • Some **undocumented** gcc extensions which were used by linux developers because "it just works and there is no any warning for VLAIS" even with `-ansi -padantic` (gcc will bark on it only with little-used `-pedantic-errors`, [thanks to Lundin](http://stackoverflow.com/a/14629651/196561)). – osgx Mar 15 '14 at 21:15
  • 1
    And there is successful LLVMLinux project by Linux Foundation and Behan Webster in 2013-2014 years: http://llvm.linuxfoundation.org/ to delete worst gcc-isms from vanilla Linux kernel. – osgx Mar 15 '14 at 21:16
11

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 --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
9

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
  • 43,947
  • 7
  • 63
  • 86
  • 1
    Also there is now Linux Foundation project "LLVMLinux" to patch linux kernel to be compilable by LLVM and clang: http://llvm.linuxfoundation.org/ – osgx Mar 15 '14 at 21:11
8

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

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
7

Yup. I've done this. See [cfe-dev] Clang builds a working Linux Kernel (Boots to RL5 with SMP, networking and X, self hosts).

approxiblue
  • 6,982
  • 16
  • 51
  • 59
wash
  • 497
  • 4
  • 7
5

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
  • 33,371
  • 15
  • 110
  • 174
  • "which is why we have the great GNU/Linux debate." Incorrect, see https://stackoverflow.com/questions/689327/is-it-possible-to-compile-linux-kernel-with-something-other-than-gcc#comment8816777_901389 . – clacke May 04 '18 at 21:25
4

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
  • 26,565
  • 10
  • 94
  • 165
1

EKOPath 4 Compiler, not now. but probably with some minor patches

https://github.com/path64/repositories

http://www.pathscale.com/ekopath-compiler-suite

plan9assembler
  • 2,862
  • 1
  • 24
  • 13
1

I am just now working on compile Linux kernel using Open64 for MIPS archtecture, and some other guys are now just working for make Open64 can build for X86 arch. Now the kernel can partly run, and still have Run fail errors.

However for the atomic problem, at least i have not come up with it. And I do not think it is really a problem.The reasons are:

  1. The Linux kernel have already been a collection of source code, which can successfully build with GCC, so it is only the compiler's problem if it can not build it, or the built kernel runs fail.

  2. If a compiler want to successfully build Linux kernel, it should obide the GNU C Extension, and this extension will give a clear discription of what a atomic operation is, so such a compile only need to generate code according to this extension.

Ling Kun
  • 11
  • 1
-3

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
  • 14,041
  • 16
  • 64
  • 80