/* Renesas RX specific support for 32-bit ELF.
- Copyright (C) 2008-2019 Free Software Foundation, Inc.
+ Copyright (C) 2008-2020 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
/* We have already done error checking in rx_table_find(). */
- buf = (char *) malloc (13 + strlen (name + 20));
+ buf = (char *) bfd_malloc (13 + strlen (name + 20));
+ if (buf == NULL)
+ return FALSE;
sprintf (buf, "$tablestart$%s", name + 20);
table_start_cache = get_symbol_value (buf,
idx = (int) (entry_vma - table_start_cache) / 4;
/* This will look like $tableentry$<N>$<name> */
- buf = (char *) malloc (12 + 20 + strlen (name + 20));
+ buf = (char *) bfd_malloc (12 + 20 + strlen (name + 20));
+ if (buf == NULL)
+ return FALSE;
+
sprintf (buf, "$tableentry$%d$%s", idx, name + 20);
h = (struct elf_link_hash_entry *) bfd_link_hash_lookup (info->hash, buf, FALSE, FALSE, TRUE);
rx_offset_for_reloc (bfd * abfd,
Elf_Internal_Rela * rel,
Elf_Internal_Shdr * symtab_hdr,
- Elf_External_Sym_Shndx * shndx_buf ATTRIBUTE_UNUSED,
+ bfd_byte * shndx_buf ATTRIBUTE_UNUSED,
Elf_Internal_Sym * intsyms,
Elf_Internal_Rela ** lrel,
bfd * input_bfd,
bfd_byte * free_contents = NULL;
Elf_Internal_Sym * intsyms = NULL;
Elf_Internal_Sym * free_intsyms = NULL;
- Elf_External_Sym_Shndx * shndx_buf = NULL;
+ bfd_byte * shndx_buf = NULL;
bfd_vma pc;
bfd_vma sec_start;
bfd_vma symval = 0;
if (shndx_hdr && shndx_hdr->sh_size != 0)
{
- bfd_size_type amt;
+ size_t amt;
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf_External_Sym_Shndx);
- shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
- if (shndx_buf == NULL)
+ if (_bfd_mul_overflow (symtab_hdr->sh_info,
+ sizeof (Elf_External_Sym_Shndx), &amt))
+ {
+ bfd_set_error (bfd_error_file_too_big);
+ goto error_return;
+ }
+ if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0)
goto error_return;
- if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread (shndx_buf, amt, abfd) != amt)
+ shndx_buf = _bfd_malloc_and_read (abfd, amt, amt);
+ if (shndx_buf == NULL)
goto error_return;
- shndx_hdr->contents = (bfd_byte *) shndx_buf;
+ shndx_hdr->contents = shndx_buf;
}
/* Get a copy of the native relocations. */
break;
case 0:
#if RX_OPCODE_BIG_ENDIAN
- imm_val = (ip[0] << 24) | (ip[1] << 16) | (ip[2] << 8) | ip[3];
+ imm_val = ((unsigned) ip[0] << 24) | (ip[1] << 16) | (ip[2] << 8) | ip[3];
#else
- imm_val = (ip[3] << 24) | (ip[2] << 16) | (ip[1] << 8) | ip[0];
+ imm_val = ((unsigned) ip[3] << 24) | (ip[2] << 16) | (ip[1] << 8) | ip[0];
#endif
break;
}
return TRUE;
error_return:
- if (free_contents != NULL)
- free (free_contents);
+ free (free_contents);
if (shndx_buf != NULL)
{
free (shndx_buf);
}
- if (free_intsyms != NULL)
- free (free_intsyms);
+ free (free_intsyms);
return FALSE;
}
Elf_Internal_Sym * isymend;
Elf_Internal_Sym * isym;
Elf_Internal_Shdr * symtab_hdr;
- bfd_boolean free_internal = FALSE, free_external = FALSE;
char * st_info_str;
char * st_info_stb_str;
char * st_other_str;
char * st_shndx_str;
- if (! internal_syms)
- {
- internal_syms = bfd_malloc (1000);
- free_internal = 1;
- }
- if (! external_syms)
- {
- external_syms = bfd_malloc (1000);
- free_external = 1;
- }
-
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
locsymcount = symtab_hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
- if (free_internal)
+ if (!internal_syms)
isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
symtab_hdr->sh_info, 0,
internal_syms, external_syms, NULL);
isym->st_other, st_other_str,
isym->st_shndx, st_shndx_str);
}
- if (free_internal)
- free (internal_syms);
- if (free_external)
- free (external_syms);
}
char *
char * cloc = (char *) location;
swapped_data = (char *) bfd_alloc (abfd, count);
+ if (swapped_data == NULL)
+ return FALSE;
for (i = 0; i < count; i += 4)
{
find all the related symbols and mark their sections as SEC_KEEP
so we don't garbage collect them. */
- buf = (char *) malloc (12 + 10 + strlen (tname));
+ buf = (char *) bfd_malloc (12 + 10 + strlen (tname));
+ if (buf == NULL)
+ return FALSE;
sprintf (buf, "$tableend$%s", tname);
h = bfd_link_hash_lookup (info->info->hash, buf, FALSE, FALSE, TRUE);
+ ent->u.def.section->output_section->vma
+ ent->u.def.section->output_offset);
- buf = (char *) malloc (12 + 10 + strlen (tname));
+ buf = (char *) bfd_malloc (12 + 10 + strlen (tname));
+ if (buf == NULL)
+ return FALSE;
sprintf (buf, "$tableend$%s", tname);
end_addr = get_symbol_value_maybe (buf, info->info);
info->table_start = start_addr;
info->table_size = (int) (end_addr - start_addr) / 4;
- info->table_handlers = (bfd_vma *) malloc (info->table_size * sizeof (bfd_vma));
- info->table_entries = (struct bfd_link_hash_entry **) malloc (info->table_size * sizeof (struct bfd_link_hash_entry));
+ info->table_handlers = (bfd_vma *)
+ bfd_malloc (info->table_size * sizeof (bfd_vma));
+ if (info->table_handlers == NULL)
+ {
+ free (buf);
+ return FALSE;
+ }
+ info->table_entries = (struct bfd_link_hash_entry **)
+ bfd_malloc (info->table_size * sizeof (struct bfd_link_hash_entry));
+ if (info->table_entries == NULL)
+ {
+ free (info->table_handlers);
+ free (buf);
+ return FALSE;
+ }
for (idx = 0; idx < (int) (end_addr - start_addr) / 4; idx ++)
{