diff options
author | Alan Modra <amodra@gmail.com> | 2019-11-25 10:07:40 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-11-25 14:32:19 +1030 |
commit | bb2942085c83289c56cc3ef8b9ab0ecf6267efa3 (patch) | |
tree | f5865525e08a0c12b146f56c4432ed876aa26d37 /bfd/elflink.c | |
parent | 618265039f697eab9e72bb58b95fc2d32925df58 (diff) | |
download | gdb-bb2942085c83289c56cc3ef8b9ab0ecf6267efa3.zip gdb-bb2942085c83289c56cc3ef8b9ab0ecf6267efa3.tar.gz gdb-bb2942085c83289c56cc3ef8b9ab0ecf6267efa3.tar.bz2 |
Pass section when available to bfd_octets_per_byte
and other tidies. I think it's better to default to passing the
section to bfd_octets_per_byte, even in cases where we know it won't
make a difference.
A number of the coff reloc functions used bfd_octets_per_byte wrongly,
not factoring it into the offset into the data buffer. As it happens,
the targets using those files always had bfd_octets_per_byte equal to
one, so there wasn't any detectable wrong behaviour. However, it is
wrong in the source and might cause trouble for anyone creating a new
target. Besides fixing that, the patch also defines OCTETS_PER_BYTE
as one in target files where that is appropriate.
bfd/
* archures.c (bfd_octets_per_byte): Tail call
bfd_arch_mach_octets_per_byte.
* coff-arm.c (OCTETS_PER_BYTE): Define.
(coff_arm_reloc): Introduce new "octets" temp. Use OCTETS_PER_BYTE
with section. Correct "addr". Remove ATTRIBUTE_UNUSED.
* coff-i386.c (coff_i386_reloc): Similarly.
* coff-mips.c (mips_reflo_reloc): Similarly.
* coff-x86_64.c (coff_amd64_reloc): Similarly.
* elf32-msp430.c (OCTETS_PER_BYTE): Define.
(rl78_sym_diff_handler): Use OCTETS_PER_BYTE, with section.
* elf32-nds32.c (nds32_elf_get_relocated_section_contents): Similarly.
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Similarly.
* elf32-pru.c (pru_elf32_do_ldi32_relocate): Similarly.
* elf32-s12z.c (opru18_reloc): Similarly.
* elf32-sh.c (sh_elf_reloc): Similarly.
* elf32-spu.c (spu_elf_rel9): Similarly.
* elf32-xtensa.c (bfd_elf_xtensa_reloc): Similarly.
* elf64-ppc.c (ppc64_elf_ha_reloc, ppc64_elf_brtaken_reloc),
(ppc64_elf_toc64_reloc): Similarly.
* bfd.c (bfd_get_section_limit): Pass section to bfd_octets_per_byte.
* cofflink.c (_bfd_coff_link_input_bfd),
(_bfd_coff_reloc_link_order): Likewise.
* elf.c (_bfd_elf_section_offset): Likewise.
* elflink.c (resolve_section, bfd_elf_perform_complex_relocation),
(elf_link_input_bfd, elf_reloc_link_order, elf_fixup_link_order),
(bfd_elf_final_link): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Don't strncmp twice
to set SEC_ELF_OCTETS.
* reloc.c (bfd_perform_relocation): Tidy SEC_ELF_OCTETS special case.
(bfd_install_relocation): Likewise.
(_bfd_final_link_relocate): Don't recalculate octets.
* syms.c (_bfd_stab_section_find_nearest_line): Introduc new
"octets" temp.
* bfd-in2.h: Regenerate.
ld/
* ldexp.c (fold_name): Pass section to bfd_octets_per_byte.
* ldlang.c (init_opb): Don't call bfd_arch_mach_octets_per_byte
unnecessarily.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r-- | bfd/elflink.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c index 824669a..5549361 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8457,7 +8457,7 @@ resolve_section (const char *name, if (strncmp (".end", name + len, 4) == 0) { *result = (curr->vma - + curr->size / bfd_octets_per_byte (abfd, NULL)); + + curr->size / bfd_octets_per_byte (abfd, curr)); return TRUE; } @@ -8752,7 +8752,7 @@ decode_complex_addend (unsigned long *start, /* in bits */ bfd_reloc_status_type bfd_elf_perform_complex_relocation (bfd *input_bfd, - asection *input_section ATTRIBUTE_UNUSED, + asection *input_section, bfd_byte *contents, Elf_Internal_Rela *rel, bfd_vma relocation) @@ -8760,6 +8760,7 @@ bfd_elf_perform_complex_relocation (bfd *input_bfd, bfd_vma shift, x, mask; unsigned long start, oplen, len, wordsz, chunksz, lsb0_p, signed_p, trunc_p; bfd_reloc_status_type r; + bfd_size_type octets; /* Perform this reloc, since it is complex. (this is not to say that it necessarily refers to a complex @@ -8778,9 +8779,8 @@ bfd_elf_perform_complex_relocation (bfd *input_bfd, else shift = (8 * wordsz) - (start + len); - x = get_value (wordsz, chunksz, input_bfd, - contents - + rel->r_offset * bfd_octets_per_byte (input_bfd, NULL)); + octets = rel->r_offset * bfd_octets_per_byte (input_bfd, input_section); + x = get_value (wordsz, chunksz, input_bfd, contents + octets); #ifdef DEBUG printf ("Doing complex reloc: " @@ -8812,8 +8812,7 @@ bfd_elf_perform_complex_relocation (bfd *input_bfd, (unsigned long) relocation, (unsigned long) (mask << shift), (unsigned long) ((relocation & mask) << shift), (unsigned long) x); #endif - put_value (wordsz, chunksz, input_bfd, x, - contents + rel->r_offset * bfd_octets_per_byte (input_bfd, NULL)); + put_value (wordsz, chunksz, input_bfd, x, contents + octets); return r; } @@ -11305,7 +11304,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) file_ptr offset = (file_ptr) o->output_offset; bfd_size_type todo = o->size; - offset *= bfd_octets_per_byte (output_bfd, NULL); + offset *= bfd_octets_per_byte (output_bfd, o); if ((o->flags & SEC_ELF_REVERSE_COPY)) { @@ -11439,6 +11438,7 @@ elf_reloc_link_order (bfd *output_bfd, bfd_byte *buf; bfd_boolean ok; const char *sym_name; + bfd_size_type octets; size = (bfd_size_type) bfd_get_reloc_size (howto); buf = (bfd_byte *) bfd_zmalloc (size); @@ -11465,10 +11465,10 @@ elf_reloc_link_order (bfd *output_bfd, break; } + octets = link_order->offset * bfd_octets_per_byte (output_bfd, + output_section); ok = bfd_set_section_contents (output_bfd, output_section, buf, - link_order->offset - * bfd_octets_per_byte (output_bfd, NULL), - size); + octets, size); free (buf); if (! ok) return FALSE; @@ -11635,7 +11635,7 @@ elf_fixup_link_order (bfd *abfd, asection *o) s = sections[n]->u.indirect.section; mask = ~(bfd_vma) 0 << s->alignment_power; offset = (offset + ~mask) & mask; - s->output_offset = offset / bfd_octets_per_byte (abfd, NULL); + s->output_offset = offset / bfd_octets_per_byte (abfd, s); sections[n]->offset = offset; offset += sections[n]->size; } @@ -12856,12 +12856,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) continue; if (strcmp (o->name, ".dynstr") != 0) { - if (! bfd_set_section_contents (abfd, o->output_section, - o->contents, - (file_ptr) o->output_offset - * bfd_octets_per_byte (abfd, - NULL), - o->size)) + bfd_size_type octets = ((file_ptr) o->output_offset + * bfd_octets_per_byte (abfd, o)); + if (!bfd_set_section_contents (abfd, o->output_section, + o->contents, octets, o->size)) goto error_return; } else |