+2020-02-19 Alan Modra <amodra@gmail.com>
+
+ * elf.c (bfd_section_from_shdr): Use bfd_zalloc rather than
+ bfd_zalloc2.
+ (assign_section_numbers): Likewise.
+ (elf_map_symbols): Likewise, and bfd_alloc rather than bfd_alloc2.
+ (_bfd_elf_map_sections_to_segments): Use bfd_malloc rather than
+ bfd_malloc2, size_t amt, and unsigned tls_count.
+ (rewrite_elf_program_header): Use bfd_malloc and size_t amt.
+ * elflink.c (elf_create_symbuf): Use bfd_malloc.
+ (elf_output_implib): Use bfd_alloc.
+
2020-02-19 Alan Modra <amodra@gmail.com>
* bfd.c (struct bfd): Move format and direction to other
sections_being_created = NULL;
if (sections_being_created == NULL)
{
- sections_being_created = (bfd_boolean *)
- bfd_zalloc2 (abfd, elf_numsections (abfd), sizeof (bfd_boolean));
+ size_t amt = elf_numsections (abfd) * sizeof (bfd_boolean);
+ sections_being_created = (bfd_boolean *) bfd_zalloc (abfd, amt);
if (sections_being_created == NULL)
return FALSE;
sections_being_created_abfd = abfd;
Elf_Internal_Shdr **i_shdrp;
struct bfd_elf_section_data *d;
bfd_boolean need_symtab;
+ size_t amt;
section_number = 1;
/* Set up the list of section header pointers, in agreement with the
indices. */
- i_shdrp = (Elf_Internal_Shdr **) bfd_zalloc2 (abfd, section_number,
- sizeof (Elf_Internal_Shdr *));
+ amt = section_number * sizeof (Elf_Internal_Shdr *);
+ i_shdrp = (Elf_Internal_Shdr **) bfd_zalloc (abfd, amt);
if (i_shdrp == NULL)
return FALSE;
unsigned int idx;
asection *asect;
asymbol **new_syms;
+ size_t amt;
#ifdef DEBUG
fprintf (stderr, "elf_map_symbols\n");
}
max_index++;
- sect_syms = (asymbol **) bfd_zalloc2 (abfd, max_index, sizeof (asymbol *));
+ amt = max_index * sizeof (asymbol *);
+ sect_syms = (asymbol **) bfd_zalloc (abfd, amt);
if (sect_syms == NULL)
return FALSE;
elf_section_syms (abfd) = sect_syms;
}
/* Now sort the symbols so the local symbols are first. */
- new_syms = (asymbol **) bfd_alloc2 (abfd, num_locals + num_globals,
- sizeof (asymbol *));
-
+ amt = (num_locals + num_globals) * sizeof (asymbol *);
+ new_syms = (asymbol **) bfd_alloc (abfd, amt);
if (new_syms == NULL)
return FALSE;
bfd_boolean phdr_in_segment;
bfd_boolean writable;
bfd_boolean executable;
- int tls_count = 0;
+ unsigned int tls_count = 0;
asection *first_tls = NULL;
asection *first_mbind = NULL;
asection *dynsec, *eh_frame_hdr;
- bfd_size_type amt;
+ size_t amt;
bfd_vma addr_mask, wrap_to = 0;
bfd_size_type phdr_size;
/* Select the allocated sections, and sort them. */
- sections = (asection **) bfd_malloc2 (bfd_count_sections (abfd),
- sizeof (asection *));
+ amt = bfd_count_sections (abfd) * sizeof (asection *);
+ sections = (asection **) bfd_malloc (amt);
if (sections == NULL)
goto error_return;
m->p_flags = PF_R;
m->p_flags_valid = 1;
s = first_tls;
- for (i = 0; i < (unsigned int) tls_count; ++i)
+ for (i = 0; i < tls_count; ++i)
{
if ((s->flags & SEC_THREAD_LOCAL) == 0)
{
(_("%pB: TLS sections are not adjacent:"), abfd);
s = first_tls;
i = 0;
- while (i < (unsigned int) tls_count)
+ while (i < tls_count)
{
if ((s->flags & SEC_THREAD_LOCAL) != 0)
{
asection *matching_lma;
asection *suggested_lma;
unsigned int j;
- bfd_size_type amt;
+ size_t amt;
asection *first_section;
if (segment->p_type == PT_NULL)
/* Allocate a segment map big enough to contain
all of the sections we have selected. */
amt = sizeof (struct elf_segment_map) - sizeof (asection *);
- amt += (bfd_size_type) section_count * sizeof (asection *);
+ amt += section_count * sizeof (asection *);
map = (struct elf_segment_map *) bfd_zalloc (obfd, amt);
if (map == NULL)
return FALSE;
pointers that we are interested in. As these sections get assigned
to a segment, they are removed from this array. */
- sections = (asection **) bfd_malloc2 (section_count, sizeof (asection *));
+ amt = section_count * sizeof (asection *);
+ sections = (asection **) bfd_malloc (amt);
if (sections == NULL)
return FALSE;
segments. Create a new segment here, initialise it
and carry on looping. */
amt = sizeof (struct elf_segment_map) - sizeof (asection *);
- amt += (bfd_size_type) section_count * sizeof (asection *);
+ amt += section_count * sizeof (asection *);
map = (struct elf_segment_map *) bfd_zalloc (obfd, amt);
if (map == NULL)
{
Elf_Internal_Sym **ind, **indbufend, **indbuf;
struct elf_symbuf_symbol *ssym;
struct elf_symbuf_head *ssymbuf, *ssymhead;
- size_t i, shndx_count, total_size;
+ size_t i, shndx_count, total_size, amt;
- indbuf = (Elf_Internal_Sym **) bfd_malloc2 (symcount, sizeof (*indbuf));
+ amt = symcount * sizeof (*indbuf);
+ indbuf = (Elf_Internal_Sym **) bfd_malloc (amt);
if (indbuf == NULL)
return NULL;
long symcount;
long src_count;
elf_symbol_type *osymbuf;
+ size_t amt;
implib_bfd = info->out_implib_bfd;
bed = get_elf_backend_data (abfd);
/* Make symbols absolute. */
- osymbuf = (elf_symbol_type *) bfd_alloc2 (implib_bfd, symcount,
- sizeof (*osymbuf));
+ amt = symcount * sizeof (*osymbuf);
+ osymbuf = (elf_symbol_type *) bfd_alloc (implib_bfd, amt);
if (osymbuf == NULL)
goto free_sym_buf;