Skip to contentSkip to conversation

Reproducible build v2

Buildroot New Gilles Chanteperdrix 4 participants 27 messages Jun 14, 2016 – Jul 17, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi,

Please find a second version of the patches, containing all patches which did not raise objections, or which have been fixed according to your advices.

The patches follow this mail and are available as a git branch:
https://git.click-hack.org/buildroot.git/log/?h=reproducible

Some modifications have been left out this time around, because as has been said in answer to the first set, because they need to be factored rather than fixed again and again for every package. Namely:
- overriding gcc macros containing build timestamps in packages;
- touching with SOURCE_DATE_EPOCH all files before starting; archiving (whether with tar, cpio, or genisoimage);
- touching the tarball before compressing it, in order to allow generating images in format where the compressor does not allow disabling timestamps (such as lzo);
- sort file list when archiving so that the archive members order do not depend on the order of files in the directory.

Unfortunately, I have other more urgent issues to work on, so I am going to abandon this work on buildroot. If anyone is interested in continuing this work, you can also find my original patches in a git branch too:
https://git.click-hack.org/buildroot.git/log/?h=reproducible.orig

Regards.

Signature · 2 lines
					    Gilles.
https://click-hack.org
#1 lore raw

PATCH 1/12 reproducibility: introduce config knob

Making the builds reproducible involves turning off build timestamps, which some users may find annoying. So make the reproducible builds optional.

---
 Config.in | 11 +++++++++++
 1 file changed, 11 insertions(+)
Config.in +11 -0
index 9fa7415..faf4c71 100644
@@ -724,6 +724,17 @@ config BR2_COMPILER_PARANOID_UNSAFE_PATH
 
 endmenu
 
+config BR2_REPRODUCIBLE
+	bool "Make the build reproducible (experimental)"
+        help
+          This option will remove all sources of non-reproducibility
+          from the build process. For a given Buildroot configuration,
+          this allows to generate exactly identical binaries from one
+          build to the other, including on different machines.
+
+          This is labeled as an experimental feature, as not all
+          packages behave properly to ensure reproducibility.
+
 endmenu
 
 source "toolchain/Config.in"
Signature · 1 line
2.8.2
#2 lore raw

PATCH 2/12 reproducibility: override locale and timezone

---
 Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
Makefile +7 -0
index 3f5c3d3..0217ff0 100644
@@ -208,6 +208,13 @@ ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
 -include $(BR2_CONFIG)
 endif
 
+export BR2_REPRODUCIBLE
+ifeq ($(BR2_REPRODUCIBLE),y)
+export TZ=UTC
+export LANG=C
+export LC_ALL=C
+endif
+
 # To put more focus on warnings, be less verbose as default
 # Use 'make V=1' to see the full commands
 ifeq ("$(origin V)", "command line")
Signature · 1 line
2.8.2
#3 lore raw

PATCH 2/12 reproducibility: override locale and timezone

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 1 line

Regards,
Yann E. MORIN.

Quoted 29 lines
---
 Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
Makefile +7 -0
index 3f5c3d3..0217ff0 100644
@@ -208,6 +208,13 @@ ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
 -include $(BR2_CONFIG)
 endif
 
+export BR2_REPRODUCIBLE
+ifeq ($(BR2_REPRODUCIBLE),y)
+export TZ=UTC
+export LANG=C
+export LC_ALL=C
+endif
+
 # To put more focus on warnings, be less verbose as default
 # Use 'make V=1' to see the full commands
 ifeq ("$(origin V)", "command line")
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#4 lore raw

PATCH 2/12 reproducibility: override locale and timezone

In reply to Gilles Chanteperdrix
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Gilles" == Gilles Chanteperdrix <[email protected]> writes:

---
 Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
Makefile +0 -0
index 3f5c3d3..0217ff0 100644

Makefile ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),) · line 211

Quoted 4 lines
Makefile +1 -0
@@ -208,6 +208,13 @@ ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
 -include $(BR2_CONFIG)
 endif
 
+export BR2_REPRODUCIBLE

I moved this down with the other exports we do for post-build / post-image scripts.

Makefile ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),) · line 212

Quoted 1 line
Makefile +1 -0
+ifeq ($(BR2_REPRODUCIBLE),y)

And added a comment why we do this.

Committed with that fixed, thanks.

Quoted 15 lines
Makefile +5 -0
+export TZ=UTC
+export LANG=C
+export LC_ALL=C
+endif
+
 # To put more focus on warnings, be less verbose as default
 # Use 'make V=1' to see the full commands
 ifeq ("$(origin V)", "command line")
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 1 line
Bye, Peter Korsgaard
#5 lore raw

PATCH 3/12 reproducibility: generate SOURCE_DATE_EPOCH

In reply to Gilles Chanteperdrix

When reproducibility is requested, generate a global SOURCE_DATE_EPOCH environment variable which contains either the date of buildroot last commit if running from a git repository, or the latest release date.

This means that all packages embedding build dates will appear to have the same build date, so in case of new commit or release, all packages will appear to have been change, even though some of them may not have changed in fact.

The meaning of SOURCE_DATE_EPOCH is specified by the following specification:
https://reproducible-builds.org/specs/source-date-epoch/

---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
Makefile +5 -0
index 0217ff0..bba7f25 100644
@@ -213,6 +213,11 @@ ifeq ($(BR2_REPRODUCIBLE),y)
 export TZ=UTC
 export LANG=C
 export LC_ALL=C
+SOURCE_DATE_GIT = $(shell GIT_DIR=$(TOPDIR)/.git $(GIT) log -1 --format=%at)
+SOURCE_DATE_CHANGES = $(shell head -n 1 $(TOPDIR)/CHANGES | \
+	sed 's/^.*Released \(.*\)$$/\1/;s/\(st\|nd\|rd\|th\),//' | \
+	LANG=C LC_ALL=C TZ=UTC xargs -i date -d \{\} +%s)
+export SOURCE_DATE_EPOCH = $(if $(wildcard $(TOPDIR)/.git),$(SOURCE_DATE_GIT),$(SOURCE_DATE_CHANGES))
 endif
 
 # To put more focus on warnings, be less verbose as default
Signature · 1 line
2.8.2
#6 lore raw

PATCH 3/12 reproducibility: generate SOURCE_DATE_EPOCH

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 23 lines

When reproducibility is requested, generate a global SOURCE_DATE_EPOCH environment variable which contains either the date of buildroot last commit if running from a git repository, or the latest release date.

This means that all packages embedding build dates will appear to have the same build date, so in case of new commit or release, all packages will appear to have been change, even though some of them may not have changed in fact.

The meaning of SOURCE_DATE_EPOCH is specified by the following specification:
https://reproducible-builds.org/specs/source-date-epoch/

---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
Makefile +0 -0
index 0217ff0..bba7f25 100644

Makefile ifeq ($(BR2_REPRODUCIBLE),y) · line 219

Quoted 7 lines
Makefile +4 -0
@@ -213,6 +213,11 @@ ifeq ($(BR2_REPRODUCIBLE),y)
 export TZ=UTC
 export LANG=C
 export LC_ALL=C
+SOURCE_DATE_GIT = $(shell GIT_DIR=$(TOPDIR)/.git $(GIT) log -1 --format=%at)
+SOURCE_DATE_CHANGES = $(shell head -n 1 $(TOPDIR)/CHANGES | \
+	sed 's/^.*Released \(.*\)$$/\1/;s/\(st\|nd\|rd\|th\),//' | \
+	LANG=C LC_ALL=C TZ=UTC xargs -i date -d \{\} +%s)

Why do you need to set TZ, LANG and LC_ALL here, since they are exported just the lines above?

However, we've just discussed that during the summer camp, and we've come to the conlusion that parsing the CHANGES file is not the best solution.

After all, what we need is a reproducible value. The one extracted from CHANGES is not absolutely right (e.g. in case one grabs a tarball from a random cset), but is close-enough to the real value that it is OK.

Yet, we think that we could just use the last second of the last minute of the last hour of the first day of the mont of the last release. (wee!) So we suggest we use the release version, which is already YYYY-MM (e.g. in my local tree):

    $ make print-version
    2016.08-git-00009-g5173895

And it is then trivial to get it to look more like YYYY-MM-01T23:59:59

and the rest is easy to go by... ;-)

What's your opinion on this?

Regards,
Yann E. MORIN.

Quoted 11 lines
Makefile +1 -0
+export SOURCE_DATE_EPOCH = $(if $(wildcard $(TOPDIR)/.git),$(SOURCE_DATE_GIT),$(SOURCE_DATE_CHANGES))
 endif
 
 # To put more focus on warnings, be less verbose as default
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

PATCH 4/12 reproducibility/linux: override build timestamp

In reply to Gilles Chanteperdrix

with SOURCE_DATE_EPOCH

---
 linux/linux.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
linux/linux.mk +8 -0
index a751da9..2a7310c 100644
@@ -97,6 +97,14 @@ LINUX_MAKE_ENV = \
 	$(TARGET_MAKE_ENV) \
 	BR_BINARIES_DIR=$(BINARIES_DIR)
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+LINUX_MAKE_ENV += \
+	KBUILD_BUILD_VERSION=1 \
+	KBUILD_BUILD_USER=buildroot \
+	KBUILD_BUILD_HOST=buildroot \
+	KBUILD_BUILD_TIMESTAMP="$(shell TZ=UTC LANG=C LC_ALL=C date -d @$(SOURCE_DATE_EPOCH))"
+endif
+
 # Get the real Linux version, which tells us where kernel modules are
 # going to be installed in the target filesystem.
 LINUX_VERSION_PROBED = `$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null`
Signature · 1 line
2.8.2
#8 lore raw

PATCH 4/12 reproducibility/linux: override build timestamp

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 12 lines

with SOURCE_DATE_EPOCH

---
 linux/linux.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
linux/linux.mk +0 -0
index a751da9..2a7310c 100644

linux/linux.mk LINUX_MAKE_ENV = \ · line 102

Quoted 6 lines
linux/linux.mk +3 -0
@@ -97,6 +97,14 @@ LINUX_MAKE_ENV = \
 	$(TARGET_MAKE_ENV) \
 	BR_BINARIES_DIR=$(BINARIES_DIR)
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+LINUX_MAKE_ENV += \
+	KBUILD_BUILD_VERSION=1 \

The kernel sets it to 0 (zero) as a fallback when there is no .version file. Should we also set it to 0, too? Note: I'm fine with 1 as well, so:

Regards,
Yann E. MORIN.

Quoted 15 lines
linux/linux.mk +5 -0
+	KBUILD_BUILD_USER=buildroot \
+	KBUILD_BUILD_HOST=buildroot \
+	KBUILD_BUILD_TIMESTAMP="$(shell TZ=UTC LANG=C LC_ALL=C date -d @$(SOURCE_DATE_EPOCH))"
+endif
+
 # Get the real Linux version, which tells us where kernel modules are
 # going to be installed in the target filesystem.
 LINUX_VERSION_PROBED = `$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null`
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#9 lore raw

PATCH 5/12 reproducibility/busybox: disable build timestamps

In reply to Gilles Chanteperdrix
---
 package/busybox/busybox.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/busybox/busybox.mk +6 -0
index 08d8e64..a3d526c 100644
@@ -36,6 +36,12 @@ BUSYBOX_MAKE_ENV = \
 	$(TARGET_MAKE_ENV) \
 	CFLAGS="$(BUSYBOX_CFLAGS)" \
 	CFLAGS_busybox="$(BUSYBOX_CFLAGS_busybox)"
+
+ifeq ($(BR2_REPRODUCIBLE),y)
+BUSYBOX_MAKE_ENV += \
+	KCONFIG_NOTIMESTAMP=1
+endif
+
 BUSYBOX_MAKE_OPTS = \
 	CC="$(TARGET_CC)" \
 	ARCH=$(KERNEL_ARCH) \
Signature · 1 line
2.8.2
#10 lore raw

PATCH 5/12 reproducibility/busybox: disable build timestamps

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 10 lines
---
 package/busybox/busybox.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/busybox/busybox.mk +0 -0
index 08d8e64..a3d526c 100644

package/busybox/busybox.mk BUSYBOX_MAKE_ENV = \ · line 42

Quoted 7 lines
package/busybox/busybox.mk +4 -0
@@ -36,6 +36,12 @@ BUSYBOX_MAKE_ENV = \
 	$(TARGET_MAKE_ENV) \
 	CFLAGS="$(BUSYBOX_CFLAGS)" \
 	CFLAGS_busybox="$(BUSYBOX_CFLAGS_busybox)"
+
+ifeq ($(BR2_REPRODUCIBLE),y)
+BUSYBOX_MAKE_ENV += \
+	KCONFIG_NOTIMESTAMP=1

This could have been a single line (since it is not too long). Otherwise;

Regards,
Yann E. MORIN.

Quoted 12 lines
package/busybox/busybox.mk +2 -0
+endif
+
 BUSYBOX_MAKE_OPTS = \
 	CC="$(TARGET_CC)" \
 	ARCH=$(KERNEL_ARCH) \
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#11 lore raw

PATCH 6/12 reproducibility/libgcrypt: override timestamps

In reply to Gilles Chanteperdrix

with SOURCE_DATE_EPOCH

---
 package/libgcrypt/libgcrypt.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/libgcrypt/libgcrypt.mk +4 -0
index 7c27a22..89fe6a0 100644
@@ -18,6 +18,10 @@ LIBGCRYPT_CONF_ENV = \
 LIBGCRYPT_CONF_OPTS = \
 	--with-gpg-error-prefix=$(STAGING_DIR)/usr
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+LIBGCRYPT_MAKE_OPTS = BUILD_TIMESTAMP=$(SOURCE_DATE)
+endif
+
 # Code doesn't build in thumb mode
 ifeq ($(BR2_arm),y)
 LIBGCRYPT_CONF_ENV += CFLAGS="$(patsubst -mthumb,,$(TARGET_CFLAGS))"
Signature · 1 line
2.8.2
#12 lore raw

PATCH 6/12 reproducibility/libgcrypt: override timestamps

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 12 lines

with SOURCE_DATE_EPOCH

---
 package/libgcrypt/libgcrypt.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/libgcrypt/libgcrypt.mk +0 -0
index 7c27a22..89fe6a0 100644

package/libgcrypt/libgcrypt.mk LIBGCRYPT_CONF_ENV = \ · line 22

Quoted 5 lines
package/libgcrypt/libgcrypt.mk +2 -0
@@ -18,6 +18,10 @@ LIBGCRYPT_CONF_ENV = \
 LIBGCRYPT_CONF_OPTS = \
 	--with-gpg-error-prefix=$(STAGING_DIR)/usr
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+LIBGCRYPT_MAKE_OPTS = BUILD_TIMESTAMP=$(SOURCE_DATE)
                                           ^^^^^^^^^^^

You probably meant SOURCE_DATE_EPOCH here, right?

Regards,
Yann E. MORIN.

Quoted 12 lines
package/libgcrypt/libgcrypt.mk +2 -0
+endif
+
 # Code doesn't build in thumb mode
 ifeq ($(BR2_arm),y)
 LIBGCRYPT_CONF_ENV += CFLAGS="$(patsubst -mthumb,,$(TARGET_CFLAGS))"
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#13 lore raw

PATCH 7/12 reproducibility/libgpg-error: override timestamps

In reply to Gilles Chanteperdrix

with SOURCE_DATE_EPOCH

---
 package/libgpg-error/libgpg-error.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/libgpg-error/libgpg-error.mk +4 -0
index 52b7058..de232eb 100644
@@ -14,4 +14,8 @@ LIBGPG_ERROR_CONFIG_SCRIPTS = gpg-error-config
 LIBGPG_ERROR_AUTORECONF = YES
 LIBGPG_ERROR_GETTEXTIZE = YES
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+LIBGPG_ERROR_MAKE_OPTS = BUILD_TIMESTAMP=$(SOURCE_DATE)
+endif
+
 $(eval $(autotools-package))
Signature · 1 line
2.8.2
#14 lore raw

PATCH 7/12 reproducibility/libgpg-error: override timestamps

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 12 lines

with SOURCE_DATE_EPOCH

---
 package/libgpg-error/libgpg-error.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/libgpg-error/libgpg-error.mk +0 -0
index 52b7058..de232eb 100644

package/libgpg-error/libgpg-error.mk LIBGPG_ERROR_CONFIG_SCRIPTS = gpg-error-config · line 18

Quoted 5 lines
package/libgpg-error/libgpg-error.mk +2 -0
@@ -14,4 +14,8 @@ LIBGPG_ERROR_CONFIG_SCRIPTS = gpg-error-config
 LIBGPG_ERROR_AUTORECONF = YES
 LIBGPG_ERROR_GETTEXTIZE = YES
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+LIBGPG_ERROR_MAKE_OPTS = BUILD_TIMESTAMP=$(SOURCE_DATE)
                                              ^^^^^^^^^^^

You probably meant SOURCE_DATE_EPOCH, right?

Regards,
Yann E. MORIN.

Quoted 10 lines
package/libgpg-error/libgpg-error.mk +2 -0
+endif
+
 $(eval $(autotools-package))
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#15 lore raw

PATCH 8/12 package/cpio: allow generating host-cpio

In reply to Gilles Chanteperdrix

In order to be sure to have a cpio binary on host which supports --reproducible.

---
 package/cpio/cpio.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/cpio/cpio.mk +6 -0
index 1576127..87b3df8 100644
@@ -18,3 +18,9 @@ CPIO_DEPENDENCIES += argp-standalone
 endif
 
 $(eval $(autotools-package))
+
+HOST_CPIO_DEPENDENCIES =
+
+$(eval $(host-autotools-package))
+
+CPIO_REPRODUCIBLE = $(HOST_DIR)/usr/bin/cpio --reproducible
Signature · 1 line
2.8.2
#16 lore raw

PATCH 8/12 package/cpio: allow generating host-cpio

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 13 lines

In order to be sure to have a cpio binary on host which supports --reproducible.

---
 package/cpio/cpio.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/cpio/cpio.mk +0 -0
index 1576127..87b3df8 100644

package/cpio/cpio.mk CPIO_DEPENDENCIES += argp-standalone · line 24

Quoted 7 lines
package/cpio/cpio.mk +4 -0
@@ -18,3 +18,9 @@ CPIO_DEPENDENCIES += argp-standalone
 endif
 
 $(eval $(autotools-package))
+
+HOST_CPIO_DEPENDENCIES =
+
+$(eval $(host-autotools-package))

We usually write all package variables first, and eventually call the package macros, like:

    [...existing stuff...]

    HOST_CPIO_DEPENDENCIES =

    $(eval $(autotools-package))
    $(eval $(host-autotools-package))

package/cpio/cpio.mk CPIO_DEPENDENCIES += argp-standalone · line 26

Quoted 1 line
package/cpio/cpio.mk +1 -0
+CPIO_REPRODUCIBLE = $(HOST_DIR)/usr/bin/cpio --reproducible

Since we now have host-cpio, we can alsso add:

    CPIO = $(HOST_DIR)/usr/bin/cpio

Regards,
Yann E. MORIN.

Quoted 7 lines
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#17 lore raw

PATCH 9/12 reproducibility/fs/cpio: generate archive with host-cpio

In reply to Gilles Chanteperdrix

Using the --reproducible option to generate a reproducible archive.

---
 fs/cpio/cpio.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/cpio/cpio.mk +8 -0
index e82167e..4da6648 100644
@@ -27,9 +27,17 @@ endif # BR2_ROOTFS_DEVICE_CREATION_STATIC
 
 ROOTFS_CPIO_PRE_GEN_HOOKS += ROOTFS_CPIO_ADD_INIT
 
+ifneq ($(BR2_REPRODUCIBLE),y)
 define ROOTFS_CPIO_CMD
 	cd $(TARGET_DIR) && find . | cpio --quiet -o -H newc > $@
 endef
+else
+ROOTFS_CPIO_DEPENDENCIES += host-cpio
+
+define ROOTFS_CPIO_CMD
+	cd $(TARGET_DIR) && find . | $(CPIO_REPRODUCIBLE) --quiet -o -H newc > $@
+endef
+endif
 
 $(BINARIES_DIR)/rootfs.cpio.uboot: $(BINARIES_DIR)/rootfs.cpio host-uboot-tools
 	$(MKIMAGE) -A $(MKIMAGE_ARCH) -T ramdisk \
Signature · 1 line
2.8.2
#18 lore raw

PATCH 9/12 reproducibility/fs/cpio: generate archive with host-cpio

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 16 lines

Using the --reproducible option to generate a reproducible archive.

---
 fs/cpio/cpio.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/cpio/cpio.mk +1 -0
index e82167e..4da6648 100644
@@ -27,9 +27,17 @@ endif # BR2_ROOTFS_DEVICE_CREATION_STATIC
 
 ROOTFS_CPIO_PRE_GEN_HOOKS += ROOTFS_CPIO_ADD_INIT
 
+ifneq ($(BR2_REPRODUCIBLE),y)

fs/cpio/cpio.mk endif # BR2_ROOTFS_DEVICE_CREATION_STATIC · line 40

Quoted 10 lines
fs/cpio/cpio.mk +7 -0
 define ROOTFS_CPIO_CMD
 	cd $(TARGET_DIR) && find . | cpio --quiet -o -H newc > $@
 endef
+else
+ROOTFS_CPIO_DEPENDENCIES += host-cpio
+
+define ROOTFS_CPIO_CMD
+	cd $(TARGET_DIR) && find . | $(CPIO_REPRODUCIBLE) --quiet -o -H newc > $@
+endef
+endif

Rather than duplicate the commands, why not something like:

    ifeq ($(BR2_REPDUCIBLE),y)
    ROOTFS_CPIO_CPIO = $(CPIO)
    else
    ROOTFS_CPIO_CPIO = $(CPIO_REPRODUCIBLE)
    endif

    define ROOTFS_CPIO_CMD
        cd $(TARGET_DIR) && find . | $(ROOTFS_CPIO_CPIO) --quiet -o -H newc > $@
    endef

Regards,
Yann E. MORIN.

Quoted 9 lines
fs/cpio/cpio.mk +0 -0
 $(BINARIES_DIR)/rootfs.cpio.uboot: $(BINARIES_DIR)/rootfs.cpio host-uboot-tools
 	$(MKIMAGE) -A $(MKIMAGE_ARCH) -T ramdisk \
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#19 lore raw

PATCH 9/12 reproducibility/fs/cpio: generate archive with host-cpio

In reply to Gilles Chanteperdrix
Quoted 12 lines · Gilles Chanteperdrix

Using the --reproducible option to generate a reproducible archive.

---
 fs/cpio/cpio.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/cpio/cpio.mk +0 -0
index e82167e..4da6648 100644

fs/cpio/cpio.mk endif # BR2_ROOTFS_DEVICE_CREATION_STATIC · line 35

Quoted 9 lines
fs/cpio/cpio.mk +3 -0
@@ -27,9 +27,17 @@ endif # BR2_ROOTFS_DEVICE_CREATION_STATIC
 
 ROOTFS_CPIO_PRE_GEN_HOOKS += ROOTFS_CPIO_ADD_INIT
 
+ifneq ($(BR2_REPRODUCIBLE),y)
 define ROOTFS_CPIO_CMD
 	cd $(TARGET_DIR) && find . | cpio --quiet -o -H newc > $@
 endef
+else
+ROOTFS_CPIO_DEPENDENCIES += host-cpio

Instead of unconditionally building host-cpio, it would be better to check if
the installed cpio supports --reproducible. Cfr. what we do for tar, in support/dependencies/check-host-tar.{sh,mk}.

Regards,
Arnout

Quoted 9 lines
fs/cpio/cpio.mk +5 -0
+
+define ROOTFS_CPIO_CMD
+	cd $(TARGET_DIR) && find . | $(CPIO_REPRODUCIBLE) --quiet -o -H newc > $@
+endef
+endif
 
 $(BINARIES_DIR)/rootfs.cpio.uboot: $(BINARIES_DIR)/rootfs.cpio host-uboot-tools
 	$(MKIMAGE) -A $(MKIMAGE_ARCH) -T ramdisk \
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#20 lore raw

PATCH 1/12 reproducibility: introduce config knob

In reply to Gilles Chanteperdrix

Gilles, All,

On 2016-06-14 17:31 +0200, Gilles Chanteperdrix spake thusly:

Quoted 5 lines

Making the builds reproducible involves turning off build timestamps, which some users may find annoying. So make the reproducible builds optional.

Quite obviously:

Note: it may take some time for my reviews on the rest of your series to come in...

Regards,
Yann E. MORIN.

Quoted 33 lines
---
 Config.in | 11 +++++++++++
 1 file changed, 11 insertions(+)
Config.in +11 -0
index 9fa7415..faf4c71 100644
@@ -724,6 +724,17 @@ config BR2_COMPILER_PARANOID_UNSAFE_PATH
 
 endmenu
 
+config BR2_REPRODUCIBLE
+	bool "Make the build reproducible (experimental)"
+        help
+          This option will remove all sources of non-reproducibility
+          from the build process. For a given Buildroot configuration,
+          this allows to generate exactly identical binaries from one
+          build to the other, including on different machines.
+
+          This is labeled as an experimental feature, as not all
+          packages behave properly to ensure reproducibility.
+
 endmenu
 
 source "toolchain/Config.in"
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#21 lore raw

PATCH 1/12 reproducibility: introduce config knob

In reply to Gilles Chanteperdrix
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Gilles" == Gilles Chanteperdrix <[email protected]> writes:

Making the builds reproducible involves turning off build timestamps, which some users may find annoying. So make the reproducible builds optional.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#22 lore raw

PATCH 10/12 cdrkit: add patch allowing to set creation date

In reply to Gilles Chanteperdrix

The patch was posted here:
https://lists.gnu.org/archive/html/bug-cpio/2014-08/msg00000.html

And allows generating reproducible iso images with genisoimage.

---
 ...-reproducible-allow-setting-creation-date.patch | 140 +++++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 package/cdrkit/0003-reproducible-allow-setting-creation-date.patch
package/cdrkit/0003-reproducible-allow-setting-creation-date.patch new file +140 -0
new file mode 100644
index 0000000..f5ed465
@@ -0,0 +1,140 @@
+diff --git a/genisoimage/.eltorito.c.swp b/genisoimage/.eltorito.c.swp
+new file mode 100644
+index 0000000..a49fcbd
+Binary files /dev/null and b/genisoimage/.eltorito.c.swp differ
+diff --git a/genisoimage/genisoimage.1 b/genisoimage/genisoimage.1
+index d05b24a..d69a1d4 100644
+--- a/genisoimage/genisoimage.1
++++ b/genisoimage/genisoimage.1
+@@ -976,6 +976,12 @@ in the
+ .I .genisoimagerc
+ file.
+ .TP
++.BI \-creation-date " epoch"
++Specifies the date to be used as creation, modification and effective
++date in the volume descriptor and for files and relocations created
++on the fly. Specified as a number of second since
++1970-01-01 00:00:00 +0000 (UTC); if 0, the current time is used.
++.TP
+ .B \-print\-size
+ Print estimated filesystem size in multiples of the sector size (2048 bytes)
+ and exit. This option is needed for
+diff --git a/genisoimage/genisoimage.c b/genisoimage/genisoimage.c
+index cfd079a..58397e9 100644
+--- a/genisoimage/genisoimage.c
++++ b/genisoimage/genisoimage.c
+@@ -169,6 +169,7 @@ char	*abstract = ABSTRACT_DEFAULT;
+ char	*volset_id = VOLSET_ID_DEFAULT;
+ char	*volume_id = VOLUME_ID_DEFAULT;
+ char	*system_id = SYSTEM_ID_DEFAULT;
++time_t  creation_date = 0;
+ char	*boot_catalog = BOOT_CATALOG_DEFAULT;
+ char	*boot_image = BOOT_IMAGE_DEFAULT;
+ char	*genboot_image = BOOT_IMAGE_DEFAULT;
+@@ -405,6 +406,8 @@ struct ld_option {
+ #define	OPTION_ALLOW_LEADING_DOTS	1070
+ #define	OPTION_PUBLISHER		1071
+ 
++#define OPTION_CREATION_DATE            1072
++
+ #ifdef		JIGDO_TEMPLATE
+ #define	OPTION_JTT_OUTPUT		1101
+ #define	OPTION_JTJ_OUTPUT		1102
+@@ -522,6 +525,8 @@ static const struct ld_option ld_options[] =
+ 	'\0', "FILE", "Check all ISO9660 names from previous session", ONE_DASH},
+ 	{{"copyright", required_argument, NULL, OPTION_COPYRIGHT},
+ 	'\0', "FILE", "Set Copyright filename", ONE_DASH},
++	{{"creation-date", required_argument, NULL, OPTION_CREATION_DATE},
++	'\0', NULL, "Set volume creation date", ONE_DASH},
+ 	{{"debug", no_argument, NULL, OPTION_DEBUG},
+ 	'\0', NULL, "Set debug flag", ONE_DASH},
+ 	{{"eltorito-boot", required_argument, NULL, 'b'},
+@@ -1721,6 +1726,22 @@ int main(int argc, char *argv[])
+ #endif
+ 			}
+ 			break;
++		case OPTION_CREATION_DATE:
++		{
++			char	*end = 0;
++
++			creation_date = strtol(optarg, &end, 10);
++			if (!end || *end != 0) {
++#ifdef	USE_LIBSCHILY
++				comerrno(EX_BAD, "Bad epoch for -creation-date\n");
++#else
++				fprintf(stderr, "Bad epoch for -creation-date\n");
++				exit(1);
++#endif
++			}
++			break;
++		}
++
+ 		case OPTION_DEBUG:
+ 			debug++;
+ 			break;
+diff --git a/genisoimage/genisoimage.h b/genisoimage/genisoimage.h
+index bbedfb0..c49576c 100644
+--- a/genisoimage/genisoimage.h
++++ b/genisoimage/genisoimage.h
+@@ -650,6 +650,7 @@ extern char	*appid;
+ extern char	*volset_id;
+ extern char	*system_id;
+ extern char	*volume_id;
++extern time_t	creation_date;
+ extern char	*boot_catalog;
+ extern char	*boot_image;
+ extern char	*genboot_image;
+diff --git a/genisoimage/tree.c b/genisoimage/tree.c
+index 7805888..f17a662 100644
+--- a/genisoimage/tree.c
++++ b/genisoimage/tree.c
+@@ -783,7 +783,11 @@ generate_reloc_directory()
+ 	struct directory_entry *s_entry;
+ 
+ 	/* Create an  entry for our internal tree */
+-	time(&current_time);
++	if (creation_date == 0) {
++		time(&current_time);
++	} else {
++		current_time = creation_date;
++	}
+ 	reloc_dir = (struct directory *)
+ 		e_malloc(sizeof (struct directory));
+ 	memset(reloc_dir, 0, sizeof (struct directory));
+@@ -2680,7 +2684,11 @@ init_fstatbuf()
+ 	time_t	current_time;
+ 
+ 	if (fstatbuf.st_ctime == 0) {
+-		time(&current_time);
++		if (creation_date == 0) {
++			time(&current_time);
++		} else {
++			current_time = creation_date;
++		}
+ 		if (rationalize_uid)
+ 			fstatbuf.st_uid = uid_to_use;
+ 		else
+diff --git a/genisoimage/write.c b/genisoimage/write.c
+index a423ab1..f63507c 100644
+--- a/genisoimage/write.c
++++ b/genisoimage/write.c
+@@ -1885,12 +1885,17 @@ pvd_write(FILE *outfile)
+ 	int		should_write;
+ 	struct tm	local;
+ 	struct tm	gmt;
++	time_t		pvd_date;
+ 
+ 
+ 	time(&begun);
+ 
+-	local = *localtime(&begun);
+-	gmt = *gmtime(&begun);
++	if (creation_date == 0) {
++		creation_date = begun;
++	}
++
++	local = *localtime(&creation_date);
++	gmt = *gmtime(&creation_date);
+ 
+ 	/*
+ 	 * There was a comment here about breaking in the year 2000.
Signature · 1 line
2.8.2
#23 lore raw

PATCH 11/12 reproducibility/fs/iso9660: reproducible iso images

When reproducibility is required, we:
- run genisoimage with the -creation-date option to avoid using the build date for files in the iso image automatically created by genisoimage (such as the catalog)
- disable the rockridge extension, as it stores each file "ctime", which can not be changed easily on the host filesystem
- force using an initrd, as a trying and booting an iso image without the rockridge extensions will not work
- use isohybrid -i option to avoid embedding a random number in the generated iso.

---
 fs/iso9660/Config.in  |  9 +++++++++
 fs/iso9660/iso9660.mk | 20 ++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)
fs/iso9660/Config.in +9 -0
index 2482e44..bb82d03 100644
@@ -71,6 +71,15 @@ config BR2_TARGET_ROOTFS_ISO9660_INITRD
 	  contain a kernel image, an initrd image (unless an initramfs
 	  linked into the kernel is used) and the bootloader.
 
+config BR2_TARGET_ROOTFS_ISO9660_REPRODUCIBLE
+       def_bool BR2_REPRODUCIBLE
+       select BR2_TARGET_ROOTFS_ISO9660_INITRD
+
+if BR2_REPRODUCIBLE
+comment "A reproducible build requires disabling the RockRidge extensions"
+comment "Which makes using an initrd the only sane solution"
+endif
+
 config BR2_TARGET_ROOTFS_ISO9660_HYBRID
 	bool "Build hybrid image"
 	depends on BR2_TARGET_ROOTFS_ISO9660_ISOLINUX
fs/iso9660/iso9660.mk +18 -2
index 32d79d7..f97a9d7 100644
@@ -143,15 +143,31 @@ ROOTFS_ISO9660_PRE_GEN_HOOKS += ROOTFS_ISO9660_DISABLE_EXTERNAL_INITRD
 endif # ROOTFS_ISO9660_USE_INITRD
 
 
+ifneq ($(BR2_REPRODUCIBLE),y)
+define ROOTFS_ISO9660_GENISOIMAGE
+	$(HOST_DIR)/usr/bin/genisoimage -R
+endef
+define ROOTFS_ISO9660_ISOHYBRID
+	$(HOST_DIR)/usr/bin/isohybrid
+endef
+else
+define ROOTFS_ISO9660_GENISOIMAGE
+	$(HOST_DIR)/usr/bin/genisoimage -creation-date $(SOURCE_DATE_EPOCH)
+endef
+define ROOTFS_ISO9660_ISOHYBRID
+	$(HOST_DIR)/usr/bin/isohybrid -i $(SOURCE_DATE_EPOCH)
+endef
+endif
+
 define ROOTFS_ISO9660_CMD
-	$(HOST_DIR)/usr/bin/genisoimage -J -R -b $(ROOTFS_ISO9660_BOOT_IMAGE) \
+	$(ROOTFS_ISO9660_GENISOIMAGE) -J -b $(ROOTFS_ISO9660_BOOT_IMAGE) \
 		-no-emul-boot -boot-load-size 4 -boot-info-table \
 		-o $@ $(ROOTFS_ISO9660_TARGET_DIR)
 endef
 
 ifeq ($(BR2_TARGET_ROOTFS_ISO9660_HYBRID),y)
 define ROOTFS_ISO9660_GEN_HYBRID
-	$(HOST_DIR)/usr/bin/isohybrid -t 0x96 $@
+	$(ROOTFS_ISO9660_ISOHYBRID) -t 0x96 $@
 endef
 
 ROOTFS_ISO9660_POST_GEN_HOOKS += ROOTFS_ISO9660_GEN_HYBRID
Signature · 1 line
2.8.2
#24 lore raw

PATCH 11/12 reproducibility/fs/iso9660: reproducible iso images

Gilles, All,

On 2016-06-14 17:32 +0200, Gilles Chanteperdrix spake thusly:

Quoted 10 lines

When reproducibility is required, we:
- run genisoimage with the -creation-date option to avoid using the build date for files in the iso image automatically created by genisoimage (such as the catalog)
- disable the rockridge extension, as it stores each file "ctime", which can not be changed easily on the host filesystem
- force using an initrd, as a trying and booting an iso image without the rockridge extensions will not work
- use isohybrid -i option to avoid embedding a random number in the generated iso.

I'm not too fond of having a huge patch in Buildroot, that has no chance of ever getting upstream (since upstream is virtually dead as there's been no activity since Oct 2010, and their homepage is now a blank page).

Instead, when programs can't be told what date to use, I'd prefer we have a look at libfaketime:
https://github.com/wolfcw/libfaketime

Then one can use the 'faketime' wrapper to force a specific date:

    faketime '2016-07-17 21:28:42' genisoimage blablalba

In which case, it might be worth doing it directly in the fs infra so that all filesystem images are handled once and for all.

Thoughts?

Regards,
Yann E. MORIN.

Quoted 71 lines
---
 fs/iso9660/Config.in  |  9 +++++++++
 fs/iso9660/iso9660.mk | 20 ++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)
fs/iso9660/Config.in +9 -0
index 2482e44..bb82d03 100644
@@ -71,6 +71,15 @@ config BR2_TARGET_ROOTFS_ISO9660_INITRD
 	  contain a kernel image, an initrd image (unless an initramfs
 	  linked into the kernel is used) and the bootloader.
 
+config BR2_TARGET_ROOTFS_ISO9660_REPRODUCIBLE
+       def_bool BR2_REPRODUCIBLE
+       select BR2_TARGET_ROOTFS_ISO9660_INITRD
+
+if BR2_REPRODUCIBLE
+comment "A reproducible build requires disabling the RockRidge extensions"
+comment "Which makes using an initrd the only sane solution"
+endif
+
 config BR2_TARGET_ROOTFS_ISO9660_HYBRID
 	bool "Build hybrid image"
 	depends on BR2_TARGET_ROOTFS_ISO9660_ISOLINUX
fs/iso9660/iso9660.mk +18 -2
index 32d79d7..f97a9d7 100644
@@ -143,15 +143,31 @@ ROOTFS_ISO9660_PRE_GEN_HOOKS += ROOTFS_ISO9660_DISABLE_EXTERNAL_INITRD
 endif # ROOTFS_ISO9660_USE_INITRD
 
 
+ifneq ($(BR2_REPRODUCIBLE),y)
+define ROOTFS_ISO9660_GENISOIMAGE
+	$(HOST_DIR)/usr/bin/genisoimage -R
+endef
+define ROOTFS_ISO9660_ISOHYBRID
+	$(HOST_DIR)/usr/bin/isohybrid
+endef
+else
+define ROOTFS_ISO9660_GENISOIMAGE
+	$(HOST_DIR)/usr/bin/genisoimage -creation-date $(SOURCE_DATE_EPOCH)
+endef
+define ROOTFS_ISO9660_ISOHYBRID
+	$(HOST_DIR)/usr/bin/isohybrid -i $(SOURCE_DATE_EPOCH)
+endef
+endif
+
 define ROOTFS_ISO9660_CMD
-	$(HOST_DIR)/usr/bin/genisoimage -J -R -b $(ROOTFS_ISO9660_BOOT_IMAGE) \
+	$(ROOTFS_ISO9660_GENISOIMAGE) -J -b $(ROOTFS_ISO9660_BOOT_IMAGE) \
 		-no-emul-boot -boot-load-size 4 -boot-info-table \
 		-o $@ $(ROOTFS_ISO9660_TARGET_DIR)
 endef
 
 ifeq ($(BR2_TARGET_ROOTFS_ISO9660_HYBRID),y)
 define ROOTFS_ISO9660_GEN_HYBRID
-	$(HOST_DIR)/usr/bin/isohybrid -t 0x96 $@
+	$(ROOTFS_ISO9660_ISOHYBRID) -t 0x96 $@
 endef
 
 ROOTFS_ISO9660_POST_GEN_HOOKS += ROOTFS_ISO9660_GEN_HYBRID
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#25 lore raw

PATCH 12/12 reproducible/syslinux: make syslinux build reproducible

In reply to Gilles Chanteperdrix

Build with the target toolchain so that the binaries are identical with different host toolchains.
Sort files lists in order to get deterministic link order. Build with HEXDATE set to the source date epoch.

---
 boot/syslinux/0001-fixed-build-order.patch | 42 ++++++++++++++++++++++++++
 boot/syslinux/syslinux.mk                  | 47 +++++++++++++++++++++++++-----
 fs/iso9660/iso9660.mk                      |  4 +--
 3 files changed, 84 insertions(+), 9 deletions(-)
 create mode 100644 boot/syslinux/0001-fixed-build-order.patch
boot/syslinux/0001-fixed-build-order.patch new file +42 -0
new file mode 100644
index 0000000..3697b74
@@ -0,0 +1,42 @@
+Sort source file names in order for the link order not to depend on the order in
+which find return file names.
+
+Signed-off-by: Gilles Chanteperdrix <[email protected]>
+-- 
+--- syslinux-6.03/core/Makefile~	2014-10-06 18:27:44.000000000 +0200
++++ syslinux-6.03/core/Makefile	2016-03-24 14:36:38.207391899 +0100
+@@ -41,9 +41,9 @@
+ # All primary source files for the main syslinux files
+ NASMSRC	 := $(wildcard $(SRC)/*.asm)
+ NASMHDR  := $(wildcard $(SRC)/*.inc)
+-CSRC	 := $(shell find $(SRC) -name '*.c' -print)
+-SSRC	 := $(shell find $(SRC) -name '*.S' -print)
+-CHDR	 := $(shell find $(SRC) -name '*.h' -print)
++CSRC	 := $(shell find $(SRC) -name '*.c' -print | sort)
++SSRC	 := $(shell find $(SRC) -name '*.S' -print | sort)
++CHDR	 := $(shell find $(SRC) -name '*.h' -print | sort)
+ OTHERSRC := keywords
+ ALLSRC    = $(NASMSRC) $(NASMHDR) $(CSRC) $(SSRC) $(CHDR) $(OTHERSRC)
+ 
+@@ -56,18 +56,18 @@
+ 	$(addprefix $(SRC)/fs/pxe/, dhcp_option.c pxe.c tftp.c urlparse.c bios.c)
+ 
+ LPXELINUX_CSRC = $(CORE_PXE_CSRC) \
+-	$(shell find $(SRC)/lwip -name '*.c' -print) \
++	$(shell find $(SRC)/lwip -name '*.c' -print | sort) \
+ 	$(addprefix $(SRC)/fs/pxe/, \
+ 		core.c dnsresolv.c ftp.c ftp_readdir.c gpxeurl.c http.c \
+ 		http_readdir.c idle.c isr.c tcp.c)
+ 
+ PXELINUX_CSRC = $(CORE_PXE_CSRC) \
+-	$(shell find $(SRC)/legacynet -name '*.c' -print)
++	$(shell find $(SRC)/legacynet -name '*.c' -print | sort)
+ 
+ LPXELINUX_OBJS = $(subst $(SRC)/,,$(LPXELINUX_CSRC:%.c=%.o))
+ PXELINUX_OBJS  = $(subst $(SRC)/,,$(PXELINUX_CSRC:%.c=%.o))
+ 
+-UNITTEST_CSRC = $(shell find $(SRC) -path '*/tests/*.c' -print)
++UNITTEST_CSRC = $(shell find $(SRC) -path '*/tests/*.c' -print | sort)
+ UNITTEST_OBJS = $(subst $(SRC)/,,$(UNITTEST_CSRC:%.c=%.o))
+ 
+ # Don't include console and network stack specific objects or unit tests
boot/syslinux/syslinux.mk +40 -7

77 lines not on this page · raw message

fs/iso9660/iso9660.mk +2 -2
index f97a9d7..db22ca4 100644
@@ -70,8 +70,6 @@ ROOTFS_ISO9660_BOOT_IMAGE = isolinux/isolinux.bin
 define ROOTFS_ISO9660_INSTALL_BOOTLOADER
 	$(INSTALL) -D -m 0644 $(BINARIES_DIR)/syslinux/* \
 		$(ROOTFS_ISO9660_TARGET_DIR)/isolinux/
-	$(INSTALL) -D -m 0644 $(HOST_DIR)/usr/share/syslinux/ldlinux.c32 \
-		$(ROOTFS_ISO9660_TARGET_DIR)/isolinux/ldlinux.c32
 endef
 endif
 
@@ -166,6 +164,8 @@ define ROOTFS_ISO9660_CMD
 endef
 
 ifeq ($(BR2_TARGET_ROOTFS_ISO9660_HYBRID),y)
+ROOTFS_ISO9660_DEPENDENCIES += host-syslinux
+
 define ROOTFS_ISO9660_GEN_HYBRID
 	$(ROOTFS_ISO9660_ISOHYBRID) -t 0x96 $@
 endef
Signature · 1 line
2.8.2
#26 lore raw

PATCH 12/12 reproducible/syslinux: make syslinux build reproducible

Gilles, All,

On 2016-06-14 17:32 +0200, Gilles Chanteperdrix spake thusly:

Quoted 4 lines

Build with the target toolchain so that the binaries are identical with different host toolchains.
Sort files lists in order to get deterministic link order. Build with HEXDATE set to the source date epoch.

It looks like those are three different changes, so should have been three different patches.

Especially the change to use the cross-toolchain should really be separate (and come first).

Further comments below...

Quoted 1 line

[--SNIP--]

boot/syslinux/0001-fixed-build-order.patch line 4

Quoted 10 lines
boot/syslinux/0001-fixed-build-order.patch new file +4 -0
new file mode 100644
index 0000000..3697b74
@@ -0,0 +1,42 @@
+Sort source file names in order for the link order not to depend on the order in
+which find return file names.
+
+Signed-off-by: Gilles Chanteperdrix <[email protected]>

Have you tried submitting this patch upstream?

We do not much like having feature patches in Buildroot, because they are a pain to maintain when we want to update the package.

Otherwise, this looks pretty simple, I guess upstream will probably like it. ;-)

[--SNIP--]

boot/syslinux/syslinux.mk SYSLINUX_LICENSE_FILES = COPYING · line 16

Quoted 10 lines
boot/syslinux/syslinux.mk +1 -1
index 82890c5..cdd5b3c 100644
@@ -13,7 +13,7 @@ SYSLINUX_LICENSE_FILES = COPYING
 
 SYSLINUX_INSTALL_IMAGES = YES
 
-SYSLINUX_DEPENDENCIES = host-nasm host-util-linux host-upx
+SYSLINUX_DEPENDENCIES = host-nasm host-util-linux host-upx host-perl host-python host-xz

Why are those new host packages needed?

Quoted 8 lines
boot/syslinux/syslinux.mk +2 -0
 ifeq ($(BR2_TARGET_SYSLINUX_LEGACY_BIOS),y)
 SYSLINUX_TARGET += bios
@@ -47,12 +47,35 @@ define SYSLINUX_CLEANUP
 endef
 SYSLINUX_POST_PATCH_HOOKS += SYSLINUX_CLEANUP
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+define SYSLINUX_REPRODUCIBLE

boot/syslinux/syslinux.mk define SYSLINUX_CLEANUP · line 61

Quoted 10 lines
boot/syslinux/syslinux.mk +10 -0
+	HEXDATE="`printf "0x%x" $(SOURCE_DATE_EPOCH)`"
+endef
+endif
+
+define SYSLINUX_MAKE
+	$(TARGET_MAKE_ENV) $(MAKE1) \
+		$(SYSLINUX_REPRODUCIBLE) \
+		NASM=$(HOST_DIR)/usr/bin/nasm \
+		PERL=$(HOST_DIR)/usr/bin/perl \
+		PYTHON=$(HOST_DIR)/usr/bin/python \

Why do we need to specify nasm, perl and python? The PATH as set by Buildroot already has the host dirs early in the PATH, so they should be found before the system ones.

boot/syslinux/syslinux.mk define SYSLINUX_CLEANUP · line 71

Quoted 10 lines
boot/syslinux/syslinux.mk +10 -0
+		UPX=$(HOST_DIR)/usr/bin/upx \
+		CC="$(TARGET_CC)" \
+		LD="$(TARGET_LD) -m elf_i386" \
+		OBJDUMP="$(TARGET_OBJDUMP)" \
+		OBJCOPY="$(TARGET_OBJCOPY)" \
+		STRIP="$(TARGET_STRIP)" \
+		AR="$(TARGET_AR)" \
+		NM="$(TARGET_NM)" \
+		RANLIB="$(TARGET_RANLIB)" \
+		XZ=$(HOST_DIR)/usr/bin/xz $(SYSLINUX_EFI_ARGS)

Ditto xz.

You're also adding more variables than were present in the existing commands; that's why using the cross-toolchain should be a separate
patch: so that we can more easily understand the changes.

Quoted 27 lines
boot/syslinux/syslinux.mk +4 -5
+endef
+
 # syslinux build system has no convenient way to pass CFLAGS,
 # and the internal zlib should take precedence so -I shouldn't
 # be used.
 define SYSLINUX_BUILD_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE1) CC="$(HOSTCC) -idirafter $(HOST_DIR)/usr/include $(HOST_LDFLAGS)" \
-		AR="$(HOSTAR)" $(SYSLINUX_EFI_ARGS) -C $(@D) $(SYSLINUX_TARGET)
+	$(SYSLINUX_MAKE) -C $(@D) $(SYSLINUX_TARGET)
 endef
 
 # While the actual bootloader is compiled for the target, several
@@ -61,8 +84,7 @@ endef
 # Repeat CC and AR, since syslinux really wants to check them at
 # install time
 define SYSLINUX_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE1) CC="$(HOSTCC) -idirafter $(HOST_DIR)/usr/include $(HOST_LDFLAGS)" \
-		AR="$(HOSTAR)" $(SYSLINUX_EFI_ARGS) INSTALLROOT=$(HOST_DIR) \
+	$(SYSLINUX_MAKE) INSTALLROOT=$(@D)/inst \
 		-C $(@D) $(SYSLINUX_TARGET) install
 endef
 
@@ -80,10 +102,21 @@ define SYSLINUX_INSTALL_IMAGES_CMDS
 	for i in $(SYSLINUX_IMAGES-y); do \
 		$(INSTALL) -D -m 0755 $(@D)/$$i $(BINARIES_DIR)/syslinux/$${i##*/}; \
 	done
-	for i in $(SYSLINUX_C32); do \

boot/syslinux/syslinux.mk define SYSLINUX_INSTALL_IMAGES_CMDS · line 113

Quoted 10 lines
boot/syslinux/syslinux.mk +5 -1
-		$(INSTALL) -D -m 0755 $(HOST_DIR)/usr/share/syslinux/$${i} \
+	for i in $(SYSLINUX_C32) ldlinux.c32; do \
+		$(INSTALL) -D -m 0755 $(@D)/inst/usr/share/syslinux/$${i} \
 			$(BINARIES_DIR)/syslinux/$${i}; \
 	done
 endef
 
+define HOST_SYSLINUX_BUILD_CMDS
+       $(HOST_MAKE_ENV) $(MAKE1) CC="$(HOSTCC) -idirafter $(HOST_DIR)/usr/include $(HOST_LDFLAGS)" \
+-               AR="$(HOSTAR)" -C $(@D) bios

^
Leading dash here?...

Also, use TABs for indentation of the *_CMDS defines.

But then, you are building the 'bios' stuff with the host compiler. Doesn't that defeats the very purpose of that patch, and contradicts the commit log itself (which states that we are now using the target toolchain) ?

boot/syslinux/syslinux.mk define SYSLINUX_INSTALL_IMAGES_CMDS · line 122

Quoted 9 lines
boot/syslinux/syslinux.mk +8 -0
+endef
+
+define HOST_SYSLINUX_INSTALL_CMDS
+       $(HOST_MAKE_ENV) $(MAKE1) CC="$(HOSTCC) -idirafter $(HOST_DIR)/usr/include $(HOST_LDFLAGS)" \
+-               AR="$(HOSTAR)" -C $(@D) INSTALLROOT=$(HOST_DIR) bios install
+endef
+
 $(eval $(generic-package))
+$(eval $(host-generic-package))

Since you submitted this patch, we've changed the way how dependencies of host packages are handled: they are no longer automatically inherited from the dependencies of the target variant; you now have to explicitly define the dependencies of the host variant.

Regards,
Yann E. MORIN.

Quoted 29 lines
fs/iso9660/iso9660.mk +2 -2
index f97a9d7..db22ca4 100644
@@ -70,8 +70,6 @@ ROOTFS_ISO9660_BOOT_IMAGE = isolinux/isolinux.bin
 define ROOTFS_ISO9660_INSTALL_BOOTLOADER
 	$(INSTALL) -D -m 0644 $(BINARIES_DIR)/syslinux/* \
 		$(ROOTFS_ISO9660_TARGET_DIR)/isolinux/
-	$(INSTALL) -D -m 0644 $(HOST_DIR)/usr/share/syslinux/ldlinux.c32 \
-		$(ROOTFS_ISO9660_TARGET_DIR)/isolinux/ldlinux.c32
 endef
 endif
 
@@ -166,6 +164,8 @@ define ROOTFS_ISO9660_CMD
 endef
 
 ifeq ($(BR2_TARGET_ROOTFS_ISO9660_HYBRID),y)
+ROOTFS_ISO9660_DEPENDENCIES += host-syslinux
+
 define ROOTFS_ISO9660_GEN_HYBRID
 	$(ROOTFS_ISO9660_ISOHYBRID) -t 0x96 $@
 endef
Signature · 6 lines
2.8.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'