Documentation/translations/zh_CN/kbuild/llvm.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/kbuild/llvm.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/kbuild/llvm.rst- Extension
.rst- Size
- 7261 bytes
- Lines
- 204
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/kbuild/llvm.rst
:Translator: 慕冬亮 Dongliang Mu <dzm91@hust.edu.cn>
==========================
使用 Clang/LLVM 构建 Linux
==========================
本文档介绍如何使用 Clang 和 LLVM 工具构建 Linux 内核。
关于
----
Linux 内核传统上一直使用 GNU 工具链(如 GCC 和 binutils)进行编译。持续的工作使得
`Clang <https://clang.llvm.org/>`_ 和 `LLVM <https://llvm.org/>`_ 工具可
作为可行的替代品。一些发行版,如 `Android <https://www.android.com/>`_、
`ChromeOS <https://www.chromium.org/chromium-os>`_、`OpenMandriva
<https://www.openmandriva.org/>`_ 和 `Chimera Linux
<https://chimera-linux.org/>`_ 使用 Clang 编译的内核。谷歌和 Meta 的数据中心
集群也运行由 Clang 编译的内核。
`LLVM 是由 C++ 对象实现的工具链组件集合 <https://www.aosabook.org/en/llvm.html>`_。
Clang 是 LLVM 的前端,支持 C 语言和内核所需的 GNU C 扩展,其发音为 "klang",而非
"see-lang"。
使用 LLVM 构建
--------------
通过以下命令调用 ``make``::
make LLVM=1
为主机目标进行编译。对于交叉编译::
make LLVM=1 ARCH=arm64
LLVM= 参数
----------
LLVM 有 GNU binutils 工具的替代品。这些工具可以单独启用。以下是支持的 make 变量
完整列表::
make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \
OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \
HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld
``LLVM=1`` 扩展为上述命令。
如果你的 LLVM 工具不在 PATH 中,你可以使用以斜杠结尾的 LLVM 变量提供它们的位置::
make LLVM=/path/to/llvm/
这将使用 ``/path/to/llvm/clang``、``/path/to/llvm/ld.lld`` 等工具。也可以
使用以下命令::
PATH=/path/to/llvm:$PATH make LLVM=1
如果你的 LLVM 工具带有版本后缀,并且你希望测试该特定版本而非无后缀的可执行文件,
类似于 ``LLVM=1``,你可以使用 ``LLVM`` 变量传递该后缀::
make LLVM=-14
这将使用 ``clang-14``、``ld.lld-14`` 等工具。为了支持带有版本后缀的树外路径组合,
我们建议::
PATH=/path/to/llvm/:$PATH make LLVM=-14
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.