# GNU编译器集合

GNU编译器集合（GNU Compiler Collection，GCC）是一套自由软件编译器套件，它将C、C++、Objective-C、Objective-C++、Fortran、Ada、Go、D、Modula-2、COBOL、Rust和Algol 68的源代码翻译为机器码，并附带这些语言的运行时库，如libstdc++<sup>[1](https://gcc.gnu.org/index.html)</sup>。它最初是作为GNU操作系统的编译器而编写的，该系统在尊重用户自由的意义上被开发为100%的自由软件<sup>[1](https://gcc.gnu.org/index.html)</sup>。该项目定期发布版本，可运行于多种原生与交叉目标平台，包括GNU/Linux；重大决策由一个指导委员会依据使命声明作出<sup>[1](https://gcc.gnu.org/index.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 首次发布 | Beta 0.9于1987年3月22日发布；1.0版于1987年5月23日发布<sup>[2](https://gcc.gnu.org/releases.html)</sup> |
| 名称 | 正式名称为“GNU编译器集合”；历史上曾称“GNU C编译器”，这一用法在指代C编译器时仍很常见<sup>[3](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)</sup> |
| 语言 | C、C++、Objective-C、Objective-C++、Fortran、Ada、Go、D、Modula-2、COBOL、Rust和Algol 68的前端<sup>[1](https://gcc.gnu.org/index.html)</sup> |
| 近期版本 | GCC 16.1（2026年4月30日）、GCC 16.2（2026年8月7日）；开发主干为GCC 17.0<sup>[2](https://gcc.gnu.org/releases.html)</sup> |
| 新前端 | COBOL于2025年4月17日加入（由COBOLworx贡献）；实验性Algol 68于2025年11月30日加入<sup>[4](https://www.gnu.org/software/gcc/index.html)</sup><sup> • </sup><sup>[1](https://gcc.gnu.org/index.html)</sup> |
| 内部表示 | 高层优化使用GENERIC和GIMPLE树，随后使用RTL表示进行机器级工作<sup>[5](https://gcc.gnu.org/onlinedocs/gccint/)</sup> |
| 自举要求 | GCC 15之前的版本可用ISO C++11编译器自举，10.5之前的版本可用ISO C++98，4.8之前的版本可用ISO C89<sup>[6](https://gcc.gnu.org/install/prerequisites.html)</sup> |

## 语言与前端

GCC是若干主要编程语言编译器的集成发行版<sup>[3](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)</sup>。编译器中特定于某一语言的部分是前端；与语言无关的组件由所有编译器共享，包含大部分优化器和为各种处理器生成机器码的后端<sup>[3](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)</sup>。

对于C以外的语言，编译器通常带有不同的名称：G++处理C++，gcobol处理COBOL，GNAT处理Ada。<sup>[3](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)</sup>除集成前端外，还有若干支持Mercury等语言的前端单独维护，必须与GCC本体一同构建<sup>[3](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)</sup>。

语言名单持续增长。COBOL前端于2025年4月17日加入，由COBOLworx贡献<sup>[4](https://www.gnu.org/software/gcc/index.html)</sup>；实验性Algol 68前端随后于2025年11月30日加入<sup>[1](https://gcc.gnu.org/index.html)</sup>。所包含的编译器均未实现为输出另一种高级语言（如C）的预处理器——这种设计曾在C++和Fortran编译器中很常见；它们都直接生成机器码<sup>[3](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)</sup>。

## 历史与版本

发布的时间线始于1987年3月22日的beta 0.9，随后在1987年和1988年间快速推出了一系列1.x版本，其中1.0版日期为1987年5月23日<sup>[2](https://gcc.gnu.org/releases.html)</sup>。该项目现在并行维护多个发布分支，每个分支只接收回归修复和文档更新。截至2026年中期，受支持的版本为GCC 16.2、15.3、14.4和13.5，而GCC 17.0正在主干上进行一般性开发<sup>[1](https://gcc.gnu.org/index.html)</sup>。

硬件支持随时间变化。在上一年恢复对Intel Itanium（IA-64）的支持后，弃用该支持一事于GCC 16重新提上议程<sup>[7](https://www.tomshardware.com/software/linux/intels-fabled-itanium-refuses-to-die-but-the-end-is-probably-near-deprecation-of-ia-64-support-is-back-on-the-chopping-block-in-gcc-version-16)</sup>。

## 架构与内部结构

内部手册描述了表示的流水线。前端将源代码解析为GENERIC树，再降级为GIMPLE——一种带类型的表示，分析和优化遍在其上运行；随后RTL表示承载机器级代码生成<sup>[5](https://gcc.gnu.org/onlinedocs/gccint/)</sup>。目标支持通过机器描述和目标描述宏来描述，手册还记录了底层运行时库、控制流图、循环分析、插件和链接时优化<sup>[5](https://gcc.gnu.org/onlinedocs/gccint/)</sup>。

人们常将它与LLVM进行结构性对比：GCC为每种目标架构维护单独的后端，而LLVM使用共享的与目标无关的代码生成器，并为不同架构配备目标特定的后端<sup>[8](https://ieee-hpec.org/wp-content/uploads/2024/09/183.pdf)</sup><sup> • </sup><sup>[16](https://llvm.org/docs/WritingAnLLVMBackend.html)</sup>。GCC采用模式匹配方法选择指令，而LLVM使用基于目标描述的表驱动方法<sup>[8](https://ieee-hpec.org/wp-content/uploads/2024/09/183.pdf)</sup>。

## 构建GCC

GCC从源码构建，默认的原生构建在调用`make`时执行三阶段自举，以检验GCC能否正确编译自身<sup>[9](https://gcc.gnu.org/install/configure.html)</sup>。自举要求多年来不断提高：15之前的版本可用ISO C++11编译器自举，10.5之前的版本可用ISO C++98编译器，4.8之前的版本可用ISO C89编译器<sup>[6](https://gcc.gnu.org/install/prerequisites.html)</sup>。在不进行三阶段自举的配置中构建所有语言，需要从现有的GCC二进制文件开始，因为C和C++以外的前端可能在其自身源码中使用GCC扩展<sup>[6](https://gcc.gnu.org/install/prerequisites.html)</sup>。

## 工具与诊断

该发行版附带的不只是编译器。gcov程序测量测试覆盖率，配套工具包括用于离线剖析数据处理的gcov-tool、用于转储剖析数据的gcov-dump，以及用于链接时优化目标文件的lto-dump<sup>[10](https://gcc.gnu.org/onlinedocs/gcc/)</sup>。自GCC 13起，编译器包含一个通过`-fanalyzer`启用的静态分析器，它会发出诸如`-Wanalyzer-double-free`、`-Wanalyzer-use-after-free`、`-Wanalyzer-file-leak`和`-Wanalyzer-tainted-array-index`等警告，每条警告都映射到相应的通用缺陷枚举条目<sup>[11](https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html)</sup>。

GCC的C扩展意义远超编译器本身。Linux内核用C编写，通常以`-std=gnu11`（ISO C11的GNU方言）用`gcc`编译，并全程依赖GNU属性和其他扩展；也支持用`clang`构建<sup>[12](https://www.kernel.org/doc/html/latest/process/programming-language.html)</sup>。

## GCC与Clang的实际比较

GCC和LLVM的Clang是两大主流开源C和C++编译器，二者之间实测的性能差异取决于工作负载和架构。2025年一项关于x86和ARM上向量化的研究报告称，在x86上，GCC对测试套件中54%的循环进行了向量化，Intel ICX编译器为50%，Clang为46%；研究结论是，在任何给定平台上，没有哪个编译器在向量化方面具有确定优势<sup>[13](https://arxiv.org/abs/2502.11906)</sup>。在AArch64高性能计算系统上，情况因基准测试而异：在NVIDIA [Grace Hopper](https://www.edgepedia.org/zh/grace-hopper)和富士通A64FX硬件上进行的一项比较中，GCC在两台机器上都产生了最佳且最一致的GEMM结果，而在Grace Hopper上启用SVE时，LLVM在MiniBude分子动力学代码上优于GCC<sup>[8](https://ieee-hpec.org/wp-content/uploads/2024/09/183.pdf)</sup>。

GCC的体量之大，足以使其本身成为一种工作负载：[SPEC CPU](https://www.edgepedia.org/zh/spec-cpu) 2026基准套件在其SPECrate和SPECspeed整数套件中都将用GCC进行代码编译列为基准测试<sup>[14](https://www.tomshardware.com/pc-components/cpus/new-server-focused-spec-cpu-2026-benchmarking-suite-has-results-for-a-raspberry-pi-5-updated-tools-feature-more-tests-and-can-run-a-wide-range-of-systems)</sup>。编译器的选择也会影响已发布的硬件结果；当AMD用SPEC CPU 2026将其EPYC“Venice”处理器与Nvidia的Vera进行基准比较时，使用的是GCC 16.1，而Nvidia的白皮书使用的是GCC 15.2，这种不一致可能对比较产生重大影响<sup>[15](https://www.tomshardware.com/pc-components/cpus/amd-shares-first-official-benchmarks-for-epyc-venice-cpus-targets-nvidia-company-claims-256-core-chip-is-more-than-twice-as-fast-as-nvidia-vera-96-core-model-20-percent-faster-per-core)</sup>。

## References

1. [GCC, the GNU Compiler Collection - GNU Project](https://gcc.gnu.org/index.html)
2. [GCC Releases - GNU Project](https://gcc.gnu.org/releases.html)
3. [G++ and GCC, Using the GNU Compiler Collection](https://gcc.gnu.org/onlinedocs/gcc/G_002b_002b-and-GCC.html)
4. [GCC, the GNU Compiler Collection - GNU Project (gnu.org)](https://www.gnu.org/software/gcc/index.html)
5. [GNU Compiler Collection (GCC) Internals](https://gcc.gnu.org/onlinedocs/gccint/)
6. [Prerequisites for GCC - GNU Project](https://gcc.gnu.org/install/prerequisites.html)
7. [Intel's Itanium deprecation back on the chopping block in GCC 16, Tom's Hardware](https://www.tomshardware.com/software/linux/intels-fabled-itanium-refuses-to-die-but-the-end-is-probably-near-deprecation-of-ia-64-support-is-back-on-the-chopping-block-in-gcc-version-16)
8. [Comparative Analysis of GCC and LLVM for Performance Optimization on AArch64, IEEE HPEC](https://ieee-hpec.org/wp-content/uploads/2024/09/183.pdf)
9. [Installing GCC: Configuration - GNU Project](https://gcc.gnu.org/install/configure.html)
10. [Top, Using the GNU Compiler Collection (GCC)](https://gcc.gnu.org/onlinedocs/gcc/)
11. [Static Analyzer Options, Using the GNU Compiler Collection (GCC)](https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html)
12. [Programming Language, The Linux Kernel documentation](https://www.kernel.org/doc/html/latest/process/programming-language.html)
13. [Comparison of Vectorization Capabilities of Different Compilers for X86 and ARM CPUs, arXiv](https://arxiv.org/abs/2502.11906)
14. [SPEC CPU 2026 benchmarking suite, Tom's Hardware](https://www.tomshardware.com/pc-components/cpus/new-server-focused-spec-cpu-2026-benchmarking-suite-has-results-for-a-raspberry-pi-5-updated-tools-feature-more-tests-and-can-run-a-wide-range-of-systems)
15. [AMD EPYC Venice benchmarks vs Nvidia Vera, Tom's Hardware](https://www.tomshardware.com/pc-components/cpus/amd-shares-first-official-benchmarks-for-epyc-venice-cpus-targets-nvidia-company-claims-256-core-chip-is-more-than-twice-as-fast-as-nvidia-vera-96-core-model-20-percent-faster-per-core)
16. [Writing an LLVM Backend - LLVM](https://llvm.org/docs/WritingAnLLVMBackend.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Compilers, interpreters, and toolchains

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/gnu-compiler-collection

English original: https://www.edgepedia.org/gnu-compiler-collection
