8 ms·
Clang (LLVM C compiler) builds a working Linux kernel
- tzury 16y agoThe LLVM project is one of those open-source project which originally aimed to do some great things and eventually found out to do even greater.
- fleitz 16y agoIt's even self hosting. This is huge.
- Rusky 16y agoThe Linux kernel is explicitly built using GNU extensions, which means that in addition to implementing the C standard, they have to deal with kernel-specific issues as well as whatever ideas GCC has. Clang as a work-alike for GCC will be/is incredibly useful and an incredible accomplishment. While being able to compile Linux is definitely helpful and a good sign of compiler maturity, the kernel developers target GCC and I'm not sure that will ever change. This (and similar projects) will probably somewhat limit Clang adoption as people will always need to keep GCC around rather than relying on the portability of using standards. :( Hopefully the competition Clang brings to the table will push at least some open source projects to be a little less reliant on GNU.
- chc 16y agoOn the other hand, Apple is pushing LLVM very hard — Xcode is growing more and more integrated with it in each release — and I would not be surprised to see Clang declared the one true Mac and iOS compiler while GCC is shown the way out. So I think we might have some healthy competition on our hands.
- rwl 16y agoWhat's wrong with relying on GNU? It's Free software that will love on as long as the concept does. You can be assured that GNU will never have the rug pulled out from under it by a corporate affiliate, anyway.
- mfukar 16y agoI don't think he meant there's anything wrong with it, only that clang/llvm might not feel like implementing certain GNU C extensions. Besides, pluralism is always good, right?
- wash 16y agoI'm a hacker. This means I tend to have a lot of strong opinions about a lot of things. There are things I don't like about GNU, there are things I do like about GNU. The same can be said for Linux, Clang, LLVM, Apple, and a long list of other things. I mostly try to ignore my personal opinions, because I'd rather code than argue about epolitics.
- Rusky 16y agoNothing's wrong with GNU; the problem is when it becomes a de-facto standard. Having more than one compiler available will improve both as they compete, and it keeps code more time-proof and gives developers and users more options.
- rwl 16y agoA lot of people have been making this claim in this thread, but I'm a little bit skeptical. For one thing, I'm skeptical of the idea that competition always improves products in a commercial setting (though it surely does under some circumstances). But more importantly, I think there is a significant disanalogy between Free software projects and businesses that sell products. Businesses compete for customer dollars. What are Free software projects competing for? Users? Credibility? I'm not sure. But it certainly doesn't seem like they have the same incentives in place. People write code for FS projects because they're interested in it, because they need the functionality, etc. -- it's something they would do even if their efforts don't attract a lot of "customers." What FS projects do compete for is the time and interest of talented programmers. For that reason, having competing projects can be more harmful to them than good, because it divides the pool of programmers: more programmer time is spent achieving common goals (like having an excellent C compiler) than would be spent if the different groups pooled their efforts. (This is not, of course, an argument that competing FS projects are always a bad thing. Obviously, competing projects, forks, etc. arise for a variety of reasons, both social and technical. But I am arguing that just competition is not necessarily a good thing, either, especially when competing projects have common goals.)
- j_baker 16y agoWhy would one want to do this (aside from it being a cool project)? What advantages does clang have over gcc for kernel hacking?
- hendler 16y ago(disclaimer: I can't answer this with authority) The reasons I get excited: * speed: faster compilation * research: interesting code introspection you can't get from GCC. * proof of concept: if you can build the linux kernel, you can probably build almost any C project * edit: as mentioned in other comments, competition is good.
- Legion 16y agoThis isn't a "hey, go do this" post. This is a milestone in the development of Clang.
- j_baker 16y agoOf course. I was just curious if this had any other value.
- fleitz 16y agoIt may make certain bugs more apparent. If you have development going on with a different compiler and it's actively maintained to work on both compilers then overall you'd get similar advantages in your code base to those that write cross-platform software. Incidentally, you get the same effect with cross-platform as you're usually targeting different compilers. Also, with less compiler specific code it will be easier to get the kernel working with other compilers, perhaps ICC.
- mzl 16y agoUnfortunately, Clang is still a bit shaky at times. In our (C++) project, we get a miscompilation in Clang that we don't get with gcc, the visual studio compiler, nor the intel compiler. It will be great when it is more stable: clang cuts the compile time by half in comparison with gcc (from 18 minutes to 9 minutes on my computer).
- jacquesm 16y agoThat's quite the milestone to achieve. I'm actually really happy to see this happen in light of the negative rap C seems to be getting just about everywhere. C is far from dead, it may have its warts but it is still very much in use in all kinds of places and a solid knowledge of C has never hurt anybody (as far as I know). Being able to compile the linux kernel and to get it to boot is a non-trivial exercise in GCC compatibility, I'm very impressed with this. I wonder if there ever will be an official 'blessing' by the kernel devs of the LLVM C compiler.
- zdw 16y agoIt's unlikely that it'll get that 'blessing' - a while back certain versions of GCC were recommended against by Linus. Also, on some esoteric platforms, GCC dropped compatibility. For example, OpenBSD still supports an older version of GCC for VAX and m88k platforms IIRC.
- igravious 16y agoI don't see why not in the long run if the devs bend over backward to maintain GCC compatibility on x86. It is never a great idea to have a single point of failure even if that point is the wonderful and awe-inspiring GCC. It is amazing to think that nearly 20 years after conception Linux maybe be built with an alternate tool chain. This is an incredible feat that has far-reaching consequences for the health of the ecosystem. Maybe Linus wasn't keen on the idea but if some people step up and bake in the support it'll be de facto blessed. Slightly off-topic, does anyone know if the Gold linker works with Clang?
- wash 16y agoGold should work. ICC has been able to compile Linux for awhile, I think.
- alanh 16y agoWith all the flak Apple has taken over dropping its commitment to one "-VM," the JVM, I'd just like to point out Apple is the primary corporate sponsor of LLVM (I understand). How many plates must they keep in the air? This one is flying pretty high.
- wash 16y agoI'm a 19 year old college student, actually. I have no affiliation with Apple, nor a formal relation with Clang or LLVM.
- alanh 16y agoSorry, but your HN bio is empty and you didn't submit the article. Did you spearhead the effort? And is my comment regarding Apple and Clang incorrect? Thanks!
- vibhavs 16y agoI'm not sure why he was downvoted. He appears to the author of the linked email. You can see at the bottom of the mail, he signed of as "Bryce Lelbach aka wash".
- deleted 16y ago[deleted]
- codedivine 16y agoSure Apple is one of the bigger sponsors of LLVM but LLVM started out as an academic project and even now lots of academics contribute to it. Apple hired the guy who originally wrote LLVM and now uses it a lot. But many other companies also utilize LLVM and contribute back to it (though not as heavily). For example, some AMD compiler folks I know said they were going to commit some changes to LLVM (not sure if they did). Adobe also uses it AFAIK for some specific tools. However, LLVM and JVM dont have much in common. JVM is popular more for its baked in libraries than its instruction set or VM efficiency (though HotSpot is a darned good VM too).
- deleted 16y ago[deleted]
- bigmac 16y agoIt looks like this was targeting an x86_64 version of the kernel. For a good reference on LLVM-supported backends, see this table: http://llvm.org/docs/CodeGenerator.html#targetfeatures http://llvm.org/docs/CodeGenerator.html#targetfeatures Clearly, x86 gets the most love. x86, ARM, PPC, and SPARC are listed as "Generally Reliable." Quite an accomplishment, given the difficulty of building up a new compiler from scratch. For now, MIPS is notably missing from the party.
- wash 16y agoUnfortunately, I'm a student with limited resources. I have three boxes, a macbook and two Atom desktops, all x86_64.
- IdeaHamster 16y ago…but it still can't compile Ruby 1.9 :-P
- program 16y agoI am very happy. I was very pleased when back in may 20 2010 they announced that clang passed its first fully-successful Boost regression test run. But this is another big step ahead. The clang static analyzer is now part of my everyday life as a programmer and everytime I read "did you mean..." on the console I am amazed as the first time. It saves me a lot of time (even compile time.)
- rbanffy 16y agoMy only worry, in the light of Oracle's spat with Google over Dalvik and its lack of teeth over the OpenJDK, is what kind of patent protection the BSD-like license of LLVM offers against Apple in case it decides every Linux kernel on every non-iPhone smartphone (something that will probably happen in a couple years) infringes some patent they have that touches LLVM in some way. Any lawyer wants to chime in?
- bramcohen 16y agoThe GPL doesn't offer any special protection against third party patents, and there's no way it could, given the way patents work.
- rbanffy 16y agoI am not considering 3rd party patents, but Apple's. If Apple includes some patented tech into a contribution to LLVM or Clang, what guarantees I have they will not sue non-Apple downstream users?
- pohl 16y ago...in case it decides every Linux kernel on every non-iPhone smartphone...infringes some patent they have that touches LLVM in some way. Is there some legal precedent you know of wherein compiler patents extend to the output of the compiler?
- rbanffy 16y agoWhat if the output of the compiler uses some method you patented?
- pohl 16y agoThen I suppose the community can fork from the revision prior to where that patented technique landed in the tree, just as with any other OSI-approved license. http://www.opensource.org/licenses/UoI-NCSA.php http://www.opensource.org/licenses/UoI-NCSA.php
- mhd 16y agoWasn't tcc able to do the same[1] quite a while ago? [1]: http://bellard.org/tcc/ http://bellard.org/tcc/
- praptak 16y agoEven better, it could compile and boot Linux directly from its source code: http://bellard.org/tcc/tccboot.html http://bellard.org/tcc/tccboot.html
- mahmud 16y agoI don't think tinycc and llvm are even in the same league in terms of optimizations. Tinycc is, well, tiny. You can get a working compiler just using syntax-directed translation schemes and it would compile any valid program. The output would even boot, but it would make baby-Muchnick cry.
- mhd 16y agoTrue, no one is comparing their performance characteristics, it's just that getting the Linux kernel to compile isn't a unique feat where you need to be on the same level as gcc and llvm. You "just" need ANSI C with GNU extensions. And not break on a couple dozen corner cases.
- ddp 16y agoThis is good news. FYI, Clang/LLVM's been building FreeBSD for a while now: http://wiki.freebsd.org/BuildingFreeBSDWithClang http://wiki.freebsd.org/BuildingFreeBSDWithClang
- brianm 16y agoFWIW, I use clang over gcc (unless there is a major overriding reason to use gcc) just for the fabulous error messages. http://clang.llvm.org/diagnostics.html http://clang.llvm.org/diagnostics.html gives some good examples, and my experience has been that the examples given on that page are pretty spot on.