aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@mips.com>2018-04-04 02:00:49 +0100
committerMaciej W. Rozycki <macro@mips.com>2018-04-04 02:00:49 +0100
commit5d7c8b80485d75242e7c78e79b3ecb4c71abaee3 (patch)
tree0765f54c77f721717e32b9bfabf612c7959b8e5d
parent707bad1b21c18cf8e570fb8df8f7c5961fb0f3a5 (diff)
downloadgdb-5d7c8b80485d75242e7c78e79b3ecb4c71abaee3.zip
gdb-5d7c8b80485d75242e7c78e79b3ecb4c71abaee3.tar.gz
gdb-5d7c8b80485d75242e7c78e79b3ecb4c71abaee3.tar.bz2
PR binutils/22875: i860/ELF: Report unsupported relocation types
Complement commit f3185997ac09 ("PR 22875: Stop strip corrupting unknown relocs"), <https://sourceware.org/ml/binutils/2018-02/msg00445.html>, and also set the `bfd_error_bad_value' error and report an unsupported relocation type if a howto lookup fails with the i860 backend, fixing a confusing `no error' error message and removing a binutils test failure: failed with: <.../binutils/strip-new: tmpdir/bintest.o: no error>, expected: <.* bad value> .../binutils/strip-new: tmpdir/bintest.o: no error FAIL: binutils-all/strip-13 with the `i860-stardent-elf' target. bfd/ * elf32-i860.c (lookup_howto): Add `abfd' parameter. Set the `bfd_error_bad_value' error and call `_bfd_error_handler' on a howto lookup failure. (elf32_i860_reloc_type_lookup): Adjust `lookup_howto' call accordingly. (elf32_i860_info_to_howto_rela): Likewise. (elf32_i860_relocate_splitn): Likewise. (elf32_i860_relocate_pc16): Likewise. (elf32_i860_relocate_pc26): Likewise. (elf32_i860_relocate_section): Likewise.
-rw-r--r--bfd/ChangeLog13
-rw-r--r--bfd/elf32-i860.c39
2 files changed, 36 insertions, 16 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 991d11b..ea2a5ab 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,18 @@
2018-04-04 Maciej W. Rozycki <macro@mips.com>
+ * elf32-i860.c (lookup_howto): Add `abfd' parameter. Set the
+ `bfd_error_bad_value' error and call `_bfd_error_handler' on a
+ howto lookup failure.
+ (elf32_i860_reloc_type_lookup): Adjust `lookup_howto' call
+ accordingly.
+ (elf32_i860_info_to_howto_rela): Likewise.
+ (elf32_i860_relocate_splitn): Likewise.
+ (elf32_i860_relocate_pc16): Likewise.
+ (elf32_i860_relocate_pc26): Likewise.
+ (elf32_i860_relocate_section): Likewise.
+
+2018-04-04 Maciej W. Rozycki <macro@mips.com>
+
* elf32-visium.c (visium_info_to_howto_rela): Correct the range
check for `visium_elf_howto_table' table access.
diff --git a/bfd/elf32-i860.c b/bfd/elf32-i860.c
index 737e7f5..d588dc5 100644
--- a/bfd/elf32-i860.c
+++ b/bfd/elf32-i860.c
@@ -745,12 +745,13 @@ static reloc_howto_type elf32_i860_howto_table [] =
static unsigned char elf_code_to_howto_index[R_860_max + 1];
static reloc_howto_type *
-lookup_howto (unsigned int rtype)
+lookup_howto (bfd *abfd, unsigned int rtype)
{
static int initialized = 0;
int i;
int howto_tbl_size = (int) (sizeof (elf32_i860_howto_table)
/ sizeof (elf32_i860_howto_table[0]));
+ reloc_howto_type *howto = NULL;
if (! initialized)
{
@@ -761,18 +762,24 @@ lookup_howto (unsigned int rtype)
elf_code_to_howto_index[elf32_i860_howto_table[i].type] = i;
}
- if (rtype > R_860_max)
- return NULL;
- i = elf_code_to_howto_index[rtype];
- if (i >= howto_tbl_size)
- return NULL;
- return elf32_i860_howto_table + i;
+ if (rtype < R_860_max)
+ {
+ i = elf_code_to_howto_index[rtype];
+ if (i < howto_tbl_size)
+ howto = elf32_i860_howto_table + i;
+ }
+ if (howto == NULL)
+ {
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ abfd, rtype);
+ bfd_set_error (bfd_error_bad_value);
+ }
+ return howto;
}
/* Given a BFD reloc, return the matching HOWTO structure. */
static reloc_howto_type *
-elf32_i860_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
- bfd_reloc_code_real_type code)
+elf32_i860_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
{
unsigned int rtype;
@@ -883,7 +890,7 @@ elf32_i860_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
default:
return NULL;
}
- return lookup_howto (rtype);
+ return lookup_howto (abfd, rtype);
}
static reloc_howto_type *
@@ -906,12 +913,12 @@ elf32_i860_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
/* Given a ELF reloc, return the matching HOWTO structure. */
static bfd_boolean
-elf32_i860_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
+elf32_i860_info_to_howto_rela (bfd *abfd,
arelent *bfd_reloc,
Elf_Internal_Rela *elf_reloc)
{
bfd_reloc->howto
- = lookup_howto ((unsigned) ELF32_R_TYPE (elf_reloc->r_info));
+ = lookup_howto (abfd, (unsigned) ELF32_R_TYPE (elf_reloc->r_info));
return bfd_reloc->howto != NULL;
}
@@ -925,7 +932,7 @@ elf32_i860_relocate_splitn (bfd *input_bfd,
{
bfd_vma insn;
reloc_howto_type *howto;
- howto = lookup_howto ((unsigned) ELF32_R_TYPE (rello->r_info));
+ howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rello->r_info));
insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
/* Relocate. */
@@ -951,7 +958,7 @@ elf32_i860_relocate_pc16 (bfd *input_bfd,
{
bfd_vma insn;
reloc_howto_type *howto;
- howto = lookup_howto ((unsigned) ELF32_R_TYPE (rello->r_info));
+ howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rello->r_info));
insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
/* Adjust for PC-relative relocation. */
@@ -983,7 +990,7 @@ elf32_i860_relocate_pc26 (bfd *input_bfd,
{
bfd_vma insn;
reloc_howto_type *howto;
- howto = lookup_howto ((unsigned) ELF32_R_TYPE (rello->r_info));
+ howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rello->r_info));
insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
/* Adjust for PC-relative relocation. */
@@ -1104,7 +1111,7 @@ elf32_i860_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
r_type = ELF32_R_TYPE (rel->r_info);
r_symndx = ELF32_R_SYM (rel->r_info);
- howto = lookup_howto ((unsigned) ELF32_R_TYPE (rel->r_info));
+ howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rel->r_info));
h = NULL;
sym = NULL;
sec = NULL;