翻译完成

This commit is contained in:
刘超智 2021-01-13 22:25:49 +08:00
parent 9f3c2468a9
commit d715e9eeba
2 changed files with 78 additions and 81 deletions

View File

@ -1,81 +0,0 @@
GCC优化 Linux、互联网和一切
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc-paper.jpg?itok=QFNUZWsV)
软件如果不能被电脑运行,那么它就是无用的。而在处理 run-time 性能的问题上即使是最有才华的开发人员也会受编译器的支配——因为如果没有可靠的编译器工具链就无法构建任何重要的东西。GNU Compiler CollectionGCC提供了一个健壮、成熟和高性能的工具帮助您充分发挥你代码的潜能。经过几十年成千上万人的开发GCC 成为了世界上最受尊敬的编译器之一。如果您正在构建应用程序而不使用 GCC那么您可能错过了最佳解决方案。
根据 LLVM.org 的说法GCC 是“如今事实上的标准开源编译器”[1]它可以从内核开始的构建完整的系统。GCC 支持超过 60 种硬件平台,包括 ARM、Intel、AMD、IBM POWER、SPARC、HP PA-RISC 和 IBM Z以及各种操作环境包括 GNU、Linux、Windows、macOS、FreeBSD、NetBSD、OpenBSD、DragonFly BSD、Solaris、AIX、HP- ux 和 RTEMS。它提供了高度兼容的 C/C++ 编译器,并支持流行的 C 库,如 GNU C Libraryglibc、Newlib、musl 和各种 BSD 操作系统中包含的 C库以及 Fortran、Ada 和 GO 语言的前端。GCC 还可以作为一个交叉编译器为运行编译器的平台以外的其他平台创建可执行代码。GCC 是紧密集成的 GNU 工具链的核心组件,由 GNU 项目产生,包括 glibc、Binutils 和 GNU 调试器GDB
“一直以来我最喜欢的 GNU 工具是 GCC。在开发工具非常昂贵的时候GCC 是第二个 GNU 工具它使一个社区能够编写和构建所有其他工具。这个工具一手改变了行业导致了自由软件运动的诞生因为一个好的、自由的编译器是一个社区软件的先决条件。”——Red Hat开源和标准团队的 Dave Neary。[2]
### 优化 Linux
As the default compiler for the Linux kernel source, GCC delivers trusted, stable performance along with the additional extensions needed to correctly build the kernel. GCC is a standard component of popular Linux distributions, such as Arch Linux, CentOS, Debian, Fedora, openSUSE, and Ubuntu, where it routinely compiles supporting system components. This includes the default libraries used by Linux (such as libc, libm, libintl, libssh, libssl, libcrypto, libexpat, libpthread, and ncurses) which depend on GCC to provide correctness and performance and are used by applications and system utilities to access Linux kernel features. Many of the application packages included with a distribution are also built with GCC, such as Python, Perl, Ruby, nginx, Apache HTTP Server, OpenStack, Docker, and OpenShift. This combination of kernel, libraries, and application software translates into a large volume of code built with GCC for each Linux distribution. For the openSUSE distribution nearly 100% of native code is built by GCC, including 6,135 source packages producing 5,705 shared libraries and 38,927 executables. This amounts to about 24,540 source packages compiled weekly. [3]
The base version of GCC included in Linux distributions is used to create the kernel and libraries that define the system Application Binary Interface (ABI). User space developers have the option of downloading the latest stable version of GCC to gain access to advanced features, performance optimizations, and improvements in usability. Linux distributions offer installation instructions or prebuilt toolchains for deploying the latest version of GCC along with other GNU tools that help to enhance developer productivity and improve deployment time.
### Optimizing the Internet
GCC is one of the most widely adopted core compilers for embedded systems, enabling the development of software for the growing world of IoT devices. GCC offers a number of extensions that make it well suited for embedded systems software development, including fine-grained control using compiler built-ins, #pragmas, inline assembly, and application-focussed command-line options. GCC supports a broad base of embedded architectures, including ARM, AMCC, AVR, Blackfin, MIPS, RISC-V, Renesas Electronics V850, and NXP and Freescale Power-based processors, producing efficient, high quality code. The cross-compilation capability offered by GCC is critical to this community, and prebuilt cross-compilation toolchains [4] are a major requirement. For example, the GNU ARM Embedded toolchains are integrated and validated packages featuring the Arm Embedded GCC compiler, libraries, and other tools necessary for bare-metal software development. These toolchains are available for cross-compilation on Windows, Linux and macOS host operating systems and target the popular ARM Cortex-R and Cortex-M processors, which have shipped in tens of billions of internet capable devices. [5]
GCC empowers Cloud Computing, providing a reliable development platform for software that needs to directly manages computing resources, like database and web serving engines and backup and security software. GCC is fully compliant with C++11 and C++14 and offers experimental support for C++17 and C++2a [6], creating performant object code with a solid debugging information. Some examples of applications that utilize GCC include: MySQL Database Management System, which requires GCC for Linux [7]; the Apache HTTP Server, which recommends using GCC [8]; and Bacula, an enterprise ready network backup tool which require GCC. [9]
### Optimizing Everything
For the research and development of the scientific codes used in High Performance Computing (HPC), GCC offers mature C, C++, and Fortran front ends as well as support for OpenMP and OpenACC APIs for directive-based parallel programming. Because GCC offers portability across computing environments, it enables code to be more easily targeted and tested across a variety of new and legacy client and server platforms. GCC offers full support for OpenMP 4.0 for C, C++ and Fortran compilers and full support for OpenMP 4.5 for C and C++ compilers. For OpenACC, GCC supports most of the 2.5 specification and performance optimizations and is the only non-commercial, nonacademic compiler to provide [OpenACC][1] support.
Code performance is an important parameter to this community and GCC offers a solid performance base. A Nov. 2017 paper published by Colfax Research evaluates C++ compilers for the speed of compiled code parallelized with OpenMP 4.x directives and for the speed of compilation time. Figure 1 plots the relative performance of the computational kernels when compiled by the different compilers and run with a single thread. The performance values are normalized so that the performance of G++ is equal to 1.0.
![performance][3]
Figure 1. Relative performance of each kernel as compiled by the different compilers. (single-threaded, higher is better).
[Used with permission][4]
The paper summarizes “the GNU compiler also does very well in our tests. G++ produces the second fastest code in three out of six cases and is amongst the fastest compiler in terms of compile time.” [10]
### Who Is Using GCC?
In The State of Developer Ecosystem Survey in 2018 by JetBrains, out of 6,000 developers who took the survey GCC is regularly used by 66% of C++ programmers and 73% of C programmers. [11] Here is a quick summary of the benefits of GCC that make it so popular with the developer community.
* For developers required to write code for a variety of new and legacy computing platforms and operating environments, GCC delivers support for the broadest range of hardware and operating environments. Compilers offered by hardware vendors focus mainly on support for their products and other open source compilers are much more limited in the hardware and operating systems supported. [12]
* There is a wide variety of GCC-based prebuilt toolchains, which has particular appeal to embedded systems developers. This includes the GNU ARM Embedded toolchains and 138 pre-compiled cross compiler toolchains available on the Bootlin web site. [13] While other open source compilers, such as Clang/LLVM, can replace GCC in existing cross compiling toolchains, these would need to be completely rebuilt by the developer. [14]
* GCC delivers to application developers trusted, stable performance from a mature compiler platform. The GCC 8/9 vs. LLVM Clang 6/7 Compiler Benchmarks On AMD EPYC article provides results of 49 benchmarks ran across the four tested compilers at three optimization levels. Coming in first 34% of the time was GCC 8.2 RC1 using "-O3 -march=native" level, while at the same optimization level LLVM Clang 6.0 came in second with wins 20% of the time. [15]
* GCC delivers improved diagnostics for compile time debugging [16] and accurate and useful information for runtime debugging. GCC is tightly integrated with GDB, a mature and feature complete tool which offers non-stop debugging that can stop a single thread at a breakpoint.
* GCC is a well supported platform with an active, committed community that supports the current and two previous releases. With releases schedule yearly this provides two years of support for a version.
### GCC: Continuing to Optimize Linux, the Internet, and Everything
GCC continues to move forward as a world-class compiler. The most current version of GCC is 8.2, which was released in July 2018 and added hardware support for upcoming Intel CPUs, more ARM CPUs and improved performance for AMDs ZEN CPU. Initial C17 support has been added along with initial work towards C++2A. Diagnostics have continued to be enhanced including better emitted diagnostics, with improved locations, location ranges, and fix-it hints, particularly in the C++ front end. A blog written by David Malcolm of Red Hat in March 2018 provides an overview of usability improvements in GCC 8. [17]
New hardware platforms continue to rely on the GCC toolchain for software development, such as RISC-V, a free and open ISA that is of interest to machine learning, Artificial Intelligence (AI), and IoT market segments. GCC continues to be a critical component in the continuing development of Linux systems. The Clear Linux Project for Intel Architecture, an emerging distribution built for cloud, client, and IoT use cases, provides a good example of how GCC compiler technology is being used and improved to boost the performance and security of a Linux-based system. GCC is also being used for application development for Microsoft's Azure Sphere, a Linux-based operating system for IoT applications that initially supports the ARM based MediaTek MT3620 processor. In terms of developing the next generation of programmers, GCC is also a core component of the Windows toolchain for Raspberry PI, the low-cost embedded board running Debian-based GNU/Linux that is used to promote the teaching of basic computer science in schools and developing countries.
GCC was first released on March 22, 1987 by Richard Stallman, the founder of the GNU Project and was considered a significant breakthrough since it was the first portable ANSI C optimizing compiler released as free software. GCC is maintained by a community of programmers from all over the world under the direction of a steering committee that ensures broad, representative oversight of the project. GCCs community approach is one of its strengths, resulting in a large and diverse community of developers and users that contribute to and provide support for the project. According to Open Hub, GCC “is one of the largest open-source teams in the world, and is in the top 2% of all project teams on Open Hub.” [18]
There has been a lot of discussion about the licensing of GCC, most of which confuses rather than enlightens. GCC is distributed under the GNU General Public License version 3 or later with the Runtime Library Exception. This is a copyleft license, which means that derivative work can only be distributed under the same license terms. GPLv3 is intended to protect GCC from being made proprietary and requires that changes to GCC code are made available freely and openly. To the end user the compiler is just the same as any other; using GCC makes no difference to any licensing choices you might make for your own code. [19]
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2018/10/gcc-optimizing-linux-internet-and-everything
作者:[Margaret Lewis][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/margaret-lewis
[b]: https://github.com/lujun9972
[1]: https://www.openacc.org/tools
[2]: /files/images/gccjpg-0
[3]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc_0.jpg?itok=HbGnRqWX "performance"
[4]: https://www.linux.com/licenses/category/used-permission

View File

@ -0,0 +1,78 @@
GCC优化 Linux、互联网和一切
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc-paper.jpg?itok=QFNUZWsV)
软件如果不能被电脑运行,那么它就是无用的。而在处理 run-time 性能的问题上即使是最有才华的开发人员也会受编译器的支配——因为如果没有可靠的编译器工具链就无法构建任何重要的东西。GNU Compiler CollectionGCC提供了一个健壮、成熟和高性能的工具帮助您充分发挥你代码的潜能。经过几十年成千上万人的开发GCC 成为了世界上最受尊敬的编译器之一。如果您正在构建应用程序而不使用 GCC那么您可能错过了最佳解决方案。
根据 LLVM.org 的说法GCC 是“如今事实上的标准开源编译器”[1]它可以从内核开始的构建完整的系统。GCC 支持超过 60 种硬件平台,包括 ARM、Intel、AMD、IBM POWER、SPARC、HP PA-RISC 和 IBM Z以及各种操作环境包括 GNU、Linux、Windows、macOS、FreeBSD、NetBSD、OpenBSD、DragonFly BSD、Solaris、AIX、HP- ux 和 RTEMS。它提供了高度兼容的 C/C++ 编译器,并支持流行的 C 库,如 GNU C Libraryglibc、Newlib、musl 和各种 BSD 操作系统中包含的 C 库,以及 Fortran、Ada 和 GO 语言的前端。GCC 还可以作为一个交叉编译器为运行编译器的平台以外的其他平台创建可执行代码。GCC 是紧密集成的 GNU 工具链的核心组件,由 GNU 项目产生,包括 glibc、Binutils 和 GNU 调试器GDB
“一直以来我最喜欢的 GNU 工具是 GCC。在开发工具非常昂贵的时候GCC 是第二个 GNU 工具,它使一个社区能够编写和构建所有其他工具。这个工具一手改变了行业,导致了自由软件运动的诞生,因为一个好的、自由的编译器是一个社区软件的先决条件。”—— Red Hat 开源和标准团队的 Dave Neary。[2]
### 优化 Linux
作为 Linux 内核源代码的默认编译器GCC 提供了可靠、稳定的性能以及正确构建内核所需的扩展。GCC 是流行的 Linux 发行版的标准组件,比如 ArchLinux、CentOS、Debian、Fedora、openSUSE 和 Ubuntu在这些发行版中GCC 通常用来编译支持系统的组件。这包括 Linux 使用的默认库(如 libc、libm、libintl、libssh、libssl、libcrypto、libexpat、libpthread 和 ncurses这些库依赖于 GCC 来提供可靠性和高性能,并且使应用程序和系统程序可以访问 Linux 内核功能。发行版中包含的许多应用程序包也是用 GCC 构建的,例如 Python、Perl、Ruby、nginx、Apache HTTP 服务器、OpenStack、Docker 和 OpenShift。各个 Linux 发行版使用 GCC 构建的大量代码组成了内核、库和应用程序软件。对于 openSUSE 发行版,几乎 100% 的本机代码是由 GCC 构建的,包括 6135 个源程序包5705 个共享库和 38927 个可执行文件。这相当于每周编译 24540 个源代码包。[3]
Linux 发行版中包含的 GCC 的基本版本用于创建定义系统应用程序二进制接口ABI的内核和库。用户空间开发者可以选择下载 GCC 的最新稳定版本以获得高级功能、性能优化和可用性改进。Linux 发行版提供安装说明或预构建的工具链,用于部署最新版本的 GCC 以及其他 GNU 工具,这些工具有助于提高开发人员的工作效率和缩短部署时间。
### 优化互联网
GCC 是嵌入式系统中被广泛采用的核心编译器之一支持为日益增长的物联网设备开发软件。GCC 提供了许多扩展,使其非常适合嵌入式系统软件开发,包括使用编译器内置的细粒度控制、#pragmas、内联汇编和以应用程序为中心的命令行选项。GCC 支持广泛的嵌入式体系结构,包括 ARM、AMCC、AVR、Blackfin、MIPS、RISC-V、Renesas Electronics V850、NXP 和 Freescale Power 处理器可以生成高效、高质量的代码。GCC 提供的交叉编译功能是开源社区至关重要的功能,预构建的交叉编译工具链[4]是被广泛运用的工具。例如GNU ARM 嵌入式工具链是集成和已被验证的软件包,具有 ARM 嵌入式 GCC 编译器、库和裸机软件开发所需的其他工具。这些工具链可用于在 Windows、Linux 和 macOS 主机操作系统上对流行的 ARM Cortex-R 和 Cortex-M 处理器进行交叉编译,这些处理器已在数百亿台支持互联网的设备中发布。[5]
GCC 支持云计算,为需要直接管理计算资源的软件提供可靠的开发平台,如数据库和 web 服务引擎以及备份和安全软件。GCC 完全兼容 C++ 11 和 C++ 14为 C++ 17 和 C++ 2a [6] 提供实验支持,创建具有可靠调试信息的性能目标代码。使用 GCC 的应用程序的一些例子包括MySQL 数据库管理系统,它依赖于 Linux 的 GCC [7]Apache HTTP 服务器,它建议使用 GCC [8]Bacula一个企业级网络备份工具它依赖于 GCC。[9]
### 优化一切
为了研究和开发用于高性能计算(HPC)的科学代码GCC 提供了成熟的 C、C++ 和 Fortran 前端,并支持基于指令的并行编程的 OpenMP 和 OpenACC api。因为 GCC 提供了跨计算环境的可移植性它使得代码能够更容易地在各种新的和遗留的客户机和服务器平台上进行测试。GCC 为 C, C++ 和 Fortran 编译器提供了 OpenMP 4.0 的完整支持,为 C 和 C++ 编译器提供了 OpenMP 4.5 完整支持。对于 OpenACC, GCC 支持大多数 2.5 规范和性能优化,并且是唯一提供 [OpenACC][1] 支持的非商业、非学术编译器。
代码性能是这个社区的一个重要参数GCC 提供了一个坚实的性能基础。Colfax Research 于 2017 年 11 月发表的一篇论文评估了 C++ 编译器在 OpenMP 4.x 指令下并行编译代码的速度和代码运行速度。图 1 描绘了不同编译器编译并使用单个线程运行时计算内核的相对性能。使 G++ 的性能标定为 1.0,将其他编译器性能值规范化处理。
![performance][3]
图1 为由不同编译器编译的每个内核的相对性能。(单线程,越高越好)。
[Used with permission][4]
论文总结道“GNU 编译器在我们的测试中也做得很好。G++ 在六种情况中的三种情况下生成的代码速度是第二快的,并且在编译时间方面是最快的编译器之一。”[10]
### 谁在用 GCC?
在 JetBrains 2018 年的开发者生态状况调查中,在接受调查的 6000 名开发者中66% 的 C++ 程序员和 73% 的 C 程序员经常使用 GCC。[11] 以下简要介绍 GCC 的优点,正是这些优点使它在开发人员社区中如此受欢迎。
* 对于需要为各种新的和遗留的计算平台和操作环境编写代码的开发人员GCC 提供了对最广泛的硬件和操作环境的支持。硬件供应商提供的编译器主要侧重于对其产品的支持,而其他开源编译器在所支持的硬件和操作系统方面则受到很大限制。[12]
* 有各种各样的基于 GCC 的预构建工具链,这对嵌入式系统开发人员特别有吸引力。这包括 GNU ARM 嵌入式工具链和 Bootlin 网站上提供的 138 个预编译交叉编译器工具链。[13] 虽然其他开源编译器(如 Clang/LLVM可以取代现有交叉编译工具链中的 GCC但开发人员需要完全重建这些工具链。[14]
* GCC 通过成熟的编译器平台向应用程序开发人员提供可靠、稳定的性能。在 AMD EPYC 平台上用 GCC 8/9 与 LLVM Clang 6/7 编译器基准测试的文章提供了 49 个基准测试的结果,这些测试的编译器在三个优化级别上运行。使用 “-O3 -march=native”级别的 GCC 8.2 RC1 在 34% 的时间里排在第一位,而在相同的优化级别 LLVM Clang 6.0 在 20% 的时间里赢得了第二位。[15]
* GCC 为编译调试 [16] 提供了改进的诊断并为运行调试提供了准确而有用的信息。GCC 与 GDB 紧密集成GDB 是一个成熟且功能齐全的工具,它提供“不间断”调试,可以在断点处停止单个线程。
* GCC 是一个受良好支持的平台,它有一个活跃的、承诺的社区,支持当前版本和以前的两个版本。对于每年发布一次的计划,这为一个版本提供了两年的支持。
### GCC仍然在继续优化 Linux互联网和所有事情
GCC 作为世界级的编译器继续向前发展。GCC 的最新版本是 8.2,于 2018 年 7 月发布,增加了对即将推出的 Intel CPU、更多 ARM CPU 的硬件支持,并提高了 AMD 的 ZEN CPU 的性能。初始 C17 支持已经添加到 C++ 2A 的初始工作中。诊断继续得到改进,包括更好的发射诊断,改进的定位、定位范围,并修复提示,特别是在 C++ 前端。Red Hat 的 David Malcolm 在 2018 年 3 月撰写的博客概述了 GCC 8 中的可用性改进。[17]
新的硬件平台继续依赖 GCC 工具链进行软件开发,例如 RISC-V这是一种对机器学习、人工智能AI和物联网细分市场感兴趣的免费开放 ISA。GCC 仍然是 Linux 系统持续开发的关键组件。Clear Linux Project for Intel Architecture 是一个针对云、客户端和物联网用例构建的新兴发行版,它提供了一个很好的示例,说明如何使用和改进 GCC 编译器技术来提高基于 Linux 的系统的性能和安全性。GCC 还被用于微软 Azure Sphere 的应用程序开发,这是一个基于 Linux 的物联网应用程序操作系统,最初支持基于 ARM 的联发科 MT3620 处理器。在开发下一代程序员方面GCC 也是树莓派的 Windows 工具链的核心组件,树莓派是一种运行基于 Debian 的 GNU/Linux 的低成本嵌入式板,用于促进学校和发展中国家的基础计算机科学教学。
GCC 于 1987 年 3 月 22 日由 GNU 项目的创始人 richardstallman 首次发布,它被认为是一个重大突破,因为它是第一个作为自由软件发布的可移植的 ANSI C 优化编译器。GCC 由来自世界各地的程序员组成的社区在指导委员会的指导下维护该指导委员会确保对项目进行广泛的、有代表性的监督。GCC 的社区方法是它的优势之一,它形成了一个由开发人员和用户组成的庞大而多样化的社区,为项目做出贡献并提供支持。根据 Open Hub“GCC 是世界上最大的开源团队之一,在 Open Hub 上的所有项目团队中排名前 2%。”[18]
关于 GCC 的许可问题人们进行了大量的讨论其中大多数是混淆而不是启发。GCC 在 GNU 通用公共许可证版本 3 或更高版本下发布,但运行时库例外。这是一个 copyleft 许可这意味着衍生作品只能在相同的许可条款下分发。GPLv3 旨在保护 GCC 不被私有化,并要求对 GCC 代码的更改可以自由公开地进行。对于“最终用户”来说,编译器与其他编译器完全相同;使用 GCC 对您自己的代码所做的任何许可选择都没有区别。[19]
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2018/10/gcc-optimizing-linux-internet-and-everything
作者:[Margaret Lewis][a]
选题:[lujun9972][b]
译者:[Chao-zhi](https://github.com/Chao-zhi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/margaret-lewis
[b]: https://github.com/lujun9972
[1]: https://www.openacc.org/tools
[2]: /files/images/gccjpg-0
[3]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc_0.jpg?itok=HbGnRqWX "performance"
[4]: https://www.linux.com/licenses/category/used-permission