LLVM vs. GCC for iOS development

23,820

Solution 1

Update: Because people are still finding this answer, I feel like I should provide a suitable update. By now, I hope it's clear that Clang is absolutely the way to go when programming, with Clang being the default compiler in the newer versions of Xcode and supporting ARC and new and upcoming language constructs (array and dictionary subscripting, literals, etc.). There's almost absolutely no reason to compile with GCC anymore, and for codebases using ARC and new features, using plain GCC is no longer relevant or possible (LLVM-GCC may support these features, but it provides no advantage over Clang now that Clang is completely stable).


By now (with LLVM-2.0 included in the Xcode 4.0 beta), LLVM is mature enough for production code use. It compiles a little quicker than GCC, and produces faster code, so use it whenever you can (pretty much, try to avoid GCC if something better is available). The standard Xcode 3.2.5 install contains LLVM-1.6 (not the latest), so I'd recommend either running some speed tests to see if there's a noticeable difference between GCC and LLVM, or compiling Clang from source and getting the latest version.

Essentially, there's no need for GCC any more, LLVM + Clang is more than enough.

Solution 2

Ok, I think none of the answers below tell the whole story, so here's my take on a response to my question:

  • LLVM compiles code faster than GCC, may create code that runs faster, and the Clang frontend provides more accurate error messages than GCC – so there are definitely reasons for switching;

  • that said, the version provided with latest stable Xcode (LLVM 1.6) is not 100% stable yet, you can run into some minor bugs if you're unlucky. So if you want to be safe, you should either compile the latest LLVM (2.0) from source, or stick to GCC for the next few months;

  • in a few months, probably when Apple releases Xcode 4, LLVM 2.0 will be the version that ships with Xcode by default, and then we should all be able to switch to it safely.

Thanks to everyone who responded, feel free to correct me if I got something wrong.

Solution 3

I have an app that seems to crash on launch on the original iPhone running iOS 3.1.3 when compiled with LLVM 2.0, but runs just fine with LLVM-GCC. I support back to iOS 3.1 so this is fatal. Not sure if there's an interaction between LLVM 2.0 and some specific code I have, but it seems best to avoid LLVM if you need to support iOS 3.x unless you can test thoroughly on legacy devices.


Update: It seems that the issue is with the device hardware rather than iOS version. 1st and 2nd generation iOS devices seems to be affected: Original iPhone, iPhone 3G, and 1st and 2nd gen iPod Touch. I believe this means it's limited to ARMv6 architectures.

Also, running a debug build via Xcode's debugger works fine, while release builds installed via iTunes do not. So it might be an interaction between CPU architecture and optimization level with LLVM 2.0.

But in any case, avoid for now ;)

Solution 4

Another major reason to switch to Clang is more accurate (column & line number ranges) and readable error messages.

Solution 5

During the latest WWDC10 they made a point of encouraging developers to use the more current LLVM compiler. I forget the exact tract that they covered it in detail - one of the "new in Xcode". Basically they suggest using LLVM-2.0 when possible, otherwise LLVM-GCC and to avoid GCC alone completely.

If you're a registered iOS developer, you can view most of the sessions free at http://developer.apple.com/videos/wwdc/2010/

Share:
23,820

Related videos on Youtube

Kuba Suder
Author by

Kuba Suder

Independent Mac/iOS and Ruby developer

Updated on May 15, 2020

Comments

  • Kuba Suder
    Kuba Suder almost 4 years

    In latest iOS SDK, Apple provides three compiler options: GCC, LLVM with Clang and LLVM-GCC. I understand more or less what these 3 mean, what LLVM and Clang are, and so on. What I don't know is what this means in practice for iPhone developers. Which of these should I use at this point, as of January 2011? Is LLVM mature enough that I can use it safely without stumbling on bugs in it too often? Does switching to LLVM have any other disadvantages? If it does, then does the speed advantage outweigh them? Are there any other reasons to switch except speed?

  • Kuba Suder
    Kuba Suder over 13 years
    So if I'm running Xcode 3 and I don't want to compile from source, LLVM + GCC is the best option?
  • Itai Ferber
    Itai Ferber over 13 years
    No, just stick with LLVM-1.6 and you'll be fine. Again, there's no reason to use GCC at all, even if combined with LLVM.
  • SinisterMJ
    SinisterMJ over 13 years
    I wouldn't go there quite yet, I've seen and have heard of significant issues yet in LLVM generated code (we had an app store submission crash that only was solved by moving the GCC compiler, at the recommendation of Apple). Possibly one more release and it'll be ready for prime time...
  • SinisterMJ
    SinisterMJ over 13 years
    However it turned out after that, some people (including myself) found some really weird bugs from LLVM only compilation. Not often but it was enough to switch back to GCC for all app store submissions. I still use LLVM for debug builds though. I think early this year LLVM will probably be stable enough to use for submissions.
  • Itai Ferber
    Itai Ferber over 13 years
    Kendall, interesting to hear the other side of things. I've not yet heard of events like this, but of course, it's probably an edge case (otherwise, Apple wouldn't be pushing for LLVM so hard). Anyway, as soon as Xcode 4 gets released (whenever that'll be) we'll all be up to date with the latest version of LLVM, and everything will be alright...
  • JeremyP
    JeremyP over 13 years
    There's a reason that Apple's production version of Xcode still uses GCC by default and that is probably that Apple does not feel that clang is ready for production applications yet. Well, I say "probably", in fact it is a guess on my part. It might just be that C++ support is not 100%.
  • Karthik Kumar Viswanathan
    Karthik Kumar Viswanathan almost 12 years
    LLVM may compile code fast, but the code which runs isn't guaranteed to run faster. I know for a fact that GCC can run unto 190+ compiler passes (including optimization passes on front end and back end) to generate an executable, which is one reason why GCC takes so much time to compile code.
  • Karthik Kumar Viswanathan
    Karthik Kumar Viswanathan almost 12 years
    In fact, pointers to actual benchmarks give better data than our comments: openbenchmarking.org/result/1204215-SU-LLVMCLANG23