27 ms·
Why Apple Chose Clang (2008)
- sanxiyn 6y agoThis is a very old comparison, circa 2008 (when Clang was started). It's mostly irrelevant today.
- JonathonW 6y agoIt is relevant to why Apple made the clang switch back when that happened, though (at least, inasmuch as there were any reasons other than "GCC is GPL and doesn't work well as a library and we want to integrate it more closely with Xcode").
- CalChris 6y agoTL;DR "GCC is licensed under the GPL license. clang uses a BSD license, which allows it to be used by projects that do not themselves want to be GPL." For example, Apple can keep their internal backends (GPU, some ARMv8 details) proprietary.
- spijdar 6y agoInterestingly, I've seen some internal Apple stuff get sent upstream to LLVM. One example is ILP32 support for AArch64, which is apparently used in the Apple Watch. It looks like all of Apple's modern SoCs are 64 bit only, and in order to reclaim some memory on constrained devices, they're using ILP32 and a 32 bit address space, with 64 bit registers and such. https://lists.llvm.org/pipermail/llvm-dev/2019-January/129788.html https://lists.llvm.org/pipermail/llvm-dev/2019-January/12978...
- ender341341 6y agoIt's honestly not that surprising, keeping the difference between their fork and upstream minimal makes it easier for them, so for things that they don't consider to be their 'secret sauce' it's easier to have the community involved in maintaining it (and everybody ends up winning).
- CalChris 6y agoYes, but that is Apple's choice rather than a licensing requirement. Apple upstreams a ton of stuff, AArch64, GlobalISel, .... But they do this by choice.
- tinus_hn 6y agoSure, but integration like llvm is integrated in Xcode would be impossible without open-sourcing Xcode.
- saagarjha 6y agoThey get upstreamed for the most part, just very slowly. There's a lot of pointer authentication stuff shipping in their toolchains currently that isn't upstream.
- arp242 6y agoIt's not just Apple that was rather miffed with gcc around that time; and it really wasn't just because of the license. See e.g. https://undeadly.org/cgi?action=article&sid=20070915195203#pid_52 https://undeadly.org/cgi?action=article&sid=20070915195203#p...
- mshockwave 6y agonot really...Apple upstream most of their AArch64 backend implementation, just like PlayStation upstream most of their (PS4) toolchain code. The rationale behind this is that maintaining a separated downstream actually has a (surprisingly) high cost.
- pvg 6y agoretitled dupe of https://news.ycombinator.com/item?id=22284397 https://news.ycombinator.com/item?id=22284397
- mhh__ 6y ago- Licence - Not designed to be difficult to extend Everything else is basically irrelevant because as Clang has aged it's both slowed down and reached parity in both compile and execution speed. Phoronix even have GCC faster than Clang at building the Linux Kernel, even in an (according to a comment) biased sample where GCC wasn't built with lto enabled. GCC also (last time I tried) does better debug info. LLVM is much easier to hack on, though, although some parts are more similar than you might expect. https://www.phoronix.com/scan.php?page=news_item&px=GCC-Faster-Kernel-Builds-Clang https://www.phoronix.com/scan.php?page=news_item&px=GCC-Fast... You should try and fettle with both to see what works best for your project.
- segfaultbuserr 6y ago> Clang has aged it's both slowed down and reached parity in both compile and execution speed A serious question: Is it correct to say that any compiler with state-of-the-art optimization cannot be fast, and clang's previous performance advantages were actually due to the lack of various optimization techniques and other features? And is there any investigation and research on the tradeoff of compiler speed/complexity vs. execution performance? Many minimalist purists claim that modern compilers are evil and it's possible to write a small and fast compiler. Yes, but at what cost? And is the cost too large to be justified, or is it that computers are acutally fast enough?
- agumonkey 6y agoBack when Clang popped, I remember gcc devs saying gcc had accumulated too much cruft over the years.
- RcouF1uZ4gsC 6y agoIt is a trade off. However, you can control those trade offs via the optimization switches. You can compare either builds with no optimization vs full optimization.
- psykotic 6y agoIt's more complicated than that. You can see what passes are run by clang with the flags -mllvm -debug-pass=Arguments. It's certainly true that -O0 involves fewer passes than -O1 which involves fewer passes than -O2. But the speed limit is defined by the architecture. A compiler that was engineered for compilation speed with a goal of -O1 tier code quality would have a very different architecture from day 1 (e.g. unified IR, fewer passes, integrated register allocation and code generation). There's been attempts at "punching through the layers" over the years with things like fastisel, but there are limits. That said, all the major compilers can deliver adequate compilation speed on the order of 50-100 kloc/sec for well-structured C code bases. Speed is much more of a serious concern if you're working on large C++ code bases. Or if you're using LLVM as a backend from a language like Julia which does the moral equivalent of C++ template instantiation at runtime and feeds it to LLVM.
- Lammy 6y agoI imagine this page's creative process to be something like: - Okay, we need to think of some reasons besides "It's not GPLv3". - In fact, let's list that one last so it looks like an afterthought that doesn't concern us so much. - Hmm, no, too conspicuous. Make it next-to-last.
- phkahler 6y ago- and let's include 2 other compilers that aren't really even in the game so it looks like we did due diligence as opposed to just writing a rejection of GCC.
- yalogin 6y agoIs there another viable option other than GCC?
- zinekeller 6y agoMSVC /s 2008? Unless you really count MSVC, no. 1998, sure, Apple could just buy (as in acquire the IP rights of) Turbo C.
- mhh__ 6y agoICC hypothetically could've been used
- fanf2 6y ago
- deleted 6y ago[deleted]
- gen220 6y agoThis is a cool repository! fairly old, as others have noted. There's a directory [1] containing some "historical notes" written by the creators of llvm: Chris Lattner and Vikram Adve. One of them is the original clang readme [2]. [1]: https://opensource.apple.com/source/clang/clang-800.0.42.1/src/docs/HistoricalNotes/ https://opensource.apple.com/source/clang/clang-800.0.42.1/s... [2]: https://opensource.apple.com/source/clang/clang-800.0.42.1/src/docs/HistoricalNotes/2007-OriginalClangReadme.txt.auto.html https://opensource.apple.com/source/clang/clang-800.0.42.1/s...
- ehvatum 6y ago> GCC does not require a C++ compiler to build it > GCC front-ends are very mature and already support C++. clang's support for C++ is nowhere near what GCC supports. These things were true when Apple first went with Clang, and this document must date from that time. GCC is now implemented in C++, and Clang’s C++ support is excellent. The only issue I have with my c++17 code in Clang is I can’t yet rely on recursive template parameter pack deduction.
- cptwunderlich 6y agoWhat, since when is GCC implemented in C++? I don't see any of that: https://github.com/gcc-mirror/gcc https://github.com/gcc-mirror/gcc Maybe in libstdc++, but what else would you use there. I wanted to know what register allocation algorithms GCC implements, but I can't even find it. It's all files with cryptic names and hundreds in one directory. You can find _even less_ documentation, talks and blog posts about GCC internals :(
- cygx 6y agoThe move to C++ as implementation language was approved in 2010[1]. The switch got flipped in 2013 with the 4.8 series[2]. [1] https://gcc.gnu.org/legacy-ml/gcc/2010-05/msg00705.html https://gcc.gnu.org/legacy-ml/gcc/2010-05/msg00705.html [2] https://gcc.gnu.org/gcc-4.8/changes.html https://gcc.gnu.org/gcc-4.8/changes.html
- chunsj 6y agoI'm sure on the part of "License to Steal". I'm not sure on the part of "Technical Pros".
- colejohnson66 6y ago> Clang does not implicitly simplify code as it parses it like GCC does. Doing so causes many problems for source analysis tools: as one simple example, if you write "x-x" in your source code, the GCC AST will contain "0", with no mention of 'x'. This is extremely bad for a refactoring tool that wants to rename 'x'. Can someone explain this Clang “pro”? If a refactoring tool wants to rename “x”, it does it to the source, not the AST, no? And if “x-x” is turned into 0 by the parser, why does it matter? Assuming “x” isn’t volatile, “x-x” is indeed 0!
- kristjansson 6y agoA refatoring tool might want to offer semantic renaming. If 'x' occurs in many places textually in the source, the only way to be sure that a rename operation only acts on the same variable, (rather than just the same string) is to (at least partially) parse the source, act on the resulting AST, and use source information in the AST to apply the change to the source. So, to avoid maintaining a separate parser, it would be nice to grab an AST from the compiler - but that AST has to match 1-1 with the source to be useful for refactoring.
- eternalban 6y agoCan't you resolve this by doing a bit of extra work in scopes that have e.g. 'x' in source but not in the corresponding AST? I wasn't sure if generated ASTs were 1-1 matched with source top-level scopes, but apparently they are: http://icps.u-strasbg.fr/~pop/images/front-end.png http://icps.u-strasbg.fr/~pop/images/front-end.png It's a bit more work than cases where AST matches source level expectations, but can't you just walk that sub-tree and figure out that '0' was 'x - x'? http://icps.u-strasbg.fr/~pop/images/plus-expr.png http://icps.u-strasbg.fr/~pop/images/plus-expr.png
- stncls 6y agoMany refactoring tools need the AST (and more) from a frontend to do type-aware refactoring, among other things. If we have, for example, struct a { int x; } sa; struct b { float x; } sb; and we want to rename sa.x into sa.y, then the refactoring tool needs to understand types in order to leave sb.x alone. And if sa.x - sa.x is not in the AST, it will not be changed into sa.y - sa.y which will yield errors.
- leeruns 6y agoCan't talk about superiority of one compared to the other without viewing the landscape of the develop, it needs to run fast, be easy to debug, compile fast. There are trade offs for all. Most serious devs likey run several ide and build chains, ea h offering its own value. For example if you want clean template debugging clang lldb is pretty nice
- dilyevsky 6y agoSlight offtopic: anyone else annoyed by the darwins crappy support for static linking and general extreme lack of documentation? E.g lack of -Bstatic option and similar?
- saagarjha 6y agoApple generally prefers dynamic linking and thus carries over to what they offer to third parties.
- dilyevsky 6y agoYeah i just hate dynamic linking and wish we’d moved past this already. Makes everything more complex for no real gain as far as i can tell...
- tsimionescu 6y agoHow do you update OpenSSL if everything statically links it?
- dilyevsky 6y agoYou still have to reload everything that dynamically linked it wont you? Also that case only applies if you didn’t make any api changes
- tsimionescu 6y agoYou can reboot the system to take care of the reload. That's vastly simpler than updating all dependent programs, especially since updating dependent programs would likely come with other changes that you may not be ready for. And yes, this is mostly useful for taking bug fixes, which most mature libraries release without API changes.
- dilyevsky 6y ago
- j16sdiz 6y agoI think this came from clang source code tar ball, not apple.
- marviio 6y agoI wonder if Swift would have happened if they went with gcc? No Lattner.