7 ms·
To add to what other people have said, you can't even compile the kernel unpatched with llvm yet. GCC is still very much a thing.
by stusmall 9y ago
To add to what other people have said, you can't even compile the kernel unpatched with llvm yet. GCC is still very much a thing.
- brianwawok 9y agoWhat would be the benefit to llvm?
- simcop2387 9y agomore portability, and some of the santiziers that clang has (ubsan, asan). They have gcc equivalents or ports but being able to use more of these kinds of tools is a good thing in the end since it'll allow more bugs to be found without an exploit.
- nullc 9y ago> and some of the santiziers that clang has (ubsan, asan) GCC has these.
- simcop2387 9y agoDo they end up finding the same issues/bugs? I thought they didn't always find the same things last I tried using them, so I'd build in both compilers to end up running tests/checks.
- CJefferson 9y agoNo sure what you mean by 'more portability'. gcc compiles to a strict subset of the architectures than llvm supports (at least, last time I checked).
- JohnStrange 9y agoYou mean superset, right?
- CJefferson 9y agoYes, and it's too late to change now, thanks.
- simcop2387 9y agoIt means that you won't end up relying on a specific compiler's quirks or implementation of the language. You can expect different compilers to handle undefined behavior in different ways which will help you catch where you're doing things you shouldn't be. And since you're no longer relying on a single compiler you are more likely to be able to support other platforms and compilers that don't have a gcc port (they do exist, even if they aren't common).
- CJefferson 9y agoYou have to rely on compiler's implementation -- you can't implement a kernel in pure C unfortunately, you need to do some things "outside" of C. In practice, most supporting of the kernel has come about by clang implementing things how gcc do them anyway.
- tscs37 9y agoNot having the kernel locked into a compiler monoculture for one.
- jhasse 9y agoWhy does that matter?
- tscs37 9y agoMonocultures of any kind in software aren't good. It leads to lock-ins, like the current kernel is locked into GCC. Some of those GCC Extensions used are effectively proprietary because "the code is the documentation" so nobody can replicate it for their own compiler. I do not believe that is healthy.
- jhasse 9y agoThat's definitely a huge disadvantage! But only supporting one compiler has the advantage that you're aren't limited to the lowest common denominator of compiler features. You'll notice this especially with C++ codebases which try to support GCC, Clang, Intel and Visual C++. You'll need a lot of macros and workarounds for each compiler's quirks.
- stusmall 9y agoWhen I'm doing a new C project I usually go out of my way to make sure it compiles clean with GCC and clang. Each compiler has its strength and weaknesses. GCC tends to produce faster code in some situations where clang has great static code analysis tools and asan is amazing. I've heard GCC has made major improvements in build speed since the last time I've started a new C project from scratch but that used to be on my list of reasons too. C can be a hard to wrangle beast and the more checks I have on my code quality the better I sleep at night.
- uep 9y agoAt least from the outside, GCC asan seems comparable to clang's right now. I haven't done back-to-back checking to see if clang finds things it doesn't. I haven't really used the undefined and thread sanitizers though.
- lmm 9y agoIt's widely viewed as better designed (though that's obviously somewhat subjective); it's more modular, and a lot of innovative work on optimization now happens there rather than in GCC.
- bluGill 9y agoIt is not GPL3 licensed. Most of the projects that have moved from gcc to llvm did it because of the license not for technical reasons. That isn't to say there are not technical reasons to say llvm is better - there are good ones. However they are not compelling like the license is. Llvm has a better internal design which should be better long term, but so far gcc generally compiles faster code which is for most people more important that internal design. Note that linux distributions are mostly built by the types of people who like the GPL3 license. Using gcc is the correct decision for most linux distributions.
- netsharc 9y agoAm I understanding it correctly that you're saying those projects switch because of the license of their compiler? As far as I know the GPL doesn't "infect" the program compiled with a GPL-licensed compiler, I can have my proprietary binary-only software compiled with the GPLed gcc just fine...
- clarry 9y ago> Am I understanding it correctly that you're saying those projects switch because of the license of their compiler? Indeed they do. $ cc --version gcc (GCC) 4.2.1 20070719 This system is stuck with a rather old branch of GCC. It won't ever be upgraded, because of the license. LLVM seems to be on its way though.
- yellowapple 9y agoIt's a factor if you're writing a compiler for a new programming language. LLVM has been a pretty common target for that (see also: Julia and Rust) both for technical reasons and because it means the language itself can be released under a non-GPL license. It's also a factor if you're distributing a compiler with your operating system. This has already driven FreeBSD (IIRC) to LLVM, and OpenBSD is starting to adopt it for a few platforms (GCC is still required due to certain OpenBSD targets that aren't supported by LLVM, but if that's ever fixed - whether because OpenBSD drops those targets or because LLVM eventually supports them - then I'd be very surprised if a switch doesn't happen for all platforms).
- microcolonel 9y agoThe "licensing" and "better design" arguments are not really compelling. As for "licensing", basically no commercial operating system distribution ships the compiler in the base system. As for "better design", LLVM still doesn't generate code as well as GCC, especially for the kernel; but over the years as the codegen has become better, the performance has come down to match GCC. LLVM has some pinhole optimizations which don't exist on GCC, and some slightly different behaviours around exotic non-standard types, but they are largely becoming the same compiler. Turns out that GCC is actually really fast for the quality of the code it generates, and Clang/LLVM take almost exactly the same amount of time to generate similar code.
- vlozko 9y agoLicensing was THE reason Apple didn't update their GCC version in Xcode and switched over to Clang/LLVM. IANAL and my history is a bit hazy but the things that Apple wanted to support and the way they wanted to go about doing it was not compatible with the GPL.
- microcolonel 9y agoApple first used LLVM for their graphics stack, and it became more attractive to them because of the JIT stuff. Bringing Clang along is more or less an artifact of that. Maybe they weren't interested in GPLv3 since the tivoization clause prohibits them from distributing the compiler on devices which can't be flashed, but I don't think it's exactly rational. They also don't update the version of Emacs that they ship, and there you could make the argument for it since it ships with the operating system. They wanted the freedom to make the base system read only, and I get that, but if LLVM weren't there they would be shipping GPLv3 GCC and Emacs 25.
- belorn 9y ago> tivoization clause prohibits them from distributing the compiler on devices which can't be flashed The tivoization clause has an explicit exception that allows for devices which can't be flashed. What the clause prohibits is the case when devices can only be flashed if you got the right developer password, and the publisher deny the owner of the device to have that password.
- stusmall 9y agoWhile I'm sure there would be benefits to LLVM from having such a well funded depend on it, the kernel has driven a lot of patches for GCC, I imagine the kernel would benefit more. Here is a list of advantages copy and pasted from llvm.linuxfoundation.org Why use Clang/LLVM with the Linux Kernel? Fast Compiles (making you able to work faster) LLVM/Clang is a fast moving project with many things fixed quickly and features added. LLVM is a family of tools used in many problem domains leading to one code base being able to build tools to work on just about anything you need: one place to add features, or fix bugs. BSD License (some people prefer this license to the GPL) Built in static analyzer Great error reporting and Fix-it hints LLVM technology can be embedded into many tools (even yours!) Already in wide used in OSS projects and in industry