|
| 1 | +This file is part of MXE. See LICENSE.md for licensing information. |
| 2 | + |
| 3 | +Contains ad hoc patches for cross building. |
| 4 | + |
| 5 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 6 | +From: Stephen Kitt < [email protected]> |
| 7 | +Date: Sat, 15 Jul 2017 00:09:40 +1000 |
| 8 | +Subject: [PATCH 1/2] Allow the PE timestamp to be specified with |
| 9 | + SOURCE_DATE_EPOCH |
| 10 | + |
| 11 | +Taken from: |
| 12 | +https://sources.debian.net/patches/binutils-mingw-w64/7.4/specify-timestamp.patch/ |
| 13 | + |
| 14 | +diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c |
| 15 | +index 1111111..2222222 100644 |
| 16 | +--- a/bfd/peXXigen.c |
| 17 | ++++ b/bfd/peXXigen.c |
| 18 | +@@ -77,6 +77,9 @@ |
| 19 | + #include <wctype.h> |
| 20 | + #endif |
| 21 | + |
| 22 | ++#include <errno.h> |
| 23 | ++#include <limits.h> |
| 24 | ++ |
| 25 | + /* NOTE: it's strange to be including an architecture specific header |
| 26 | + in what's supposed to be general (to PE/PEI) code. However, that's |
| 27 | + where the definitions are, and they don't vary per architecture |
| 28 | +@@ -856,7 +859,36 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in, void * out) |
| 29 | + /* Use a real timestamp by default, unless the no-insert-timestamp |
| 30 | + option was chosen. */ |
| 31 | + if ((pe_data (abfd)->timestamp) == -1) |
| 32 | +- H_PUT_32 (abfd, time (0), filehdr_out->f_timdat); |
| 33 | ++ { |
| 34 | ++ time_t now; |
| 35 | ++ char *source_date_epoch; |
| 36 | ++ unsigned long long epoch; |
| 37 | ++ char *endptr; |
| 38 | ++ |
| 39 | ++ now = time (0); |
| 40 | ++ source_date_epoch = getenv("SOURCE_DATE_EPOCH"); |
| 41 | ++ if (source_date_epoch) { |
| 42 | ++ errno = 0; |
| 43 | ++ epoch = strtoull(source_date_epoch, &endptr, 10); |
| 44 | ++ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) |
| 45 | ++ || (errno != 0 && epoch == 0)) { |
| 46 | ++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", |
| 47 | ++ strerror(errno)); |
| 48 | ++ } else if (endptr == source_date_epoch) { |
| 49 | ++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", |
| 50 | ++ endptr); |
| 51 | ++ } else if (*endptr != '\0') { |
| 52 | ++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", |
| 53 | ++ endptr); |
| 54 | ++ } else if (epoch > ULONG_MAX) { |
| 55 | ++ _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu\n", |
| 56 | ++ ULONG_MAX, epoch); |
| 57 | ++ } else { |
| 58 | ++ now = epoch; |
| 59 | ++ } |
| 60 | ++ } |
| 61 | ++ H_PUT_32 (abfd, now, filehdr_out->f_timdat); |
| 62 | ++ } |
| 63 | + else |
| 64 | + H_PUT_32 (abfd, pe_data (abfd)->timestamp, filehdr_out->f_timdat); |
| 65 | + |
| 66 | +diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em |
| 67 | +index 1111111..2222222 100644 |
| 68 | +--- a/ld/emultempl/pe.em |
| 69 | ++++ b/ld/emultempl/pe.em |
| 70 | +@@ -318,7 +318,7 @@ gld${EMULATION_NAME}_add_options |
| 71 | + OPTION_USE_NUL_PREFIXED_IMPORT_TABLES}, |
| 72 | + {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE}, |
| 73 | + {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE}, |
| 74 | +- {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP}, |
| 75 | ++ {"insert-timestamp", optional_argument, NULL, OPTION_INSERT_TIMESTAMP}, |
| 76 | + {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP}, |
| 77 | + #ifdef DLL_SUPPORT |
| 78 | + /* getopt allows abbreviations, so we do this to stop it |
| 79 | +diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em |
| 80 | +index 1111111..2222222 100644 |
| 81 | +--- a/ld/emultempl/pep.em |
| 82 | ++++ b/ld/emultempl/pep.em |
| 83 | +@@ -337,7 +337,7 @@ gld${EMULATION_NAME}_add_options |
| 84 | + {"no-bind", no_argument, NULL, OPTION_NO_BIND}, |
| 85 | + {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER}, |
| 86 | + {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE}, |
| 87 | +- {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP}, |
| 88 | ++ {"insert-timestamp", optional_argument, NULL, OPTION_INSERT_TIMESTAMP}, |
| 89 | + {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP}, |
| 90 | + {"build-id", optional_argument, NULL, OPTION_BUILD_ID}, |
| 91 | + {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION}, |
| 92 | +diff --git a/ld/pe-dll.c b/ld/pe-dll.c |
| 93 | +index 1111111..2222222 100644 |
| 94 | +--- a/ld/pe-dll.c |
| 95 | ++++ b/ld/pe-dll.c |
| 96 | +@@ -27,6 +27,8 @@ |
| 97 | + #include "safe-ctype.h" |
| 98 | + #include "ctf-api.h" |
| 99 | + |
| 100 | ++#include <errno.h> |
| 101 | ++#include <limits.h> |
| 102 | + #include <time.h> |
| 103 | + |
| 104 | + #include "ld.h" |
| 105 | +@@ -1220,7 +1222,36 @@ fill_edata (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED) |
| 106 | + memset (edata_d, 0, edata_sz); |
| 107 | + |
| 108 | + if (pe_data (abfd)->timestamp == -1) |
| 109 | +- H_PUT_32 (abfd, time (0), edata_d + 4); |
| 110 | ++ { |
| 111 | ++ time_t now; |
| 112 | ++ char *source_date_epoch; |
| 113 | ++ unsigned long long epoch; |
| 114 | ++ char *endptr; |
| 115 | ++ |
| 116 | ++ now = time(0); |
| 117 | ++ source_date_epoch = getenv("SOURCE_DATE_EPOCH"); |
| 118 | ++ if (source_date_epoch) { |
| 119 | ++ errno = 0; |
| 120 | ++ epoch = strtoull(source_date_epoch, &endptr, 10); |
| 121 | ++ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) |
| 122 | ++ || (errno != 0 && epoch == 0)) { |
| 123 | ++ einfo("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", |
| 124 | ++ strerror(errno)); |
| 125 | ++ } else if (endptr == source_date_epoch) { |
| 126 | ++ einfo("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", |
| 127 | ++ endptr); |
| 128 | ++ } else if (*endptr != '\0') { |
| 129 | ++ einfo("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", |
| 130 | ++ endptr); |
| 131 | ++ } else if (epoch > ULONG_MAX) { |
| 132 | ++ einfo("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu\n", |
| 133 | ++ ULONG_MAX, epoch); |
| 134 | ++ } else { |
| 135 | ++ now = epoch; |
| 136 | ++ } |
| 137 | ++ } |
| 138 | ++ H_PUT_32 (abfd, now, edata_d + 4); |
| 139 | ++ } |
| 140 | + else |
| 141 | + H_PUT_32 (abfd, pe_data (abfd)->timestamp, edata_d + 4); |
| 142 | + |
| 143 | + |
| 144 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 145 | +From: Tony Theodore < [email protected]> |
| 146 | +Date: Fri, 23 Apr 2021 09:10:50 +1000 |
| 147 | +Subject: [PATCH 2/2] PE/Windows x86_64: Fix weak undef symbols after image |
| 148 | + base change |
| 149 | + |
| 150 | +See: |
| 151 | +https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0ff9fad8bf790eebb21a1c1ee378f1c2dd1971af |
| 152 | + |
| 153 | +diff --git a/bfd/cofflink.c b/bfd/cofflink.c |
| 154 | +index 1111111..2222222 100644 |
| 155 | +--- a/bfd/cofflink.c |
| 156 | ++++ b/bfd/cofflink.c |
| 157 | +@@ -3118,6 +3118,21 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd, |
| 158 | + return FALSE; |
| 159 | + case bfd_reloc_overflow: |
| 160 | + { |
| 161 | ++ |
| 162 | ++ /* Ignore any weak undef symbols that may have overflowed. Due to |
| 163 | ++ PR ld/19011 the base address is now in the upper 64-bit address |
| 164 | ++ range. This means that when _bfd_final_link_relocate calculates |
| 165 | ++ the overlow it takes the distance between the symbol and the VMA |
| 166 | ++ which will now always overflow as 0 - 64-bit addr > 32-bit range |
| 167 | ++ of the relocation. This ends up creating PR ld/26659. */ |
| 168 | ++ if (val == 0 |
| 169 | ++ /* Reverse the hack where 4 is subtracted from the addend. */ |
| 170 | ++ && (addend + 4) == 0 |
| 171 | ++ && sym->n_sclass == C_NT_WEAK |
| 172 | ++ && bfd_coff_classify_symbol (output_bfd, sym) |
| 173 | ++ == COFF_SYMBOL_UNDEFINED) |
| 174 | ++ break; |
| 175 | ++ |
| 176 | + const char *name; |
| 177 | + char buf[SYMNMLEN + 1]; |
| 178 | + |
0 commit comments