diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-09-16 07:11:16 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-09-16 07:11:31 -0700 |
commit | 36068e2fa5460e6cfa1f5f359df6f37c497aab50 (patch) | |
tree | 9852e7ae898e51e89bb77fbab30606d76c6acf74 /bfd | |
parent | 337882d477675296a22fd8c1f7412ca30c70d9b0 (diff) | |
download | gdb-36068e2fa5460e6cfa1f5f359df6f37c497aab50.zip gdb-36068e2fa5460e6cfa1f5f359df6f37c497aab50.tar.gz gdb-36068e2fa5460e6cfa1f5f359df6f37c497aab50.tar.bz2 |
elf/x86-64: Adjust relocation for PE/x86-64 inputs
PE linker calls _bfd_relocate_contents to resolve relocation, instead of
bfd_perform_relocation. But ELF linker calls bfd_perform_relocation, not
_bfd_relocate_contents. When linking PE/x86-64 inputs to generate ELF
output, we need to adjust PE/x86-64 relocations in bfd_perform_relocation.
Enable PE/x86-64 in bfd together with PEI/x86-64. Update run_ld_link_tests
to handle bzip2 binary inputs.
bfd/
PR ld/26583
* config.bfd (targ64_selvecs, targ_selvecs): Add x86_64_pe_vec
to x86_64_pei_vec.
* reloc.c: Include "coff/internal.h".
(bfd_perform_relocation): Adjust relocation for PE/x86-64 inputs.
ld/
PR ld/26583
* testsuite/ld-x86-64/pe-x86-64-1.od: New file.
* testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64.exp: Likewise.
* testsuite/lib/ld-lib.exp (run_ld_link_tests): Handle bz2 binary
inputs.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 8 | ||||
-rw-r--r-- | bfd/config.bfd | 16 | ||||
-rw-r--r-- | bfd/reloc.c | 18 |
3 files changed, 34 insertions, 8 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b01cd95..75904fe 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2020-09-16 H.J. Lu <hongjiu.lu@intel.com> + + PR ld/26583 + * config.bfd (targ64_selvecs, targ_selvecs): Add x86_64_pe_vec + to x86_64_pei_vec. + * reloc.c: Include "coff/internal.h". + (bfd_perform_relocation): Adjust relocation for PE/x86-64 inputs. + 2020-09-16 Alan Modra <amodra@gmail.com> * elf-bfd.h (elf_symbol_from): Remove unused ABFD parameter. diff --git a/bfd/config.bfd b/bfd/config.bfd index 6c2919e..4900735 100644 --- a/bfd/config.bfd +++ b/bfd/config.bfd @@ -564,13 +564,13 @@ case "${targ}" in i[3-7]86-*-solaris2*) targ_defvec=i386_elf32_sol2_vec targ_selvecs="iamcu_elf32_vec i386_coff_vec i386_pei_vec" - targ64_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec x86_64_pei_vec" + targ64_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec x86_64_pe_vec x86_64_pei_vec" want64=true ;; #ifdef BFD64 x86_64-*-solaris2*) targ_defvec=i386_elf32_sol2_vec - targ_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pei_vec" + targ_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec" want64=true ;; #endif @@ -609,7 +609,7 @@ case "${targ}" in i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu) targ_defvec=i386_elf32_fbsd_vec targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_pei_vec i386_coff_vec" - targ64_selvecs="x86_64_elf64_fbsd_vec x86_64_elf64_vec x86_64_pei_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" + targ64_selvecs="x86_64_elf64_fbsd_vec x86_64_elf64_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" # FreeBSD <= 4.0 supports only the old nonstandard way of ABI labelling. case "${targ}" in i[3-7]86-*-freebsd3* | i[3-7]86-*-freebsd4 | i[3-7]86-*-freebsd4.0*) @@ -632,7 +632,7 @@ case "${targ}" in i[3-7]86-*-linux-*) targ_defvec=i386_elf32_vec targ_selvecs="iamcu_elf32_vec i386_pei_vec" - targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" ;; i[3-7]86-*-redox*) targ_defvec=i386_elf32_vec @@ -660,7 +660,7 @@ case "${targ}" in targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec l1om_elf64_vec k1om_elf64_vec" case "${targ}" in x86_64-*-rtems*) - targ_selvecs="${targ_selvecs} x86_64_pei_vec" + targ_selvecs="${targ_selvecs} x86_64_pe_vec x86_64_pei_vec" esac want64=true ;; @@ -671,17 +671,17 @@ case "${targ}" in ;; x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) targ_defvec=x86_64_elf64_fbsd_vec - targ_selvecs="i386_elf32_fbsd_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pei_vec i386_elf32_vec x86_64_elf64_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" + targ_selvecs="i386_elf32_fbsd_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec i386_elf32_vec x86_64_elf64_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" want64=true ;; x86_64-*-netbsd* | x86_64-*-openbsd*) targ_defvec=x86_64_elf64_vec - targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" want64=true ;; x86_64-*-linux-*) targ_defvec=x86_64_elf64_vec - targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" want64=true ;; x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin) diff --git a/bfd/reloc.c b/bfd/reloc.c index dc923fe..9639ad2 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -51,6 +51,7 @@ SECTION #include "bfdlink.h" #include "libbfd.h" #include "bfdver.h" +#include "coff/internal.h" /* DOCDD INODE @@ -904,6 +905,23 @@ space consuming. For each target: } } } + else if (abfd->xvec->flavour == bfd_target_coff_flavour + && (input_section->output_section->owner->xvec->flavour + == bfd_target_elf_flavour) + && strcmp (abfd->xvec->name, "pe-x86-64") == 0 + && strcmp (input_section->output_section->owner->xvec->name, + "elf64-x86-64") == 0) + { + /* NB: bfd_perform_relocation isn't called to generate PE binary. + _bfd_relocate_contents is called instead. When linking PE + object files to generate ELF output, _bfd_relocate_contents + isn't called and bfd_perform_relocation is used. We need to + adjust relocation here. */ + relocation -= reloc_entry->addend; + if (howto->type >= R_AMD64_PCRLONG_1 + && howto->type <= R_AMD64_PCRLONG_5) + relocation -= (bfd_vma)(howto->type - R_AMD64_PCRLONG); + } /* FIXME: This overflow checking is incomplete, because the value might have overflowed before we get here. For a correct check we |