| | {{infobox |
| | | title = GNU Compiler Collection |
| | | name = GCC |
| | | developer = GNU Project / Free Software Foundation |
| | | first_release = March 22, 1987 (as GNU C Compiler) |
| | | written_in = C and C++ |
| | | license = GPL-3.0-or-later with GCC Runtime Library Exception |
| | | platform = Cross-platform — ~30+ CPU families, every major OS |
| | | website = gcc.gnu.org |
| | }} |
| | |
| | # GCC |
| | |
| | **GCC** — originally the **GNU C Compiler**, today the **GNU Compiler Collection** — is the oldest and most widely ported free compiler toolchain in the world. Richard Stallman released it on March 22, 1987 as the first production-quality free-software compiler, and it became the load-bearing piece of the GNU project: without a compiler that could be freely copied and ported, the rest of GNU's tools — and eventually Linux itself — could not have been built by volunteers on whatever hardware they happened to own. |
| | |
| | Forty years later GCC remains the default toolchain on virtually every Linux and BSD system, the compiler the Linux kernel is built with, and the reference implementation against which the C and C++ standards are measured. Its reach is so total that a new CPU architecture is not considered real until GCC supports it. |
| | |
| | ```fact |
| | GCC's `-fdump-tree-all` and `-fdump-rtl-all` flags can emit every internal representation a program passes through — on a large file, that is hundreds of intermediate dumps from the first parsed tree down to the final scheduler's instruction list. It is the only major toolchain that will show you *everything* it is thinking. |
| | ``` |
| | |
| | # From C compiler to Compiler Collection |
| | |
| | The original 1987 release compiled exactly one language: C, for a handful of Motorola and SPARC targets. Stallman's design — deliberately influenced by the MIT "lambda compiler" research — already separated *language parsing* from *code generation*, which meant new front ends and new targets could be added without touching the shared middle. |
| | |
| | Over the following decades the collection grew into a matrix: |
| | |
| | | Front end | Language | Status | |
| | |---|---|---| |
| | | `gcc` | C | mature — the reference implementation | |
| | | `g++` | C++ | mature — same binary, `libstdc++` | |
| | | `gfortran` | Fortran 77–2023 | mature — scientific computing backbone | |
| | | `GNAT` | Ada 83–2022 | mature — certified toolchains (AdaCore) | |
| | | `gccgo` | Go | lags official Go releases | |
| | | `gccrs` | Rust | in development | |
| | | `gdc` | D | mature | |
| | | `gcobol` | COBOL | active | |
| | | `gm2` | Modula-2 | active | |
| | | `gcj` | Java | removed (GCC 7, 2016) | |
| | |
| | The project is legendary for what it *includes* rather than what it excludes: the same pipeline that compiles embedded Ada for a radiation-hardened satellite processor also compiles COBOL for an IBM mainframe and modern C++23 for a desktop. |
| | |
| | # Architecture — GIMPLE and RTL |
| | |
| | GCC's middle end is a two-IR pipeline. A front end (C, C++, Fortran, Ada, whatever) parses source into a tree, lowers it into **GIMPLE** — a language-independent three-address SSA form — where the high-level optimizers run: constant folding, dead code elimination, loop transformations, inlining, vectorization, devirtualization. |
| | |
| | GIMPLE is then expanded into **RTL** — register-transfer language, GCC's older and lower IR, inherited directly from the 1987 design — where the machine-dependent passes run: instruction selection via *machine descriptions* (`.md` files written in a Lisp-like DSL that describe every instruction pattern a CPU supports), register allocation, instruction scheduling, and peephole optimization. |
| | |
| | The `.md` machine description is the whole porting story: a new CPU family needs a description of its registers, addressing modes, and instruction patterns — typically 5,000–20,000 lines — and every GCC front end immediately works on the new target. That is why gfortran runs on the same obscure microcontrollers C does, and why the first compiler for a new RISC-V variant is always GCC before it is anything else. |
| | |
| | # Why GCC still matters |
| | |
| | **The Linux kernel is a GCC program.** Linus Torvalds has never hidden his opinion that Clang is the better compiler *architecture* — but the kernel uses GCC-specific extensions in thousands of places, and for three decades GCC was the only toolchain that could build it. Clang can now compile the kernel, but GCC remains the reference. |
| | |
| | **It is the optimizer of last resort.** `-O3` in GCC applies roughly 200 optimization passes. Its auto-vectorizer, polyhedral loop optimizer (`GRAPHITE`), link-time optimizer (`-flto`), and profile-guided optimizer (`-fprofile-use`) produce code that on many workloads still beats LLVM — especially on exotic targets where LLVM has no backend at all. |
| | |
| | **The Ada connection is unusually deep.** Every Ada compiler anyone uses — AdaCore's GNAT, the FSF's own GNAT — is a GCC front end. When an Airbus A380's flight control software is certified to DO-178C Level A, the machine code was generated by GCC's RTL backend. [[GNAT]] deserves its own page for this reason: it is simultaneously the most important Ada toolchain ever made and a GCC subproject most programmers have never heard of. |
| | |
| | **gfortran kept Fortran alive.** When the commercial Fortran vendors folded or were acquired, gfortran — the GCC front end — became the de facto Fortran 90/2003/2008/2018 implementation on every platform. Weather models, computational fluid dynamics, quantum chemistry — an enormous fraction of the world's scientific computing still compiles through it. |
| | |
| | **The warning system set the standard.** `-Wall`, `-Wextra`, `-Wpedantic`, `-fanalyzer`, `-fsanitize=` — GCC's diagnostics and sanitizers defined what "the compiler is your first static analyzer" means, a philosophy Clang borrowed and extended. |
| | |
| | # GCC vs Clang — the great rivalry |
| | |
| | The rivalry that began when Apple adopted LLVM in 2005 has made both toolchains dramatically better. Clang's diagnostic quality forced GCC to rewrite its error printer; GCC's warning breadth forced Clang to match; LLVM's modularity inspired GCC's plugin architecture; GCC's GPL discipline inspired LLVM's more permissive approach. Today the two are approximately comparable on mainstream x86/ARM workloads — benchmarks split roughly 50/50 depending on the codebase — but they remain philosophically different: |
| | |
| | | | GCC | LLVM/Clang | |
| | |---|---|---| |
| | | License | GPLv3 + runtime exception | Apache 2.0 with LLVM exception | |
| | | Architecture | monolithic front/middle/back | modular libraries | |
| | | IR | GIMPLE → RTL (two-stage) | single LLVM IR | |
| | | Portability | ~30+ targets, decades-deep | fewer targets, newer | |
| | | Diagnostic style | thorough, historically cryptic | designed for readability | |
| | | Windows support | via MinGW-w64/Cygwin | native (clang-cl) | |
| | | Who uses it | Linux distros, kernel, embedded, GNAT/Ada, gfortran | Apple, Android, FreeBSD, Rust, Swift, Zig | |
| | |
| | They are not enemies — `gcc` and `clang` binaries are frequently interchangeable as `cc` on the same system, and much of the modern C/C++ ecosystem is tested against both. |
| | |
| | # Cross-compilation and bootstrap |
| | |
| | GCC is the canonical cross-compiler. `x86_64-w64-mingw32-gcc` builds Windows binaries from Linux; `arm-none-eabi-gcc` builds bare-metal ARM firmware; a `--target=powerpc64le-linux-gnu` configure flag produces a toolchain emitting code for a different architecture entirely. Nearly every embedded product on Earth — routers, car ECUs, medical devices, satellites — is built by a GCC cross-compiler. |
| | |
| | GCC is also famously **self-hosting**: GCC is written in C and C++, and is built by the previous version of GCC. The three-stage bootstrap (`stage1` compiled by the system compiler → `stage2` compiled by stage1 → `stage3` compiled by stage2, compared byte-for-byte) is itself a correctness check — if stage2 and stage3 differ, the compiler miscompiled itself. |
| | |
| | # The toolchain ecosystem around it |
| | |
| | A GCC install is never just `gcc`: it is `cpp` (the preprocessor), `as` (GNU assembler, through Binutils), `ld`/`gold`/`ld.lld` (linkers), `libgcc`/`libstdc++`/`libgfortran`/`libgnat` (runtime libraries), `gdb` (the GNU debugger), `nm`/`objdump`/`readelf`/`strip`/`ar` (binary utilities), `make`/`cmake`/`ninja` (build drivers), and the cross-prefixed variants of all of them. The phrase "GCC toolchain" describes this whole assembly line. |
| | |
| | # See also |
| | |
| | - [[Compilers]] — the toolchain families compared |
| | - [[LLVM]] — the modular challenger |
| | - [[GNAT]] — GCC's Ada front end |
| | - [[FORTRAN]] — gfortran's language |
| | - [[Ada Programming Language]] · [[C Programming Language]] · [[COBOL]] — languages GCC serves |
| | - [[AdaLogic BASIC]] — ALB's FASM and C backends bypass GCC, but ALB's Ada backend feeds GNAT/GCC directly |
| | - [[GNU]] · [[Linux]] · [[History of Programming]] |
| | |
| | # References |
| | |
| - | 1. Stallman, Richard. "The GNU Manifesto" (1985); GCC 1.0 announcement, March 1987. |
| - | 2. *GCC Internals* — the machine-description and pass documentation, gcc.gnu.org/onlinedocs. |
| + | 1. Stallman, Richard. "The [GNU Manifesto](https://www.gnu.org/gnu/manifesto.html)" (1985); GCC 1.0 announcement, March 1987. |
| + | 2. *[GCC Internals](https://gcc.gnu.org/onlinedocs/gccint/)* — the machine-description and pass documentation, [gcc.gnu.org/onlinedocs](https://gcc.gnu.org/onlinedocs/gccint/). |
| | 3. von Hagen, William. *The Definitive Guide to GCC*, 2nd ed. (Apress, 2006). |
| | 4. Novillo, Diego. "Design and Implementation of Tree SSA" (GCC Developers Summit, 2004) — the GIMPLE paper. |
| - | 5. Bashe et al. *IBM's Early Computers* (MIT Press, 1986) — for the FORTRAN I context GCC inherited. |
| - | 6. gcc.gnu.org — source, release notes, and front-end matrix. |
| + | 5. Bashe et al. *[IBM's Early Computers](https://mitpress.mit.edu/9780262022938/ibms-early-computers/)* (MIT Press, 1986) — for the FORTRAN I context GCC inherited. |
| + | 6. [gcc.gnu.org](https://gcc.gnu.org) — source, release notes, and front-end matrix. |
| | |
| | [[Category:Programming]] |
| | [[Category:Technology]] |
| | [[Category:GNU]] |
| | |