mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
8c0546e928
When linking Windows x86-64 relocatable object files to generate x86-64 ELF executable, we need to subtract __ImageBase, aka __executable_start, for R_AMD64_IMAGEBASE relocation: 1. Add link_info to struct output_elf_obj_tdata to store linker info and _bfd_get_link_info() to retrieve it. 2. Add ldelf_set_output_arch to set up link_info. 3. Add pex64_link_add_symbols to create an indirect reference to __executable_start for __ImageBase to support R_AMD64_IMAGEBASE relocation when adding symbols from Windows x86-64 relocatable object files to generate x86-64 ELF executable. 4. Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. bfd/ PR ld/27425 PR ld/27432 * bfd.c (_bfd_get_link_info): New function. * elf-bfd.h (output_elf_obj_tdata): Add link_info. (elf_link_info): New. * libbfd-in.h (_bfd_get_link_info): New prototype. * coff-x86_64.c (coff_amd64_reloc): Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. * pe-x86_64.c: Include "coff/internal.h" and "libcoff.h". (pex64_link_add_symbols): New function. (coff_bfd_link_add_symbols): New macro. * libbfd.h: Regenerated. ld/ PR ld/27425 PR ld/27432 * ldelf.c (ldelf_set_output_arch): New function. * ldelf.h (ldelf_set_output_arch): New prototype. * emultempl/elf.em (LDEMUL_SET_OUTPUT_ARCH): Default to ldelf_set_output_arch. * ld-x86-64/pe-x86-64-1.od: Expect __executable_start. * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise. * testsuite/ld-x86-64/pe-x86-64-6.obj.bz2: New file. * testsuite/ld-x86-64/pe-x86-64-6.od: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Run ld/27425 test.
86 lines
2.2 KiB
Plaintext
86 lines
2.2 KiB
Plaintext
# Expect script for ELF tests with pe-x86-64 inputs.
|
|
# Copyright (C) 2020-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.
|
|
#
|
|
|
|
# Only for Linux/x86-64.
|
|
if {![istarget "x86_64-*-linux*"] } {
|
|
return
|
|
}
|
|
|
|
run_ld_link_tests [list \
|
|
[list \
|
|
"Build pe-x86-64-1" \
|
|
"-m elf_x86_64 --entry=begin" \
|
|
"" \
|
|
"" \
|
|
{pe-x86-64-1a.obj.bz2 pe-x86-64-1b.obj.bz2 pe-x86-64-1c.obj.bz2} \
|
|
{{objdump {-dw --sym} pe-x86-64-1.od}} \
|
|
"pe-x86-64-1" \
|
|
] \
|
|
[list \
|
|
"Build pe-x86-64-2" \
|
|
"-m elf_x86_64 --entry=begin" \
|
|
"" \
|
|
"" \
|
|
{pe-x86-64-2a.obj.bz2 pe-x86-64-2b.obj.bz2 pe-x86-64-2c.obj.bz2} \
|
|
{{objdump {-dw --sym} pe-x86-64-2.od}} \
|
|
"pe-x86-64-2" \
|
|
] \
|
|
[list \
|
|
"Build pe-x86-64-3" \
|
|
"-m elf_x86_64 --entry=begin" \
|
|
"" \
|
|
"" \
|
|
{pe-x86-64-3a.obj.bz2 pe-x86-64-3b.obj.bz2 pe-x86-64-3c.obj.bz2 \
|
|
pe-x86-64-3d.obj.bz2 } \
|
|
{{objdump {-dw --sym} pe-x86-64-3.od}} \
|
|
"pe-x86-64-3" \
|
|
] \
|
|
[list \
|
|
"Build pe-x86-64-4" \
|
|
"-m elf_x86_64 --entry=begin" \
|
|
"" \
|
|
"" \
|
|
{pe-x86-64-4a.obj.bz2 pe-x86-64-4b.obj.bz2 pe-x86-64-4c.obj.bz2 \
|
|
pe-x86-64-4d.obj.bz2 } \
|
|
{{objdump {-dw --sym} pe-x86-64-4.od}} \
|
|
"pe-x86-64-4" \
|
|
] \
|
|
[list \
|
|
"Build pe-x86-64-5" \
|
|
"-m elf_x86_64 --entry=begin" \
|
|
"" \
|
|
"" \
|
|
{pe-x86-64-5.obj.bz2 } \
|
|
{{objdump {-dw --sym} pe-x86-64-5.od} \
|
|
{readelf {-s -x .data} pe-x86-64-5.rd}} \
|
|
"pe-x86-64-5" \
|
|
] \
|
|
[list \
|
|
"Build pe-x86-64-6" \
|
|
"-m elf_x86_64 --entry=main" \
|
|
"" \
|
|
"" \
|
|
{pe-x86-64-6.obj.bz2 } \
|
|
{{objdump {-dw --sym} pe-x86-64-6.od}} \
|
|
"pe-x86-64-6" \
|
|
] \
|
|
]
|