GCC Lines of Code: What the Count Includes
The GNU Compiler Collection (GCC) contains roughly 15–16 million lines of code in its current release, but that figure is not a single, fixed number: it depends on which version you count, whether you include the C and C++ standard libraries, and whether you count generated files. The most commonly cited number, about 15.4 million lines for GCC 12, comes from the project’s own gcc/ directory and includes the compiler front ends, middle end, back ends, and supporting runtime libraries, but excludes the separate libstdc++ source and the build-generated files.
The Project’s Own Count
GCC is developed as a single source tree with several top-level directories. The core compiler lives in gcc/, and that is the directory the project’s maintainers refer to when they give a line count. For GCC 12.2, the gcc/ directory contains about 7.5 million lines of C and C++ source, plus another 7.9 million lines of headers, machine descriptions, and build scripts. That gives the 15.4 million figure. The count is taken from the source files that are actually compiled or processed by the build system, not from the raw repository including every generated file.
What the Count Does Not Include
The 15.4 million number deliberately excludes several large components that ship with GCC but live outside the gcc/ directory:
- libstdc++ – the C++ standard library, which adds roughly 3.5 million lines of its own (headers and source).
- libgcc – the low-level runtime support library, about 100,000 lines.
- libgfortran, libgo, libobjc, libsanitizer – runtime libraries for Fortran, Go, Objective-C, and sanitizers, together adding another 1–2 million lines.
- Generated files – the build process creates C files from machine description (.md) files and from parser generators (like bison). Those generated files are not counted in the source line total because they are reproducible from the source.
If you include everything in the GCC release tarball, the total is closer to 20–22 million lines. The difference matters because a casual reader might see “15 million” and assume that is the whole compiler, when it is only the core.
How the Count Is Measured
Line counts are usually produced with a tool like cloc or wc -l, but the results vary by tool. cloc ignores blank lines and comment-only lines by default, while wc -l counts every newline. The GCC project itself does not publish an official count in the release notes; the numbers you see in articles come from independent measurements. For a given version, the difference between cloc and wc -l can be 20–30% because GCC source files are heavily commented and have many blank lines for readability.
Another subtlety: GCC’s source is written in C and C++, but the machine description files (.md) are a domain-specific language that describes instruction patterns. Those files are counted as source, and they are substantial – about 1.5 million lines across all targets. They are not “code” in the traditional sense, but they are part of what makes the compiler work.
Why the Number Changes Over Time
GCC grows with each release. The 4.8 release (2013) had about 8 million lines in gcc/; GCC 8 (2018) was around 12 million; GCC 12 (2022) is 15.4 million. The growth comes from new target architectures (RISC-V, for example), new language front ends (GCC 13 added Modula-2), and ongoing optimization work. The count also jumps when a new language front end is merged, because each front end adds tens of thousands of lines for parsing and semantic analysis.
Comparing with Other Compilers
To put the number in perspective, LLVM/Clang – the main open-source alternative – has a similar size. The LLVM core plus Clang is also around 15–16 million lines, though the exact figure depends on which subprojects you include (LLVM includes the debugger, libc++, and other tools). GCC is often described as having a larger codebase because it supports more target architectures and more front ends (C, C++, Fortran, Ada, Go, D, Modula-2, Objective-C) than Clang (C, C++, Objective-C, and experimental Fortran). But the raw line counts are comparable.
Common Misconceptions
One frequent mistake is to quote the line count for the whole GCC repository as if it were the compiler itself. Another is to assume that a higher line count means a worse compiler. GCC’s size is partly a result of its portability – it supports dozens of CPU architectures, each with its own machine description and target-specific code. That is not bloat; it is a feature. The trade-off is that GCC is harder to modify than a smaller compiler, but the codebase has been maintained for over 30 years and is well structured.
Another misconception is that the line count includes the test suite. The GCC test suite lives in gcc/testsuite/ and contains about 5 million lines of test cases. Those are not counted in the 15.4 million figure because they are not compiled into the compiler – they are run against it. If you include the tests, the total for gcc/ rises to over 20 million.
Why the Exact Number Matters (and Why It Doesn’t)
For most users, the line count is trivia. It does not affect how GCC behaves or how well it optimizes code. But the number is useful for project managers, researchers studying open-source scale, and developers considering contributing to GCC. It gives a rough idea of the learning curve: reading the entire core is a multi-month effort. The count also matters for security audits – a larger codebase means a larger attack surface, though GCC’s long history and active review process mitigate that.
If you want to reproduce the count yourself, download a GCC release tarball, extract it, and run cloc gcc/ (excluding the testsuite directory) or use wc -l $(find gcc -name '*.c' -o -name '*.h' -o -name '*.md'). You will get a number close to 15 million, but not exactly the same as any published figure because the exact set of files varies by tool and by what you consider “source.”
Frequently Asked Questions
Does the 15 million include the C library (glibc)?
No. GCC does not include glibc; glibc is a separate project maintained by the GNU C Library developers. GCC only provides the compiler and its own runtime libraries (libgcc, libstdc++, etc.). The system C library is part of the operating system, not the compiler.
Why is GCC so much bigger than a simple compiler like TCC?
Tiny C Compiler (TCC) is about 60,000 lines because it only targets x86 and only supports C, with minimal optimization. GCC supports dozens of architectures, many languages, and performs aggressive optimizations. Each added feature requires code, so the size scales accordingly.
Is the line count increasing or decreasing?
It is increasing. Each major release adds new targets, new optimizations, and new language features. Occasionally a front end is removed (e.g., Java was removed in GCC 7), but the overall trend is upward.
How many lines are in the Linux kernel compared to GCC?
The Linux kernel is much larger – around 30 million lines for recent versions. The kernel includes drivers for every piece of hardware, which is why it dwarfs a compiler. GCC’s 15 million lines are focused on a single task: translating source code into machine code.
Does the count include the build system files?
Yes, the 15.4 million figure includes Makefiles, configure scripts, and other build infrastructure that lives in gcc/. These files are not compiled into the compiler, but they are part of the source tree and are necessary to build it.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.