aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorTamar Christina <tamar.christina@arm.com>2021-04-01 17:10:38 +0100
committerTamar Christina <tamar.christina@arm.com>2021-04-01 17:54:04 +0100
commit74edb473c9ecf5e2053ecf8e429ee608feafb9e1 (patch)
tree11f8dfbfd750cdc3fc6f4a2e122916ace08e52dc /bfd
parentcaaf412e9890dac4323b47b58cd38b7ebb26a7db (diff)
downloadfsf-binutils-gdb-74edb473c9ecf5e2053ecf8e429ee608feafb9e1.zip
fsf-binutils-gdb-74edb473c9ecf5e2053ecf8e429ee608feafb9e1.tar.gz
fsf-binutils-gdb-74edb473c9ecf5e2053ecf8e429ee608feafb9e1.tar.bz2
PE/Windows x86_64: Fix weak undef symbols after image base change
The change in PR19011 changed the image load address from being in the lower 32-bit address space to the higher 64-bit address space. However when you have a weak undef symbol which stays undef at the end of linking the linker has to resolve this (Windows loader does not support undef symbols). As such typically these would resolve to 0. The relocation used for these weak symbols are the normal 32-bit PC_REL call relocs. So when doing the overflow check LD checks if the distance between the symbol and the call is within range. However now that the load address is > 32-bits and the symbol val is 0 this overflow check will always fail. As such the linker gives a bogus error. This patch makes the linker not emit the overflow failure but chooses to still let the check be performed (as it's mid-end code). One down side of this is that it does break the common convention that the call be to sym at 0x0. i.e. before you'd get 401015: 74 05 je 40101c 401017: e8 e4 ef bf ff callq 0 and now you get 140001015: 74 05 je 14000101c 140001017: e8 e4 ef ff bf call 100000000 since the call is PC_REL there's no way to get the range large enough to resolve to 0. As such I have chosen to leave it as the furthest simple range that we can still represent. By only ignoring the error we leave the symbol value itself to still be 0 such that the if(<symbol>) checks still work correctly. bfd/ChangeLog: 2021-04-01 Tamar Christina <tamar.christina@arm.com> PR ld/26659 * cofflink.c (_bfd_coff_generic_relocate_section): Ignore overflow. ld/ChangeLog: 2021-04-01 Tamar Christina <tamar.christina@arm.com> PR ld/26659 * testsuite/ld-pe/pe.exp: Add test. * testsuite/ld-pe/pr26659-weak-undef-sym.d: New test. * testsuite/ld-pe/pr26659-weak-undef-sym.s: New test.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/cofflink.c15
2 files changed, 20 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 4977dc9..0fcdf19 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-01 Tamar Christina <tamar.christina@arm.com>
+
+ PR ld/26659
+ * cofflink.c (_bfd_coff_generic_relocate_section): Ignore overflow.
+
2021-04-01 Martin Liska <mliska@suse.cz>
* ecoff.c (strneq): Remove strneq and use startswith.
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index c6b65c7..dd3e8dd 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -3129,6 +3129,21 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
return false;
case bfd_reloc_overflow:
{
+
+ /* Ignore any weak undef symbols that may have overflowed. Due to
+ PR ld/19011 the base address is now in the upper 64-bit address
+ range. This means that when _bfd_final_link_relocate calculates
+ the overlow it takes the distance between the symbol and the VMA
+ which will now always overflow as 0 - 64-bit addr > 32-bit range
+ of the relocation. This ends up creating PR ld/26659. */
+ if (val == 0
+ /* Reverse the hack where 4 is subtracted from the addend. */
+ && (addend + 4) == 0
+ && sym->n_sclass == C_NT_WEAK
+ && bfd_coff_classify_symbol (output_bfd, sym)
+ == COFF_SYMBOL_UNDEFINED)
+ break;
+
const char *name;
char buf[SYMNMLEN + 1];