In association with heise online

Looking for a real life

GCC has come a long way from its origins but the hegemony of GCC as the free compiler of choice cannot be taken for granted.

The current challenger is LLVM. LLVM is often talked about as a replacement for GCC, not least by Linus Torvalds in 2007, in what may have been a throw away complaint directed at the GCC developers which ends with "I think LLVM is a much more interesting project."

GCC tends to adhere to ANSI standards and is reluctant to support extensions to the standards - with some exceptions, which are for the most part historical - and this has been a source of frustration to some developers. Torvalds has his own take on this, which is that "For some reason, compiler developers seem to be far enough removed from 'real life' that they have a tendency to talk in terms of 'this is what the spec says' rather than 'this is a problem'."

A compiler writer might reply that an open standard is an open standard whether it is the standard for OOXML or ODF or a language, and the dilemma for the compiler writer is that real life is inconsistent.

Apple talk

LLVM grew out of a paper entitled "Architecture for a Next-Generation GCC"PDF, by Chris Lattner and Vikram Adve, which was presented to the Annual GCC Developers Summit in 2003, and was developed at the University of Illinois at Urbana, Champaign. Chris Lattner is now employed by Apple, and Apple has a significant investment in the development of LLVM and Clang, a native C / C++ compiler built on the framework of LLVM.

Both are released under a BSD-style licence which allows developers or chip manufacturers to add proprietary extensions and modifications; this has the perceived advantage of preserving 'trade secrets' for some chip manufacturers, or alternatively, of building proprietary 'front ends' for proprietary languages.

As Andreas Stiller observes, compiler code can reveal your secrets: "For architectural in-depth characteristics, the GNU and Open64 source files represent a fertile Zen garden. As Dresdenboy blogged, they were an early source for data on cache sizes and latencies of AMD's next generation of processors called Bulldozer and have now disclosed the number of functional units: 4 ALUs, 3 AGUs, 4 FPUs."

The flip side of this is that there is no requirement to release the GPL'd code before the chip is out there, and closed 'back ends' limit the opportunities for programmers to experiment and explore.

Part of Apple's interest in an alternative compiler was because of the low priority given by GCC developers to Objective-C development, and the greater flexibility and control it derives from its stewardship of LLVM and Clang. Apple intends LLVM and Clang to be the default compilation option for future releases of OS X.

On your toes

LLVM and Clang have an immediate appeal to programmers. LLVM is fresh and new, and GCC has been around forever. LLVM and Clang have the advantage of a clean code base and the input of twenty-five years of academic advances in compiler technology, including the cumulative experience of GCC.

LLVM provides modularity, and utilises modified GCC 'front ends' to support languages that lack a native LLVM implementation. LLVM is developer friendly and elements of the framework have been used externally to compile languages such as Ruby, Python, Haskell, Java, D, PHP, Pure and Lua, and can be used to interface both proprietary and free IDEs.

Clang compiles code faster than GCC (which may or may not be explained by processor hungry optimisations in GCC), has a JIT option, and claims a more friendly debugger and more coherent error messages. However benchmarks of code compiled with LLVM, show that code generated by GCC tends to be about 10 per cent faster (which may also be explained by optimisations in GCC).

GCC retains the advantage of extreme portability and multi-language capability. But its greatest asset may be its independence from any single commercial entity, which ensures adherence to standards and support from all sectors of industry. GCC has been emblematic of free software for more than twenty years, and while any piece of software is ultimately replaceable, its continued growth and success may well be a measure of free software's continuing ability to stretch its horizons.

GCC 4.5 was released in April 2010. A major new feature is a plug-in facility for third party code. One of the first plug-ins on offer is DragonEgg, an LLVM back end for GCC.

For other feature articles by Richard Hillesley, please see the archive.

Print Version | Permalink: http://h-online.com/-1066831
  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit
 


  • July's Community Calendar





The H Open

The H Security

The H Developer

The H Internet Toolkit