How to build the same Linux Kernel twice sources and get the same checksum
Asked Answered
E

6

6

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?

Edmanda answered 29/6, 2009 at 8:1 Comment(1)
Edition by @RamenChef does not make any sense... Is it actually possible StackOverflow is becoming so bad?Edmanda
F
8

The date of build 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 scripts/mkcompile_h, where you find the following line :

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

By removing the date from the pervious line, you should be able to get rid of the build time dependency.

Fy answered 29/6, 2009 at 9:8 Comment(0)
E
5

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.

Edmanda answered 31/7, 2009 at 21:12 Comment(0)
F
3

@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 ;-)

Fitful answered 13/1, 2014 at 17:22 Comment(1)
Great addition but I had solved my problem. Check out here https://mcmap.net/q/1610242/-how-to-build-the-same-linux-kernel-twice-sources-and-get-the-same-checksumEdmanda
H
1

Even a simple hello world compiled twice results in different binaries. Somehow the linker is adding some information that changes in each build.

Hover answered 29/6, 2009 at 9:10 Comment(1)
Is that still true when the resulting binary is stripped ?Fy
P
0

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)

Pomegranate answered 29/6, 2009 at 8:6 Comment(0)
H
0

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.

Hydrochloride answered 29/6, 2009 at 8:6 Comment(1)
Even with exactly the same environment setup (same sources, same compiler and same dependencies) two successive build give a different checksum. I think the problem is around compilation options and I don't know which compilation options it's possible to change to get the same checksum without modify the kernel correctness.Edmanda

© 2022 - 2024 — McMap. All rights reserved.