aboutsummaryrefslogtreecommitdiff
path: root/bfd/peXXigen.c
diff options
context:
space:
mode:
authorJohannes Schauer Marin Rodrigues <josch@debian.org>2023-07-24 16:59:19 +0100
committerNick Clifton <nickc@redhat.com>2023-07-24 16:59:19 +0100
commit6badd1020f5bebd3f60a780b8e41a1b581046087 (patch)
tree0b1d5349acee5860922b00f2bf00c958d34b0d43 /bfd/peXXigen.c
parent4701770c57af26fd410f652dc5f742a10d1c54dc (diff)
downloadfsf-binutils-gdb-6badd1020f5bebd3f60a780b8e41a1b581046087.zip
fsf-binutils-gdb-6badd1020f5bebd3f60a780b8e41a1b581046087.tar.gz
fsf-binutils-gdb-6badd1020f5bebd3f60a780b8e41a1b581046087.tar.bz2
objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible.
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.
Diffstat (limited to 'bfd/peXXigen.c')
-rw-r--r--bfd/peXXigen.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index da53f34..cdd89f8 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -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);