This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] Allow to override build date with SOURCE_DATE_EPOCH


in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.

This helps making xen efi binaries build reproducibly by default
much more elegantly than
https://lists.xenproject.org/archives/html/xen-devel/2018-10/msg01850.html
---
 bfd/peXXigen.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index bfa21166ae..778dbf1191 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -880,7 +880,14 @@ _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)->insert_timestamp))
-    H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
+    {
+      time_t build_time;
+      const char *source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
+      if (source_date_epoch == NULL
+          || (build_time = strtoll (source_date_epoch, NULL, 10)) <= 0)
+        build_time = time (0);
+      H_PUT_32 (abfd, build_time, filehdr_out->f_timdat);
+    }
   else
     H_PUT_32 (abfd, 0, filehdr_out->f_timdat);
 
-- 
2.16.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]