[patch] objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible
Matthias Klose
doko@debian.org
Wed Jul 19 10:54:58 GMT 2023
This is forwarded from https://bugs.debian.org/1040450
is this suitable upstream, or should it be kept as a local patch?
SOURCE_DATE_EPOCH is also respected in GCC upstream.
Hi,
steps to reproduce the unreproducibility:
$ objcopy /usr/lib/systemd/boot/efi/linuxaa64.efi.stub bootaa64_1
$ objcopy /usr/lib/systemd/boot/efi/linuxaa64.efi.stub bootaa64_2
$ cmp bootaa64_1 bootaa64_2
bootaa64_1 bootaa64_2 differ: byte 137, line 1
The resulting bootaa64.efi will have the local time embedded which makes it
unreproducible unless faketime is used. Setting SOURCE_DATE_EPOCH or adding
--enable-deterministic-archives does not make a difference.
I identified the part of the code that generates this timestamp and pasted a
preliminary patch fixing this issue to the end of this email. With that patch,
setting SOURCE_DATE_EPOCH=0 results in a file with:
$ objdump -x bootaa64.efi
[...]
Time/Date Thu Jan 1 01:00:00 1970
Since building binutils takes 7.4 hours on my machine and since I have never
interacted with binutils upstream before, I'd appreciate if you could take it
from here and see that this problem gets fixed in binutils upstream the way
that its developers like to see this fixed.
Thanks!
cheers, josch
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -847,9 +847,17 @@ _bfd_XXi_only_swap_filehdr_out (bfd * ab
/* Use a real timestamp by default, unless the no-insert-timestamp
option was chosen. */
- if ((pe_data (abfd)->timestamp) == -1)
- H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
- else
+ if ((pe_data (abfd)->timestamp) == -1) {
+ time_t now;
+ char *source_date_epoch;
+ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+ if (source_date_epoch) {
+ now = (time_t)strtoll(source_date_epoch, NULL, 10);
+ } else {
+ now = time(NULL);
+ }
+ H_PUT_32 (abfd, now, filehdr_out->f_timdat);
+ } else
H_PUT_32 (abfd, pe_data (abfd)->timestamp, filehdr_out->f_timdat);
PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
More information about the Binutils
mailing list