diff options
author | Alan Modra <amodra@gmail.com> | 2021-03-04 22:58:54 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-03-05 14:57:42 +1030 |
commit | b01b5d9a0b16fd81cc5535ba70c3ed267d9d7ac0 (patch) | |
tree | cd3d250769b4e3e0341c9d6a71b0a0a6aa7c4022 /bfd/reloc.c | |
parent | 7a39bd53dcc1753d69d3c1216883e59dce366176 (diff) | |
download | binutils-gdb-b01b5d9a0b16fd81cc5535ba70c3ed267d9d7ac0.tar.gz |
Move x86_64 PE changes out of bfd_perform_relocation
bfd_perform_relocation should not have special case target code. This
patch moves the code that was there for x86_64 PE linking to ELF
output into the x86_64 PE howto special function, correcting that
function for linking to targets other than ELF too. The fixes in
bfd_perform_relocation were over-complicated due to needing to
compensate for things that had already gone wrong in coff_amd64_reloc.
In particular, an adjustment for pc-relative relocs was done in a way
that meant adjustment for things related to symbol offsets was lost.
I think those two things are orthogonal, but who knows with COFF where
addends and symbol values are found randomly in the section contents.
Note that linking natively to an x86_64 PE output relocates by
coff_pe_amd64_relocate_section, which does not use arelent relocs or
bfd_perform_relocation, but be aware of coff_amd64_rtype_to_howto
hacking addends for relocations. The adjustments for a particular
relocation type there and in coff_amd64_reloc ought to match after
taking into consideration CALC_ADDEND. They don't. For example,
the pc-relative adjustment for R_PCRWORD is 2 bytes in
coff_amd64_reloc and 4 bytes in coff_amd64_rtype_to_howto.
* reloc.c (bfd_perform_relocation): Revert 2021-01-12 and
2020-09-16 changes.
* coff-x86_64.c (coff_amd64_reloc): Do more or less the same
adjustments here instead. Separate pc-relative adjustments
from symbol related adjustments. Tidy comments and formatting.
Diffstat (limited to 'bfd/reloc.c')
-rw-r--r-- | bfd/reloc.c | 26 |
1 files changed, 1 insertions, 25 deletions
diff --git a/bfd/reloc.c b/bfd/reloc.c index a7547187ebe..5ed7bb8e596 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -51,7 +51,7 @@ SECTION #include "bfdlink.h" #include "libbfd.h" #include "bfdver.h" -#include "coff/x86_64.h" + /* DOCDD INODE @@ -905,30 +905,6 @@ 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); - else if (howto->type == R_AMD64_DIR64 - || howto->type == R_AMD64_DIR32) - { - bfd_vma val = read_reloc (abfd, (bfd_byte *) data + octets, - howto); - relocation -= val & howto->src_mask; - } - } /* FIXME: This overflow checking is incomplete, because the value might have overflowed before we get here. For a correct check we |