+Fri Dec 1 14:46:51 1995 Ian Lance Taylor <ian@cygnus.com>
+
+ * libbfd.c (bfd_malloc, bfd_realloc): New functions.
+ (bfd_zmalloc): Return PTR, not char *. Take size_t, not
+ bfd_size_type.
+ * libbfd-in.h (bfd_malloc, bfd_realloc): Declare.
+ (bfd_zmalloc): Change declaration.
+ * libbfd.h: Rebuild.
+ * Many files: Use bfd_malloc and bfd_realloc rather than malloc
+ and realloc. Don't set bfd_error_no_memory if they fail.
+
Thu Nov 30 19:32:26 1995 Kim Knuttila <krk@cygnus.com>
* coff-ppc.c: Added macros to tidy up toc cell treatment. Numerous
later on. If we put them on the obstack it might not be
possible to free them. */
syms = ((struct external_nlist *)
- malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
+ bfd_malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
if (syms == (struct external_nlist *) NULL && count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
|| (bfd_read (syms, 1, exec_hdr (abfd)->a_syms, abfd)
return false;
strings = (char *) obj_aout_string_window (abfd).data;
#else
- strings = (char *) malloc ((size_t) stringsize + 1);
+ strings = (char *) bfd_malloc ((size_t) stringsize + 1);
if (strings == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
/* Skip space for the string count in the buffer for convenience
when using indexes. */
cached_size = (obj_aout_external_sym_count (abfd)
* sizeof (aout_symbol_type));
- cached = (aout_symbol_type *) malloc (cached_size);
+ cached = (aout_symbol_type *) bfd_malloc (cached_size);
if (cached == NULL && cached_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (cached_size != 0)
memset (cached, 0, cached_size);
count = reloc_size / each_size;
- reloc_cache = (arelent *) malloc ((size_t) (count * sizeof (arelent)));
+ reloc_cache = (arelent *) bfd_malloc ((size_t) (count * sizeof (arelent)));
if (reloc_cache == NULL && count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
memset (reloc_cache, 0, count * sizeof (arelent));
- relocs = malloc ((size_t) reloc_size);
+ relocs = bfd_malloc ((size_t) reloc_size);
if (relocs == NULL && reloc_size != 0)
{
free (reloc_cache);
- bfd_set_error (bfd_error_no_memory);
return false;
}
adata (abfd).line_buf = buf = NULL;
else
{
- adata (abfd).line_buf = buf = (char *) malloc (filelen + funclen + 2);
- if (adata (abfd).line_buf == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ buf = (char *) bfd_malloc (filelen + funclen + 2);
+ adata (abfd).line_buf = buf;
+ if (buf == NULL)
+ return false;
}
if (main_file_name != NULL)
goto error_return;
/* Allocate buffers to hold section contents and relocs. */
- aout_info.contents = (bfd_byte *) malloc (max_contents_size);
- aout_info.relocs = (PTR) malloc (max_relocs_size);
- aout_info.symbol_map = (int *) malloc (max_sym_count * sizeof (int *));
+ aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size);
+ aout_info.relocs = (PTR) bfd_malloc (max_relocs_size);
+ aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int *));
aout_info.output_syms = ((struct external_nlist *)
- malloc ((max_sym_count + 1)
- * sizeof (struct external_nlist)));
+ bfd_malloc ((max_sym_count + 1)
+ * sizeof (struct external_nlist)));
if ((aout_info.contents == NULL && max_contents_size != 0)
|| (aout_info.relocs == NULL && max_relocs_size != 0)
|| (aout_info.symbol_map == NULL && max_sym_count != 0)
|| aout_info.output_syms == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* If we have a symbol named __DYNAMIC, force it out now. This is
required by SunOS. Doing this here rather than in sunos.c is a
return false;
count = reloc_size / sizeof (struct relocation_info);
- relocs = (struct relocation_info *) malloc (reloc_size);
- if (!relocs && reloc_size != 0) {
- bfd_set_error (bfd_error_no_memory);
+ relocs = (struct relocation_info *) bfd_malloc (reloc_size);
+ if (!relocs && reloc_size != 0)
return false;
- }
- reloc_cache = (arelent *) malloc ((count+1) * sizeof (arelent));
+ reloc_cache = (arelent *) bfd_malloc ((count+1) * sizeof (arelent));
if (!reloc_cache) {
if (relocs != NULL)
free ((char*)relocs);
- bfd_set_error (bfd_error_no_memory);
return false;
}
int extern_mask, pcrel_mask, len_2, callj_mask;
if (count == 0) return true;
generic = section->orelocation;
- native = ((struct relocation_info *) malloc (natsize));
- if (!native && natsize != 0) {
- bfd_set_error (bfd_error_no_memory);
+ native = ((struct relocation_info *) bfd_malloc (natsize));
+ if (!native && natsize != 0)
return false;
- }
if (abfd->xvec->header_byteorder_big_p)
{
{
long reloc_count;
- reloc_vector = (arelent **) malloc (reloc_size);
+ reloc_vector = (arelent **) bfd_malloc (reloc_size);
if (reloc_vector == NULL && reloc_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* Get the relocs and think about them */
reloc_count =
data, relocateable,
symbols);
- reloc_vector = (arelent **) malloc (reloc_size);
+ reloc_vector = (arelent **) bfd_malloc (reloc_size);
if (reloc_vector == NULL && reloc_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
input_section->reloc_done = 1;
if (reloc_size < 0)
goto error_return;
- reloc_vector = (arelent **) malloc (reloc_size);
+ reloc_vector = (arelent **) bfd_malloc (reloc_size);
if (reloc_vector == NULL && reloc_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (! bfd_get_section_contents (input_bfd, input_section, data,
(file_ptr) 0, input_section->_raw_size))
if (! info->relocateable)
return true;
- esym = (bfd_byte *) malloc (symesz);
+ esym = (bfd_byte *) bfd_malloc (symesz);
if (esym == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
return false;
if (info->keep_memory)
contents = (bfd_byte *) bfd_alloc (abfd, sec->_raw_size);
else
- contents = (bfd_byte *) malloc ((size_t) sec->_raw_size);
+ contents = (bfd_byte *) bfd_malloc ((size_t) sec->_raw_size);
if (contents == (bfd_byte *) NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (! bfd_get_section_contents (abfd, sec, (PTR) contents,
(file_ptr) 0, sec->_raw_size))
goto error_return;
{
/* add this entry to our toc addr-offset-name list */
struct list_ele *t;
- t = malloc(sizeof(struct list_ele));
+ t = bfd_malloc (sizeof (struct list_ele));
+ if (t == NULL)
+ abort ();
t->next = 0;
t->offset = our_toc_offset;
t->name = name;
contents = coff_section_data (abfd, sec)->contents;
else
{
- contents = (bfd_byte *) malloc (sec->_raw_size);
+ contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
if (contents == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
free_contents = contents;
if (! bfd_get_section_contents (abfd, sec, contents,
Perhaps, if info->keep_memory is false, we
should free them, if we are permitted to,
when we leave sh_coff_relax_section. */
- ocontents = (bfd_byte *) malloc (o->_raw_size);
+ ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
if (ocontents == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (! bfd_get_section_contents (abfd, o, ocontents,
(file_ptr) 0,
o->_raw_size))
goto error_return;
internal_syms = ((struct internal_syment *)
- malloc (obj_raw_syment_count (input_bfd)
- * sizeof (struct internal_syment)));
+ bfd_malloc (obj_raw_syment_count (input_bfd)
+ * sizeof (struct internal_syment)));
if (internal_syms == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
- sections = (asection **) malloc (obj_raw_syment_count (input_bfd)
- * sizeof (asection *));
+ sections = (asection **) bfd_malloc (obj_raw_syment_count (input_bfd)
+ * sizeof (asection *));
if (sections == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
isymp = internal_syms;
secpp = sections;
if (external_relocs == NULL)
{
- free_external = (bfd_byte *) malloc (sec->reloc_count * relsz);
+ free_external = (bfd_byte *) bfd_malloc (sec->reloc_count * relsz);
if (free_external == NULL && sec->reloc_count > 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
external_relocs = free_external;
}
if (internal_relocs == NULL)
{
free_internal = ((struct internal_reloc *)
- malloc (sec->reloc_count
- * sizeof (struct internal_reloc)));
+ bfd_malloc (sec->reloc_count
+ * sizeof (struct internal_reloc)));
if (free_internal == NULL && sec->reloc_count > 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
internal_relocs = free_internal;
}
size = obj_raw_syment_count (abfd) * symesz;
- syms = (PTR) malloc (size);
+ syms = (PTR) bfd_malloc (size);
if (syms == NULL && size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
|| bfd_read (syms, size, 1, abfd) != size)
return NULL;
}
- strings = (char *) malloc (strsize);
+ strings = (char *) bfd_malloc (strsize);
if (strings == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return NULL;
- }
+ return NULL;
if (bfd_read (strings + STRING_SIZE_SIZE,
strsize - STRING_SIZE_SIZE, 1, abfd)
}
/* Read the symbolic information header. */
- raw = (PTR) malloc ((size_t) external_hdr_size);
+ raw = (PTR) bfd_malloc ((size_t) external_hdr_size);
if (raw == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
|| (bfd_read (raw, external_hdr_size, 1, abfd)
sofar = _bfd_ecoff_sizeof_headers (abfd, false);
/* Sort the sections by VMA. */
- sorted_hdrs = (asection **) malloc (abfd->section_count
- * sizeof (asection *));
+ sorted_hdrs = (asection **) bfd_malloc (abfd->section_count
+ * sizeof (asection *));
if (sorted_hdrs == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
for (current = abfd->sections, i = 0;
current != NULL;
current = current->next, i++)
siz = filhsz;
if (siz < aoutsz)
siz = aoutsz;
- buff = (PTR) malloc ((size_t) siz);
+ buff = (PTR) bfd_malloc ((size_t) siz);
if (buff == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
}
internal_f.f_nscns = 0;
/* Read in the external symbols and external strings. */
external_ext_size = backend->debug_swap.external_ext_size;
esize = symhdr->iextMax * external_ext_size;
- external_ext = (PTR) malloc (esize);
+ external_ext = (PTR) bfd_malloc (esize);
if (external_ext == NULL && esize != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0
|| bfd_read (external_ext, 1, esize, abfd) != esize)
goto error_return;
- ssext = (char *) malloc (symhdr->issExtMax);
+ ssext = (char *) bfd_malloc (symhdr->issExtMax);
if (ssext == NULL && symhdr->issExtMax != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
|| (bfd_read (ssext, 1, symhdr->issExtMax, abfd) !=
/* Read in the external symbols and external strings. */
external_ext_size = ecoff_backend (abfd)->debug_swap.external_ext_size;
esize = symhdr->iextMax * external_ext_size;
- external_ext = (PTR) malloc (esize);
+ external_ext = (PTR) bfd_malloc (esize);
if (external_ext == NULL && esize != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0
|| bfd_read (external_ext, 1, esize, abfd) != esize)
goto error_return;
- ssext = (char *) malloc (symhdr->issExtMax);
+ ssext = (char *) bfd_malloc (symhdr->issExtMax);
if (ssext == NULL && symhdr->issExtMax != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
|| (bfd_read (ssext, 1, symhdr->issExtMax, abfd)
debug->ptr = NULL; \
else \
{ \
- debug->ptr = (type) malloc ((size_t) (size * symhdr->count)); \
+ debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
if (debug->ptr == NULL) \
{ \
- bfd_set_error (bfd_error_no_memory); \
ret = false; \
goto return_something; \
} \
/* Get the section contents. We allocate memory for the larger of
the size before relocating and the size after relocating. */
- contents = (bfd_byte *) malloc (raw_size >= cooked_size
- ? (size_t) raw_size
- : (size_t) cooked_size);
+ contents = (bfd_byte *) bfd_malloc (raw_size >= cooked_size
+ ? (size_t) raw_size
+ : (size_t) cooked_size);
if (contents == NULL && raw_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* If we are relaxing, the contents may have already been read into
memory, in which case we copy them into our new buffer. We don't
external_relocs = section_tdata->external_relocs;
else
{
- external_relocs = (PTR) malloc ((size_t) external_relocs_size);
+ external_relocs = (PTR) bfd_malloc ((size_t) external_relocs_size);
if (external_relocs == NULL && external_relocs_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
|| (bfd_read (external_relocs, 1, external_relocs_size, input_bfd)
/* Get some memory and swap out the reloc. */
external_reloc_size = ecoff_backend (output_bfd)->external_reloc_size;
- rbuf = (bfd_byte *) malloc ((size_t) external_reloc_size);
+ rbuf = (bfd_byte *) bfd_malloc ((size_t) external_reloc_size);
if (rbuf == (bfd_byte *) NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
(*ecoff_backend (output_bfd)->swap_reloc_out) (output_bfd, &in, (PTR) rbuf);
if (want < ALLOC_SIZE)
want = ALLOC_SIZE;
}
- if (*buf == NULL)
- newbuf = (char *) malloc (have + want);
- else
- newbuf = (char *) realloc (*buf, have + want);
+ newbuf = (char *) bfd_realloc (*buf, have + want);
if (newbuf == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
*buf = newbuf;
*bufend = *buf + have + want;
return true;
{
struct accumulate *ainfo;
- ainfo = (struct accumulate *) malloc (sizeof (struct accumulate));
+ ainfo = (struct accumulate *) bfd_malloc (sizeof (struct accumulate));
if (!ainfo)
- {
- bfd_set_error (bfd_error_no_memory);
- return NULL;
- }
+ return NULL;
if (! bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
1021))
return NULL;
information that should not be merged. */
name = input_debug->ss + fdr.issBase + fdr.rss;
- lookup = (char *) malloc (strlen (name) + 20);
+ lookup = (char *) bfd_malloc (strlen (name) + 20);
if (lookup == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
sprintf (lookup, "%s %lx", name, fdr.csym);
fh = string_hash_lookup (&ainfo->fdr_hash, lookup, true, true);
SET (cbExtOffset, iextMax, swap->external_ext_size);
#undef SET
- buff = (PTR) malloc ((size_t) swap->external_hdr_size);
+ buff = (PTR) bfd_malloc ((size_t) swap->external_hdr_size);
if (buff == NULL && swap->external_hdr_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
(*swap->swap_hdr_out) (abfd, symhdr, buff);
if (bfd_write (buff, 1, swap->external_hdr_size, abfd)
bfd_byte *s;
i = swap->debug_align - (total & (swap->debug_align - 1));
- s = (bfd_byte *) malloc (i);
+ s = (bfd_byte *) bfd_malloc (i);
if (s == NULL && i != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
memset ((PTR) s, 0, i);
if (bfd_write ((PTR) s, 1, i, abfd) != i)
if (! ecoff_write_symhdr (abfd, debug, swap, where))
goto error_return;
- space = (PTR) malloc (ainfo->largest_file_shuffle);
+ space = (PTR) bfd_malloc (ainfo->largest_file_shuffle);
if (space == NULL && ainfo->largest_file_shuffle != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (! ecoff_write_shuffle (abfd, swap, ainfo->line, space)
|| ! ecoff_write_shuffle (abfd, swap, ainfo->pdr, space)
bfd_byte *s;
i = swap->debug_align - (total & (swap->debug_align - 1));
- s = (bfd_byte *) malloc (i);
+ s = (bfd_byte *) bfd_malloc (i);
if (s == NULL && i != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset ((PTR) s, 0, i);
if (bfd_write ((PTR) s, 1, i, abfd) != i)
{
i = (swap->debug_align
- (debug->symbolic_header.issExtMax & (swap->debug_align - 1)));
- s = (bfd_byte *) malloc (i);
+ s = (bfd_byte *) bfd_malloc (i);
if (s == NULL && i != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset ((PTR) s, 0, i);
if (bfd_write ((PTR) s, 1, i, abfd) != i)
{
{
if (line_info->find_buffer != NULL)
free (line_info->find_buffer);
- buffer = (char *) malloc (len);
+ buffer = (char *) bfd_malloc (len);
if (buffer == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
line_info->find_buffer = buffer;
}
char *alc;
len = strlen (sec->name);
- alc = (char *) malloc (len - 2);
+ alc = (char *) bfd_malloc (len - 2);
if (alc == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
strncpy (alc, sec->name, len - 3);
alc[len - 3] = '\0';
s = bfd_get_section_by_name (abfd, alc);
/* Select the allocated sections, and sort them. */
- sections = (asection **) malloc (bfd_count_sections (abfd)
- * sizeof (asection *));
+ sections = (asection **) bfd_malloc (bfd_count_sections (abfd)
+ * sizeof (asection *));
if (sections == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
i = 0;
for (s = abfd->sections; s != NULL; s = s->next)
/* Temporarily allocate room for the raw ELF symbols. */
x_symp = ((Elf_External_Sym *)
- malloc (symcount * sizeof (Elf_External_Sym)));
+ bfd_malloc (symcount * sizeof (Elf_External_Sym)));
if (x_symp == NULL && symcount != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd)
!= symcount * sizeof (Elf_External_Sym))
&& (asect->reloc_count
== d->rel_hdr.sh_size / d->rel_hdr.sh_entsize));
- allocated = (PTR) malloc ((size_t) d->rel_hdr.sh_size);
+ allocated = (PTR) bfd_malloc ((size_t) d->rel_hdr.sh_size);
if (allocated == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0
|| (bfd_read (allocated, 1, d->rel_hdr.sh_size, abfd)
asection *newsect;
if (hdr->p_filesz > 0
- && (buf = (char *) malloc ((size_t) hdr->p_filesz)) != NULL
+ && (buf = (char *) bfd_malloc ((size_t) hdr->p_filesz)) != NULL
&& bfd_seek (abfd, hdr->p_offset, SEEK_SET) != -1
&& bfd_read ((PTR) buf, hdr->p_filesz, 1, abfd) == hdr->p_filesz)
{
}
else if (hdr->p_filesz > 0)
{
- bfd_set_error (bfd_error_no_memory);
return false;
}
return true;
c = bfd_ardata (abfd)->symdef_count;
if (c == 0)
return true;
- defined = (boolean *) malloc (c * sizeof (boolean));
- included = (boolean *) malloc (c * sizeof (boolean));
+ defined = (boolean *) bfd_malloc (c * sizeof (boolean));
+ included = (boolean *) bfd_malloc (c * sizeof (boolean));
if (defined == (boolean *) NULL || included == (boolean *) NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset (defined, 0, c * sizeof (boolean));
memset (included, 0, c * sizeof (boolean));
extsymoff = hdr->sh_info;
}
- buf = (Elf_External_Sym *) malloc (extsymcount * sizeof (Elf_External_Sym));
+ buf = ((Elf_External_Sym *)
+ bfd_malloc (extsymcount * sizeof (Elf_External_Sym)));
if (buf == NULL && extsymcount != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* We store a pointer to the hash table entry for each external
symbol. */
int elfsec;
unsigned long link;
- dynbuf = (Elf_External_Dyn *) malloc ((size_t) s->_raw_size);
+ dynbuf = (Elf_External_Dyn *) bfd_malloc ((size_t) s->_raw_size);
if (dynbuf == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (! bfd_get_section_contents (abfd, s, (PTR) dynbuf,
(file_ptr) 0, s->_raw_size))
BFD_ASSERT (s != NULL);
newsize = s->_raw_size + sizeof (Elf_External_Dyn);
- if (s->contents == NULL)
- newcontents = (bfd_byte *) malloc (newsize);
- else
- newcontents = (bfd_byte *) realloc (s->contents, newsize);
+ newcontents = (bfd_byte *) bfd_realloc (s->contents, newsize);
if (newcontents == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
dyn.d_tag = tag;
dyn.d_un.d_val = val;
if (keep_memory)
internal_relocs = (Elf_Internal_Rela *) bfd_alloc (abfd, size);
else
- internal_relocs = alloc2 = (Elf_Internal_Rela *) malloc (size);
+ internal_relocs = alloc2 = (Elf_Internal_Rela *) bfd_malloc (size);
if (internal_relocs == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
}
if (external_relocs == NULL)
{
- alloc1 = (PTR) malloc ((size_t) rel_hdr->sh_size);
+ alloc1 = (PTR) bfd_malloc ((size_t) rel_hdr->sh_size);
if (alloc1 == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
external_relocs = alloc1;
}
goto error_return;
p = ((struct elf_link_hash_entry **)
- malloc (o->reloc_count
- * sizeof (struct elf_link_hash_entry *)));
+ bfd_malloc (o->reloc_count
+ * sizeof (struct elf_link_hash_entry *)));
if (p == NULL && o->reloc_count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
elf_section_data (o)->rel_hashes = p;
pend = p + o->reloc_count;
for (; p < pend; p++)
else
finfo.symbuf_size = max_sym_count;
finfo.symbuf = ((Elf_External_Sym *)
- malloc (finfo.symbuf_size * sizeof (Elf_External_Sym)));
+ bfd_malloc (finfo.symbuf_size * sizeof (Elf_External_Sym)));
if (finfo.symbuf == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* Start writing out the symbol table. The first symbol is always a
dummy symbol. */
/* Allocate some memory to hold information read in from the input
files. */
- finfo.contents = (bfd_byte *) malloc (max_contents_size);
- finfo.external_relocs = (PTR) malloc (max_external_reloc_size);
+ finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
+ finfo.external_relocs = (PTR) bfd_malloc (max_external_reloc_size);
finfo.internal_relocs = ((Elf_Internal_Rela *)
- malloc (max_internal_reloc_count
- * sizeof (Elf_Internal_Rela)));
+ bfd_malloc (max_internal_reloc_count
+ * sizeof (Elf_Internal_Rela)));
finfo.external_syms = ((Elf_External_Sym *)
- malloc (max_sym_count * sizeof (Elf_External_Sym)));
+ bfd_malloc (max_sym_count
+ * sizeof (Elf_External_Sym)));
finfo.internal_syms = ((Elf_Internal_Sym *)
- malloc (max_sym_count * sizeof (Elf_Internal_Sym)));
- finfo.indices = (long *) malloc (max_sym_count * sizeof (long));
- finfo.sections = (asection **) malloc (max_sym_count * sizeof (asection *));
+ bfd_malloc (max_sym_count
+ * sizeof (Elf_Internal_Sym)));
+ finfo.indices = (long *) bfd_malloc (max_sym_count * sizeof (long));
+ finfo.sections = ((asection **)
+ bfd_malloc (max_sym_count * sizeof (asection *)));
if ((finfo.contents == NULL && max_contents_size != 0)
|| (finfo.external_relocs == NULL && max_external_reloc_size != 0)
|| (finfo.internal_relocs == NULL && max_internal_reloc_count != 0)
|| (finfo.internal_syms == NULL && max_sym_count != 0)
|| (finfo.indices == NULL && max_sym_count != 0)
|| (finfo.sections == NULL && max_sym_count != 0))
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* Since ELF permits relocations to be against local symbols, we
must have the local symbols available when we do the relocations.
count = reloc_size / each_size;
- reloc_cache = (arelent *) malloc (count * sizeof (arelent));
+ reloc_cache = (arelent *) bfd_malloc (count * sizeof (arelent));
if (!reloc_cache && count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
memset (reloc_cache, 0, count * sizeof (arelent));
relocs = (PTR) bfd_alloc (abfd, reloc_size);
ieee_symbol_type *new =
(ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
if (!new)
- {
- bfd_set_error (bfd_error_no_error);
- return NULL;
- }
+ return NULL;
new->symbol.the_bfd = abfd;
return &new->symbol;
}
bfd_byte *data = 0;
int offset;
- data = (bfd_byte *) malloc ((size_t) bfd_section_size (abfd,
- rel_section));
+ data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd,
+ rel_section));
if (data == NULL && bfd_section_size (abfd, rel_section) != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
datasize = bfd_section_size (abfd, rel_section);
bfd_get_section_contents (abfd,
if (bfd_section_size (abfd, section) == 0)
return true;
- data = (bfd_byte *) malloc ((size_t) bfd_section_size (abfd, section));
+ data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
datasize = bfd_section_size (abfd, section);
if (data == NULL && datasize != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
bfd_get_section_contents (abfd,
section,
if (bfd_section_size (abfd, section) == 0)
return true;
- data = (bfd_byte *) malloc ((size_t) bfd_section_size (abfd, section));
+ data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
datasize = bfd_section_size (abfd, section);
if (data == NULL && datasize != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
bfd_get_section_contents (abfd,
section,
/* First, read in space names */
- space_strings = malloc (file_hdr->space_strings_size);
+ space_strings = bfd_malloc (file_hdr->space_strings_size);
if (!space_strings && file_hdr->space_strings_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
goto error_return;
}
/* Now that we've read in all the subspace records, we need to assign
a target index to each subspace. */
- subspace_sections = (asection **) malloc (total_subspaces
- * sizeof (asection *));
+ subspace_sections = (asection **) bfd_malloc (total_subspaces
+ * sizeof (asection *));
if (subspace_sections == NULL)
goto error_return;
/* Compute total symbol table size and allocate a chunk of memory
to hold the symbol table as we build it. */
symtab_size = num_syms * sizeof (struct symbol_dictionary_record);
- som_symtab = (struct symbol_dictionary_record *) malloc (symtab_size);
+ som_symtab = (struct symbol_dictionary_record *) bfd_malloc (symtab_size);
if (som_symtab == NULL && symtab_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset (som_symtab, 0, symtab_size);
/* Walk over each symbol. */
}
/* Allocate and read in the string table. */
- stringtab = malloc (obj_som_stringtab_size (abfd));
+ stringtab = bfd_malloc (obj_som_stringtab_size (abfd));
if (stringtab == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
memset (stringtab, 0, obj_som_stringtab_size (abfd));
if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) < 0)
stringtab = obj_som_stringtab (abfd);
- symbase = (som_symbol_type *)
- malloc (symbol_count * sizeof (som_symbol_type));
+ symbase = ((som_symbol_type *)
+ bfd_malloc (symbol_count * sizeof (som_symbol_type)));
if (symbase == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset (symbase, 0, symbol_count * sizeof (som_symbol_type));
/* Read in the external SOM representation. */
- buf = malloc (symbol_count * symsize);
+ buf = bfd_malloc (symbol_count * symsize);
if (buf == NULL && symbol_count * symsize != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
goto error_return;
if (bfd_read (buf, symbol_count * symsize, 1, abfd)
/* Got to read the damn contents first. We don't
bother saving the contents (yet). Add it one
day if the need arises. */
- section->contents = malloc (section->_raw_size);
+ section->contents = bfd_malloc (section->_raw_size);
if (section->contents == NULL)
return -1;
parsed. We must do so now to know how many relocations exist. */
if (section->reloc_count == -1)
{
- external_relocs = (char *) malloc (fixup_stream_size);
+ external_relocs = (char *) bfd_malloc (fixup_stream_size);
if (external_relocs == (char *) NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
/* Read in the external forms. */
if (bfd_seek (abfd,
obj_som_reloc_filepos (abfd) + section->rel_filepos,
file_ptr lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
hash_table =
- (unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int));
+ (unsigned int *) bfd_malloc (lst_header->hash_size
+ * sizeof (unsigned int));
if (hash_table == NULL && lst_header->hash_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* Don't forget to initialize the counter! */
*count = 0;
file_ptr lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
hash_table =
- (unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int));
+ (unsigned int *) bfd_malloc (lst_header->hash_size
+ * sizeof (unsigned int));
if (hash_table == NULL && lst_header->hash_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
som_dict =
- (struct som_entry *) malloc (lst_header->module_count
- * sizeof (struct som_entry));
+ (struct som_entry *) bfd_malloc (lst_header->module_count
+ * sizeof (struct som_entry));
if (som_dict == NULL && lst_header->module_count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* Read in the hash table. The has table is an array of 32bit file offsets
which point to the hash chains. */
unsigned int maxname = abfd->xvec->ar_max_namelen;
hash_table =
- (unsigned int *) malloc (lst.hash_size * sizeof (unsigned int));
+ (unsigned int *) bfd_malloc (lst.hash_size * sizeof (unsigned int));
if (hash_table == NULL && lst.hash_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
som_dict =
- (struct som_entry *) malloc (lst.module_count
- * sizeof (struct som_entry));
+ (struct som_entry *) bfd_malloc (lst.module_count
+ * sizeof (struct som_entry));
if (som_dict == NULL && lst.module_count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
last_hash_entry =
((struct lst_symbol_record **)
- malloc (lst.hash_size * sizeof (struct lst_symbol_record *)));
+ bfd_malloc (lst.hash_size * sizeof (struct lst_symbol_record *)));
if (last_hash_entry == NULL && lst.hash_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
/* Lots of fields are file positions relative to the start
of the lst record. So save its location. */
curr_som_offset = (curr_som_offset + 0x1) & ~0x1;
/* FIXME should be done with buffers just like everything else... */
- lst_syms = malloc (nsyms * sizeof (struct lst_symbol_record));
+ lst_syms = bfd_malloc (nsyms * sizeof (struct lst_symbol_record));
if (lst_syms == NULL && nsyms != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
- strings = malloc (string_size);
+ goto error_return;
+ strings = bfd_malloc (string_size);
if (strings == NULL && string_size != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
p = strings;
curr_lst_sym = lst_syms;
{
if (buf != NULL)
free (buf);
- buf = (bfd_byte *) malloc (bytes * 2);
+ buf = (bfd_byte *) bfd_malloc (bytes * 2);
if (buf == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
bufsize = bytes * 2;
}
{
if (buf != NULL)
free (buf);
- buf = (bfd_byte *) malloc (bytes * 2);
+ buf = (bfd_byte *) bfd_malloc (bytes * 2);
if (buf == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
bufsize = bytes * 2;
}
if (info->dyninfo.ld_buckets > info->dynsym_count)
abort ();
table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
- table = (bfd_byte *) malloc (table_size);
+ table = (bfd_byte *) bfd_malloc (table_size);
if (table == NULL && table_size != 0)
abort ();
if (bfd_seek (abfd, info->dyninfo.ld_hash, SEEK_SET) != 0
bfd_byte *contents;
add = 8 - (s->_raw_size & 7);
- contents = (bfd_byte *) realloc (s->contents,
- (size_t) (s->_raw_size + add));
+ contents = (bfd_byte *) bfd_realloc (s->contents,
+ (size_t) (s->_raw_size + add));
if (contents == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
memset (contents + s->_raw_size, 0, (size_t) add);
s->contents = contents;
s->_raw_size += add;
return true;
if (! info->keep_memory)
- relocs = free_relocs = malloc ((size_t) rel_size);
+ relocs = free_relocs = bfd_malloc ((size_t) rel_size);
else
{
struct aout_section_data_struct *n;
else
{
set_aout_section_data (sec, n);
- relocs = malloc ((size_t) rel_size);
+ relocs = bfd_malloc ((size_t) rel_size);
aout_section_data (sec)->relocs = relocs;
}
}
if (relocs == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
|| bfd_read (relocs, 1, rel_size, abfd) != rel_size)
There are no debugging symbols in the dynamic symbols. */
s = bfd_get_section_by_name (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
- if (s->contents == NULL)
- contents = (bfd_byte *) malloc (len + 1);
- else
- contents = (bfd_byte *) realloc (s->contents,
- (size_t) (s->_raw_size + len + 1));
+ contents = (bfd_byte *) bfd_realloc (s->contents,
+ s->_raw_size + len + 1);
if (contents == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
s->contents = contents;
h->dynstr_index = s->_raw_size;
scanning along the relocs as we process the csects. We index
into reloc_info using the section target_index. */
reloc_info = ((struct reloc_info_struct *)
- malloc ((abfd->section_count + 1)
- * sizeof (struct reloc_info_struct)));
+ bfd_malloc ((abfd->section_count + 1)
+ * sizeof (struct reloc_info_struct)));
if (reloc_info == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset ((PTR) reloc_info, 0,
(abfd->section_count + 1) * sizeof (struct reloc_info_struct));
xcoff_read_internal_relocs (abfd, o, true, (bfd_byte *) NULL,
false, (struct internal_reloc *) NULL);
reloc_info[o->target_index].csects =
- (asection **) malloc (o->reloc_count * sizeof (asection *));
+ (asection **) bfd_malloc (o->reloc_count * sizeof (asection *));
if (reloc_info[o->target_index].csects == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
memset (reloc_info[o->target_index].csects, 0,
o->reloc_count * sizeof (asection *));
}
{
bfd_byte *linenos;
- linenos = (bfd_byte *) malloc (o->lineno_count * linesz);
+ linenos = (bfd_byte *) bfd_malloc (o->lineno_count * linesz);
if (linenos == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
reloc_info[o->target_index].linenos = linenos;
if (bfd_seek (abfd, o->line_filepos, SEEK_SET) != 0
|| (bfd_read (linenos, linesz, o->lineno_count, abfd)
goto error_return;
}
- buf = (bfd_byte *) malloc (lsec->_raw_size);
+ buf = (bfd_byte *) bfd_malloc (lsec->_raw_size);
if (buf == NULL && lsec->_raw_size > 0)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (! bfd_get_section_contents (abfd, lsec, (PTR) buf, (file_ptr) 0,
lsec->_raw_size))
char *fnname;
struct xcoff_link_hash_entry *hfn;
- fnname = (char *) malloc (strlen (h->root.root.string) + 2);
+ fnname = (char *) bfd_malloc (strlen (h->root.root.string) + 2);
if (fnname == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
fnname[0] = '.';
strcpy (fnname + 1, h->root.root.string);
hfn = xcoff_link_hash_lookup (xcoff_hash_table (info),
bfd_alloc, because I expect that, when linking many files
together, many of the strings will be the same. Storing the
strings in the hash table should save space in this case. */
- debug_contents = (bfd_byte *) malloc (subdeb->_raw_size);
+ debug_contents = (bfd_byte *) bfd_malloc (subdeb->_raw_size);
if (debug_contents == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (! bfd_get_section_contents (sub, subdeb, (PTR) debug_contents,
(file_ptr) 0, subdeb->_raw_size))
goto error_return;
while (ldinfo->string_size + len + 3 > newalc)
newalc *= 2;
- if (ldinfo->strings == NULL)
- newstrings = (bfd_byte *) malloc (newalc);
- else
- newstrings = ((bfd_byte *)
- realloc ((PTR) ldinfo->strings, newalc));
+ newstrings = ((bfd_byte *)
+ bfd_realloc ((PTR) ldinfo->strings, newalc));
if (newstrings == NULL)
{
ldinfo->failed = true;
- bfd_set_error (bfd_error_no_memory);
return false;
}
ldinfo->string_alc = newalc;
/* We use section_count + 1, rather than section_count, because
the target_index fields are 1 based. */
- finfo.section_info = ((struct xcoff_link_section_info *)
- malloc ((abfd->section_count + 1)
- * sizeof (struct xcoff_link_section_info)));
+ finfo.section_info =
+ ((struct xcoff_link_section_info *)
+ bfd_malloc ((abfd->section_count + 1)
+ * sizeof (struct xcoff_link_section_info)));
if (finfo.section_info == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
for (i = 0; i <= abfd->section_count; i++)
{
finfo.section_info[i].relocs = NULL;
would be slow. */
finfo.section_info[o->target_index].relocs =
((struct internal_reloc *)
- malloc (o->reloc_count * sizeof (struct internal_reloc)));
+ bfd_malloc (o->reloc_count * sizeof (struct internal_reloc)));
finfo.section_info[o->target_index].rel_hashes =
((struct xcoff_link_hash_entry **)
- malloc (o->reloc_count
+ bfd_malloc (o->reloc_count
* sizeof (struct xcoff_link_hash_entry *)));
if (finfo.section_info[o->target_index].relocs == NULL
|| finfo.section_info[o->target_index].rel_hashes == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (o->reloc_count > max_output_reloc_count)
max_output_reloc_count = o->reloc_count;
/* Allocate some buffers used while linking. */
finfo.internal_syms = ((struct internal_syment *)
- malloc (max_sym_count
- * sizeof (struct internal_syment)));
- finfo.sym_indices = (long *) malloc (max_sym_count * sizeof (long));
+ bfd_malloc (max_sym_count
+ * sizeof (struct internal_syment)));
+ finfo.sym_indices = (long *) bfd_malloc (max_sym_count * sizeof (long));
finfo.outsyms = ((bfd_byte *)
- malloc ((size_t) ((max_sym_count + 1) * symesz)));
- finfo.linenos = (bfd_byte *) malloc (max_lineno_count
- * bfd_coff_linesz (abfd));
- finfo.contents = (bfd_byte *) malloc (max_contents_size);
- finfo.external_relocs = (bfd_byte *) malloc (max_reloc_count * relsz);
+ bfd_malloc ((size_t) ((max_sym_count + 1) * symesz)));
+ finfo.linenos = (bfd_byte *) bfd_malloc (max_lineno_count
+ * bfd_coff_linesz (abfd));
+ finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
+ finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz);
if ((finfo.internal_syms == NULL && max_sym_count > 0)
|| (finfo.sym_indices == NULL && max_sym_count > 0)
|| finfo.outsyms == NULL
|| (finfo.linenos == NULL && max_lineno_count > 0)
|| (finfo.contents == NULL && max_contents_size > 0)
|| (finfo.external_relocs == NULL && max_reloc_count > 0))
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
obj_raw_syment_count (abfd) = 0;
xcoff_data (abfd)->toc = (bfd_vma) -1;