History

kheaders: make headers archive reproducible

In commit 43d8ce9d65a5 ("Provide in-kernel headers to make extending kernel easier") a new mechanism was introduced, for kernels >=5.2, which embeds the kernel headers in the kernel image or a module and exposes them in procfs for use by userland tools. The archive containing the header files has nondeterminism caused by header files metadata. This patch normalizes the metadata and utilizes KBUILD_BUILD_TIMESTAMP if provided and otherwise falls back to the default behaviour. In commit f7b101d33046 ("kheaders: Move from proc to sysfs") it was modified to use sysfs and the script for generation of the archive was renamed to what is being patched.

Dmitry Goldin committed 7 years ago

Commit 86cdd2f1 parent d188b8c2 files · +13 −5Browse files

Unified · Split

2 files
  1. Documentation/kbuild/reproducible-builds.rst +9 −4
  2. kernel/gen_kheaders.sh +4 −1
Documentation/kbuild/reproducible-builds.rst+9−4
@@ -16,16 +16,21 @@ the kernel may be unreproducible, and how to avoid them. · 15 unmodified lines
16Timestamps16Timestamps
17----------17----------
18 18
19The kernel embeds a timestamp in two places:19The kernel embeds timestamps in three places:
20 20
21* The version string exposed by ``uname()`` and included in21* The version string exposed by ``uname()`` and included in
22 ``/proc/version``22 ``/proc/version``
23 23
24* File timestamps in the embedded initramfs24* File timestamps in the embedded initramfs
25 25
26By default the timestamp is the current time. This must be overridden26* If enabled via ``CONFIG_IKHEADERS``, file timestamps of kernel
27using the `KBUILD_BUILD_TIMESTAMP`_ variable. If you are building27 headers embedded in the kernel or respective module,
28from a git commit, you could use its commit date.28 exposed via ``/sys/kernel/kheaders.tar.xz``
29
30By default the timestamp is the current time and in the case of
31``kheaders`` the various files' modification times. This must
32be overridden using the `KBUILD_BUILD_TIMESTAMP`_ variable.
33If you are building from a git commit, you could use its commit date.
29 34
30The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros,35The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros,
31and enables warnings if they are used. If you incorporate external36and enables warnings if they are used. If you incorporate external
kernel/gen_kheaders.sh+4−1
@@ -71,7 +71,10 @@ done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1 · 70 unmodified lines
71find $cpio_dir -type f -print0 |71find $cpio_dir -type f -print0 |
72 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'72 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
73 73
74tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null74# Create archive and try to normalize metadata for reproducibility
75tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \
76 --owner=0 --group=0 --sort=name --numeric-owner \
77 -Jcf $tarfile -C $cpio_dir/ . > /dev/null
75 78
76echo "$src_files_md5" > kernel/kheaders.md579echo "$src_files_md5" > kernel/kheaders.md5
77echo "$obj_files_md5" >> kernel/kheaders.md580echo "$obj_files_md5" >> kernel/kheaders.md5

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t