This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 2/2] Allow to override build date with SOURCE_DATE_EPOCH
- From: "Bernhard M. Wiedemann" <bwiedemann at suse dot de>
- To: binutils at sourceware dot org
- Cc: "Linda Zhang" <lindasc at qq dot com>, "Nick Clifton" <nickc at redhat dot com>, "Bernhard M. Wiedemann" <bwiedemann at suse dot de>
- Date: Fri, 26 Oct 2018 07:59:27 +0200
- Subject: [PATCH 2/2] Allow to override build date with SOURCE_DATE_EPOCH
- References: <20181026055927.23012-1-bwiedemann@suse.de>
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