aboutsummaryrefslogtreecommitdiff
path: root/bfd/bfd.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-03-05 18:24:56 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-03-05 18:25:06 -0800
commit8c0546e928b557f10cb5aba2a91f3ecee660029d (patch)
treefa6de685644e0fc9b754cd1d81a28c1a7f6c3ee8 /bfd/bfd.c
parentb0a8c2ff9c1b5f7d2e1ef1e0d65dcff0e9f089cc (diff)
downloadgdb-8c0546e928b557f10cb5aba2a91f3ecee660029d.zip
gdb-8c0546e928b557f10cb5aba2a91f3ecee660029d.tar.gz
gdb-8c0546e928b557f10cb5aba2a91f3ecee660029d.tar.bz2
elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASE
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.
Diffstat (limited to 'bfd/bfd.c')
-rw-r--r--bfd/bfd.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/bfd/bfd.c b/bfd/bfd.c
index f194433..2c62085 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2808,3 +2808,14 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
*ptr_size = size;
return TRUE;
}
+
+/* Get the linker information. */
+
+struct bfd_link_info *
+_bfd_get_link_info (bfd *abfd)
+{
+ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ return NULL;
+
+ return elf_link_info (abfd);
+}