GNU Compiler Collection
The
GNU Compiler Collection (usually shortened to
GCC) is a set of
programming language compilers produced by the
GNU Project. It is
free software distributed by the
Free Software Foundation (FSF) under the
GPL, and is a key component of the
GNU toolchain. It is the standard compiler for the
open source Unix-like operating systems.
Originally named the
GNU C Compiler, because it only handled the
C programming language, GCC was later extended to compile
C++,
Fortran,
Ada, and others.
Overview
GCC was originally written by Richard Stallman in 1987 as the compiler for the GNU Project, in order to have a compiler available that was free software. Its development was closely shepherded by the FSF.
In 1997, a group of developers dissatisfied with the slow pace and closed nature of official GCC development formed a project called EGCS (Experimental/Enhanced GNU Compiler System) which merged several experimental forks into a single project forked from GCC. EGCS development subsequently proved sufficiently more vital than GCC development that EGCS was eventually "blessed" as the official version of GCC in April 1999.
GCC is now maintained by a varied group of programmers from around the world. It has been ported to more kinds of processors and operating systems than any other compiler.
GCC has been adopted as the main compiler used to build and develop for a number of systems, including GNU/Linux, the BSDss, Mac OS X, NeXTSTEP and BeOS.
Languages
As of version 3.2, the standard compiler release includes front ends for:\n* Ada (GCC for Ada aka GNAT)\n* C\n* C++ (GCC for C++ aka G++)\n* Fortran (GCC for Fortran aka G77)\n* Java (GCC for Java aka GCJ)\n* Objective-C\n* Treelang
A front end for CHILL was previously included, but has been dropped owing to a lack of maintenance. Pascal, Modula-2, Modula-3, Mercury and Objective-C++ frontends also exist.
Architectures
GCC target processors (as of version 3.2) include:\n* Alpha\n* ARM\n* H8/300\n* System/370, System 390\n* X86 and X86-64\n* IA-64 "Itanium"\n* Motorola 68000\n* Motorola 88000\n* MIPS\n* PA-RISC\n* PDP-11\n* PowerPC\n* SuperH\n* SPARC\n* VAX
Lesser-known target processors supported in the standard release have included A29K, ARC, Atmel AVR, C4x, CRIS, D30V, DSP16xx, FR-30, FR-V, Intel i960, IP2000, M32R, 68HC11, MCORE, MMIX, MN10200, MN10300, NS32K, ROMP, Stormy16, V850, Xtensa. Additional processors, such as the D10V and Z8000, have been supported by GCC versions maintained separately from the FSF version.
Structure
GCC's external interface is generally standard for a Unix compiler. Users invoke a driver program named gcc, which interprets command arguments, decides which language compilers to use for each input file, runs the assembler on their output, and then possibly runs the linker to produce a complete program.
Each of the language compilers is a separate program that takes in source code and produces assembly language. All have a common internal structure; a per-language front end that parses the languages and produces an abstract syntax tree ("tree" for short), and a back end that converts the trees to GCC's Register Transfer Language, runs various compiler optimizations, then produces assembly language using architecture-specific pattern matching originally based on an algorithm of Jack Davidson and Chris Fraser.
Nearly all of GCC is written in C, although much of the Ada frontend is written in Ada.
Front ends
Frontends vary internally, having to produce trees that can be handled by the backend. Some parsers use a YACC-type grammar specification, and the others are hand-coded recursive descent parsers.
The tree representation of a program is more-or-less independent of the processor being targeted. However, confusingly, the meaning of a tree is somewhat different for different language front-ends, and front-ends can provide their own tree codes. They are implemented as C language unions.
Back end
The behavior of the GCC back end is partly specified by preprocessor macros and functions specific to a target architecture, for instance to define the endianness, word size, and calling conventions. The front part of the back end uses these to help decide RTL generation, so although GCC's RTL is nominally processor-independent, the initial sequence of abstract instructions is already adapted to the target.
The exact set of GCC optimizations varies from release to release as it develops, but includes the standard algorithms, such as jump optimization, jump threading, common subexpression elimination, instruction scheduling, and so forth.
A "reloading" phase changes abstract (pseudo-) registers into real machine registers, using data collected from the patterns describing the target's instruction set. This is a somewhat complicated phase, because it must account for the vagaries of all of GCC's targets.
The final phase is somewhat anticlimactic, since the patterns to match were generally chosen during reloading, and so the assembly code is simply built by running substitutions of registers and addresses into the strings specifying the instructions.
Reference
\n* Richard M. Stallman, Using and Porting the GNU Compiler Collection (Free Software Foundation, 1988-2004)\n* An Introduction to GCC (ISBN 0954161793)
See also
\n*GCC-XML\n*GCC Introspector\n*LLVM
External links
\n* GCC homepage\n* Building and Testing gcc/glibc cross toolchains\n* Wendling's overview of trees
Category:GNU project software\nCategory:Computer programming tools
\n\n\n\n\n\n\n\n\n