aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf32-nios2.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf32-nios2.c')
-rw-r--r--bfd/elf32-nios2.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c
index 29e1e5a..e160054 100644
--- a/bfd/elf32-nios2.c
+++ b/bfd/elf32-nios2.c
@@ -31,6 +31,7 @@
#include "elf/nios2.h"
#include "opcode/nios2.h"
#include "elf32-nios2.h"
+#include "libiberty.h"
/* Use RELA relocations. */
#ifndef USE_RELA
@@ -1578,10 +1579,8 @@ lookup_howto (unsigned int rtype, bfd *abfd)
int i;
/* R2 relocations are a superset of R1, so use that for the lookup
table. */
- int r1_howto_tbl_size = (int) (sizeof (elf_nios2_r1_howto_table_rel)
- / sizeof (elf_nios2_r1_howto_table_rel[0]));
- int r2_howto_tbl_size = (int) (sizeof (elf_nios2_r2_howto_table_rel)
- / sizeof (elf_nios2_r2_howto_table_rel[0]));
+ int r1_howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r1_howto_table_rel);
+ int r2_howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r2_howto_table_rel);
if (!initialized)
{
@@ -1597,18 +1596,19 @@ lookup_howto (unsigned int rtype, bfd *abfd)
}
}
- BFD_ASSERT (rtype <= R_NIOS2_ILLEGAL);
+ if (rtype > R_NIOS2_ILLEGAL)
+ return NULL;
i = elf_code_to_howto_index[rtype];
if (BFD_IS_R2 (abfd))
{
if (i >= r2_howto_tbl_size)
- return 0;
+ return NULL;
return elf_nios2_r2_howto_table_rel + i;
}
else
{
if (i >= r1_howto_tbl_size)
- return 0;
+ return NULL;
return elf_nios2_r1_howto_table_rel + i;
}
}
@@ -1620,7 +1620,8 @@ struct elf_reloc_map
enum elf_nios2_reloc_type elf_val;
};
-static const struct elf_reloc_map nios2_reloc_map[] = {
+static const struct elf_reloc_map nios2_reloc_map[] =
+{
{BFD_RELOC_NONE, R_NIOS2_NONE},
{BFD_RELOC_NIOS2_S16, R_NIOS2_S16},
{BFD_RELOC_NIOS2_U16, R_NIOS2_U16},
@@ -2954,18 +2955,16 @@ nios2_elf32_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
return TRUE;
}
-
/* Implement bfd_elf32_bfd_reloc_type_lookup:
Given a BFD reloc type, return a howto structure. */
+
static reloc_howto_type *
nios2_elf32_bfd_reloc_type_lookup (bfd *abfd,
bfd_reloc_code_real_type code)
{
int i;
- for (i = 0;
- i < (int) (sizeof (nios2_reloc_map) / sizeof (struct elf_reloc_map));
- ++i)
+ for (i = 0; i < (int) ARRAY_SIZE (nios2_reloc_map); ++i)
if (nios2_reloc_map[i].bfd_val == code)
return lookup_howto (nios2_reloc_map[i].elf_val, abfd);
return NULL;
@@ -2973,6 +2972,7 @@ nios2_elf32_bfd_reloc_type_lookup (bfd *abfd,
/* Implement bfd_elf32_bfd_reloc_name_lookup:
Given a reloc name, return a howto structure. */
+
static reloc_howto_type *
nios2_elf32_bfd_reloc_name_lookup (bfd *abfd,
const char *r_name)
@@ -2984,32 +2984,40 @@ nios2_elf32_bfd_reloc_name_lookup (bfd *abfd,
if (BFD_IS_R2 (abfd))
{
howto_tbl = elf_nios2_r2_howto_table_rel;
- howto_tbl_size = (int) (sizeof (elf_nios2_r2_howto_table_rel)
- / sizeof (elf_nios2_r2_howto_table_rel[0]));
+ howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r2_howto_table_rel);
}
else
{
howto_tbl = elf_nios2_r1_howto_table_rel;
- howto_tbl_size = (int) (sizeof (elf_nios2_r1_howto_table_rel)
- / sizeof (elf_nios2_r1_howto_table_rel[0]));
+ howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r1_howto_table_rel);
}
for (i = 0; i < howto_tbl_size; i++)
if (howto_tbl[i].name && strcasecmp (howto_tbl[i].name, r_name) == 0)
return howto_tbl + i;
+
return NULL;
}
/* Implement elf_info_to_howto:
Given a ELF32 relocation, fill in a arelent structure. */
-static void
+
+static bfd_boolean
nios2_elf32_info_to_howto (bfd *abfd, arelent *cache_ptr,
Elf_Internal_Rela *dst)
{
unsigned int r_type;
r_type = ELF32_R_TYPE (dst->r_info);
- cache_ptr->howto = lookup_howto (r_type, abfd);
+ if ((cache_ptr->howto = lookup_howto (r_type, abfd)) == NULL)
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ abfd, r_type);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ return TRUE;
}
/* Return the base VMA address which should be subtracted from real addresses