Documentation/translations/zh_CN/kbuild/reproducible-builds.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/kbuild/reproducible-builds.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/kbuild/reproducible-builds.rst- Extension
.rst- Size
- 4990 bytes
- Lines
- 115
- 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/reproducible-builds.rst
:Translator: 慕冬亮 Dongliang Mu <dzm91@hust.edu.cn>
============
可重现的构建
============
通常希望使用相同工具集构建相同源代码是可重现的,即,输出始终完全相同。这使得能够验证
二进制分发或嵌入式系统的构建基础设施未被篡改。这样也更容易验证源代码或工具的更改不会
影响最终生成的二进制文件。
`可重现构建项目`_ 提供了有关该主题的更多信息。本文档涵盖了构建内核可能不可重现的
各种原因,以及如何避免这些问题。
时间戳
------
内核在三个地方嵌入时间戳:
* 通过 ``uname()`` 显示与包含在 ``/proc/version`` 中的版本字符串
* initramfs 中的文件时间戳
* 如果启动 ``CONFIG_IKHEADERS``,内核或相应模块中嵌入的内核头文件的时间戳,
通过 ``/sys/kernel/kheaders.tar.xz`` 显示
默认情况下,时间戳为当前时间或内核头文件的修改时间。这个内容必须使用
`KBUILD_BUILD_TIMESTAMP`_ 变量进行覆盖。如果你从某个 git 提交进行构建,
可以使用其提交日期。
内核 *不* 使用 ``__DATE__`` 和 ``__TIME__`` 宏,并在使用这些宏时启用警告。
如果你合并的外部代码使用这些宏,则必须通过设置 `SOURCE_DATE_EPOCH`_ 环境
变量来覆盖它们对应的时间戳。
用户,主机
----------
内核在 ``/proc/version`` 中嵌入构建用户和主机名。必须使用
`KBUILD_BUILD_USER 和 KBUILD_BUILD_HOST`_ 变量来覆盖这些设置。如果
您从某个 git 提交进行构建,可以使用其提交者地址。
绝对文件名
----------
当内核在树外构建时,调试信息可能包括源文件的绝对文件名。这些信息必须通过在
`KCFLAGS`_ 变量中包含 ``-fdebug-prefix-map`` 选项来覆盖。
根据使用的编译器,``__FILE__`` 宏在树外构建中也可能扩展为绝对文件名。Kbuild
自动使用 ``-fmacro-prefix-map`` 选项来防止这种情况,前提是它被支持。
可重现构建网站提供了有关这些 `prefix-map 选项`_ 的更多信息。
在源包中的生成文件
------------------
在 ``tools/`` 子目录下,一些程序的构建过程并不完全支持树外构建。这可能导致后续
使用如 ``make rpm-pkg`` 构建的源码包包含生成的文件。在构建源码包之前,您应该通过
运行 ``make mrproper`` 或 ``git clean -d -f -x`` 来确保源码树是干净的。
模块签名
--------
如果你启用 ``CONFIG_MODULE_SIG_ALL``,默认行为是为每次构建生成不同的临时密钥,
从而导致模块不可重现。然而,将签名密钥包含在源代码中显然会违背签名模块的目的。
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.