From 80425e6c822142cc43999dece179009412b7f190 Mon Sep 17 00:00:00 2001 From: Jim Kingdon Date: Thu, 10 Mar 1994 02:09:10 +0000 Subject: * 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. --- bfd/reloc.c | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'bfd/reloc.c') diff --git a/bfd/reloc.c b/bfd/reloc.c index 4323d9a..1c367cc 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -1607,27 +1607,34 @@ bfd_generic_get_relocated_section_contents (abfd, link_info, link_order, data, 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; @@ -1659,21 +1666,21 @@ bfd_generic_get_relocated_section_contents (abfd, link_info, link_order, data, 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: @@ -1684,9 +1691,12 @@ bfd_generic_get_relocated_section_contents (abfd, link_info, link_order, data, } } } - - + if (reloc_vector != NULL) + free (reloc_vector); return data; - + error_return: + if (reloc_vector != NULL) + free (reloc_vector); + return NULL; } -- cgit v1.1