aboutsummaryrefslogtreecommitdiff
path: root/bfd/coff-mips.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-11-25 10:07:40 +1030
committerAlan Modra <amodra@gmail.com>2019-11-25 14:32:19 +1030
commitbb2942085c83289c56cc3ef8b9ab0ecf6267efa3 (patch)
treef5865525e08a0c12b146f56c4432ed876aa26d37 /bfd/coff-mips.c
parent618265039f697eab9e72bb58b95fc2d32925df58 (diff)
downloadgdb-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/coff-mips.c')
-rw-r--r--bfd/coff-mips.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/bfd/coff-mips.c b/bfd/coff-mips.c
index c9c7fc6..76de320 100644
--- a/bfd/coff-mips.c
+++ b/bfd/coff-mips.c
@@ -31,6 +31,9 @@
#include "coff/mips.h"
#include "libcoff.h"
#include "libecoff.h"
+
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
/* Prototypes for static functions. */
static bfd_reloc_status_type
@@ -484,13 +487,13 @@ mips_refhi_reloc (bfd *abfd ATTRIBUTE_UNUSED,
relocation described above. */
static bfd_reloc_status_type
-mips_reflo_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+mips_reflo_reloc (bfd *abfd,
arelent *reloc_entry,
asymbol *symbol,
void * data,
asection *input_section,
bfd *output_bfd,
- char **error_message ATTRIBUTE_UNUSED)
+ char **error_message)
{
if (mips_refhi_list != NULL)
{
@@ -503,11 +506,12 @@ mips_reflo_reloc (bfd *abfd ATTRIBUTE_UNUSED,
unsigned long val;
unsigned long vallo;
struct mips_hi *next;
+ bfd_size_type octets = (reloc_entry->address
+ * OCTETS_PER_BYTE (abfd, input_section));
+ bfd_byte *loc = (bfd_byte *) data + octets;
- if (! bfd_reloc_offset_in_range (reloc_entry->howto, abfd,
- input_section,
- reloc_entry->address
- * bfd_octets_per_byte (abfd, NULL)))
+ if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd,
+ input_section, octets))
return bfd_reloc_outofrange;
/* Do the REFHI relocation. Note that we actually don't
@@ -515,8 +519,7 @@ mips_reflo_reloc (bfd *abfd ATTRIBUTE_UNUSED,
where to find the low 16 bits of the addend needed by the
REFHI. */
insn = bfd_get_32 (abfd, l->addr);
- vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
- & 0xffff);
+ vallo = bfd_get_32 (abfd, loc) & 0xffff;
val = ((insn & 0xffff) << 16) + vallo;
val += l->addend;
@@ -544,7 +547,7 @@ mips_reflo_reloc (bfd *abfd ATTRIBUTE_UNUSED,
/* Now do the REFLO reloc in the usual way. */
return mips_generic_reloc (abfd, reloc_entry, symbol, data,
- input_section, output_bfd, error_message);
+ input_section, output_bfd, error_message);
}
/* Do a GPREL relocation. This is a 16 bit value which must become