diff options
author | Alan Modra <amodra@gmail.com> | 2022-06-08 09:49:09 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-06-08 21:33:00 +0930 |
commit | 57698478b75319a962b899c3f8d3a03baa5eaab4 (patch) | |
tree | b8c1b2c7f1dcb060a535ac8a21745bdf55698a40 /bfd/coff64-rs6000.c | |
parent | 5d2834cc7e943014cff0cef6a2a25972eb85d84a (diff) | |
download | gdb-57698478b75319a962b899c3f8d3a03baa5eaab4.zip gdb-57698478b75319a962b899c3f8d3a03baa5eaab4.tar.gz gdb-57698478b75319a962b899c3f8d3a03baa5eaab4.tar.bz2 |
Don't encode reloc.size
I expect the encoded reloc.size field originally came from aout
r_length ecoding, but somehow went wrong for 64-bit relocs (which
should have been encoded as 3). Toss all that out, just use a byte
size instead. The changes outside of reloc.c in this patch should
make the code independent of how reloc.size is encoded.
* reloc.c (struct reloc_howto_struct): Increase size field by
one bit. Comment.
(HOWTO_RSIZE): Don't encode size.
(bfd_get_reloc_size): Adjust, and make it an inline function.
(read_reloc, write_reloc): Adjust.
* bfd-in2.h: Regenerate.
* aout-ns32k.c: Include libbfd.h.
(put_reloc): Don't use howto->size directly. Calculate r_length
using bfd_log2 and bfd_get_reloc_size.
* aoutx.h (swap_std_reloc_out): Likewise.
(aout_link_reloc_link_order): Likewise.
* i386lynx.c (swap_std_reloc_out
* mach-o-i386.c (bfd_mach_o_i386_swap_reloc_out
* pdp11.c (aout_link_reloc_link_order
* coff-arm.c (coff_arm_reloc): Don't use howto->size directly,
use bfd_get_reloc_size instead and adjust switch cases.
* coff-i386.c (coff_i386_reloc): Similarly.
* coff-x86_64.c (coff_amd64_reloc): Likewise.
* cpu-ns32k.c (do_ns32k_reloc): Likewise.
* elf32-arc.c (arc_do_relocation): Likewise.
* elf32-arm.c (elf32_arm_final_link_relocate): Likewise.
* elf32-bfin.c (bfin_bfd_reloc): Likewise.
* elf32-cr16.c (cr16_elf_final_link_relocate): Likewise.
* elf32-cris.c (cris_elf_pcrel_reloc): Likewise.
* elf32-crx.c (crx_elf_final_link_relocate): Likewise.
* elf32-csky.c (csky_elf_relocate_section): Likewise.
* elf32-d10v.c (extract_rel_addend, insert_rel_addend): Likewise.
* elf32-i386.c (elf_i386_relocate_section): Likewise.
* elf32-m32r.c (m32r_elf_generic_reloc): Likewise.
* elf32-nds32.c (nds32_elf_generic_reloc): Likewise.
* syms.c (_bfd_stab_section_find_nearest_line): Likewise.
* coff-rs6000.c (xcoff_ppc_relocate_section): Adjust howto.size.
* coff64-rs6000.c (xcoff64_ppc_relocate_section): Likewise.
Diffstat (limited to 'bfd/coff64-rs6000.c')
-rw-r--r-- | bfd/coff64-rs6000.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c index 5df3dc1..ce1c518 100644 --- a/bfd/coff64-rs6000.c +++ b/bfd/coff64-rs6000.c @@ -1587,7 +1587,9 @@ xcoff64_ppc_relocate_section (bfd *output_bfd, case R_POS: case R_NEG: howto.bitsize = (rel->r_size & 0x3f) + 1; - howto.size = howto.bitsize > 16 ? (howto.bitsize > 32 ? 4 : 2) : 1; + howto.size = HOWTO_RSIZE (howto.bitsize <= 16 + ? 2 : howto.bitsize <= 32 + ? 4 : 8); howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize); break; @@ -1680,12 +1682,18 @@ xcoff64_ppc_relocate_section (bfd *output_bfd, abort (); /* Get the value we are going to relocate. */ - if (1 == howto.size) - value_to_relocate = bfd_get_16 (input_bfd, location); - else if (2 == howto.size) - value_to_relocate = bfd_get_32 (input_bfd, location); - else - value_to_relocate = bfd_get_64 (input_bfd, location); + switch (bfd_get_reloc_size (&howto)) + { + case 2: + value_to_relocate = bfd_get_16 (input_bfd, location); + break; + case 4: + value_to_relocate = bfd_get_32 (input_bfd, location); + break; + default: + value_to_relocate = bfd_get_64 (input_bfd, location); + break; + } /* overflow. @@ -1729,13 +1737,18 @@ xcoff64_ppc_relocate_section (bfd *output_bfd, + relocation) & howto.dst_mask)); /* Put the value back in the object file. */ - if (1 == howto.size) - bfd_put_16 (input_bfd, value_to_relocate, location); - else if (2 == howto.size) - bfd_put_32 (input_bfd, value_to_relocate, location); - else - bfd_put_64 (input_bfd, value_to_relocate, location); - + switch (bfd_get_reloc_size (&howto)) + { + case 2: + bfd_put_16 (input_bfd, value_to_relocate, location); + break; + case 4: + bfd_put_32 (input_bfd, value_to_relocate, location); + break; + default: + bfd_put_64 (input_bfd, value_to_relocate, location); + break; + } } return true; } |