How to build the same Linux kernel twice and get the same checksum

I am looking if it is possible to build the same Linux Kerneltwice (same sources, same environment, same parameters, same compiler) and get the same checksum. Does anyone know how to do this?

+6
linux binary kernel checksum binary-reproducibility
source share
6 answers

The build date is included in the version, see init version.c:

const char linux_banner[] = "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n"; 

and UTS_VERSION is defined in include / linux / compile.h:

 /* This file is auto generated, version 1 */ /* PREEMPT */ #define UTS_MACHINE "arm" #define UTS_VERSION "#1 PREEMPT Mon Jun 29 10:49:17 CEST 2009" #define LINUX_COMPILE_TIME "10:49:17" #define LINUX_COMPILE_BY "cynove" #define LINUX_COMPILE_HOST "jp" #define LINUX_COMPILE_DOMAIN "evonyc" #define LINUX_COMPILER "gcc version 4.3.2 (crosstool-NG-1.4.0) " 

compile.h is generated by / mkcompile _h scripts, where you will find the following line:

 UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS `LC_ALL=C LANG=C date`" 

By removing date from a permeable string, you can get rid of build-time dependencies.

+8
source share

Shodanex's answer is correct but incomplete. After some research, I found that the Linux kernel binary includes ramfs by default, which is another reason for the differences between the two kernel compilations (the CPIO RAMFS header inserts a date). It is not possible to disable this feature, but it is possible to provide ramfs by default. When you do this, you will receive exactly the same checksum.

Thanks. Your answers help me solve my problem.

+5
source share

@gsempe, would you like to find this: "Make the kernel construct deterministic" link http://lwn.net/Articles/437864/

you can get rid of certain sources of noise (noise ... in the eyes of the beholder ;-)

+2
source share

Even a simple hello world compiled twice leads to different binary files. One way or another, the linker adds some information that changes in each assembly.

+1
source share

The quickest way to check is to do, make a copy, clear, and then do it again. If the checksum matches, then this is possible. If not, this suggests that Make changes some source files in some way (build numbering, build date, etc.)

0
source share

Presumably building a kernel in the same environment will result in the same checksum. So, the same compiler (the same version of the same compiler), exactly the same source, the same dependencies (even if it applies to kernel compilation), etc.

0
source share

All Articles