如何构建相同的 Linux 内核两次源并获得相同的校验和
我正在寻找是否可以构建相同的 Linux 内核两次(相同的源、相同的环境、相同的选项、相同的编译器)并获得相同的校验和。 有人知道该怎么做吗?
I'm searching if it's possible to build the same Linux Kerneltwice (same sources, same environment, same options, same compiler) and get the same checksum.
Anybody knows how to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
构建日期包含在版本中,请参见 init version.c :
并且 UTS_VERSION 定义在 include/linux/compile.h 中:
compile.h 由 script/mkcompile_h 生成,您可以在其中找到以下行:
通过删除 < code>date 从上一行开始,您应该能够摆脱构建时间依赖性。
The date of build is included in the version, see init version.c :
and UTS_VERSION is defined in include/linux/compile.h :
compile.h is generated by scripts/mkcompile_h, where you find the following line :
By removing the
date
from the pervious line, you should be able to get rid of the build time dependency.shodanex的答案是正确的但不完整。
经过一番研究,我发现 Linux 内核二进制文件嵌入了默认的 ramfs,这是两个内核编译之间存在差异的另一个原因(CPIO RAMFS 标头嵌入日期)。 无法禁用此功能,但可以提供默认的 ramfs。
当您这样做时,您会得到完全相同的校验和。
谢谢。 您的回答对我解决问题有很大帮助。
shodanex's answer is right but incomplete.
After some research I found Linux kernel binary embeds a default ramfs which is another reason of differences between two kernels compilations (CPIO RAMFS header embeds date). It's impossible to disable this feature but it's possible to provide a default ramfs.
When you do so, you get exactly the same checksum.
Thank you. Your answers help me a lot to resolve my problem.
@gsempe,你想寻找这个:“使内核构建具有确定性”
参考号 http://lwn.net/Articles/437864/
可以删除某些来源噪音的
(噪音……情人眼里出西施;-)
@gsempe, you would like to look for this: "Make kernel build deterministic"
ref. http://lwn.net/Articles/437864/
it is possible to get rid of certain sources of noise
(noise is ... in the eye of the beholder ;-)
即使是一个简单的 hello world 编译两次也会产生不同的二进制文件。 链接器以某种方式添加了一些在每个构建中都会更改的信息。
Even a simple hello world compiled twice results in different binaries. Somehow the linker is adding some information that changes in each build.
最快的检查方法是制作、复制、清理,然后再次制作。 如果校验和匹配,则有可能。 如果没有,则表明 Make 正在以某种方式更改某些源文件(构建编号、构建日期等)
Quickest way to check would be to make, take a copy, make clean, and then make again. If the checksum matches, then its possible. If not then that suggests that Make is altering some source files in some way (build numbering, build date etc)
据推测,在相同的环境中构建内核将产生相同的校验和。 因此,相同的编译器(相同编译器的相同版本)、完全相同相同的源、相同的依赖项(如果这甚至适用于内核编译)等等。
Presumably, building the kernel in the same environment will result in the same checksum. So, same compiler (same version of the same compiler), exactly the same source, same dependencies (if that's even applicable to a kernel compile), etc.