mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-06 12:09:26 +08:00
74edb473c9
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.
112 lines
3.4 KiB
Plaintext
112 lines
3.4 KiB
Plaintext
# Expect script for simple PE tests that require the just-built binutils only.
|
|
# Copyright (C) 2004-2021 Free Software Foundation, Inc.
|
|
#
|
|
# This file is part of the GNU Binutils.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
# MA 02110-1301, USA.
|
|
#
|
|
|
|
# These tests can only be run on PE/COFF platforms.
|
|
if {![is_pecoff_format]} {
|
|
return
|
|
}
|
|
|
|
# This test can only be run on PE/COFF platforms that support .secrel32.
|
|
if {[istarget i*86-*-cygwin*]
|
|
|| [istarget i*86-*-pe]
|
|
|| [istarget i*86-*-mingw*]
|
|
|| [istarget x86_64-*-mingw*]
|
|
|| [istarget arm-wince-pe] } {
|
|
|
|
if {[istarget x86_64-*-mingw*] } {
|
|
set pe_tests {
|
|
{".secrel32" "--disable-reloc-section" "" "" {secrel1.s secrel2.s}
|
|
{{objdump -s secrel_64.d}} "secrel.x"}
|
|
{"Empty export table" "" "" "" "exports.s"
|
|
{{objdump -p exports64.d}} "exports.dll"}
|
|
{"TLS directory entry" "" "" "" "tlssec.s"
|
|
{{objdump -p tlssec64.d}} "tlssec.dll"}
|
|
}
|
|
} elseif {[istarget i*86-*-cygwin*] } {
|
|
set pe_tests {
|
|
{".secrel32" "--disable-auto-import --disable-reloc-section" "" "" {secrel1.s secrel2.s}
|
|
{{objdump -s secrel.d}} "secrel.x"}
|
|
{"Empty export table" "" "" "" "exports.s"
|
|
{{objdump -p exports.d}} "exports.dll"}
|
|
{"TLS directory entry" "" "" "" "tlssec.s"
|
|
{{objdump -p tlssec32.d}} "tlssec.dll"}
|
|
}
|
|
} else {
|
|
set pe_tests {
|
|
{".secrel32" "--disable-reloc-section" "" "" {secrel1.s secrel2.s}
|
|
{{objdump -s secrel.d}} "secrel.x"}
|
|
{"Empty export table" "" "" "" "exports.s"
|
|
{{objdump -p exports.d}} "exports.dll"}
|
|
{"TLS directory entry" "" "" "" "tlssec.s"
|
|
{{objdump -p tlssec32.d}} "tlssec.dll"}
|
|
}
|
|
}
|
|
|
|
run_ld_link_tests $pe_tests
|
|
}
|
|
|
|
run_dump_test "image_size"
|
|
run_dump_test "export_dynamic_warning"
|
|
|
|
run_dump_test "longsecn"
|
|
run_dump_test "longsecn-1"
|
|
run_dump_test "longsecn-2"
|
|
run_dump_test "longsecn-3"
|
|
run_dump_test "longsecn-4"
|
|
run_dump_test "longsecn-5"
|
|
|
|
run_dump_test "orphan"
|
|
run_dump_test "orphan_nu"
|
|
|
|
run_dump_test "reloc"
|
|
|
|
run_dump_test "weakdef-1"
|
|
|
|
run_dump_test "pr19803"
|
|
run_dump_test "pr26659-weak-undef-sym"
|
|
set pr19803_dll {
|
|
{ "PR 19803: not exporting swept symbols"
|
|
"-shared --out-implib dx.dll --gc-sections"
|
|
"" "" {pr19803.s}
|
|
{{objdump "--syms dx.dll" pr19803.e}}
|
|
"a.exe"}
|
|
}
|
|
# This test is *supposed* to fail. If the symbol defined in pr19803.e is
|
|
# found then it was not stripped from the export dll, despite the fact that
|
|
# it (should have been) garbage collected from the executable.
|
|
setup_xfail *-*-*
|
|
run_ld_link_tests $pr19803_dll
|
|
|
|
if {[istarget x86_64-*-mingw*] } {
|
|
run_dump_test "cfi"
|
|
} elseif {[istarget i*86-*-cygwin*] || [istarget i*86-*-mingw*] } {
|
|
run_dump_test "cfi32"
|
|
}
|
|
|
|
set foreign_sym_test {
|
|
{"non-C aligned common" "" "" "" {non-c-lang-syms.s}
|
|
{{nm -C non-c-lang-syms.d}} "non-c-lang-syms.x"}
|
|
}
|
|
|
|
# MCore rearranges symbol order.
|
|
setup_xfail mcore-*-pe
|
|
run_ld_link_tests $foreign_sym_test
|