我在一个非常受监管的环境中工作,我们需要能够生成相同的二进制输入,每次构建产品时都给出相同的源代码。我们目前使用的是旧版本的 g++,该版本已被修补,不会在生成的二进制文件中写入日期/时间之类的内容,这些内容会因构建而异,但我想更新到 g++ 4.7.2。有谁知道补丁,或者对我需要寻找什么来获取两个相同的源代码并生成相同的二进制输出有建议?
Debian可重现的构建项目 https://wiki.debian.org/ReproducibleBuilds尝试逐字节标准化 Debian 软件包,并收到了2016 年 Linux 基金会资助 http://web.archive.org/web/20190723155526/https://www.linuxfoundation.org/press-release/2016/11/the-linux-foundations-core-infrastructure-initiative-renews-funding-for-reproducible-builds-project/.
虽然这可能不仅仅包括编译,但您应该看一下它。
这也向我指出本文 http://blog.mindfab.net/2013/12/on-way-to-deterministic-binariy-gcc.html,它在 @Employed 所说的基础上添加了以下几点:
- 将源代码放在固定文件夹中(例如
/tmp/build
)来处理__FILE__
- for
__DATE__
, __TIME__
, __TIMESTAMP__
:
- libfaketime:https://github.com/wolfcw/libfaketime https://github.com/wolfcw/libfaketime
- 覆盖这些宏
-D
-
-Wdate-time
or -Werror=date-time
:如果出现以下任一情况,则发出警告或失败__TIME__
, __DATE__
or __TIMESTAMP__
被使用。 Linux内核4.4默认使用它。
- use the
D
标志与ar
,或使用https://github.com/nh2/ar-timestamp-wiper/tree/master https://github.com/nh2/ar-timestamp-wiper/tree/master擦拭邮票
-
-fno-guess-branch-probability
: 较旧的手动版本 https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Optimize-Options.html说这是非决定论的根源,但是不再 https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/Optimize-Options.html#Optimize-Options。不确定这是否涵盖在-frandom-seed
or not.
构建根 https://buildroot.org/ has a BR2_REPRODUCIBLE
选项可能会在包级别上提供一些想法,但目前还远未完成。
相关主题:
- https://superuser.com/questions/639351/does-recompiling-a-program- Produce-a-bit-for-bit-identical-binary https://superuser.com/questions/639351/does-recompiling-a-program-produce-a-bit-for-bit-identical-binary
- https://www.quora.com/What-can-be-the-possible-reasons-for-the-object-code-of-an-unchanged-C-file-to-change-on-recompilation https://www.quora.com/What-can-be-the-possible-reasons-for-the-object-code-of-an-unchanged-C-file-to-change-on-recompilation
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)