Skip to content

Commit 5d5f922

Browse files
mudongliangJonathan Corbet
authored andcommitted
docs/zh_CN: add the translation of kbuild/gcc-plugins.rst
Finish the translation of kbuild/gcc-plugins.rst and move gcc-plugins from TODO to the main body. Update to commit 3832d1f ("docs/core-api: expand Fedora instructions for GCC plugins") Signed-off-by: Dongliang Mu <[email protected]> Reviewed-by: Alex Shi <[email protected]> Reviewed-by: Yanteng Si <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]> Message-ID: <[email protected]>
1 parent c5d436f commit 5d5f922

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
.. include:: ../disclaimer-zh_CN.rst
4+
5+
:Original: Documentation/kbuild/gcc-plugins.rst
6+
:Translator: 慕冬亮 Dongliang Mu <[email protected]>
7+
8+
================
9+
GCC 插件基础设施
10+
================
11+
12+
13+
介绍
14+
====
15+
16+
GCC 插件是为编译器提供额外功能的可加载模块 [1]_。它们对于运行时插装和静态分析非常有用。
17+
我们可以在编译过程中通过回调 [2]_,GIMPLE [3]_,IPA [4]_ 和 RTL Passes [5]_
18+
(译者注:Pass 是编译器所采用的一种结构化技术,用于完成编译对象的分析、优化或转换等功能)
19+
来分析、修改和添加更多的代码。
20+
21+
内核的 GCC 插件基础设施支持构建树外模块、交叉编译和在单独的目录中构建。插件源文件必须由
22+
C++ 编译器编译。
23+
24+
目前 GCC 插件基础设施只支持一些架构。搜索 "select HAVE_GCC_PLUGINS" 来查找支持
25+
GCC 插件的架构。
26+
27+
这个基础设施是从 grsecurity [6]_ 和 PaX [7]_ 移植过来的。
28+
29+
--
30+
31+
.. [1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html
32+
.. [2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API
33+
.. [3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html
34+
.. [4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html
35+
.. [5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html
36+
.. [6] https://grsecurity.net/
37+
.. [7] https://pax.grsecurity.net/
38+
39+
40+
目的
41+
====
42+
43+
GCC 插件的设计目的是提供一个用于试验 GCC 或 Clang 上游没有的潜在编译器功能的场所。
44+
一旦它们的实用性得到验证,这些功能将被添加到 GCC(和 Clang)的上游。随后,在所有
45+
支持的 GCC 版本都支持这些功能后,它们会被从内核中移除。
46+
47+
具体来说,新插件应该只实现上游编译器(GCC 和 Clang)不支持的功能。
48+
49+
当 Clang 中存在 GCC 中不存在的某项功能时,应努力将该功能做到 GCC 上游(而不仅仅
50+
是作为内核专用的 GCC 插件),以使整个生态都能从中受益。
51+
52+
类似的,如果 GCC 插件提供的功能在 Clang 中 **** 存在,但该功能被证明是有用的,也应
53+
努力将该功能上传到 GCC(和 Clang)。
54+
55+
在上游 GCC 提供了某项功能后,该插件将无法在相应的 GCC 版本(以及更高版本)下编译。
56+
一旦所有内核支持的 GCC 版本都提供了该功能,该插件将从内核中移除。
57+
58+
59+
文件
60+
====
61+
62+
**$(src)/scripts/gcc-plugins**
63+
64+
这是 GCC 插件的目录。
65+
66+
**$(src)/scripts/gcc-plugins/gcc-common.h**
67+
68+
这是 GCC 插件的兼容性头文件。
69+
应始终包含它,而不是单独的 GCC 头文件。
70+
71+
**$(src)/scripts/gcc-plugins/gcc-generate-gimple-pass.h,
72+
$(src)/scripts/gcc-plugins/gcc-generate-ipa-pass.h,
73+
$(src)/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h,
74+
$(src)/scripts/gcc-plugins/gcc-generate-rtl-pass.h**
75+
76+
这些头文件可以自动生成 GIMPLE、SIMPLE_IPA、IPA 和 RTL passes 的注册结构。
77+
与手动创建结构相比,它们更受欢迎。
78+
79+
80+
用法
81+
====
82+
83+
你必须为你的 GCC 版本安装 GCC 插件头文件,以 Ubuntu 上的 gcc-10 为例::
84+
85+
apt-get install gcc-10-plugin-dev
86+
87+
或者在 Fedora 上::
88+
89+
dnf install gcc-plugin-devel libmpc-devel
90+
91+
或者在 Fedora 上使用包含插件的交叉编译器时::
92+
93+
dnf install libmpc-devel
94+
95+
在内核配置中启用 GCC 插件基础设施与一些你想使用的插件::
96+
97+
CONFIG_GCC_PLUGINS=y
98+
CONFIG_GCC_PLUGIN_LATENT_ENTROPY=y
99+
...
100+
101+
运行 gcc(本地或交叉编译器),确保能够检测到插件头文件::
102+
103+
gcc -print-file-name=plugin
104+
CROSS_COMPILE=arm-linux-gnu- ${CROSS_COMPILE}gcc -print-file-name=plugin
105+
106+
"plugin" 这个词意味着它们没有被检测到::
107+
108+
plugin
109+
110+
完整的路径则表示插件已经被检测到::
111+
112+
/usr/lib/gcc/x86_64-redhat-linux/12/plugin
113+
114+
编译包括插件在内的最小工具集::
115+
116+
make scripts
117+
118+
或者直接在内核中运行 make,使用循环复杂性 GCC 插件编译整个内核。
119+
120+
121+
4. 如何添加新的 GCC 插件
122+
========================
123+
124+
GCC 插件位于 scripts/gcc-plugins/。你需要将插件源文件放在 scripts/gcc-plugins/ 目录下。
125+
子目录创建并不支持,你必须添加在 scripts/gcc-plugins/Makefile、scripts/Makefile.gcc-plugins
126+
和相关的 Kconfig 文件中。

Documentation/translations/zh_CN/kbuild/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
:maxdepth: 1
1414

1515
headers_install
16+
gcc-plugins
1617

1718
TODO:
1819

@@ -24,7 +25,6 @@ TODO:
2425
- modules
2526
- issues
2627
- reproducible-builds
27-
- gcc-plugins
2828
- llvm
2929

3030
.. only:: subproject and html

0 commit comments

Comments
 (0)