all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Carl Dong <contact@carldong.me>
To: 40362@debbugs.gnu.org
Subject: [bug#40362] [PATCH] gnu: cross-base: Add mingw-w64 specific binutils patches.
Date: Tue, 31 Mar 2020 22:48:24 +0000	[thread overview]
Message-ID: <Zel3Xcb7x0-7-LXef-o7GY6JJbcTvq0PC6BXddwDh4YrO7Trk2Tz8dC4WZQEw14bd6vb04AbS79Z6MAr4sRyecgmHoau2BR12fXXsAgJCAw=@carldong.me> (raw)

These patches were originally found at the debian mingw-w64 team's
binutils repo, and should improve the reproducibility of our mingw-w64
toolchain.

* gnu/packages/patches/binutils-mingw-w64-reproducible-import-libraries.patch:
New file.
* gnu/packages/patches/binutils-mingw-w64-specify-timestamp.patch:
New file.
* gnu/packages/cross-base.scm (cross-binutils): Apply relevant patches
if target is mingw-w64.
(package-with-extra-patches): New procedure.
---
 gnu/packages/cross-base.scm                   |  21 ++-
 ...gw-w64-reproducible-import-libraries.patch |  22 +++
 ...binutils-mingw-w64-specify-timestamp.patch | 137 ++++++++++++++++++
 3 files changed, 175 insertions(+), 5 deletions(-)
 create mode 100755 gnu/packages/patches/binutils-mingw-w64-reproducible-import-libraries.patch
 create mode 100755 gnu/packages/patches/binutils-mingw-w64-specify-timestamp.patch

diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index ab866eebc6..571a47f72a 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -76,6 +76,12 @@
     (source (origin (inherit (package-source original))
               (patches (list patch))))))

+(define (package-with-extra-patches original patches)
+  "Return package ORIGINAL with all PATCHES appended to its list of patches."
+  (package-with-patch original
+                      `(,@(origin-patches (package-source original))
+                        ,@patches))
+
 (define (cross-binutils target)
   "Return a cross-Binutils for TARGET."
   (let ((binutils (package (inherit binutils)
@@ -97,11 +103,16 @@
                         `(cons "--with-sysroot=/" ,flags)))))))

     ;; For Xtensa, apply Qualcomm's patch.
-    (cross (if (string-prefix? "xtensa-" target)
-               (package-with-patch binutils
-                                   (search-patch
-                                    "ath9k-htc-firmware-binutils.patch"))
-               binutils)
+    (cross (cond ((string-prefix? "xtensa-" target)
+                  (package-with-patch binutils
+                                      (search-patch
+                                       "ath9k-htc-firmware-binutils.patch")))
+                 ((target-mingw? target)
+                  (package-with-extra-patches binutils
+                                              (search-patches
+                                               "binutils-mingw-w64-specify-timestamp.patch"
+                                               "binutils-mingw-w64-reproducible-import-libraries.patch")))
+                 (else binutils))
            target)))

 (define (cross-gcc-arguments target xgcc libc)
diff --git a/gnu/packages/patches/binutils-mingw-w64-reproducible-import-libraries.patch b/gnu/packages/patches/binutils-mingw-w64-reproducible-import-libraries.patch
new file mode 100755
index 0000000000..3e48b87935
--- /dev/null
+++ b/gnu/packages/patches/binutils-mingw-w64-reproducible-import-libraries.patch
@@ -0,0 +1,22 @@
+This following patch was originally found at the debian mingw-w64 team's
+binutils repo located here:
+https://salsa.debian.org/mingw-w64-team/binutils-mingw-w64.git
+
+Invoke the following in the aforementioned repo to see the original patch:
+
+  $ git show da63f6b:debian/patches/reproducible-import-libraries.patch
+
+Description: Make DLL import libraries reproducible
+Author: Benjamin Moody <benjamin.moody@gmail.com>
+Bug-Debian: https://bugs.debian.org/915055
+
+--- a/ld/pe-dll.c
++++ b/ld/pe-dll.c
+@@ -2844,6 +2844,7 @@
+
+   bfd_set_format (outarch, bfd_archive);
+   outarch->has_armap = 1;
++  outarch->flags |= BFD_DETERMINISTIC_OUTPUT;
+
+   /* Work out a reasonable size of things to put onto one line.  */
+   ar_head = make_head (outarch);
diff --git a/gnu/packages/patches/binutils-mingw-w64-specify-timestamp.patch b/gnu/packages/patches/binutils-mingw-w64-specify-timestamp.patch
new file mode 100755
index 0000000000..b785043b62
--- /dev/null
+++ b/gnu/packages/patches/binutils-mingw-w64-specify-timestamp.patch
@@ -0,0 +1,137 @@
+This following patch was originally found at the debian mingw-w64 team's
+binutils repo located here:
+https://salsa.debian.org/mingw-w64-team/binutils-mingw-w64.git
+
+Invoke the following in the aforementioned repo to see the original patch:
+
+  $ git show da63f6b:debian/patches/specify-timestamp.patch
+
+Description: Allow the PE timestamp to be specified
+Author: Stephen Kitt <skitt@debian.org>
+
+--- a/bfd/peXXigen.c
++++ b/bfd/peXXigen.c
+@@ -70,6 +70,9 @@
+ #include <wctype.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
+@@ -879,10 +882,38 @@
+
+   /* 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);
+-  else
++  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);
++  } else {
+     H_PUT_32 (abfd, 0, filehdr_out->f_timdat);
++  }
+
+   PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
+ 		      filehdr_out->f_symptr);
+--- a/ld/pe-dll.c
++++ b/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"
+@@ -1202,8 +1204,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/ld/emultempl/pe.em
++++ b/ld/emultempl/pe.em
+@@ -303,7 +303,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/ld/emultempl/pep.em
++++ b/ld/emultempl/pep.em
+@@ -321,7 +321,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}
--
2.25.1

             reply	other threads:[~2020-03-31 22:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 22:48 Carl Dong [this message]
2020-04-01 14:14 ` [bug#40362] [PATCH] gnu: cross-base: Add mingw-w64 specific binutils patches Mathieu Othacehe
2020-04-01 19:54   ` Carl Dong
2020-04-02  9:45     ` Mathieu Othacehe
2020-04-02 15:53       ` Marius Bakke
2020-04-02 16:12         ` Mathieu Othacehe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='Zel3Xcb7x0-7-LXef-o7GY6JJbcTvq0PC6BXddwDh4YrO7Trk2Tz8dC4WZQEw14bd6vb04AbS79Z6MAr4sRyecgmHoau2BR12fXXsAgJCAw=@carldong.me' \
    --to=contact@carldong.me \
    --cc=40362@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.