X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=bfd%2Felf32-rx.c;h=e2f4c9fb34a0fde327c12b8c89e5cd22e25ef4b8;hb=8c0546e928b557f10cb5aba2a91f3ecee660029d;hp=bd08eb47d8aa8d667b82996dc44edcccefe777a1;hpb=2bb3687ba8720558082d1575823868286d7916b5;p=binutils-gdb.git diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c index bd08eb47d8a..e2f4c9fb34a 100644 --- a/bfd/elf32-rx.c +++ b/bfd/elf32-rx.c @@ -1,5 +1,5 @@ /* Renesas RX specific support for 32-bit ELF. - Copyright (C) 2008-2020 Free Software Foundation, Inc. + Copyright (C) 2008-2021 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -576,7 +576,9 @@ rx_elf_relocate_section /* 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, @@ -618,7 +620,10 @@ rx_elf_relocate_section idx = (int) (entry_vma - table_start_cache) / 4; /* This will look like $tableentry$$ */ - 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); @@ -3032,8 +3037,7 @@ elf32_rx_relax_section (bfd * abfd, return TRUE; error_return: - if (free_contents != NULL) - free (free_contents); + free (free_contents); if (shndx_buf != NULL) { @@ -3041,8 +3045,7 @@ elf32_rx_relax_section (bfd * abfd, free (shndx_buf); } - if (free_intsyms != NULL) - free (free_intsyms); + free (free_intsyms); return FALSE; } @@ -3083,10 +3086,8 @@ bfd_elf32_rx_set_target_flags (bfd_boolean user_no_warn_mismatch, Returns a static pointer. */ static const char * -describe_flags (flagword flags) +describe_flags (flagword flags, char *buf) { - static char buf [128]; - buf[0] = 0; if (flags & E_FLAG_RX_64BIT_DOUBLES) @@ -3167,13 +3168,15 @@ rx_elf_merge_private_bfd_data (bfd * ibfd, struct bfd_link_info *info) } else { + char buf[128]; + _bfd_error_handler (_("there is a conflict merging the" " ELF header flags from %pB"), ibfd); _bfd_error_handler (_(" the input file's flags: %s"), - describe_flags (new_flags)); + describe_flags (new_flags, buf)); _bfd_error_handler (_(" the output file's flags: %s"), - describe_flags (old_flags)); + describe_flags (old_flags, buf)); error = TRUE; } } @@ -3192,6 +3195,7 @@ rx_elf_print_private_bfd_data (bfd * abfd, void * ptr) { FILE * file = (FILE *) ptr; flagword flags; + char buf[128]; BFD_ASSERT (abfd != NULL && ptr != NULL); @@ -3201,7 +3205,7 @@ rx_elf_print_private_bfd_data (bfd * abfd, void * ptr) flags = elf_elfheader (abfd)->e_flags; fprintf (file, _("private flags = 0x%lx:"), (long) flags); - fprintf (file, "%s", describe_flags (flags)); + fprintf (file, "%s", describe_flags (flags, buf)); return TRUE; } @@ -3335,26 +3339,14 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms) 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); @@ -3406,10 +3398,6 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms) 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 * @@ -3618,6 +3606,8 @@ rx_set_section_contents (bfd * abfd, char * cloc = (char *) location; swapped_data = (char *) bfd_alloc (abfd, count); + if (swapped_data == NULL) + return FALSE; for (i = 0; i < count; i += 4) { @@ -3782,7 +3772,9 @@ rx_table_find (struct bfd_hash_entry *vent, void *vinfo) 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); @@ -3911,7 +3903,9 @@ rx_table_map (struct bfd_hash_entry *vent, void *vinfo) + 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); @@ -3931,8 +3925,21 @@ rx_table_map (struct bfd_hash_entry *vent, void *vinfo) 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 ++) {