Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 3.2.1 GCC CLANG and LLVM demystification

The readme included with the new Xcode 3.2.1 this week says the following:

  • Static code analysis is fully integrated within the Xcode IDE via the Build and Analyze option under the Build menu or via custom build settings
  • GCC 4.2 is the default system compiler for the 10.6 SDK
  • The optional LLVM compiler is included using two different front ends - the Clang compiler is a leading-edge parser that offers dramatically improved compile times. For maximum compatibility, the GCC LLVM compiler utilizes the LLVM back-end with the GCC 4.2 parser.
  • New optional Clang-LLVM 1.0 compiler uses the much faster Clang front-end parser coupled with the LLVM back-end compiler for fast compiles and fast executable code. Many projects will benefit from this compiler combination, although GCC 4.2 is still the system default. The Clang-LLVM 1.0 compiler will fall back to using LLVM-GCC 4.2 when it encounters C++ code.

Our company has existing projects that are pure C, Objective-C, and Objective-C++ for desktop and iphone. Can someone summarize at a high-level the differences between LLVM, GCC, CLANG, CLANG-LLVM, WordFoo et. al. and explain what they are and when we should be using each and for what? It would be nice to have links to more a detailed explanation, but I'm really just looking for a high-level overview.

like image 471
slf Avatar asked Oct 11 '09 16:10

slf


People also ask

Is LLVM compatible with GCC?

Yes, for C code Clang and GCC are compatible (they both use the GNU Toolchain for linking, in fact.)

Does Xcode include LLVM?

Xcode also includes the LLVM GCC compiler, which uses the GCC compiler front end for maximum compatibility, and the LLVM back end, which takes advantage of LLVM's advanced code generator. This shows the flexibility of a library-based approach to compiler development.

Is LLVM same as Clang?

LLVM is a backend compiler meant to build compilers on top of it. It deals with optimizations and production of code adapted to the target architecture. CLang is a front end which parses C, C++ and Objective C code and translates it into a representation suitable for LLVM.

Does LLVM come with Clang?

Clang operates in tandem with the LLVM compiler back end and has been a subproject of LLVM 2.6 and later. As with LLVM, it is free and open-source software under the Apache License 2.0 software license.


1 Answers

In a nutshell:

Compilers are basically split into two parts. One being the front-end that contains the parser and semantic analysis for the programming language. The front-end produces some kind of intermediate representation of your code. Then there's the backend which takes the stuff the front-end produced, optimizes it, and eventually generates assembly code.

  • GCC: well known compiler, contains both front-ends for various languages and back-ends for many processor architectures
  • LLVM: a set of back-ends for various architectures (and other low-level stuff)
  • clang: a new front-end for C, Objective-C, and C++; uses the LLVM back-ends. You'll get more readable errors and warnings from your compiler and shorter compile times. You might also encounter incompatibilities or bugs; clang is a very young project.
  • LLVM-GCC: GCC's front-end with LLVM's back-end. LLVM's back-end is faster than GCC's.

clang's (Objective-)C++ support is far from being complete so it calls llvm-gcc when it encounters a C++ source file. It also contains the static analyzer that is now integrated into Xcode. Some people say LLVM's back-end generates better code than GCC's but your mileage may vary. LLVM also supports link-time optimizations (which you can enable in Xcode's project settings). They may produce faster code.

Apple wants to replace GCC with clang in the future because they have a policy against GPLv3 licensed code (GCC 4.2 is the last version that's licensed under GPLv2).

like image 164
d0k Avatar answered Sep 22 '22 01:09

d0k