]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unrep...
authorJohannes Schauer Marin Rodrigues <josch@debian.org>
Mon, 24 Jul 2023 15:59:19 +0000 (16:59 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 24 Jul 2023 15:59:19 +0000 (16:59 +0100)
bfd
  * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): If inserting a timestamp, use the value held in the SOURCE_DATE_EPOCH environment variable, if it is defined.
binutils
  * doc/binutils.texi (objcopy): Document change in behaviour of objcopy's --preserve-dates command line option.
ld
  * pe-dll.c (fill_edata): If inserting a timestamp, use the value held in the SOURCE_DATE_EPOCH environment variable, if it is defined.
  * ld.texi (--insert-timestamp): Document change in behaviour.

bfd/ChangeLog
bfd/peXXigen.c
binutils/ChangeLog
binutils/doc/binutils.texi
ld/ChangeLog
ld/ld.texi
ld/pe-dll.c

index db032df5ac2c04e541ad0ad5769f1c30356de92b..56c858e6ce4c878c494802843e1e5e6721cb44c4 100644 (file)
@@ -1,3 +1,9 @@
+2023-07-24  Johannes Schauer Marin Rodrigues  <josch@debian.org>
+
+       * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): If inserting a
+       timestamp, use the value held in the SOURCE_DATE_EPOCH environment
+       variable, if it is defined.
+
 2023-07-24  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * reloc.c: New reloc BFD_RELOC_BPF_DISPCALL32.
index da53f349dd03792978e15a99393f62b9874d806e..cdd89f8033052001f8e89b17939142a17052c749 100644 (file)
@@ -838,7 +838,20 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in, void * out)
   /* 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);
+    {
+      time_t now;
+      char *source_date_epoch;
+
+      /* If the SOURCE_DATE_EPOCH environment variable is
+        defined then use that as the time, otherwise use
+        the current time.  */
+      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);
 
index 097673f783e68604163d6a4854e33b390916838b..cfd4d1ad45e742eef6ebf2d94a54da157b12427c 100644 (file)
@@ -1,3 +1,8 @@
+2023-07-24  Johannes Schauer Marin Rodrigues  <josch@debian.org>
+
+       * doc/binutils.texi (objcopy): Document change in behaviour of
+       objcopy's --preserve-dates command line option.
+
 2023-07-09  Fangrui Song  <maskray@google.com>
 
        PR 30592
index 309bedf6110997174e8f4ff55d2fb1de0159816c..9f80f398c9de95ef0f83e25241889e8878ec8ba3 100644 (file)
@@ -1626,6 +1626,11 @@ commands.  If the input was '12345678' then the outputs would be
 Set the access and modification dates of the output file to be the same
 as those of the input file.
 
+This option also copies the date stored in a PE format file's header,
+unless the SOURCE_DATE_EPOCH environment variable is defined.  If it
+is defined then this variable will be used as the date stored in the
+header, interpreted as the number of seconds since the Unix epoch.
+
 @item -D
 @itemx --enable-deterministic-archives
 @cindex deterministic archives
index 27988491efdb8c8ad1429edd184a5562149c1d32..99029f1e18678670a81303edabeb076027828967 100644 (file)
@@ -1,3 +1,10 @@
+2023-07-24  Johannes Schauer Marin Rodrigues  <josch@debian.org>
+
+       * pe-dll.c (fill_edata): If inserting a timestamp, use the value
+       held in the SOURCE_DATE_EPOCH environment variable, if it is
+       defined.
+       * ld.texi (--insert-timestamp): Document change in behaviour.
+
 2023-07-03  Nick Clifton  <nickc@redhat.com>
 
        * configure: Regenerate.
index 75e82eda00462f6ceaeea9e4d4a4757609ae93fc..24e9debfb5f9817987fe10a25b7d79f917bf8493 100644 (file)
@@ -3571,6 +3571,11 @@ can be used to insert a zero value for the timestamp, this ensuring
 that binaries produced from identical sources will compare
 identically.
 
+If @option{--insert-timestamp} is active then the time inserted is
+either the time that the linking takes place or, if the
+@code{SOURCE_DATE_EPOCH} environment variable is defined, the number
+of seconds since Unix epoch as specified by that variable.
+
 @kindex --enable-reloc-section
 @item --enable-reloc-section
 @itemx --disable-reloc-section
index 02e03d169489259818e2e45f034b1ee44890b4d4..a95b85c60dd21fa893af491f247f4d86b794de2c 100644 (file)
@@ -1231,7 +1231,18 @@ fill_edata (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
   memset (edata_d, 0, edata_sz);
 
   if (pe_data (abfd)->timestamp == -1)
-    H_PUT_32 (abfd, time (0), edata_d + 4);
+    {
+      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, edata_d + 4);
+    }
   else
     H_PUT_32 (abfd, pe_data (abfd)->timestamp, edata_d + 4);