[tor-commits] [tor-messenger-build/master] binutils: add patch to define PE timestamps using SOURCE_DATE_EPOCH
boklm at torproject.org
boklm at torproject.org
Fri Oct 16 17:25:26 UTC 2015
commit 7209f00a2c3f4aa068da5c8bb5fc532611765d07
Author: Nicolas Vigier <boklm at torproject.org>
Date: Fri Oct 16 00:39:21 2015 +0200
binutils: add patch to define PE timestamps using SOURCE_DATE_EPOCH
Patch from Debian:
https://anonscm.debian.org/cgit/collab-maint/binutils-mingw-w64.git/
SOURCE_DATE_EPOCH specification:
https://reproducible-builds.org/specs/source-date-epoch/
---
projects/binutils/build | 5 +-
projects/binutils/config | 5 +-
projects/binutils/peXXigen.patch | 14 ----
projects/binutils/specify-timestamp.patch | 123 +++++++++++++++++++++++++++++
4 files changed, 130 insertions(+), 17 deletions(-)
diff --git a/projects/binutils/build b/projects/binutils/build
index 765c4c9..3531e89 100644
--- a/projects/binutils/build
+++ b/projects/binutils/build
@@ -8,8 +8,9 @@ cd [% project %]-[% c("version") %]
sed 's/= extern_rt_rel_d;/= extern_rt_rel_d;\n memset (extern_rt_rel_d, 0, PE_IDATA5_SIZE);/' -i ld/pe-dll.c
# Needed for the hardening...
patch -p1 < ../enable-reloc-section-ld.patch
-# Zeroing timestamps in PE headers reliably, see bug 12753.
-patch -p1 < ../peXXigen.patch
+# specify-timestamp patch from Stephen Kitt <steve at sk2.org>
+# https://anonscm.debian.org/cgit/collab-maint/binutils-mingw-w64.git/
+patch -p2 < ../specify-timestamp.patch
[% END -%]
./configure --prefix=$distdir [% c('var/configure_opt') %]
make -j4
diff --git a/projects/binutils/config b/projects/binutils/config
index 7bd26f5..dee7ef0 100644
--- a/projects/binutils/config
+++ b/projects/binutils/config
@@ -29,5 +29,8 @@ input_files:
- project: docker-image
- filename: enable-reloc-section-ld.patch
enable: '[% c("var/windows") %]'
- - filename: peXXigen.patch
+
+ # specify-timestamp patch from Stephen Kitt <steve at sk2.org>
+ # https://anonscm.debian.org/cgit/collab-maint/binutils-mingw-w64.git/
+ - filename: specify-timestamp.patch
enable: '[% c("var/windows") %]'
diff --git a/projects/binutils/peXXigen.patch b/projects/binutils/peXXigen.patch
deleted file mode 100644
index f07dcf5..0000000
--- a/projects/binutils/peXXigen.patch
+++ /dev/null
@@ -1,14 +0,0 @@
-diff -crB binutils-2.24/bfd/peXXigen.c binutils-2.24/bfd/peXXigen.c
-*** binutils-2.24/bfd/peXXigen.c Tue Nov 26 11:37:33 2013
---- binutils-2.24/bfd/peXXigen.c Mon Aug 4 07:10:15 2014
-***************
-*** 795,800 ****
---- 795,802 ----
- /* Only use a real timestamp if the option was chosen. */
- if ((pe_data (abfd)->insert_timestamp))
- H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
-+ else
-+ H_PUT_32 (abfd, 0, filehdr_out->f_timdat);
-
- PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
- filehdr_out->f_symptr);
diff --git a/projects/binutils/specify-timestamp.patch b/projects/binutils/specify-timestamp.patch
new file mode 100644
index 0000000..37f4347
--- /dev/null
+++ b/projects/binutils/specify-timestamp.patch
@@ -0,0 +1,123 @@
+--- a/upstream/bfd/peXXigen.c
++++ b/upstream/bfd/peXXigen.c
+@@ -66,6 +66,9 @@
+ #include <wchar.h>
+ #endif
+
++#include <errno.h>
++#include <limits.h>
++
+ /* NOTE: it's strange to be including an architecture specific header
+ in what's supposed to be general (to PE/PEI) code. However, that's
+ where the definitions are, and they don't vary per architecture
+@@ -873,8 +876,36 @@
+ H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns);
+
+ /* Only use a real timestamp if the option was chosen. */
+- if ((pe_data (abfd)->insert_timestamp))
+- H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
++ if (pe_data (abfd)->insert_timestamp) {
++ time_t now;
++ char *source_date_epoch;
++ unsigned long long epoch;
++ char *endptr;
++
++ now = time(NULL);
++ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
++ if (source_date_epoch) {
++ errno = 0;
++ epoch = strtoull(source_date_epoch, &endptr, 10);
++ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
++ || (errno != 0 && epoch == 0)) {
++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n",
++ strerror(errno));
++ } else if (endptr == source_date_epoch) {
++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n",
++ endptr);
++ } else if (*endptr != '\0') {
++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
++ endptr);
++ } else if (epoch > ULONG_MAX) {
++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu\n",
++ ULONG_MAX, epoch);
++ } else {
++ now = epoch;
++ }
++ }
++ H_PUT_32 (abfd, now, filehdr_out->f_timdat);
++ }
+
+ PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
+ filehdr_out->f_symptr);
+--- a/upstream/ld/pe-dll.c
++++ b/upstream/ld/pe-dll.c
+@@ -26,6 +26,8 @@
+ #include "filenames.h"
+ #include "safe-ctype.h"
+
++#include <errno.h>
++#include <limits.h>
+ #include <time.h>
+
+ #include "ld.h"
+@@ -1185,8 +1187,36 @@
+
+ memset (edata_d, 0, edata_sz);
+
+- if (pe_data (abfd)->insert_timestamp)
+- H_PUT_32 (abfd, time (0), edata_d + 4);
++ if (pe_data (abfd)->insert_timestamp) {
++ time_t now;
++ char *source_date_epoch;
++ unsigned long long epoch;
++ char *endptr;
++
++ now = time(NULL);
++ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
++ if (source_date_epoch) {
++ errno = 0;
++ epoch = strtoull(source_date_epoch, &endptr, 10);
++ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
++ || (errno != 0 && epoch == 0)) {
++ einfo("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n",
++ strerror(errno));
++ } else if (endptr == source_date_epoch) {
++ einfo("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n",
++ endptr);
++ } else if (*endptr != '\0') {
++ einfo("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
++ endptr);
++ } else if (epoch > ULONG_MAX) {
++ einfo("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu\n",
++ ULONG_MAX, epoch);
++ } else {
++ now = epoch;
++ }
++ }
++ H_PUT_32 (abfd, now, edata_d + 4);
++ }
+
+ if (pe_def_file->version_major != -1)
+ {
+--- a/upstream/ld/emultempl/pe.em
++++ b/upstream/ld/emultempl/pe.em
+@@ -307,7 +307,7 @@
+ OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
+ {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
+ {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
+- {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
++ {"insert-timestamp", optional_argument, NULL, OPTION_INSERT_TIMESTAMP},
+ {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
+ #ifdef DLL_SUPPORT
+ /* getopt allows abbreviations, so we do this to stop it
+--- a/upstream/ld/emultempl/pep.em
++++ b/upstream/ld/emultempl/pep.em
+@@ -324,7 +324,7 @@
+ {"no-bind", no_argument, NULL, OPTION_NO_BIND},
+ {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
+ {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
+- {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
++ {"insert-timestamp", optional_argument, NULL, OPTION_INSERT_TIMESTAMP},
+ {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
+ {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
+ {NULL, no_argument, NULL, 0}
More information about the tor-commits
mailing list