From patchwork Tue Mar 31 22:48:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Dong X-Patchwork-Id: 21023 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D2E7D27BBE4; Tue, 31 Mar 2020 23:49:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 4263127BBE1 for ; Tue, 31 Mar 2020 23:49:15 +0100 (BST) Received: from localhost ([::1]:44904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJPh4-0007ma-RW for patchwork@mira.cbaines.net; Tue, 31 Mar 2020 18:49:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50482) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJPgt-0007mP-Jo for guix-patches@gnu.org; Tue, 31 Mar 2020 18:49:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJPgr-00084G-TZ for guix-patches@gnu.org; Tue, 31 Mar 2020 18:49:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53887) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJPgr-000842-QK for guix-patches@gnu.org; Tue, 31 Mar 2020 18:49:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jJPgr-0001qq-ND for guix-patches@gnu.org; Tue, 31 Mar 2020 18:49:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40362] [PATCH] gnu: cross-base: Add mingw-w64 specific binutils patches. Resent-From: Carl Dong Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 31 Mar 2020 22:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40362 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40362@debbugs.gnu.org X-Debbugs-Original-To: "guix-patches@gnu.org" Received: via spool by submit@debbugs.gnu.org id=B.15856949317098 (code B ref -1); Tue, 31 Mar 2020 22:49:01 +0000 Received: (at submit) by debbugs.gnu.org; 31 Mar 2020 22:48:51 +0000 Received: from localhost ([127.0.0.1]:37200 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jJPgh-0001qQ-7o for submit@debbugs.gnu.org; Tue, 31 Mar 2020 18:48:51 -0400 Received: from lists.gnu.org ([209.51.188.17]:37336) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jJPge-0001qG-L8 for submit@debbugs.gnu.org; Tue, 31 Mar 2020 18:48:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49463) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJPga-0007lz-3a for guix-patches@gnu.org; Tue, 31 Mar 2020 18:48:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJPgU-0007AB-VQ for guix-patches@gnu.org; Tue, 31 Mar 2020 18:48:41 -0400 Received: from mail1.protonmail.ch ([185.70.40.18]:35724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJPgR-000727-Si for guix-patches@gnu.org; Tue, 31 Mar 2020 18:48:36 -0400 Date: Tue, 31 Mar 2020 22:48:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carldong.me; s=protonmail; t=1585694909; bh=9L7FkF1hH2awWCzwCvF/gzC+wB6jeLokZbYK4/mdEog=; h=Date:To:From:Reply-To:Subject:From; b=W2/kWdG9uSJuRACL7oZ4P0EidclHLSXNhVt6/6P2bvCslX3hFn0od4buC69g+0l1c ZjamSH8V8UGUvYyoFPORI6WGD5OB/VilA65u4EvrNOnwWDUEymY+eeq1OI5SDFL9NL U/0TvYyirO50dSZW3ctN0ZnVOtvQiYtXDicwEb/g= From: Carl Dong Message-ID: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Carl Dong Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 -- 2.25.1 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 +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 + +--- a/bfd/peXXigen.c ++++ b/bfd/peXXigen.c +@@ -70,6 +70,9 @@ + #include + #endif + ++#include ++#include ++ + /* 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 ++#include + #include + + #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}