Documentation/translations/zh_CN/kbuild/gcc-plugins.rst

Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/kbuild/gcc-plugins.rst

File Facts

System
Linux kernel
Corpus path
Documentation/translations/zh_CN/kbuild/gcc-plugins.rst
Extension
.rst
Size
4234 bytes
Lines
127
Domain
Support Tooling And Documentation
Bucket
Documentation
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

.. SPDX-License-Identifier: GPL-2.0

.. include:: ../disclaimer-zh_CN.rst

:Original: Documentation/kbuild/gcc-plugins.rst
:Translator: 慕冬亮 Dongliang Mu <dzm91@hust.edu.cn>

================
GCC 插件基础设施
================


介绍
====

GCC 插件是为编译器提供额外功能的可加载模块 [1]_。它们对于运行时插装和静态分析非常有用。
我们可以在编译过程中通过回调 [2]_,GIMPLE [3]_,IPA [4]_ 和 RTL Passes [5]_
(译者注:Pass 是编译器所采用的一种结构化技术,用于完成编译对象的分析、优化或转换等功能)
来分析、修改和添加更多的代码。

内核的 GCC 插件基础设施支持构建树外模块、交叉编译和在单独的目录中构建。插件源文件必须由
C++ 编译器编译。

目前 GCC 插件基础设施只支持一些架构。搜索 "select HAVE_GCC_PLUGINS" 来查找支持
GCC 插件的架构。

这个基础设施是从 grsecurity [6]_  和 PaX [7]_ 移植过来的。

--

.. [1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html
.. [2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API
.. [3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html
.. [4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html
.. [5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html
.. [6] https://grsecurity.net/
.. [7] https://pax.grsecurity.net/


目的
====

GCC 插件的设计目的是提供一个用于试验 GCC 或 Clang 上游没有的潜在编译器功能的场所。
一旦它们的实用性得到验证,这些功能将被添加到 GCC(和 Clang)的上游。随后,在所有
支持的 GCC 版本都支持这些功能后,它们会被从内核中移除。

具体来说,新插件应该只实现上游编译器(GCC 和 Clang)不支持的功能。

当 Clang 中存在 GCC 中不存在的某项功能时,应努力将该功能做到 GCC 上游(而不仅仅
是作为内核专用的 GCC 插件),以使整个生态都能从中受益。

类似的,如果 GCC 插件提供的功能在 Clang 中 **不** 存在,但该功能被证明是有用的,也应
努力将该功能上传到 GCC(和 Clang)。

在上游 GCC 提供了某项功能后,该插件将无法在相应的 GCC 版本(以及更高版本)下编译。
一旦所有内核支持的 GCC 版本都提供了该功能,该插件将从内核中移除。


文件
====

**$(src)/scripts/gcc-plugins**

	这是 GCC 插件的目录。

**$(src)/scripts/gcc-plugins/gcc-common.h**

	这是 GCC 插件的兼容性头文件。
	应始终包含它,而不是单独的 GCC 头文件。

Annotation

Implementation Notes