16 ms·
Clang vs. other open-source compilers
- peter_d_sherman 7y agoExcerpt: "Clang can serialize its AST out to disk and read it back into another program, which is useful for whole program analysis. GCC does not have this. GCC's PCH mechanism (which is just a dump of the compiler memory image) is related, but is architecturally only able to read the dump back into the exact same executable as the one that produced it (it is not a structured format)." Clang, you had me at 'hello'. The point I outlined above is just icing on the cake!
- mhh__ 7y agoGCC can dump it's AST https://stackoverflow.com/questions/15800230/how-can-i-dump-an-abstract-syntax-tree-generated-by-gcc-into-a-dot-file https://stackoverflow.com/questions/15800230/how-can-i-dump-...
- Ace17 7y agoGCC can dump its internal representation at almost every stage of the compilation process. However, it's intended for diagnosing issues in the compilers or plugins ; it's definitely not meant to be used as an interoperable format to be loaded back into a program. gcc doesn't even provide a way to specify the output path for the dump file (too bad, as reliable AST dumping could enable implementing ast-based-ccache (instead of preprocessed-code-based-ccache, for compilation-caching of preprocessor-less languages)).
- SeekingMeaning 7y agoI mean Elsa and and PCC are cool, but who actually uses them? Clang and GCC are pretty much all there is, but regardless it’s nice to know what people have tried/are trying to do. These bullet points in particular make me want to tinker with PCC and see how much it is (and is not) capable of: > The PCC source base is very small and builds quickly with just a C compiler. > PCC doesn't support Objective-C or C++ and doesn't aim to support C++.
- vyjcgtyjb 7y agoMany use Microsoft's and Intel's.
- thenewnewguy 7y agoThis is a page about _open source_ compilers.
- oaiey 7y agoConsidering how old this page is (2009 it seems) when they update it they should include msvc. Cannot imagine Microsoft will not open source it for another 10 years.
- StephanTLavavej 7y agoMSVC’s STL (which I work on) is now open source, under the Apache+LLVM license: https://github.com/microsoft/STL https://github.com/microsoft/STL . At this time, there are no plans to open source the MSVC compiler.
- deleted 7y ago[deleted]
- kick 7y agoPCC was at one time basically the standard C compiler, and you can port it to just about any architecture you want in less than a day. It also shipped with many historic operating systems, Plan 9 from Bell Laboratories being one of them, if I remember correctly.
- Taniwha 7y agoAnd Unix
- 4ad 7y agoPcc was never used in Plan 9. The Plan 9 C compilers[1][2] were written by Ken Thompson, and later reused in the Go toolchain. [1] http://doc.cat-v.org/plan_9/4th_edition/papers/compiler http://doc.cat-v.org/plan_9/4th_edition/papers/compiler [2] http://doc.cat-v.org/plan_9/4th_edition/papers/comp http://doc.cat-v.org/plan_9/4th_edition/papers/comp
- gok 7y agoThis is staggeringly out of date (it's from around 2007) and really ought to be taken down.
- mattst88 7y agoCould you provide a few examples of what information is out of date?
- srott 7y agoThis one is also outdated: https://www.phoronix.com/scan.php?page=article&item=gcc7-clang4-jan&num=4 https://www.phoronix.com/scan.php?page=article&item=gcc7-cla... haven't checked recently, because gcc sped up and still produces better binaries It can dump AST and much more: https://godbolt.org/ https://godbolt.org/
- gok 7y agoGCC's diagnostic system has been completely re-written, for example
- NilsIRL 7y agoLink time optimization is possible with GCC.
- notaplumber 7y ago> GCC is licensed under the GPL license. Clang uses a BSD license ... Looks like this hasn't been updated in a while. As of Clang 9.0 they migrated everything to the Apache 2.0 license, which is not nearly as permissive as BSD. Apache 2.0 mixes US Contract law with Copyright law, and that is considered wholly "not permissive enough" by many, most notably OpenBSD which is stuck on Clang 8.0.1. They also migrated the libc++/libc++abi C++ standard libraries from MIT to Apache 2.0 as well (which was a real dick move), but they don't care.
- Joky 7y agoMinor precision: it is Apache 2.0 with LLVM exceptions, the exceptions are intended to address libc++ and other runtime use-cases I believe.
- chipperyman573 7y agoWhy were the license changes made?
- pnako 7y agohttps://llvm.org/foundation/relicensing/ https://llvm.org/foundation/relicensing/ Addressing the patents question seems to be the main reason.
- notaplumber 7y agoI wish more people would have seen through this, but alas.. this is the real reason. Corporate pressure, agenda, not the best interest of the open source community. http://lists.llvm.org/pipermail/llvm-dev/2015-October/091536.html http://lists.llvm.org/pipermail/llvm-dev/2015-October/091536... "1) Some contributors are actively blocked from contributing code to LLVM." > These contributors have been holding back patches for quite some time that they’d like to upstream. Corporate contributors (in particular) often have patents on many different things, and while it is reasonable for them to grant access to patents related to LLVM, the wording in the Developer Policy can be interpreted to imply that unrelated parts of their IP could accidentally be granted to LLVM (through “scope creep”). [..] > This is a complicated topic that deals with legal issues and our primary goal is to unblock contributions from specific corporate contributors." Legally dubious relicensing was not only unnecessary, it is now preventing 9.0> use and future contributions, OpenBSD, which has a long history of opposing Apache 2.0. And using LLVM/Clang as the default compiler for the kernel/userland and a ports tree with 10,000 software packages. https://marc.info/?l=openbsd-misc&m=147503691302850&w=2 https://marc.info/?l=openbsd-misc&m=147503691302850&w=2 http://lists.llvm.org/pipermail/llvm-dev/2017-April/112300.html http://lists.llvm.org/pipermail/llvm-dev/2017-April/112300.h...
- nwallin 7y agoI mean this is fine for an advertisement, but it woefully oversells clang if you're trying to meaningfully compare these things. A lot of what they're saying is misleading and or false. In the early days, clang was significantly faster in compilation than GCC. They also barely implemented any code optimization. Now that clang generates code which is about 90% as fast, generally, as C++, its compilation speeds and memory usage have understandably bloated considerably. Note that I say 90% as fast generally. It still hasn't caught up completely. Clang pioneered LTO, but GCC does it better now. Other people have mentioned gcc's previously terrible error message and inability to dumb ASTs. I don't think this is up to HN standards.
- dman 7y agogcc error messages have improved massively since llvm came out.
- nwallin 7y agoYes. I don't believe clang is any better than GCC anymore. But other commenters have talked about it, and I don't want to be redundant.
- dxf 7y agoI think it's great that gcc, Clang, and MSVC all push each other to improve their compile/link performance, code generation, error messaging, etc.
- msla 7y agoWhich is why some people get a bit nervous when one tool (clang and the LLVM universe in general, curl, WebKit) becomes such a massive de facto standard it completely marginalizes competition. This is even true if something is Open Source: X11 edged out everything else in that general space (MGR, NeWS) to the point those two things I just mentioned are pretty well forgotten, and we don't know what we lost because of that. It's possible some spaces can't have more than one player due to network effects (like network protocols, such as the Web); the history of the Internet looks like a Pod People or Borg plot where a more diverse ecosystem is consumed and replaced by a single all-consuming entity that gradually assimilates all distinct individuals. What we lost in diversity we gained in losing bizarre email gateways, I suppose. But languages are meant to be written to actual, real-world, written down standards, right? No possibility of friction when moving from one compiler to another, right?
- bla3 7y agoAs far as I know that page is many years old, from when clang was very new and comparing to e.g. Elsa made sense. The gcc comparison is probably pretty out of date.
- qeqeqeqe 7y agoThis info is from 2007, the title should reflect that. This is not a useful post.
- BinaryIdiot 7y agoAs far as I can tell this page first appeared in 2008. Many of these points are outdated (some woefully so). This shouldn't be on the frontpage of HN. If anything, Clang should take this down or revise it.
- fouc 7y agoClang takes up to 90GB of disk space [0] [0] https://lists.llvm.org/pipermail/llvm-dev/2019-April/132028.html https://lists.llvm.org/pipermail/llvm-dev/2019-April/132028....
- endorphone 7y agoThe overwhelming bulk of users are going to install a binary package, not build from source. LLVM 9.0 with Clang, a huge array of tools, etc, is 1.9GB on macOS.
- swiley 7y agoThe point of open source is that individuals from the community can read and modify their tools. Anything that makes that harder is a bad thing, it might be justified but it’s still bad.
- justinclift 7y agoNote that's only when building in debug mode, which doesn't seem to be needed by many people. Most developers who compile from source (eg working on LLVM itself) don't need that. Building in release mode is much smaller probably ~5GB or so (from rough memory, it's been a while).