14 ms·
Why is FreeBSD deprecating GCC in favor of Clang/LLVM?
- saurik 13y agoIt continues to be disappointing (which I think is the least strong word that could be used) that clang's website attempts to demonstrate the superiority of clang by comparing against the error messages from gcc 4.2, a version of gcc that wasn't even the most current when that comparison was published. This then leads to people accepting this as fact (especially amongst developers targeting Apple products who don't even seem to realize versions of gcc later than 4.2 exist, as Apple refused to continue work on gcc due to the licensing changes) an turn up in answers like this one as the "most notable" technical advantage of the product. In fact, the error messages of the two systems are largely a tradeoff at this point, and in a project I work on that compiles using both gcc and clang (targeting MinGW and OSX) simultaneously, on multiple occasions gcc has returned the more useful error messages (even if you discount the times when clang outright crashes while trying to compile my code, something gcc hasn't done to me in a decade). Even to the extent to which clang is better (which is mostly how it will guess what you meant and then compile the rest of the file under that assumption), it is kind of insulting in an open source context to treat that as a competitive advantage when I'm certain gcc would have loved that patch as a contribution.
- aspensmonster 13y ago>as Apple refused to continue work on gcc due to the licensing changes This. As stated in the accepted answer in the linked article, licensing issues are the real reason. Technical differences are ephemeral. The competition between GCC and LLVM has a habit of inducing improvments in both projects. By all means, at any given point in time one project can have an edge over another in this niche or that edge case. But fundamentally this is a philosophical divide between Free Software and Open Source Software.
- JoshTriplett 13y agoThis is a licensing debate, but please don't conflate that with a divide between "Free Software" and "Open Source". Both GCC and LLVM/clang qualify as both Free Software and Open Source software. Both terms encompass both copyleft and non-copyleft (all-permissive) licensing. GCC uses a copyleft license; LLVM/clang uses an all-permissive license. FreeBSD prefers to avoid dependencies on copyleft code, especially in their core; thus, they naturally prefer LLVM/clang.
- aspensmonster 13y agoApologies. That is a better comparison: A divide between copyleft licensing and permissive licensing.
- foobarbazqux 13y agoThen again, copyleft licensing is idiomatic of free software, and permissive licensing is idiomatic of open source software. This essay covers the essential differences: http://www.linfo.org/open_source.html http://www.linfo.org/open_source.html
- air 13y agoThat's a very misleading essay. "It is that, whereas free software is always also open source, open source software does not necessarily have to be free software. That is, software can be open source without granting its users the additional freedoms that free software guarantees." This is incorrect, and the example given was incorrect. The terms are identical in meaning. Open source was coined to be a trademark for free software.
- foobarbazqux 13y agoIf I give you Tivoized BSD code, this is open source but not free software, at least since GPLv3.
- 13y ago
- jevinskie 13y ago> Technical differences are ephemeral. Hardly the case when you want to extend/embed your compiler frontend/backend. In this case, LLVM/Clang shine. They are written in fairly clean and comprehensible C++ libraries. Most CLI tools are well under 1k lines! GCC is a real pain to even comprehend, let alone extend/embed!
- belorn 13y agoClang only support a subset of the features that GCC has, so it is naturally easier to comprehend. Reading the user manual, more "tricky" GCC extensions is intentionally not implemented because they would be too hard to implement. If you think this is good/bad for Clang/GCC, depend if you ever used said features, or if one prefer a smaller compiler which has less features.
- chongli 13y agoIt's not really more/less features so much as it is a tradeoff. LLVM is extremely powerful in that it lets you write front-ends for many different languages without worrying about the complexities of native code gen. Likewise, it lets you write backends for other target platforms (i.e. JavaScript), allowing you to gain the ability to port those languages to new platforms easily. Thirdly, you can write optimizers for LLVM's intermediate representation and gain the benefit across most/all front-end languages and back-end platforms. GCC, on the other hand, seems to have a much narrower focus but with a lot more optimizations and weird extensions.
- statusgraph 13y agoThis is exactly GCC's architecture as well, where front-ends are transpiled into a generic language, which is then compiled into native code for a given platform.
- cperciva 13y agoThat's how GCC works internally, but neither the front-ends nor the back-ends are available to use individually. Indeed, RMS specifically avoided having a flexible architecture similar to llvm, because he was afraid such flexibility would be used for non-GPL "plugins".
- saurik 13y ago(Right. I think we are in agreement, but to be very clear for others who might only read these comments: the accepted answer is from where I quoted the "most notable" technical benefit.)
- hcarvalhoalves 13y ago> clang's website attempts to demonstrate the superiority of clang by comparing against the error messages from gcc 4.2 Even if it that doesn't hold true anymore, I think it's valid to highlight since it's one of the motivations, probably one of the original creators' pain points with GCC. The website reads: Some of the goals for the project include the following: End-User Features: - Expressive diagnostics (examples)
- eonil 13y agoClang is targeting specific market - free and non-GPLv3 compiler (with OBJC support). The sales catchphrase superior error message is still true for the people in the market. And comparison with compiler in GPLv3 is meaningless to them. You're just out of target.
- kps 13y agoYou could always submit a patch. talks about the experience provided by the command line compiler, contrasting -Clang output to GCC 4.2's output in several examples. +Clang output to that of GCC 4.2 (current when the Clang project began) +in several examples. <!--
- rsynnott 13y ago> clang's website attempts to demonstrate the superiority of clang by comparing against the error messages from gcc 4.2, a version of gcc that wasn't even the most current when that comparison was published. This is the latest version available by default on MacOS and FreeBSD (for licensing reasons; subsequent versions are GPLv3), the two operating systems where clang sees most use.
- saurik 13y agoAt which point you may as well just point out "clang is maintained; unlike gcc 4.2, which at best will only receive back-ported compilation and security fixes, clang is under active development" ;P. You don't even need to motivate "better": it just needs to be "all least sort of as good". In the end, the only legit reason for this change is licensing, and any references to technical superiority between clang and gcc as a whole are red herrings at best and disingenuous at worst.
- rsynnott 13y agoApple certainly has technical reasons for using clang; good luck getting the degree of integration XCode has with clang with GCC (the plugin system added as a response to clang existing would help, but would not be sufficient in itself). BSD has less clear ones, though I would hope that other C/C++ IDEs will start adding similar levels of integration. Ultimately, clang offers a way forward without having to adopt GPLv3 software, and besides that offers considerable benefit to people making development tools. Its big selling point has never really been speed; that it can generally keep up is enough. EDIT: You could certainly also make the claim that Clang's far faster compilation is a technical feature, especially for C++ programmers. There are actually people who use clang for development, for the fast compilation and static analysis, then build for production with a newish GCC.
- saurik 13y agoMy comment complains about the error handling comparison and then makes assertions about the "only legit reason for this change" <- "this change", of course, being the one to FreeBSD. I am not quite certain how issues Apple runs into with Xcode are relevant (and talking about hypothetical future IDEs, which certainly would not be FreeBSD-specific and which would treat clang as any other library to depend on, doesn't make the motivation any more clear to me). To address your second paragraphs, I am responding to a comment (yours) justifying why clang should spend time on their website making comparisons against gcc 4.2, a stance you defend by stating that that is the version that people are using instead of clang. Now, in your response to my defense against that point, you are bringing up legitimate technical benefits of clang against all versions of gcc... ...but I would never, nor have I so far in this thread, complained that those benefits didn't exist; I especially haven't claimed that those version-independent architecture benefits shouldn't be mentioned on their website. My complaint, remember, is that there are specific nebulous benefits (error output) being touted against gcc 4.2 as the "most notable" (according to the SO answer being discussed) technical be benefit of this project. That specific benefit only exists because of a licensing decision, as gcc after-4.2 does not have error output this bad (not do I believe it did in 4.3 trunk at the time that website was published). The honest reason, if "error output" is important, as to why clang is better than gcc for FreeBSD is thereby "licensing", as if licensing weren't the real reason that benefit evaporates: it is no better than just pointing out that gcc 4.2 is unmaintained. However, and again, you are more than welcome to be happy or excited about any other real benefits, either to other parties or the ones in question, but your comments in this context are anticipating complaints I haven't made and in fact is aggressively arguing with me over something I don't even disagree with: it is as if you see anyone complaining about clang and presume "they must just be a hater" and knee-jerk your way through a muscle-memory argument over "why clang is better" (something I have no strong opinion about).
- 6ren 13y agogcc 4.2.1 was the last version to use GPLv2. Later versions switched to GPLv3, which the BSD guys couldn't swallow. From skimming the answer, I think it's pretty clear that the switch wasn't due to technical reasons, but that Clang/LLVM is now "good enough". It seems reasonable for FreeBSD to favour BSD licensing.
- saurik 13y agoI am not exactly certain what you are disagreeing with from what I said (as I agree that the only legitimate reason is licensing), so I guess I'll justt point out that the answer you apparently only "skimmed" has a section on "technical benefits" that specifically listed a "most notable" example being improved error messages.
- 6ren 13y agoYes, I read that bit. Your objection seemed to be about the comparison with an older version of gcc, and I was noting why that comparison was legitimate, for them. EDIT Ah, I see how: you're talking about clang's website, whereas I'm talking about the submitted link, which is about FreeBSD. Note: the same argument also applies to other companies avoiding the GPLv3, which would explain why clang's website uses gcc 4.2 in its comparison. Though people here mentioned the GPLv3, no one noted that 4.2 was when the gcc license switched to it (I checked the HN comments). FWIW I've seen a GPL project eventually lose out to a BSD-style competitor, and the latter were surprisingly nasty about it, similar to what you're saying. This might be due to commercial interests vigorously supporting the BSD-style version for reasons of MONEY. But apart from nastiness, it makes sense that a more permissive license, being free to a wider audience, will be more popular. OTOH perhaps here, for a compiler, requiring people to give back (GPL) will work better? OTOH2, promising new tech always gets a certain ersatz caché - whether that promise is fulfilled or not.
- saurik 13y agoThe submitted link has a section on technical benefits to FreeBSD for making this switch which directly links to clang's website for what this submitted link's accepted answer considers the "most notable" technical benefit.
- cmccabe 13y agoWell, I like the clang error messages better than gcc's, and I use recent versions. And to refer to the major architectural differences between the two as something that could be bridged by a single "patch" is a little silly. gcc is still better at optimization, though. For now. [edit: wow, people are really confused here. Guys, LLVM was designed from the start to have a clean separation between passes. You can compile some other language to the LLVM bytecode and then just use the code generator, for example. It even includes a JIT! In contrast, gcc is a huge monolith. The projects are written in different languages, too... C++ versus C. tl;dr is that when you say that "the only difference is the license," you sound like someone saying "the only difference between Ruby and Java is the file extension." Pointy haired.]
- illumen 13y agogcc is in C++ for a while now. gcc has been becoming more modular over previous releases, and is becoming more modular in the future. For example, there are plugins since 2010. Your information is outdated, so it makes your opinion seem uninformed.
- cmccabe 13y agoMost of gcc is still written in C. Only a tiny amount of new code is in C++. In my opinion, that's the worst of both worlds-- inconsistent code, plus C++ overheads. I work with some fairly recent version of both compilers-- gcc 4.7.2 and clang 3.2. I also know a developer on the LLVM team. clang is way ahead of gcc in many ways, and the gcc devs know it. We still ship software built with gcc, rather than clang, because gcc is still better at optimization. (gcc also supports more obscure targets, though that's not our biggest concern). We also make use of llvm's ability to dynamically recompile code on the fly in Cloudera Impala. More information here: http://blog.cloudera.com/blog/2013/02/inside-cloudera-impala-runtime-code-generation/ http://blog.cloudera.com/blog/2013/02/inside-cloudera-impala... This would not be possible with gcc no matter how much work we did (license issues-- Impala is Apache 2.0, gcc is GPLv3).
- saurik 13y agoWhen a parse failure occurs, making an educated guess and continuing is not a "major architectural difference". (As for your edit, I now challenge you to tell us how these architecture passed and the JIT help FreeBSD's use cases. That said, my comment you are responding to just expresses bother about the "most notable" technical benefit listed by this SO answer, so I'm not even certain why you feel talking about other things is relevant.)
- lbenes 13y agoThe real disappointment to me is that this decision was made over an irrational licensing issue instead of technical merits. If Clang was superior to GCC in the vast majority of benchmarks, then I would support this decision. But that’s not the case, GCC is still leading in many benchmarks and can be an order of magnitude faster when the commonly used OpenMP library is used.[1] BSD users are the losers here. [1] http://www.phoronix.com/scan.php?page=article&item=llvm_33svn_competes&num=5 http://www.phoronix.com/scan.php?page=article&item=llvm_33sv...
- D9u 13y agoI've been using clang/LLVM in my FreeBSD system for several months now, and I've noticed that clang builds faster than gcc, and I've not had any issues with reliability, so I don't see what the problem is here. Also, as noted in the comments on StackExchange, BSD licensing vs GPL may be reason enough to discontinue the use of gcc in FreeBSD systems.
- lmm 13y agoless-optimizing compilers usually build faster than more-optimizing compilers.
- jorgecastillo 13y agoI would say that the license is to a certain degree also a technical reason to use LLVM. Projects, corporations or people can integrate LLVM into their product with less hassle than with GCC. You can't integrate GCC into a product directly, GCC can only be used as an independent binary. I would think that this would make LLVM more enticing to developers. Obviously this depends on the intended use if all you need is a compiler GCC might still be the better choice.
- superbaconman 13y agoPolitics really does destroy all that is holy. in this case free software. should I be able to extend free software for profit or not? I would say yes... but there are some cases in which I would say no. for a compiler I would say no one should be able to make money off an extension. it just doesn't make since.
- icarus127 13y agoI was thinking this as well. I see the GPL, and Copy Left licensing in general, as a sort of regulatory force in free software. If you want to participate the GPL will put constraints on you to play nice with others in the FOSS space. Given what happened in the financial markets as they were deregulated I am extremely suspicious of the notion that removing the constraints of Copy Left will actually be positive in the long run. I have no doubt that it will help companies like Apple but I don't see the benefit for the wider community of developers.
- jcase 13y agoI'm not sure this is true (anymore?). There are many open source projects who are thriving under non copyleft licenses. If someone wanted to be a dick about it they could release modified GPL code as one big diff and publish it on some obscure webpage only their customers have access to. Instead we see more and more companies and individuals becoming friendly open source citizens. Perhaps some because the GPL mandates it but I would like to think mainly because they feel it's right thing to do—copyleft or not.
- icarus127 13y agoI too share your general optimism about the current state of open source. I really hope that you are correct in your conclusion that the GPL mandate is unnecessary because, as we see here, many projects are trying to get away from it. However, I feel we have a number of historical examples of what happens when constraints are lifted in a space that has a number of very powerful players. None of them look like anything I want the Open Source movement to look like.
- guelo 13y agoWould the world be a better place if Apple weren't allowed to Tivoize the iDevices because all the free software in them were licensed under GPLv3? I'd say yes.
- jevinskie 13y agoWho is to say all free software developers want to prevent Tivoization? If all developers wanted to prevent that, they would use GPLv3! Clearly many developers like the MIT/BSD licenses. Are you advocating that these developers switch to GPLv3 or... what is your alternative?
- MBCook 13y agoTorvalds himself has said that he things Tivoization should be allowed, but many other big kernel developers disagree.
- belorn 13y agoWhen describing what an other person has said, please do not slim it down to the point where it losses context. What he has said is that he personally don't like DRM, but he thinks it outside the scope of the kernel and a software license (see https://groups.google.com/forum/#!topic/fa.linux.kernel/L5NRD_ONkIk[1-25-false] https://groups.google.com/forum/#!topic/fa.linux.kernel/L5NR...)
- DenisM 13y agoI've seen an interview with Linus when he actually said just that: GPLv2 is about "if you used/changed my code I want to see it", whereas GPLv3 is about "If you used/changed my code I want to play with your hardware", and that he is not in favor of V3 for that reason as he doesn't feel its demands are "justified". So MBCook's statement is fairly accurate, to the best of my memory.
- Dylan16807 13y ago
- plywoodtrees 13y agogcc, for the sake of wanting to make it hard to call it from proprietary front-ends, is architecturally tangled. (See http://comments.gmane.org/gmane.comp.gcc.devel/59296 http://comments.gmane.org/gmane.comp.gcc.devel/59296 - the "new methods" mentioned there never emerged). Proposals to refactor it have been vetoed by rms. As a result, gcc is substantially harder to understand and work on than other compilers of similar scope. As a result, new development effort, both personal and corporate, is going into clang. As a result, even if clang is only approximately at parity with gcc now, people expect it to improve faster in future, and therefore to be a better choice now. All of these contribute to what http://lists.freebsd.org/pipermail/freebsd-questions/2012-June/242709.html http://lists.freebsd.org/pipermail/freebsd-questions/2012-Ju... says are non-licence reasons to replace gcc: 1) GCC's continuously increasing propensity to generate "bad code", 2) The inability of GCC mamintainers to fix _long-standing_ bugs, some have been identified for over a decade, and have not been fixed. 3) The continuously increasing trend of introducing 'non standard' features, 4) The growing need to 'write around' correct/valid code that GCC will not compile. 5) The fact that the GCC code is 'unmaintainable' -- *NO*ONE* (other than someone who has been working with GCC internals for "forever" --a decade at an absolute minimum) has any chance of 'understanding' what it is doing internally.
- sanxiyn 13y ago"New methods" did emerge, and the result is GCC plugin. http://gcc.gnu.org/wiki/plugins http://gcc.gnu.org/wiki/plugins GCC plugin needs to be GPL-compatible, and GCC includes a license check similar to Linux kernel module tainting. (Instead of tainting, you can't run plugin at all.) http://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html http://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html
- LeeLorean 13y agoIn a word - Apple. IOS and OSX borrow heavily from BSD Apple has made more money form free software than anyone else, and they can pressure FreeBSD to stay away from GPL3
- mbreese 13y agoIn a word - no. FreeBSD has been around a lot longer than Apple's switch to Darwin. FreeBSD has a long history of preferring BSD licensed code to GPL licensed code. Apple has just financed clang/llvm. Apple has their reasons for using clang, and FreeBSD has theirs. FreeBSD didn't need any pressure from Apple to make the switch.
- rsynnott 13y ago> they can pressure FreeBSD to stay away from GPL3 Yes; Apple can pressure the FreeBSD project to stay away from GPLv3, through their evil Apple magic. In fact, they are presumably pressuring the whole world to stay away from GPLv3, as it has seen almost no adoption outside the FSF! Naughty, naughty Apple. If not for mean ol' Apple, the FreeBSD project would no doubt rush to embrace GPLv3, discarding their horrible old BSD license!
- hclose 13y agoIt could be nice to cross-compile for OSX/iOS on FreeBSD. I could do without the Xcode bloat.
- stox 13y agoBe glad for the rise of Clang/LLVM. When there is a serious competitor, quality will stay higher and the projects will evolve faster. ie. Clang will force gcc to become better. gcc will force Clang to become better. End result, we all WIN!
- hobs 13y agoor more commonly I see with the big projects: 1. Big open source software project has almost all of the market share for specific task. 2. Userbase gets tired of old/bad/needless/shitty management stuff in the underlying whatever. 3. New hotness(or several) appears on stage 4. One emerges as main successor to (1) 5. Goto 1
- octo_t 13y agoNot in the case of big software projects (and your C compiler is undoubtedly a big software project). Its taken about 10 years and millions of man hours to get clang/llvm on a performance parity with gcc. Any new C compiler has to either just be a C -> optimised C compiler (in which case why not just write an LLVM pass) or duplicate all of the optimisations which exist in LLVM/gcc.
- MichaelMoser123 13y agoI did not understand the 'political' issue: The GPLv3 license does not apply to executable files created by gcc; you can even use gcc to create proprietary products. What is the problem of using gcc 4.7 in order to compile BSD if the license does not apply to the executable - BSD in this case ?
- merijnv 13y agoFreeBSD is not just a kernel, it also ships with a userland, which includes a C compiler (obviously). In other words, FreeBSD ships with a gcc binary, which means FreeBSD is distributing gcc, which means all clauses in the GPLv3 apply to them. Any group/company/whatever wishing to ship FreeBSD that doesn't strip out the compiler will be affected similarly.
- sanxiyn 13y agoWhile Clang's GCC compatibility is quite good, 12.1% of Debian archive still fails to build with Clang. It is an almost drop-in replacement, but not a drop-in replacement. http://clang.debian.net/ http://clang.debian.net/
- mitchty 13y agoWhy would it be drop in? The default for clang is c99, for gcc it is still c89, if this was never specified in makefiles you're in for a world of possible hurt. Most "errors" I see on that page amount to boring differences of how the compilers treat C, or how clang doesn't support some random gcc extension, or how clang differs in its interpretation of implementation defined behavior.
- sanxiyn 13y agoI am just pointing this out because some people on this thread are claiming "I have been using Clang for N months and had no problem". I believe them, but it won't necessarily work for you, because Clang is not a drop-in replacement. Clang doesn't need to be a drop-in replacement and I think it shouldn't be, but let the buyers beware.
- mitchty 13y agoGotcha, I just notice most problems seem to be of the "clang interprets the standard this way, therefore it must be wrong because gcc compiles it". I think having multiple different interpretations of undefined behavior a good thing. Means new standards could likely define it. Also shows how much code manages to compile that probably shouldn't. I know i've been surprised with what ambiguous stuff gcc has allowed in my own code.
- pjmlp 13y agoYeah, this is because many tend to confuse their C or C++ compiler accepts with what the ISO/ANSI standard states. Any C or C++ developer doing cross platform development, even if only across UNIX platforms, will have lots of war stories to tell about using different compiler vendors across systems.