cruft (like the #pragma alloca for AIX).
In addition to that problem, the C alloca calls xmalloc, which
means checking for being out of memory can't work right. The
following changes remove all uses of alloca from BFD.
* hosts/solaris2.h: Remove alloca cruft.
* som.c: Replace alloca with a fixed size auto array.
* aoutx.h, elfcode.h, nlmcode.h, bout.c, coff-alpha.c, ecoff.c,
ecofflink.c, elf32-hppa.c, elf32-mips.c, linker.c, reloc.c, som.c:
Replace alloca with malloc and appropriate error checking and
freeing.
* linker.c: Replace alloca with obstack_alloc.
* libbfd.h: Rebuilt.
+Wed Mar 9 17:17:53 1994 Jim Kingdon (kingdon@lioth.cygnus.com)
+
+ * libbfd-in.h: Remove alloca cruft. It was missing some necessary
+ cruft (like the #pragma alloca for AIX).
+ In addition to that problem, the C alloca calls xmalloc, which
+ means checking for being out of memory can't work right. The
+ following changes remove all uses of alloca from BFD.
+ * hosts/solaris2.h: Remove alloca cruft.
+ * som.c: Replace alloca with a fixed size auto array.
+ * aoutx.h, elfcode.h, nlmcode.h, bout.c, coff-alpha.c, ecoff.c,
+ ecofflink.c, elf32-hppa.c, elf32-mips.c, linker.c, reloc.c, som.c:
+ Replace alloca with malloc and appropriate error checking and
+ freeing.
+ * linker.c: Replace alloca with obstack_alloc.
+ * libbfd.h: Rebuilt.
+
Tue Mar 8 12:10:38 1994 Ian Lance Taylor (ian@cygnus.com)
* coff-mips.c (mips_relocate_section): Handle MIPS_R_LITERAL like
p != (struct bfd_link_order *) NULL;
p = p->next)
{
- /* If we might be using the C based alloca function, we need
- to dump the memory allocated by aout_link_input_bfd. */
-#ifndef __GNUC__
-#ifndef alloca
- (void) alloca (0);
-#endif
-#endif
if (p->type == bfd_indirect_link_order
&& (bfd_get_flavour (p->u.indirect.section->owner)
== bfd_target_aout_flavour))
bfd *input_bfd;
{
bfd_size_type sym_count;
- int *symbol_map;
+ int *symbol_map = NULL;
BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
return false;
sym_count = obj_aout_external_sym_count (input_bfd);
- symbol_map = (int *) alloca ((size_t) sym_count * sizeof (int));
+ symbol_map = (int *) malloc ((size_t) sym_count * sizeof (int));
+ if (symbol_map == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ return false;
+ }
/* Write out the symbols and get a map of the new indices. */
if (! aout_link_write_symbols (finfo, input_bfd, symbol_map))
- return false;
+ goto error_return;
/* Relocate and write out the sections. */
if (! aout_link_input_section (finfo, input_bfd,
&finfo->dreloff,
exec_hdr (input_bfd)->a_drsize,
symbol_map))
- return false;
+ goto error_return;
/* If we are not keeping memory, we don't need the symbols any
longer. We still need them if we are keeping memory, because the
if (! finfo->info->keep_memory)
{
if (! aout_link_free_symbols (input_bfd))
- return false;
+ goto error_return;
}
+ if (symbol_map != NULL)
+ free (symbol_map);
return true;
+ error_return:
+ if (symbol_map != NULL)
+ free (symbol_map);
+ return false;
}
/* Adjust and write out the symbols for an a.out file. Set the new
char *strings;
enum bfd_link_strip strip;
enum bfd_link_discard discard;
- struct external_nlist *output_syms;
+ struct external_nlist *output_syms = NULL;
struct external_nlist *outsym;
register struct external_nlist *sym;
struct external_nlist *sym_end;
strip = finfo->info->strip;
discard = finfo->info->discard;
output_syms = ((struct external_nlist *)
- alloca ((size_t) (sym_count + 1) * EXTERNAL_NLIST_SIZE));
+ malloc ((size_t) (sym_count + 1) * EXTERNAL_NLIST_SIZE));
+ if (output_syms == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
outsym = output_syms;
/* First write out a symbol for this object file, unless we are
bfd_size_type outsym_count;
if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
- return false;
+ goto error_return;
outsym_count = outsym - output_syms;
if (bfd_write ((PTR) output_syms, (bfd_size_type) EXTERNAL_NLIST_SIZE,
(bfd_size_type) outsym_count, output_bfd)
!= outsym_count * EXTERNAL_NLIST_SIZE)
- return false;
+ goto error_return;
finfo->symoff += outsym_count * EXTERNAL_NLIST_SIZE;
}
+ if (output_syms != NULL)
+ free (output_syms);
return true;
+ error_return:
+ if (output_syms != NULL)
+ free (output_syms);
+ return false;
}
/* Write out a symbol that was not associated with an a.out input
int *symbol_map;
{
bfd_size_type input_size;
- bfd_byte *contents;
- PTR relocs;
+ bfd_byte *contents = NULL;
+ PTR relocs = NULL;
/* Get the section contents. */
input_size = bfd_section_size (input_bfd, input_section);
- contents = (bfd_byte *) alloca (input_size);
+ contents = (bfd_byte *) malloc (input_size);
+ if (contents == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
if (! bfd_get_section_contents (input_bfd, input_section, (PTR) contents,
(file_ptr) 0, input_size))
- return false;
+ goto error_return;
/* Read in the relocs. */
- relocs = (PTR) alloca (rel_size);
+ relocs = (PTR) malloc (rel_size);
+ if (relocs == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
|| bfd_read (relocs, 1, rel_size, input_bfd) != rel_size)
- return false;
+ goto error_return;
/* Relocate the section contents. */
if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
if (! aout_link_input_section_std (finfo, input_bfd, input_section,
(struct reloc_std_external *) relocs,
rel_size, contents, symbol_map))
- return false;
+ goto error_return;
}
else
{
(PTR) contents,
input_section->output_offset,
input_size))
- return false;
+ goto error_return;
/* If we are producing relocateable output, the relocs were
modified, and we now write them out. */
if (finfo->info->relocateable)
{
if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
- return false;
+ goto error_return;
if (bfd_write (relocs, (bfd_size_type) 1, rel_size, finfo->output_bfd)
!= rel_size)
- return false;
+ goto error_return;
*reloff_ptr += rel_size;
/* Assert that the relocs have not run into the symbols, and
<= obj_datasec (finfo->output_bfd)->rel_filepos)));
}
+ if (relocs != NULL)
+ free (relocs);
+ if (contents != NULL)
+ free (contents);
return true;
+ error_return:
+ if (relocs != NULL)
+ free (relocs);
+ if (contents != NULL)
+ free (contents);
+ return false;
}
/* Get the section corresponding to a reloc index. */
if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
!= EXEC_BYTES_SIZE) {
- bfd_error = wrong_format;
+ bfd_set_error (bfd_error_wrong_format);
return 0;
}
anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
if (N_BADMAG (anexec)) {
- bfd_error = wrong_format;
+ bfd_set_error (bfd_error_wrong_format);
return 0;
}
rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
if (rawptr == NULL) {
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
goto doit;
}
- bfd_error = invalid_operation;
+ bfd_set_error (bfd_error_invalid_operation);
return false;
doit:
relocs = (struct relocation_info *) malloc (reloc_size);
if (!relocs) {
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
reloc_cache = (arelent *) malloc ((count+1) * sizeof (arelent));
if (!reloc_cache) {
free ((char*)relocs);
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) {
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
free (reloc_cache);
free (relocs);
return false;
generic = section->orelocation;
native = ((struct relocation_info *) malloc (natsize));
if (!native) {
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
sec_ptr asect;
{
if (bfd_get_format (abfd) != bfd_object) {
- bfd_error = invalid_operation;
+ bfd_set_error (bfd_error_invalid_operation);
return 0;
}
if (asect == obj_bsssec (abfd))
return 0;
- bfd_error = invalid_operation;
+ bfd_set_error (bfd_error_invalid_operation);
return 0;
}
\f
if (abfd->output_has_begun == false) { /* set by bfd.c handler */
if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) /*||
(obj_textsec (abfd)->_cooked_size == 0) || (obj_datasec (abfd)->_cooked_size == 0)*/) {
- bfd_error = invalid_operation;
+ bfd_set_error (bfd_error_invalid_operation);
return false;
}
asection *input_section = i;
int shrink = 0 ;
boolean new = false;
+ arelent **reloc_vector = NULL;
bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
input_section);
if (reloc_size)
{
- arelent **reloc_vector = (arelent **)alloca(reloc_size);
+ reloc_vector = (arelent **) malloc (reloc_size);
+ if (reloc_vector == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
/* Get the relocs and think about them */
if (bfd_canonicalize_reloc(input_bfd, input_section, reloc_vector,
}
input_section->_cooked_size = input_section->_raw_size - shrink;
+ if (reloc_vector != NULL)
+ free (reloc_vector);
return new;
+ error_return:
+ if (reloc_vector != NULL)
+ free (reloc_vector);
+ return false;
}
static bfd_byte *
asection *input_section = link_order->u.indirect.section;
bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
input_section);
- arelent **reloc_vector = (arelent **)alloca(reloc_size);
+ arelent **reloc_vector = NULL;
/* If producing relocateable output, don't bother to relax. */
if (relocateable)
data, relocateable,
symbols);
+ reloc_vector = (arelent **) malloc (reloc_size);
+ if (reloc_vector == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
input_section->reloc_done = 1;
/* read in the section */
}
}
}
+ if (reloc_vector != NULL)
+ free (reloc_vector);
return data;
+ error_return:
+ if (reloc_vector != NULL)
+ free (reloc_vector);
+ return NULL;
}
/***********************************************************************/
{
const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
bfd_size_type external_hdr_size;
- PTR raw;
+ PTR raw = NULL;
HDRR *internal_symhdr;
/* See if we've already read it in. */
}
/* Read the symbolic information header. */
- raw = (PTR) alloca ((size_t) external_hdr_size);
+ raw = (PTR) malloc ((size_t) external_hdr_size);
+ if (raw == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
|| (bfd_read (raw, external_hdr_size, 1, abfd)
!= external_hdr_size))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
internal_symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
(*backend->debug_swap.swap_hdr_in) (abfd, raw, internal_symhdr);
if (internal_symhdr->magic != backend->debug_swap.sym_magic)
{
bfd_set_error (bfd_error_bad_value);
- return false;
+ goto error_return;
}
/* Now we can get the correct number of symbols. */
bfd_get_symcount (abfd) = (internal_symhdr->isymMax
+ internal_symhdr->iextMax);
+ if (raw != NULL)
+ free (raw);
return true;
+ error_return:
+ if (raw != NULL)
+ free (raw);
+ return false;
}
/* Read in and swap the important symbolic information for an ECOFF
bfd_size_type data_size;
bfd_vma data_start;
bfd_size_type bss_size;
- PTR buff;
+ PTR buff = NULL;
+ PTR reloc_buff = NULL;
struct internal_filehdr internal_f;
struct internal_aouthdr internal_a;
int i;
/* Write section headers to the file. */
- buff = (PTR) alloca (scnhsz);
+ /* Allocate buff big enough to hold a section header,
+ file header, or a.out header. */
+ {
+ bfd_size_type siz;
+ siz = scnhsz;
+ if (siz < filhsz)
+ siz = filhsz;
+ if (siz < aoutsz)
+ siz = aoutsz;
+ buff = (PTR) malloc (siz);
+ if (buff == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+ }
+
internal_f.f_nscns = 0;
if (bfd_seek (abfd, (file_ptr) (filhsz + aoutsz), SEEK_SET) != 0)
- return false;
+ goto error_return;
for (current = abfd->sections;
current != (asection *) NULL;
current = current->next)
bfd_coff_swap_scnhdr_out (abfd, (PTR) §ion, buff);
if (bfd_write (buff, 1, scnhsz, abfd) != scnhsz)
- return false;
+ goto error_return;
if ((section.s_flags & STYP_TEXT) != 0
|| ((section.s_flags & STYP_RDATA) != 0
/* Write out the file header and the optional header. */
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
- return false;
+ goto error_return;
- buff = (PTR) alloca (filhsz);
bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, buff);
if (bfd_write (buff, 1, filhsz, abfd) != filhsz)
- return false;
+ goto error_return;
- buff = (PTR) alloca (aoutsz);
bfd_coff_swap_aouthdr_out (abfd, (PTR) &internal_a, buff);
if (bfd_write (buff, 1, aoutsz, abfd) != aoutsz)
- return false;
+ goto error_return;
/* Build the external symbol information. This must be done before
writing out the relocs so that we know the symbol indices. The
? true : false),
ecoff_get_extr, ecoff_set_index)
== false)
- return false;
+ goto error_return;
/* Write out the relocs. */
for (current = abfd->sections;
if (current->reloc_count == 0)
continue;
- buff = bfd_alloc (abfd, current->reloc_count * external_reloc_size);
- if (buff == NULL)
+ reloc_buff =
+ bfd_alloc (abfd, current->reloc_count * external_reloc_size);
+ if (reloc_buff == NULL)
{
bfd_set_error (bfd_error_no_memory);
- return false;
+ goto error_return;
}
reloc_ptr_ptr = current->orelocation;
reloc_end = reloc_ptr_ptr + current->reloc_count;
- out_ptr = (char *) buff;
+ out_ptr = (char *) reloc_buff;
for (;
reloc_ptr_ptr < reloc_end;
reloc_ptr_ptr++, out_ptr += external_reloc_size)
}
if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
- return false;
- if (bfd_write (buff, external_reloc_size, current->reloc_count, abfd)
+ goto error_return;
+ if (bfd_write (reloc_buff,
+ external_reloc_size, current->reloc_count, abfd)
!= external_reloc_size * current->reloc_count)
- return false;
- bfd_release (abfd, buff);
+ goto error_return;
+ bfd_release (abfd, reloc_buff);
+ reloc_buff = NULL;
}
/* Write out the symbolic debugging information. */
if (bfd_ecoff_write_debug (abfd, debug, &backend->debug_swap,
ecoff_data (abfd)->sym_filepos)
== false)
- return false;
+ goto error_return;
}
}
if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
SEEK_SET) != 0)
- return false;
+ goto error_return;
if (bfd_read (&c, 1, 1, abfd) == 0)
c = 0;
if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
SEEK_SET) != 0)
- return false;
+ goto error_return;
if (bfd_write (&c, 1, 1, abfd) != 1)
- return false;
+ goto error_return;
}
+ if (reloc_buff != NULL)
+ bfd_release (abfd, reloc_buff);
+ if (buff != NULL)
+ free (buff);
return true;
+ error_return:
+ if (reloc_buff != NULL)
+ bfd_release (abfd, reloc_buff);
+ if (buff != NULL)
+ free (buff);
+ return false;
}
\f
/* Archive handling. ECOFF uses what appears to be a unique type of
= backend->debug_swap.swap_ext_in;
HDRR *symhdr;
bfd_size_type external_ext_size;
- PTR external_ext;
+ PTR external_ext = NULL;
size_t esize;
- char *ssext;
+ char *ssext = NULL;
char *ext_ptr;
char *ext_end;
*pneeded = false;
if (! ecoff_slurp_symbolic_header (abfd))
- return false;
+ goto error_return;
/* If there are no symbols, we don't want it. */
if (bfd_get_symcount (abfd) == 0)
- return true;
+ goto successful_return;
symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
/* 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) alloca (esize);
+ external_ext = (PTR) malloc (esize);
+ if (external_ext == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0
|| bfd_read (external_ext, 1, esize, abfd) != esize)
- return false;
+ goto error_return;
+
+ ssext = (char *) malloc (symhdr->issExtMax);
+ if (ssext == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
- ssext = (char *) alloca (symhdr->issExtMax);
if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
|| bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax)
- return false;
+ goto error_return;
/* Look through the external symbols to see if they define some
symbol that is currently undefined. */
/* Include this element. */
if (! (*info->callbacks->add_archive_element) (info, abfd, name))
- return false;
+ goto error_return;
if (! ecoff_link_add_externals (abfd, info, external_ext, ssext))
- return false;
+ goto error_return;
*pneeded = true;
- return true;
+ goto successful_return;
}
+ successful_return:
+ if (external_ext != NULL)
+ free (external_ext);
+ if (ssext != NULL)
+ free (ssext);
return true;
+ error_return:
+ if (external_ext != NULL)
+ free (external_ext);
+ if (ssext != NULL)
+ free (ssext);
+ return false;
}
/* Add symbols from an ECOFF object file to the global linker hash
{
HDRR *symhdr;
bfd_size_type external_ext_size;
- PTR external_ext;
+ PTR external_ext = NULL;
size_t esize;
- char *ssext;
+ char *ssext = NULL;
+ boolean result;
if (! ecoff_slurp_symbolic_header (abfd))
return false;
/* 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) alloca (esize);
+ external_ext = (PTR) malloc (esize);
+ if (external_ext == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0
|| bfd_read (external_ext, 1, esize, abfd) != esize)
- return false;
+ goto error_return;
+
+ ssext = (char *) malloc (symhdr->issExtMax);
+ if (ssext == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
- ssext = (char *) alloca (symhdr->issExtMax);
if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
|| bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax)
- return false;
-
- return ecoff_link_add_externals (abfd, info, external_ext, ssext);
+ goto error_return;
+
+ result = ecoff_link_add_externals (abfd, info, external_ext, ssext);
+
+ if (ssext != NULL)
+ free (ssext);
+ if (external_ext != NULL)
+ free (external_ext);
+ return result;
+
+ error_return:
+ if (ssext != NULL)
+ free (ssext);
+ if (external_ext != NULL)
+ free (external_ext);
+ return false;
}
/* Add the external symbols of an object file to the global linker
{
boolean ret;
- /* If we might be using the C based alloca function, dump memory
- allocated by ecoff_final_link_debug_accumulate. */
-#ifndef __GNUC__
-#ifndef alloca
- (void) alloca (0);
-#endif
-#endif
-
if (bfd_get_flavour (input_bfd) == bfd_target_ecoff_flavour)
{
/* Abitrarily set the symbolic header vstamp to the vstamp
p != (struct bfd_link_order *) NULL;
p = p->next)
{
- /* If we might be using the C based alloca function, we need
- to dump the memory allocated by the function
- ecoff_indirect_link_order. */
-#ifndef __GNUC__
-#ifndef alloca
- (void) alloca (0);
-#endif
-#endif
if (p->type == bfd_indirect_link_order
&& (bfd_get_flavour (p->u.indirect.section->owner)
== bfd_target_ecoff_flavour))
debug->ptr = NULL; \
else \
{ \
- debug->ptr = (type) alloca (size * symhdr->count); \
+ debug->ptr = (type) malloc (size * symhdr->count); \
+ if (debug->ptr == NULL) \
+ { \
+ bfd_set_error (bfd_error_no_memory); \
+ ret = false; \
+ goto return_something; \
+ } \
if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
!= 0) \
|| (bfd_read (debug->ptr, size, symhdr->count, \
input_bfd) != size * symhdr->count)) \
- return false; \
+ { \
+ ret = false; \
+ goto return_something; \
+ } \
}
READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
&ecoff_backend (output_bfd)->debug_swap,
input_bfd, debug, swap, info));
+ return_something:
+ if (debug->line != NULL)
+ free (debug->line);
+ if (debug->external_dnr != NULL)
+ free (debug->external_dnr);
+ if (debug->external_pdr != NULL)
+ free (debug->external_pdr);
+ if (debug->external_sym != NULL)
+ free (debug->external_sym);
+ if (debug->external_opt != NULL)
+ free (debug->external_opt);
+ if (debug->external_aux != NULL)
+ free (debug->external_aux);
+ if (debug->ss != NULL)
+ free (debug->ss);
+ if (debug->external_fdr != NULL)
+ free (debug->external_fdr);
+ if (debug->external_rfd != NULL)
+ free (debug->external_rfd);
+
/* Make sure we don't accidentally follow one of these pointers on
to the stack. */
debug->line = NULL;
asection *input_section;
bfd *input_bfd;
bfd_size_type input_size;
- bfd_byte *contents;
+ bfd_byte *contents = NULL;
bfd_size_type external_reloc_size;
bfd_size_type external_relocs_size;
- PTR external_relocs;
+ PTR external_relocs = NULL;
BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
/* Get the section contents. */
input_size = bfd_section_size (input_bfd, input_section);
- contents = (bfd_byte *) alloca (input_size);
+ contents = (bfd_byte *) malloc (input_size);
+ if (contents == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
if (! bfd_get_section_contents (input_bfd, input_section, (PTR) contents,
(file_ptr) 0, input_size))
- return false;
+ goto error_return;
/* Get the relocs. */
external_reloc_size = ecoff_backend (input_bfd)->external_reloc_size;
external_relocs_size = external_reloc_size * input_section->reloc_count;
- external_relocs = (PTR) alloca (external_relocs_size);
+ external_relocs = (PTR) malloc (external_relocs_size);
+ if (external_relocs == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ 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)
!= external_relocs_size))
- return false;
+ goto error_return;
/* Relocate the section contents. */
if (! ((*ecoff_backend (input_bfd)->relocate_section)
(output_bfd, info, input_bfd, input_section, contents,
external_relocs)))
- return false;
+ goto error_return;
/* Write out the relocated section. */
if (! bfd_set_section_contents (output_bfd,
(PTR) contents,
input_section->output_offset,
input_size))
- return false;
+ goto error_return;
/* If we are producing relocateable output, the relocs were
modified, and we write them out now. We use the reloc_count
SEEK_SET) != 0
|| (bfd_write (external_relocs, 1, external_relocs_size, output_bfd)
!= external_relocs_size))
- return false;
+ goto error_return;
output_section->reloc_count += input_section->reloc_count;
}
+ if (contents != NULL)
+ free (contents);
+ if (external_relocs != NULL)
+ free (external_relocs);
return true;
+
+ error_return:
+ if (contents != NULL)
+ free (contents);
+ if (external_relocs != NULL)
+ free (external_relocs);
+ return false;
}
/* Make space to hold the relocations for the stub section. */
reloc_size = bfd_get_reloc_upper_bound (stub_bfd, stub_sec);
- reloc_vector = (arelent **) alloca (reloc_size);
+ reloc_vector = (arelent **) malloc (reloc_size);
+ if (reloc_vector == NULL)
+ {
+ /* FIXME: should be returning an error so the caller can
+ clean up */
+ abort ();
+ }
/* If we have relocations, do them. */
if (bfd_canonicalize_reloc (stub_bfd, stub_sec, reloc_vector,
}
}
}
+ free (reloc_vector);
/* All done with the relocations. Set the final contents
of the stub section. FIXME: no check of return value! */
asymbol *new_syms = NULL;
int new_cnt = 0;
int new_max = 0;
+ arelent **reloc_vector = NULL;
/* Relocations are in different places depending on whether this is
an output section or an input section. Also, the relocations are
to straighten this out for us . */
if (asec->reloc_count > 0)
{
- arelent **reloc_vector
- = (arelent **) alloca (asec->reloc_count * (sizeof (arelent *) + 1));
+ reloc_vector
+ = (arelent **) malloc (asec->reloc_count * (sizeof (arelent *) + 1));
+ if (reloc_vector == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
/* Make sure the canonical symbols are hanging around in a convient
location. */
if (!abfd->outsymbols)
{
bfd_set_error (bfd_error_no_memory);
- abort ();
+ goto error_return;
}
abfd->symcount = bfd_canonicalize_symtab (abfd, abfd->outsymbols);
}
new_syms = (asymbol *)
realloc (new_syms, new_max * sizeof (asymbol));
if (new_syms == NULL)
- abort ();
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
}
/* Build the argument relocation stub. */
new_syms = (asymbol *)
realloc (new_syms, (new_max * sizeof (asymbol)));
if (! new_syms)
- abort ();
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
}
/* Build the long-call stub. */
}
}
+ if (reloc_vector != NULL)
+ free (reloc_vector);
/* Return the new symbols and update the counters. */
*new_sym_cnt = new_cnt;
return new_syms;
+
+ error_return:
+ if (reloc_vector != NULL)
+ free (reloc_vector);
+ /* FIXME: This is bogus. We should be returning NULL. But do the callers
+ check for that? */
+ abort ();
}
/* Set the contents of a particular section at a particular location. */
&& !strcmp ("str", asect->name + strlen (asect->name) - 3))
{
size_t len = strlen (asect->name) + 1;
- char *s = (char *) alloca (len);
+ char *s = (char *) malloc (len);
+ if (s == NULL)
+ /* FIXME: Should deal more gracefully with errors. */
+ abort ();
strcpy (s, asect->name);
s[len - 4] = 0;
asect = bfd_get_section_by_name (abfd, s);
+ free (s);
if (!asect)
abort ();
elf_section_data(asect)->this_hdr.sh_link = this_idx;
Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
Elf_Internal_Shdr *i_shdrp;
Elf_Internal_Phdr *phdr;
- char *done;
+ char *done = NULL;
unsigned int i, n_left = 0;
file_ptr lowest_offset = 0;
struct seg_info *seg = NULL;
- done = (char *) alloca (i_ehdrp->e_shnum);
+ done = (char *) malloc (i_ehdrp->e_shnum);
+ if (done == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
memset (done, 0, i_ehdrp->e_shnum);
for (i = 1; i < i_ehdrp->e_shnum; i++)
{
if (!snew)
{
bfd_set_error (bfd_error_no_memory);
- return false;
+ goto error_return;
}
s_ptr = &seg;
while (*s_ptr != (struct seg_info *) NULL)
i_ehdrp->e_phnum = n_segs;
}
elf_write_phdrs (abfd, i_ehdrp, elf_tdata (abfd)->phdr, i_ehdrp->e_phnum);
+ if (done != NULL)
+ free (done);
return true;
+ error_return:
+ if (done != NULL)
+ free (done);
+ return false;
}
static boolean
elf_symbol_type *sym; /* Pointer to current bfd symbol */
elf_symbol_type *symbase; /* Buffer for generated bfd symbols */
Elf_Internal_Sym i_sym;
- Elf_External_Sym *x_symp;
+ Elf_External_Sym *x_symp = NULL;
/* this is only valid because there is only one symtab... */
/* FIXME: This is incorrect, there may also be a dynamic symbol
/* Temporarily allocate room for the raw ELF symbols. */
x_symp = ((Elf_External_Sym *)
- alloca (symcount * sizeof (Elf_External_Sym)));
+ malloc (symcount * sizeof (Elf_External_Sym)));
+ if (x_symp == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd)
!= symcount * sizeof (Elf_External_Sym))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Skip first symbol, which is a null dummy. */
for (i = 1; i < symcount; i++)
*symptrs = 0; /* Final null pointer */
}
+ if (x_symp != NULL)
+ free (x_symp);
return true;
+ error_return:
+ if (x_symp != NULL)
+ free (x_symp);
+ return false;
}
/* Return the number of bytes required to hold the symtab vector.
#include "hosts/sysv4.h"
-#ifndef __GNUC__
-#include <alloca.h>
-#endif
-
#ifndef __GNUC__
/* get around a bug in the Sun C compiler */
#define const
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* Use builtin alloca for gcc. */
-#ifdef __GNUC__
-#ifndef alloca
-#define alloca __builtin_alloca
-#endif
-#endif
-
/* Align an address upward to a boundary, expressed as a number of bytes.
E.g. align to an 8-byte boundary with argument of 8. */
#define BFD_ALIGN(this, boundary) \
#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
-/* There is major inconsistency in how running out of memory is handled.
- Some routines return a NULL, and set bfd_error to no_memory.
- However, obstack routines can't do this ... */
-
char *bfd_zmalloc PARAMS ((bfd_size_type size));
-/* From libiberty. */
-extern PTR xmalloc PARAMS ((size_t));
-/* SIZE is bfd_size_type. */
-#define bfd_xmalloc(size) xmalloc ((size_t) size)
-/* Defined without an argument so its address can be used. */
-#define bfd_xmalloc_by_size_t xmalloc
/* These routines allocate and free things on the BFD's obstack. Note
that realloc can never occur in place. */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* Use builtin alloca for gcc. */
-#ifdef __GNUC__
-#ifndef alloca
-#define alloca __builtin_alloca
-#endif
-#endif
-
/* Align an address upward to a boundary, expressed as a number of bytes.
E.g. align to an 8-byte boundary with argument of 8. */
#define BFD_ALIGN(this, boundary) \
#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
-/* There is major inconsistency in how running out of memory is handled.
- Some routines return a NULL, and set bfd_error to no_memory.
- However, obstack routines can't do this ... */
-
char *bfd_zmalloc PARAMS ((bfd_size_type size));
-/* From libiberty. */
-extern PTR xmalloc PARAMS ((size_t));
-/* SIZE is bfd_size_type. */
-#define bfd_xmalloc(size) xmalloc ((size_t) size)
-/* Defined without an argument so its address can be used. */
-#define bfd_xmalloc_by_size_t xmalloc
/* These routines allocate and free things on the BFD's obstack. Note
that realloc can never occur in place. */
FILE *
bfd_cache_lookup_worker PARAMS ((bfd *abfd));
-void
+boolean
bfd_constructor_entry PARAMS ((bfd *abfd,
asymbol **symbol_ptr_ptr,
CONST char*type));
{
struct nlm_obj_tdata *preserved_tdata = nlm_tdata (abfd);
boolean (*backend_object_p) PARAMS ((bfd *));
- PTR x_fxdhdr;
+ PTR x_fxdhdr = NULL;
Nlm_Internal_Fixed_Header *i_fxdhdrp;
const char *signature;
enum bfd_architecture arch;
/* Read in the fixed length portion of the NLM header in external format. */
- x_fxdhdr = (PTR) alloca (nlm_fixed_header_size (abfd));
+ x_fxdhdr = (PTR) malloc (nlm_fixed_header_size (abfd));
+ if (x_fxdhdr == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto got_no_match;
+ }
if (bfd_read ((PTR) x_fxdhdr, nlm_fixed_header_size (abfd), 1, abfd) !=
nlm_fixed_header_size (abfd))
bfd_zalloc (abfd, sizeof (struct nlm_obj_tdata));
if (nlm_tdata (abfd) == NULL)
{
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
goto got_no_match;
}
if (arch != bfd_arch_unknown)
bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
+ if (x_fxdhdr != NULL)
+ free (x_fxdhdr);
return (abfd -> xvec);
got_wrong_format_error:
- bfd_error = wrong_format;
+ bfd_set_error (bfd_error_wrong_format);
got_no_match:
nlm_tdata (abfd) = preserved_tdata;
+ if (x_fxdhdr != NULL)
+ free (x_fxdhdr);
return (NULL);
}
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> descriptionLength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_read ((PTR) nlm_variable_header (abfd) -> descriptionText,
1, abfd) !=
nlm_variable_header (abfd) -> descriptionLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
nlm_variable_header (abfd) -> stackSize = get_word (abfd, (bfd_byte *) temp);
if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
nlm_variable_header (abfd) -> reserved = get_word (abfd, (bfd_byte *) temp);
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> oldThreadName))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> screenNameLength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_read ((PTR) nlm_variable_header (abfd) -> screenName,
1, abfd) !=
nlm_variable_header (abfd) -> screenNameLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> threadNameLength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_read ((PTR) nlm_variable_header (abfd) -> threadName,
1, abfd) !=
nlm_variable_header (abfd) -> threadNameLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
return (true);
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> descriptionLength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_write ((PTR) nlm_variable_header (abfd) -> descriptionText,
1, abfd) !=
nlm_variable_header (abfd) -> descriptionLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
(bfd_byte *) temp);
if (bfd_write ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
(bfd_byte *) temp);
if (bfd_write ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> oldThreadName))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> screenNameLength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_write ((PTR) nlm_variable_header (abfd) -> screenName,
1, abfd) !=
nlm_variable_header (abfd) -> screenNameLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
1, abfd) !=
sizeof (nlm_variable_header (abfd) -> threadNameLength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_write ((PTR) nlm_variable_header (abfd) -> threadName,
1, abfd) !=
nlm_variable_header (abfd) -> threadNameLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
return (true);
if (bfd_read ((PTR) tempstr, sizeof (tempstr), 1, abfd) !=
sizeof (tempstr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_seek (abfd, position, SEEK_SET) == -1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (strncmp (tempstr, "VeRsIoN#", 8) == 0)
Nlm_External_Version_Header thdr;
if (bfd_read ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
memcpy (nlm_version_header (abfd) -> stamp, thdr.stamp,
Nlm_External_Extended_Header thdr;
if (bfd_read ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
memcpy (nlm_extended_header (abfd) -> stamp, thdr.stamp,
Nlm_External_Custom_Header thdr;
if (bfd_read ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
memcpy (nlm_custom_header (abfd) -> stamp, thdr.stamp,
1, abfd)
!= sizeof (nlm_copyright_header (abfd)->stamp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_read ((PTR) &(nlm_copyright_header (abfd)
->copyrightMessageLength),
1, 1, abfd) != 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
/* The copyright message is a variable length string. */
1, abfd) !=
nlm_copyright_header (abfd) -> copyrightMessageLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
}
(bfd_byte *) thdr.day);
if (bfd_write ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
}
(bfd_byte *) thdr.reserved5);
if (bfd_write ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
}
(bfd_byte *) thdr.debugRecLength);
if (bfd_write ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
}
if (bfd_write ((PTR) thdr.stamp, sizeof (thdr.stamp), 1, abfd)
!= sizeof (thdr.stamp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
thdr.copyrightMessageLength[0] =
nlm_copyright_header (abfd)->copyrightMessageLength;
if (bfd_write ((PTR) thdr.copyrightMessageLength, 1, 1, abfd) != 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
/* The copyright message is a variable length string. */
1, abfd) !=
nlm_copyright_header (abfd) -> copyrightMessageLength + 1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
}
if (bfd_seek (abfd, i_fxdhdrp -> publicsOffset, SEEK_SET) == -1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
bfd_zalloc (abfd, totsymcount * sizeof (nlm_symbol_type)));
if (!sym)
{
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
nlm_set_symbols (abfd, sym);
if (bfd_read ((PTR) &symlength, sizeof (symlength), 1, abfd)
!= sizeof (symlength))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
sym -> symbol.the_bfd = abfd;
sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
if (!sym -> symbol.name)
{
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
if (bfd_read ((PTR) sym -> symbol.name, symlength, 1, abfd)
!= symlength)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
/* Cast away const. */
((char *) (sym -> symbol.name))[symlength] = '\0';
if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
sym -> symbol.flags = BSF_GLOBAL | BSF_EXPORT;
{
if (bfd_seek (abfd, i_fxdhdrp -> debugInfoOffset, SEEK_SET) == -1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
|| (bfd_read ((PTR) &symlength, sizeof (symlength), 1, abfd)
!= sizeof (symlength)))
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
sym -> symbol.the_bfd = abfd;
sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
if (!sym -> symbol.name)
{
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
if (bfd_read ((PTR) sym -> symbol.name, symlength, 1, abfd)
!= symlength)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
/* Cast away const. */
if (bfd_seek (abfd, i_fxdhdrp -> externalReferencesOffset, SEEK_SET)
== -1)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return (false);
}
if (bfd_seek (abfd, nlm_fixed_header (abfd)->relocationFixupOffset,
SEEK_SET) != 0)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
secs = (asection **) bfd_alloc (abfd, count * sizeof (asection *));
if (rels == NULL || secs == NULL)
{
- bfd_error = no_memory;
+ bfd_set_error (bfd_error_no_memory);
return false;
}
nlm_relocation_fixups (abfd) = rels;
if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) != 0
|| bfd_write (location, 1, count, abfd) != count)
{
- bfd_error = system_call_error;
+ bfd_set_error (bfd_error_system_call);
return false;
}
asymbol **sym_ptr_ptr;
file_ptr last;
boolean (*write_prefix_func) PARAMS ((bfd *));
- unsigned char *fixed_header = (unsigned char *) alloca (nlm_fixed_header_size (abfd));
+ unsigned char *fixed_header = NULL;
+
+ fixed_header = (unsigned char *) malloc (nlm_fixed_header_size (abfd));
+ if (fixed_header == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
if (abfd->output_has_begun == false
&& nlm_compute_section_file_positions (abfd) == false)
- return false;
+ goto error_return;
/* Write out the variable length headers. */
if (bfd_seek (abfd,
nlm_optional_prefix_size (abfd) + nlm_fixed_header_size (abfd),
SEEK_SET) != 0)
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
if (nlm_swap_variable_header_out (abfd) == false
|| nlm_swap_auxiliary_headers_out (abfd) == false)
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
/* A weak check on whether the section file positions were
reasonable. */
if (bfd_tell (abfd) > nlm_fixed_header (abfd)->codeImageOffset)
{
- bfd_error = invalid_operation;
- return false;
+ bfd_set_error (bfd_error_invalid_operation);
+ goto error_return;
}
/* Advance to the relocs. */
if (bfd_seek (abfd, nlm_fixed_header (abfd)->relocationFixupOffset,
SEEK_SET) != 0)
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
/* The format of the relocation entries is dependent upon the
/* We need to know how to write out imports */
if (write_import_func == NULL)
{
- bfd_error = invalid_operation;
- return false;
+ bfd_set_error (bfd_error_invalid_operation);
+ goto error_return;
}
rel_ptr_ptr = sec->orelocation;
{
++internal_reloc_count;
if ((*write_import_func) (abfd, sec, rel) == false)
- return false;
+ goto error_return;
}
else
++external_reloc_count;
* sizeof (struct reloc_and_sec)));
if (external_relocs == (struct reloc_and_sec *) NULL)
{
- bfd_error = no_memory;
- return false;
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
}
i = 0;
for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next)
if ((*nlm_write_external_func (abfd)) (abfd, cnt, sym,
&external_relocs[i])
== false)
- return false;
+ goto error_return;
i += cnt;
}
{
/* We can't handle an exported symbol that is not in
the code or data segment. */
- bfd_error = invalid_operation;
- return false;
+ bfd_set_error (bfd_error_invalid_operation);
+ goto error_return;
}
}
if (write_export_func)
{
if ((*write_export_func) (abfd, sym, offset) == false)
- return false;
+ goto error_return;
}
else
{
!= sizeof (bfd_byte))
|| bfd_write (sym->name, len, 1, abfd) != len)
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
put_word (abfd, offset, temp);
if (bfd_write (temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
}
}
if (bfd_write (&type, sizeof (bfd_byte), 1, abfd)
!= sizeof (bfd_byte))
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
put_word (abfd, offset, temp);
if (bfd_write (temp, sizeof (temp), 1, abfd) != sizeof (temp))
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
len = strlen (sym->name);
!= sizeof (bfd_byte))
|| bfd_write (sym->name, len, 1, abfd) != len)
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
}
nlm_fixed_header (abfd)->numberOfDebugRecords = c;
nlm_get_text_low (abfd);
if (bfd_seek (abfd, 0, SEEK_SET) != 0)
- return false;
+ goto error_return;
write_prefix_func = nlm_write_prefix_func (abfd);
if (write_prefix_func)
{
if ((*write_prefix_func) (abfd) == false)
- return false;
+ goto error_return;
}
BFD_ASSERT (bfd_tell (abfd) == nlm_optional_prefix_size (abfd));
if (bfd_write (fixed_header, nlm_fixed_header_size (abfd), 1, abfd)
!= nlm_fixed_header_size (abfd))
{
- bfd_error = system_call_error;
- return false;
+ bfd_set_error (bfd_error_system_call);
+ goto error_return;
}
+ if (fixed_header != NULL)
+ free (fixed_header);
return true;
+
+ error_return:
+ if (fixed_header != NULL)
+ free (fixed_header);
+ return false;
}
bfd *input_bfd = link_order->u.indirect.section->owner;
asection *input_section = link_order->u.indirect.section;
-
-
size_t reloc_size = bfd_get_reloc_upper_bound(input_bfd, input_section);
- arelent **reloc_vector = (arelent **) alloca(reloc_size);
+ arelent **reloc_vector = NULL;
+
+ reloc_vector = (arelent **) malloc (reloc_size);
+ if (reloc_vector == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
/* read in the section */
- bfd_get_section_contents(input_bfd,
- input_section,
- (PTR) data,
- 0,
- input_section->_raw_size);
-
-/* We're not relaxing the section, so just copy the size info */
+ if (!bfd_get_section_contents(input_bfd,
+ input_section,
+ (PTR) data,
+ 0,
+ input_section->_raw_size))
+ goto error_return;
+
+ /* We're not relaxing the section, so just copy the size info */
input_section->_cooked_size = input_section->_raw_size;
input_section->reloc_done = true;
-
- if (bfd_canonicalize_reloc(input_bfd,
- input_section,
- reloc_vector,
- symbols) )
+ if (!bfd_canonicalize_reloc (input_bfd,
+ input_section,
+ reloc_vector,
+ symbols))
+ goto error_return;
+
{
arelent **parent;
for (parent = reloc_vector; * parent != (arelent *)NULL;
if (! ((*link_info->callbacks->undefined_symbol)
(link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
input_bfd, input_section, (*parent)->address)))
- return NULL;
+ goto error_return;
break;
case bfd_reloc_dangerous:
BFD_ASSERT (error_message != (char *) NULL);
if (! ((*link_info->callbacks->reloc_dangerous)
(link_info, error_message, input_bfd, input_section,
(*parent)->address)))
- return NULL;
+ goto error_return;
break;
case bfd_reloc_overflow:
if (! ((*link_info->callbacks->reloc_overflow)
(link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
(*parent)->howto->name, (*parent)->addend,
input_bfd, input_section, (*parent)->address)))
- return NULL;
+ goto error_return;
break;
case bfd_reloc_outofrange:
default:
}
}
}
-
-
+ if (reloc_vector != NULL)
+ free (reloc_vector);
return data;
-
+ error_return:
+ if (reloc_vector != NULL)
+ free (reloc_vector);
+ return NULL;
}
/* First, read in space names */
- space_strings = alloca (file_hdr->space_strings_size);
+ space_strings = malloc (file_hdr->space_strings_size);
if (!space_strings)
- return false;
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
- return false;
+ goto error_return;
if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
!= file_hdr->space_strings_size)
- return false;
+ goto error_return;
/* Loop over all of the space dictionaries, building up sections */
for (space_index = 0; space_index < file_hdr->space_total; space_index++)
/* Read the space dictionary element */
if (bfd_seek (abfd, file_hdr->space_location
+ space_index * sizeof space, SEEK_SET) < 0)
- return false;
+ goto error_return;
if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
- return false;
+ goto error_return;
/* Setup the space name string */
space.name.n_name = space.name.n_strx + space_strings;
/* Make a section out of it */
space_asect = make_unique_section (abfd, space.name.n_name, space_index);
if (!space_asect)
- return false;
+ goto error_return;
/* Now, read in the first subspace for this space */
if (bfd_seek (abfd, file_hdr->subspace_location
+ space.subspace_index * sizeof subspace,
SEEK_SET) < 0)
- return false;
+ goto error_return;
if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
- return false;
+ goto error_return;
/* Seek back to the start of the subspaces for loop below */
if (bfd_seek (abfd, file_hdr->subspace_location
+ space.subspace_index * sizeof subspace,
SEEK_SET) < 0)
- return false;
+ goto error_return;
/* Setup the start address and file loc from the first subspace record */
space_asect->vma = subspace.subspace_start;
space_asect->filepos = subspace.file_loc_init_value;
space_asect->alignment_power = log2 (subspace.alignment);
if (space_asect->alignment_power == -1)
- return false;
+ goto error_return;
/* Initialize save_subspace so we can reliably determine if this
loop placed any useful values into it. */
/* Read in the next subspace */
if (bfd_read (&subspace, 1, sizeof subspace, abfd)
!= sizeof subspace)
- return false;
+ goto error_return;
/* Setup the subspace name string */
subspace.name.n_name = subspace.name.n_strx + space_strings;
space.subspace_index + subspace_index);
if (!subspace_asect)
- return false;
+ goto error_return;
/* Keep an easy mapping between subspaces and sections. */
som_section_data (subspace_asect)->subspace_index
subspace_asect->filepos = subspace.file_loc_init_value;
subspace_asect->alignment_power = log2 (subspace.alignment);
if (subspace_asect->alignment_power == -1)
- return false;
+ goto error_return;
}
/* Yow! there is no subspace within the space which actually
has initialized information in it; this should never happen
as far as I know. */
if (!save_subspace.file_loc_init_value)
- return false;
+ goto error_return;
/* Setup the sizes for the space section based upon the info in the
last subspace of the space. */
space_asect->_raw_size = save_subspace.file_loc_init_value
- space_asect->filepos + save_subspace.initialization_length;
}
+ if (space_strings != NULL)
+ free (space_strings);
return true;
+
+ error_return:
+ if (space_strings != NULL)
+ free (space_strings);
+ return false;
}
/* Read in a SOM object and make it into a BFD. */
unsigned int *total_reloc_sizep;
{
unsigned int i, j;
- unsigned char *tmp_space, *p;
+ /* Chunk of memory that we can use as buffer space, then throw
+ away. */
+ unsigned char tmp_space[SOM_TMP_BUFSIZE];
+ unsigned char *p;
unsigned int total_reloc_size = 0;
unsigned int subspace_reloc_size = 0;
unsigned int num_spaces = obj_som_file_hdr (abfd)->space_total;
asection *section = abfd->sections;
- /* Get a chunk of memory that we can use as buffer space, then throw
- away. */
- tmp_space = alloca (SOM_TMP_BUFSIZE);
memset (tmp_space, 0, SOM_TMP_BUFSIZE);
p = tmp_space;
unsigned long current_offset;
unsigned int *string_sizep;
{
- unsigned char *tmp_space, *p;
+ /* Chunk of memory that we can use as buffer space, then throw
+ away. */
+ unsigned char tmp_space[SOM_TMP_BUFSIZE];
+ unsigned char *p;
unsigned int strings_size = 0;
asection *section;
- /* Get a chunk of memory that we can use as buffer space, then throw
- away. */
- tmp_space = alloca (SOM_TMP_BUFSIZE);
memset (tmp_space, 0, SOM_TMP_BUFSIZE);
p = tmp_space;
hold the string length + the string itself + null terminator. */
if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
{
- if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
+ if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd)
!= p - tmp_space)
{
bfd_set_error (bfd_error_system_call);
/* Done with the space/subspace strings. Write out any information
contained in a partial block. */
- if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd) != p - tmp_space)
+ if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd) != p - tmp_space)
{
bfd_set_error (bfd_error_system_call);
return false;
unsigned int *string_sizep;
{
unsigned int i;
- unsigned char *tmp_space, *p;
+
+ /* Chunk of memory that we can use as buffer space, then throw
+ away. */
+ unsigned char tmp_space[SOM_TMP_BUFSIZE];
+ unsigned char *p;
unsigned int strings_size = 0;
- /* Get a chunk of memory that we can use as buffer space, then throw
- away. */
- tmp_space = alloca (SOM_TMP_BUFSIZE);
memset (tmp_space, 0, SOM_TMP_BUFSIZE);
p = tmp_space;
current buffer contents now. */
if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
{
- if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
+ if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd)
!= p - tmp_space)
{
bfd_set_error (bfd_error_system_call);
}
/* Scribble out any partial block. */
- if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd) != p - tmp_space)
+ if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd) != p - tmp_space)
{
bfd_set_error (bfd_error_system_call);
return false;
unsigned int num_syms = bfd_get_symcount (abfd);
file_ptr symtab_location = obj_som_file_hdr (abfd)->symbol_location;
asymbol **bfd_syms = bfd_get_outsymbols (abfd);
- struct symbol_dictionary_record *som_symtab;
+ struct symbol_dictionary_record *som_symtab = NULL;
int i, symtab_size;
/* 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 *) alloca (symtab_size);
+ som_symtab = (struct symbol_dictionary_record *) malloc (symtab_size);
+ if (som_symtab == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
memset (som_symtab, 0, symtab_size);
/* Walk over each symbol. */
if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_write ((PTR) som_symtab, symtab_size, 1, abfd) != symtab_size)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
- return true;
+
+ if (som_symtab != NULL)
+ free (som_symtab);
+ return true;
+ error_return:
+ if (som_symtab != NULL)
+ free (som_symtab);
+ return false;
}
/* Write an object in SOM format. */
int symbol_count = bfd_get_symcount (abfd);
int symsize = sizeof (struct symbol_dictionary_record);
char *stringtab;
- struct symbol_dictionary_record *buf, *bufp, *endbufp;
+ struct symbol_dictionary_record *buf = NULL, *bufp, *endbufp;
som_symbol_type *sym, *symbase;
/* Return saved value if it exists. */
if (obj_som_symtab (abfd) != NULL)
- return true;
+ goto successful_return;
/* Special case. This is *not* an error. */
if (symbol_count == 0)
- return true;
+ goto successful_return;
if (!som_slurp_string_table (abfd))
- return false;
+ goto error_return;
stringtab = obj_som_stringtab (abfd);
if (symbase == NULL)
{
bfd_set_error (bfd_error_no_memory);
- return false;
+ goto error_return;
}
/* Read in the external SOM representation. */
- buf = alloca (symbol_count * symsize);
+ buf = malloc (symbol_count * symsize);
if (buf == NULL)
{
bfd_set_error (bfd_error_no_memory);
- return false;
+ goto error_return;
}
if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_read (buf, symbol_count * symsize, 1, abfd)
!= symbol_count * symsize)
{
bfd_set_error (bfd_error_no_symbols);
- return (false);
+ goto error_return;
}
/* Iterate over all the symbols and internalize them. */
/* Save our results and return success. */
obj_som_symtab (abfd) = symbase;
+ successful_return:
+ if (buf != NULL)
+ free (buf);
return (true);
+
+ error_return:
+ if (buf != NULL)
+ free (buf);
+ return false;
}
/* Canonicalize a SOM symbol table. Return the number of entries
symindex *count;
{
unsigned int i;
- unsigned int *hash_table =
- (unsigned int *) alloca (lst_header->hash_size * sizeof (unsigned int));
+ unsigned int *hash_table = NULL
file_ptr lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
+ hash_table =
+ (unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int));
+ if (hash_table == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
/* Don't forget to initialize the counter! */
*count = 0;
!= lst_header->hash_size * 4)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Walk each chain counting the number of symbols found on that particular
if (bfd_seek (abfd, lst_filepos + hash_table[i], SEEK_SET) < 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Read in this symbol and update the counter. */
!= sizeof (lst_symbol))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
(*count)++;
< 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Read the symbol in and update the counter. */
!= sizeof (lst_symbol))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
(*count)++;
}
}
+ if (hash_table != NULL)
+ free (hash_table);
return true;
+
+ error_return:
+ if (hash_table != NULL)
+ free (hash_table);
+ return false;
}
/* Fill in the canonical archive symbols (SYMS) from the archive described
{
unsigned int i, len;
carsym *set = syms[0];
- unsigned int *hash_table =
- (unsigned int *) alloca (lst_header->hash_size * sizeof (unsigned int));
- struct som_entry *som_dict =
- (struct som_entry *) alloca (lst_header->module_count
- * sizeof (struct som_entry));
+ unsigned int *hash_table = NULL;
+ struct som_entry *som_dict = NULL;
file_ptr lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
+ hash_table =
+ (unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int));
+ if (hash_table == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
+ som_dict =
+ (struct som_entry *) malloc (lst_header->module_count
+ * sizeof (struct som_entry));
+ if (som_dict == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
/* Read in the hash table. The has table is an array of 32bit file offsets
which point to the hash chains. */
if (bfd_read ((PTR) hash_table, lst_header->hash_size, 4, abfd)
!= lst_header->hash_size * 4)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Seek to and read in the SOM dictionary. We will need this to fill
if (bfd_seek (abfd, lst_filepos + lst_header->dir_loc, SEEK_SET) < 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_read ((PTR) som_dict, lst_header->module_count,
!= lst_header->module_count * sizeof (struct som_entry))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Walk each chain filling in the carsyms as we go along. */
if (bfd_seek (abfd, lst_filepos + hash_table[i], SEEK_SET) < 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_read ((PTR) & lst_symbol, 1, sizeof (lst_symbol), abfd)
!= sizeof (lst_symbol))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Get the name of the symbol, first get the length which is stored
+ lst_symbol.name.n_strx - 4, SEEK_SET) < 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_read (&len, 1, 4, abfd) != 4)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Allocate space for the name and null terminate it too. */
if (!set->name)
{
bfd_set_error (bfd_error_no_memory);
- return false;
+ goto error_return;
}
if (bfd_read (set->name, 1, len, abfd) != len)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
set->name[len] = 0;
< 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_read ((PTR) & lst_symbol, 1, sizeof (lst_symbol), abfd)
!= sizeof (lst_symbol))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Seek to the name length & string and read them in. */
+ lst_symbol.name.n_strx - 4, SEEK_SET) < 0)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
if (bfd_read (&len, 1, 4, abfd) != 4)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Allocate space for the name and null terminate it too. */
if (!set->name)
{
bfd_set_error (bfd_error_no_memory);
- return false;
+ goto error_return;
}
if (bfd_read (set->name, 1, len, abfd) != len)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
set->name[len] = 0;
}
/* If we haven't died by now, then we successfully read the entire
archive symbol table. */
+ if (hash_table != NULL)
+ free (hash_table);
+ if (som_dict != NULL)
+ free (som_dict);
return true;
+
+ error_return:
+ if (hash_table != NULL)
+ free (hash_table);
+ if (som_dict != NULL)
+ free (som_dict);
+ return false;
}
/* Read in the LST from the archive. */
struct lst_header lst;
{
file_ptr lst_filepos;
- char *strings, *p;
- struct lst_symbol_record *lst_syms, *curr_lst_sym;
+ char *strings = NULL, *p;
+ struct lst_symbol_record *lst_syms = NULL, *curr_lst_sym;
bfd *curr_bfd = abfd->archive_head;
- unsigned int *hash_table =
- (unsigned int *) alloca (lst.hash_size * sizeof (unsigned int));
- struct som_entry *som_dict =
- (struct som_entry *) alloca (lst.module_count
+ unsigned int *hash_table = NULL;
+ struct som_entry *som_dict = NULL;
+ struct lst_symbol_record **last_hash_entry = NULL;
+ unsigned int curr_som_offset, som_index;
+
+ hash_table =
+ (unsigned int *) malloc (lst.hash_size * sizeof (unsigned int));
+ if (hash_table == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+ som_dict =
+ (struct som_entry *) malloc (lst.module_count
* sizeof (struct som_entry));
- struct lst_symbol_record **last_hash_entry =
+ if (som_dict == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
+ last_hash_entry =
((struct lst_symbol_record **)
- alloca (lst.hash_size * sizeof (struct lst_symbol_record *)));
- unsigned int curr_som_offset, som_index;
+ malloc (lst.hash_size * sizeof (struct lst_symbol_record *)));
+ if (last_hash_entry == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
/* Lots of fields are file positions relative to the start
of the lst record. So save its location. */
curr_som_offset = 8 + 2 * sizeof (struct ar_hdr) + lst.file_end;
/* FIXME should be done with buffers just like everything else... */
- lst_syms = alloca (nsyms * sizeof (struct lst_symbol_record));
- strings = alloca (string_size);
+ lst_syms = malloc (nsyms * sizeof (struct lst_symbol_record));
+ if (lst_syms == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+ strings = malloc (string_size);
+ if (strings == NULL)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ goto error_return;
+ }
+
p = strings;
curr_lst_sym = lst_syms;
to it. It's a little slimey to grab the symbols via obj_som_symtab,
but doing so avoids allocating lots of extra memory. */
if (som_slurp_symbol_table (curr_bfd) == false)
- return false;
+ goto error_return;
sym = obj_som_symtab (curr_bfd);
curr_count = bfd_get_symcount (curr_bfd);
!= lst.hash_size * 4)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* Then the SOM dictionary. */
!= lst.module_count * sizeof (struct som_entry))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* The library symbols. */
!= nsyms * sizeof (struct lst_symbol_record))
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
/* And finally the strings. */
if (bfd_write ((PTR) strings, string_size, 1, abfd) != string_size)
{
bfd_set_error (bfd_error_system_call);
- return false;
+ goto error_return;
}
+ if (hash_table != NULL)
+ free (hash_table);
+ if (som_dict != NULL)
+ free (som_dict);
+ if (last_hash_entry != NULL)
+ free (last_hash_entry);
+ if (lst_syms != NULL)
+ free (lst_syms);
+ if (strings != NULL)
+ free (strings);
return true;
+
+ error_return:
+ if (hash_table != NULL)
+ free (hash_table);
+ if (som_dict != NULL)
+ free (som_dict);
+ if (last_hash_entry != NULL)
+ free (last_hash_entry);
+ if (lst_syms != NULL)
+ free (lst_syms);
+ if (strings != NULL)
+ free (strings);
+
+ return false;
}
/* Write out the LST for the archive.