public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch] objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible
@ 2023-07-19 10:54 Matthias Klose
  2023-07-19 11:02 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Klose @ 2023-07-19 10:54 UTC (permalink / raw)
  To: binutils

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,



^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <168983055254.2785030.15255872242112800439@localhost>]

end of thread, other threads:[~2023-07-24 16:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 10:54 [patch] objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible Matthias Klose
2023-07-19 11:02 ` Nick Clifton
     [not found] <168983055254.2785030.15255872242112800439@localhost>
2023-07-20 11:08 ` Nick Clifton
2023-07-20 23:15   ` Johannes Schauer Marin Rodrigues
2023-07-24 16:01     ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).