return true;
}
-/* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
- is contained by the region START .. END. The types of ADDR, START
- and END should all be the same. Note both ADDR + NELEM and END
- point to just beyond the end of the regions that are being tested. */
-#define IN_RANGE(START,END,ADDR,NELEM) \
- (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
+/* Check that reloc at R_OFFSET of size R_SIZE can apply to LEN bytes. */
+
+static inline bool
+in_range (size_t len, bfd_vma r_offset, unsigned int r_size)
+{
+ return r_offset <= len && r_size <= len - r_offset;
+}
/* Check to see if the given reloc needs to be handled in a target specific
manner. If so then process the reloc and return TRUE otherwise return
target_specific_reloc_handling (Filedata *filedata,
Elf_Internal_Rela *reloc,
unsigned char *start,
- unsigned char *end,
+ size_t size,
Elf_Internal_Sym *symtab,
uint64_t num_syms)
{
unsigned int reloc_size = 0;
int leb_ret = 0;
- if (reloc->r_offset < (size_t) (end - start))
- value = read_leb128 (start + reloc->r_offset, end, false,
- &reloc_size, &leb_ret);
+ if (reloc->r_offset < size)
+ value = read_leb128 (start + reloc->r_offset, start + size,
+ false, &reloc_size, &leb_ret);
if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8)
error (_("LoongArch ULEB128 field at 0x%lx contains invalid "
"ULEB128 value\n"),
break;
case 11: /* R_MSP430_GNU_SET_ULEB128 */
case 22: /* R_MSP430X_GNU_SET_ULEB128 */
- if (reloc->r_offset < (size_t) (end - start))
- read_leb128 (start + reloc->r_offset, end, false,
+ if (reloc->r_offset < size)
+ read_leb128 (start + reloc->r_offset, start + size, false,
&reloc_size, &leb_ret);
break;
default:
value = reloc->r_addend + (symtab[sym_index].st_value
- saved_sym->st_value);
- if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
+ if (in_range (size, reloc->r_offset, reloc_size))
byte_put (start + reloc->r_offset, value, reloc_size);
else
/* PR 21137 */
value = reloc->r_addend + (symtab[sym_index].st_value
- saved_sym->st_value);
- if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
+ if (in_range (size, reloc->r_offset, reloc_size))
byte_put (start + reloc->r_offset, value, reloc_size);
else
error (_("MN10300 sym diff reloc contains invalid offset:"
break;
case 0x41: /* R_RL78_ABS32. */
- if (IN_RANGE (start, end, start + reloc->r_offset, 4))
+ if (in_range (size, reloc->r_offset, 4))
byte_put (start + reloc->r_offset, value, 4);
else
error (_("RL78 sym diff reloc contains invalid offset: "
return true;
case 0x43: /* R_RL78_ABS16. */
- if (IN_RANGE (start, end, start + reloc->r_offset, 2))
+ if (in_range (size, reloc->r_offset, 2))
byte_put (start + reloc->r_offset, value, 2);
else
error (_("RL78 sym diff reloc contains invalid offset: "
uint64_t *num_relocs_return)
{
Elf_Internal_Shdr * relsec;
- unsigned char * end = start + size;
if (relocs_return != NULL)
{
reloc_type = get_reloc_type (filedata, rp->r_info);
- if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
+ if (target_specific_reloc_handling (filedata, rp, start, size, symtab, num_syms))
continue;
else if (is_none_reloc (filedata, reloc_type))
continue;
continue;
}
- rloc = start + rp->r_offset;
- if (!IN_RANGE (start, end, rloc, reloc_size))
+ if (!in_range (size, rp->r_offset, reloc_size))
{
warn (_("skipping invalid relocation offset %#" PRIx64
" in section %s\n"),
printable_section_name (filedata, section));
continue;
}
+ rloc = start + rp->r_offset;
sym_index = get_reloc_symindex (rp->r_info);
if (sym_index >= num_syms)
free (symtab);
/* Let the target specific reloc processing code know that
we have finished with these relocs. */
- target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
+ target_specific_reloc_handling (filedata, NULL, NULL, 0, NULL, 0);
if (relocs_return)
{