Make all callers of malloc or realloc (including via obstacks)
authorDavid MacKenzie <djm@cygnus>
Sat, 12 Feb 1994 00:45:54 +0000 (00:45 +0000)
committerDavid MacKenzie <djm@cygnus>
Sat, 12 Feb 1994 00:45:54 +0000 (00:45 +0000)
check the result for NULL.  Most set bfd_error to no_memory and
return in that case; a few are harder to fix, and are marked
with "FIXME <return type>".

* elf32-hppa.c (hppa_elf_build_arg_reloc_stub
hppa_elf_build_long_branch_stub):  Check bfd_make_empty_symbol return.
* linker.c (_bfd_generic_link_output_symbols
_bfd_generic_link_write_global_symbol): Ditto
* section.c (bfd_make_section_anyway): Ditto.

* tekhex.c (find_chunk tekhex_mkobject): Check bfd_alloc.
(first_phase): Ditto.  FIXME void
(tekhex_make_empty_symbol): Check bfd_zalloc.

* sunos.c (sunos_read_dynamic_info): Check bfd_zalloc.
(MY(read_dynamic_symbols) MY(read_dynamic_relocs)): Check bfd_alloc.

* stringhash.c (_bfd_stringtab_hash_newfunc): Check bfd_hash_allocate.

* srec.c: Indent.
(fillup_symbols): Check bfd_alloc.  FIXME void
(srec_mkobject srec_get_section_contents
srec_set_section_contents): Check bfd_alloc.
(srec_make_empty_symbol): Check bfd_zalloc.

* som.c (hppa_som_gen_reloc_type): Check bfd_alloc_by_size_t.
(make_unique_section): Check bfd_alloc.
(som_new_section_hook): Check bfd_zalloc.
(bfd_som_attach_aux_hdr): Ditto.  FIXME void

* rs6000-core.c (rs6000coff_core_p): Check bfd_zalloc.

* osf-core.c (osf_core_make_empty_symbol): Check bfd_zalloc.
(osf_core_core_file_p): Check bfd_alloc.

* oasys.c (oasys_slurp_symbol_table oasys_archive_p
oasys_mkobject oasys_object_p oasys_new_section_hook
oasys_set_section_contents): Check bfd_alloc.
(oasys_slurp_section_data): Check bfd_zalloc and bfd_alloc.
(oasys_make_empty_symbol): Check bfd_zalloc.

* nlmcode.h (nlm_make_empty_symbol): Check bfd_zalloc.
(nlm_slurp_symbol_table): Check bfd_zalloc and bfd_alloc.

* nlm32-sparc.c (nlm_sparc_read_import): Check bfd_alloc.

* nlm32-i386.c (nlm_i386_read_import): Check bfd_alloc.

* nlm32-alpha.c (nlm_alpha_read_import): Check bfd_alloc.

* linker.c (_bfd_link_hash_newfunc
(generic_link_hash_newfunc
(archive_hash_newfunc
(_bfd_generic_link_add_one_symbol): Check bfd_hash_allocate.
(_bfd_generic_final_link
(_bfd_generic_link_output_symbols
(default_indirect_link_order): Check bfd_alloc.
(bfd_new_link_order): Check bfd_alloc_by_size_t.

* irix-core.c (irix_core_make_empty_symbol): Check bfd_zalloc.

* ieee.c: Indent.
(read_id get_symbol get_section_entry ieee_archive_p ieee_object_p
ieee_slurp_section_data ieee_new_section_hook): Check bfd_alloc.
(do_one): Check bfd_alloc.  Return a boolean.
(ieee_slurp_section_data): Check it.
(init_for_output): Check bfd_alloc.  Return a boolean.
(ieee_set_section_contents): Check it.
(do_with_relocs):  Check bfd_alloc.  Return a boolean.
(ieee_bfd_debug_info_accumulate): Ditto.  FIXME void.
(ieee_mkobject): Check bfd_zalloc.
(ieee_make_empty_symbol): Check bfd_zmalloc.

* hpux-core.c (hpux_core_make_empty_symbol): Check
bfd_zalloc.

* hppabsd-core.c (hppabsd_core_make_empty_symbol): Check
bfd_zalloc.
(hppabsd_core_core_file_p): Check bfd_zalloc.

* hp300hpux.c (MY(slurp_symbol_table)): Check bfd_alloc.

* elfcode.h (elf_new_section_hook): Check bfd_alloc.
(bfd_section_from_phdr): Ditto.
(write_relocs): Ditto.  FIXME void
(elf_map_symbols assign_section_numbers map_program_segments):
Ditto.  Return a boolean.
(swap_out_syms): Ditto.  Check elf_map_symbols.
(elf_slurp_symbol_table): Check bfd_zalloc.
(elf_slurp_reloca_table): Check bfd_alloc.
(elf_slurp_reloc_table): Ditto.
(elf_compute_section_file_positions): Check assign_section_numbers.
(assign_file_positions_except_relocs): Return a boolean.
Check map_program_segments.
(elf_compute_section_file_positions): Check it.

* elf32-mips.c (mips_elf_final_link): Check bfd_alloc.

* elf32-hppa.c (hppa_elf_stub_branch_reloc): Check bfd_zmalloc and
realloc.
(hppa_elf_stub_reloc): Ditto.
(hppa_elf_build_arg_reloc_stub): Check bfd_zalloc.
(hppa_elf_build_long_branch_stub): Ditto.
(elf32_hppa_backend_symbol_table_processing): Ditto.

* ecoff.c (ecoff_set_symbol_info): Check bfd_alloc.  Return a boolean.
(ecoff_slurp_symbol_table): Check it.
(ecoff_slurp_armap): Check bfd_alloc.
(ecoff_write_armap): Check bfd_zalloc.
(ecoff_link_hash_newfunc): Check bfd_hash_allocate and
_bfd_link_hash_newfunc.
(ecoff_link_add_externals): Check bfd_alloc.

* ctor.c (bfd_constructor_entry): Check bfd_alloc.

* coffgen.c (coff_real_object_p): Check bfd_alloc.
(coff_renumber_symbols): Check bfd_alloc_by_size_t.  Return a boolean.
(coff_write_symbol): Check bfd_alloc.  FIXME int
(coff_write_linenumbers): Check bfd_alloc.  Return a boolean.
(coff_section_symbol): Check bfd_alloc_by_size_t.
(coff_get_normalized_symtab): Check bfd_alloc.
(coff_bfd_make_debug_symbol): Check bfd_zalloc.
* libcoff-in.h: Change decls of coff_renumber_symbols,
coff_write_linenumbers.
* libcoff.h: Rebuilt.
* coffcode.h (coff_write_object_contents): Check
coff_renumber_symbols, coff_write_linenumbers.

* coffcode.h: Indent.
(coff_add_missing_symbols): Check bfd_alloc_by_size_t.  Return a
boolean.
(coff_write_object_contents): Check it.

* coff-alpha.c (alpha_relocate_section): Check bfd_alloc.
* coff-mips.c (mips_relocate_section): Ditto.

* archive.c (bfd_slurp_bsd_armap_f2): Check bfd_alloc value.
(do_slurp_bsd_armap): Ditto.
(compute_and_write_armap): Check bfd_realloc value.

* aoutx.h (translate_from_native_sym_flags): Check bfd_alloc
return value.  Return boolean value.
(NAME(aout,make_empty_symbol)): Check bfd_zalloc return value.
(NAME(aout,slurp_symbol_table)): Check bf_alloc and bfd_zalloc
return value.
(add_to_stringtab): Ditto.  FIXME void
(aout_link_hash_newfunc): Check bfd_hash_allocate return value.
(aout_link_add_symbols): Check bfd_alloc value.
(translate_symbol_table): Check translate_from_native_sym_flags.
* hp300hpux.c (MY(slurp_symbol_table)): Ditto.
* aoutx.h (aout_link_hash_newfunc): Check _bfd_link_hash_newfunc.

* opncls.c (bfd_zalloc bfd_realloc): Check result of bfd_alloc.

* opncls.c (obstack_chunk_alloc): Define as malloc, not
bfd_xmalloc_by_size_t.
(_bfd_new_bfd): Check obstack_begin for 0 return.

* ieee.c (obstack_chunk_alloc): Define as malloc, not
bfd_xmalloc_by_size_t.
(ieee_archive_p): Check obstack_begin for 0 return and
obstack_finish for NULL return.

* hash.c (obstack_chunk_alloc): Define as malloc, not
bfd_xmalloc_by_size_t.
(bfd_hash_table_init_n): Check obstack_begin for 0 return and
obstack_finish for NULL return.
(bfd_hash_lookup): Check obstack_alloc for NULL return.

* ecofflink.c (obstack_chunk_alloc): Define as malloc, not
bfd_xmalloc_by_size_t.
bfd_ecoff_debug_accumulate
bfd_ecoff_debug_accumulate_other): Check obstack_alloc.
(add_file_shuffle add_memory_shuffle): Check obstack_alloc for
NULL return.  Return boolean, not void.
(bfd_ecoff_debug_init): Check obstack_begin for 0 return.
(bfd_ecoff_debug_accumulate): Check add_file_shuffle
and add_memory_shuffle return.
(string_hash_newfunc): Check bfd_hash_allocate and bfd_hash_newfunc.
(bfd_ecoff_debug_accumulate): Check bfd_alloc.
(ecoff_add_string): Check add_memory_shuffle return.

* libbfd-in.h (xmalloc, bfd_xmalloc, bfd_xmalloc_by_size_t):
Remove decls.
* libbfd.h: Rebuilt.

31 files changed:
bfd/ChangeLog
bfd/aoutx.h
bfd/archive.c
bfd/coff-alpha.c
bfd/coff-mips.c
bfd/coffcode.h
bfd/coffgen.c
bfd/ctor.c
bfd/ecoff.c
bfd/ecofflink.c
bfd/elf32-hppa.c
bfd/elf32-mips.c
bfd/elfcode.h
bfd/hash.c
bfd/hp300hpux.c
bfd/hppabsd-core.c
bfd/ieee.c
bfd/linker.c
bfd/nlm32-alpha.c
bfd/nlm32-i386.c
bfd/nlm32-sparc.c
bfd/nlmcode.h
bfd/oasys.c
bfd/opncls.c
bfd/osf-core.c
bfd/rs6000-core.c [new file with mode: 0644]
bfd/section.c
bfd/som.c
bfd/srec.c
bfd/sunos.c
bfd/tekhex.c

index 140a921d6e58bd00d73ac0544de22f72be65d8a4..00d698cc4875d6c60a281d9853bae153daf30eda 100644 (file)
@@ -1,3 +1,192 @@
+Tue Feb  8 08:57:31 1994  David J. Mackenzie  (djm@thepub.cygnus.com)
+
+       Make all callers of malloc or realloc (including via obstacks)
+       check the result for NULL.  Most set bfd_error to no_memory and
+       return in that case; a few are harder to fix, and are marked
+       with "FIXME <return type>".
+
+       * elf32-hppa.c (hppa_elf_build_arg_reloc_stub
+       hppa_elf_build_long_branch_stub):  Check bfd_make_empty_symbol return.
+       * linker.c (_bfd_generic_link_output_symbols
+       _bfd_generic_link_write_global_symbol): Ditto
+       * section.c (bfd_make_section_anyway): Ditto.
+
+       * tekhex.c (find_chunk tekhex_mkobject): Check bfd_alloc.
+       (first_phase): Ditto.  FIXME void
+       (tekhex_make_empty_symbol): Check bfd_zalloc.
+
+       * sunos.c (sunos_read_dynamic_info): Check bfd_zalloc.
+       (MY(read_dynamic_symbols) MY(read_dynamic_relocs)): Check bfd_alloc.
+
+       * stringhash.c (_bfd_stringtab_hash_newfunc): Check bfd_hash_allocate.
+
+       * srec.c: Indent.
+       (fillup_symbols): Check bfd_alloc.  FIXME void
+       (srec_mkobject srec_get_section_contents
+       srec_set_section_contents): Check bfd_alloc. 
+       (srec_make_empty_symbol): Check bfd_zalloc.
+
+       * som.c (hppa_som_gen_reloc_type): Check bfd_alloc_by_size_t.
+       (make_unique_section): Check bfd_alloc.
+       (som_new_section_hook): Check bfd_zalloc.
+       (bfd_som_attach_aux_hdr): Ditto.  FIXME void
+
+       * rs6000-core.c (rs6000coff_core_p): Check bfd_zalloc.
+
+       * osf-core.c (osf_core_make_empty_symbol): Check bfd_zalloc.
+       (osf_core_core_file_p): Check bfd_alloc.
+
+       * oasys.c (oasys_slurp_symbol_table oasys_archive_p
+       oasys_mkobject oasys_object_p oasys_new_section_hook
+       oasys_set_section_contents): Check bfd_alloc.
+       (oasys_slurp_section_data): Check bfd_zalloc and bfd_alloc.
+       (oasys_make_empty_symbol): Check bfd_zalloc.
+
+       * nlmcode.h (nlm_make_empty_symbol): Check bfd_zalloc.
+       (nlm_slurp_symbol_table): Check bfd_zalloc and bfd_alloc.
+
+       * nlm32-sparc.c (nlm_sparc_read_import): Check bfd_alloc.
+
+       * nlm32-i386.c (nlm_i386_read_import): Check bfd_alloc.
+
+       * nlm32-alpha.c (nlm_alpha_read_import): Check bfd_alloc.
+
+       * linker.c (_bfd_link_hash_newfunc
+       (generic_link_hash_newfunc
+       (archive_hash_newfunc
+       (_bfd_generic_link_add_one_symbol): Check bfd_hash_allocate.
+       (_bfd_generic_final_link
+       (_bfd_generic_link_output_symbols
+       (default_indirect_link_order): Check bfd_alloc.
+       (bfd_new_link_order): Check bfd_alloc_by_size_t.
+
+       * irix-core.c (irix_core_make_empty_symbol): Check bfd_zalloc.
+
+       * ieee.c: Indent.
+       (read_id get_symbol get_section_entry ieee_archive_p ieee_object_p
+       ieee_slurp_section_data ieee_new_section_hook): Check bfd_alloc.
+       (do_one): Check bfd_alloc.  Return a boolean.
+       (ieee_slurp_section_data): Check it.
+       (init_for_output): Check bfd_alloc.  Return a boolean.
+       (ieee_set_section_contents): Check it.
+       (do_with_relocs):  Check bfd_alloc.  Return a boolean.
+       (ieee_bfd_debug_info_accumulate): Ditto.  FIXME void.
+       (ieee_mkobject): Check bfd_zalloc.
+       (ieee_make_empty_symbol): Check bfd_zmalloc.
+
+       * hpux-core.c (hpux_core_make_empty_symbol): Check
+       bfd_zalloc.
+
+       * hppabsd-core.c (hppabsd_core_make_empty_symbol): Check
+       bfd_zalloc.
+       (hppabsd_core_core_file_p): Check bfd_zalloc.
+
+       * hp300hpux.c (MY(slurp_symbol_table)): Check bfd_alloc.
+
+       * elfcode.h (elf_new_section_hook): Check bfd_alloc.
+       (bfd_section_from_phdr): Ditto.
+       (write_relocs): Ditto.  FIXME void
+       (elf_map_symbols assign_section_numbers map_program_segments):
+       Ditto.  Return a boolean. 
+       (swap_out_syms): Ditto.  Check elf_map_symbols.
+       (elf_slurp_symbol_table): Check bfd_zalloc.
+       (elf_slurp_reloca_table): Check bfd_alloc.
+       (elf_slurp_reloc_table): Ditto.
+       (elf_compute_section_file_positions): Check assign_section_numbers.
+       (assign_file_positions_except_relocs): Return a boolean.
+       Check map_program_segments.
+       (elf_compute_section_file_positions): Check it.
+
+       * elf32-mips.c (mips_elf_final_link): Check bfd_alloc.
+
+       * elf32-hppa.c (hppa_elf_stub_branch_reloc): Check bfd_zmalloc and
+       realloc. 
+       (hppa_elf_stub_reloc): Ditto.
+       (hppa_elf_build_arg_reloc_stub): Check bfd_zalloc.
+       (hppa_elf_build_long_branch_stub): Ditto.
+       (elf32_hppa_backend_symbol_table_processing): Ditto.
+
+       * ecoff.c (ecoff_set_symbol_info): Check bfd_alloc.  Return a boolean.
+       (ecoff_slurp_symbol_table): Check it.
+       (ecoff_slurp_armap): Check bfd_alloc.
+       (ecoff_write_armap): Check bfd_zalloc.
+       (ecoff_link_hash_newfunc): Check bfd_hash_allocate and
+       _bfd_link_hash_newfunc. 
+       (ecoff_link_add_externals): Check bfd_alloc.
+
+       * ctor.c (bfd_constructor_entry): Check bfd_alloc.
+
+       * coffgen.c (coff_real_object_p): Check bfd_alloc.
+       (coff_renumber_symbols): Check bfd_alloc_by_size_t.  Return a boolean.
+       (coff_write_symbol): Check bfd_alloc.  FIXME int
+       (coff_write_linenumbers): Check bfd_alloc.  Return a boolean.
+       (coff_section_symbol): Check bfd_alloc_by_size_t.
+       (coff_get_normalized_symtab): Check bfd_alloc.
+       (coff_bfd_make_debug_symbol): Check bfd_zalloc.
+       * libcoff-in.h: Change decls of coff_renumber_symbols,
+       coff_write_linenumbers.
+       * libcoff.h: Rebuilt.
+       * coffcode.h (coff_write_object_contents): Check
+       coff_renumber_symbols, coff_write_linenumbers.
+
+       * coffcode.h: Indent.
+       (coff_add_missing_symbols): Check bfd_alloc_by_size_t.  Return a
+       boolean. 
+       (coff_write_object_contents): Check it.
+
+       * coff-alpha.c (alpha_relocate_section): Check bfd_alloc.
+       * coff-mips.c (mips_relocate_section): Ditto.
+
+       * archive.c (bfd_slurp_bsd_armap_f2): Check bfd_alloc value.
+       (do_slurp_bsd_armap): Ditto.
+       (compute_and_write_armap): Check bfd_realloc value.
+
+       * aoutx.h (translate_from_native_sym_flags): Check bfd_alloc
+       return value.  Return boolean value.
+       (NAME(aout,make_empty_symbol)): Check bfd_zalloc return value.
+       (NAME(aout,slurp_symbol_table)): Check bf_alloc and bfd_zalloc
+       return value.
+       (add_to_stringtab): Ditto.  FIXME void
+       (aout_link_hash_newfunc): Check bfd_hash_allocate return value.
+       (aout_link_add_symbols): Check bfd_alloc value.
+       (translate_symbol_table): Check translate_from_native_sym_flags.
+       * hp300hpux.c (MY(slurp_symbol_table)): Ditto.
+       * aoutx.h (aout_link_hash_newfunc): Check _bfd_link_hash_newfunc.
+
+       * opncls.c (bfd_zalloc bfd_realloc): Check result of bfd_alloc.
+
+       * opncls.c (obstack_chunk_alloc): Define as malloc, not
+       bfd_xmalloc_by_size_t. 
+       (_bfd_new_bfd): Check obstack_begin for 0 return.
+
+       * ieee.c (obstack_chunk_alloc): Define as malloc, not
+       bfd_xmalloc_by_size_t. 
+       (ieee_archive_p): Check obstack_begin for 0 return and
+       obstack_finish for NULL return.
+
+       * hash.c (obstack_chunk_alloc): Define as malloc, not
+       bfd_xmalloc_by_size_t. 
+       (bfd_hash_table_init_n): Check obstack_begin for 0 return and
+       obstack_finish for NULL return.
+       (bfd_hash_lookup): Check obstack_alloc for NULL return.
+
+       * ecofflink.c (obstack_chunk_alloc): Define as malloc, not
+       bfd_xmalloc_by_size_t. 
+       bfd_ecoff_debug_accumulate
+       bfd_ecoff_debug_accumulate_other): Check obstack_alloc.
+       (add_file_shuffle add_memory_shuffle): Check obstack_alloc for
+       NULL return.  Return boolean, not void.
+       (bfd_ecoff_debug_init): Check obstack_begin for 0 return.
+       (bfd_ecoff_debug_accumulate): Check add_file_shuffle
+       and add_memory_shuffle return. 
+       (string_hash_newfunc): Check bfd_hash_allocate and bfd_hash_newfunc.
+       (bfd_ecoff_debug_accumulate): Check bfd_alloc.
+       (ecoff_add_string): Check add_memory_shuffle return.
+
+       * libbfd-in.h (xmalloc, bfd_xmalloc, bfd_xmalloc_by_size_t):
+       Remove decls. 
+       * libbfd.h: Rebuilt.
+
 Fri Feb 11 15:35:32 1994  Stu Grossman  (grossman at cygnus.com)
 
        * configure.host:  Add Lynx/rs6000 support.
index bff9b2bb568dcfa12a8626900e517dacc382b178..d5698dc43bf89edb30374f387475c993d20c49c6 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD semi-generic back-end for a.out binaries.
-   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -452,7 +452,7 @@ DEFUN(NAME(aout,some_aout_object_p),(abfd, execp, callback_to_real_object_p),
 #ifdef THIS_IS_ONLY_DOCUMENTATION
   /* The common code can't fill in these things because they depend
      on either the start address of the text segment, the rounding
-     up of virtual addersses between segments, or the starting file
+     up of virtual addresses between segments, or the starting file
      position of the text segment -- all of which varies among different
      versions of a.out.  */
 
@@ -1083,7 +1083,7 @@ DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),
 /* Only in their own functions for ease of debugging; when sym flags have
   stabilised these should be inlined into their (single) caller */
 
-static void
+static boolean
 DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd),
        struct external_nlist *sym_pointer AND
        aout_symbol_type * cache_ptr AND
@@ -1100,8 +1100,14 @@ DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd),
        char *copy = bfd_alloc (abfd, strlen (cache_ptr->symbol.name) + 1);
        asection *section;
        asection *into_section;
-
        arelent_chain *reloc = (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
+
+       if (!copy || !reloc)
+         {
+           bfd_error = no_memory;
+           return false;
+         }
+
        strcpy (copy, cache_ptr->symbol.name);
 
        /* Make sure that this bfd has a section with the right contructor
@@ -1130,7 +1136,8 @@ DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd),
            cache_ptr->type = N_BSS;
            break;
          default:
-           abort ();
+           bfd_error = bad_value;
+           return false;
          }
 
        /* Build a relocation pointing into the constuctor section
@@ -1292,10 +1299,10 @@ DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd),
     }
   if (cache_ptr->symbol.section == 0)
     abort ();
+  return true;
 }
 
 
-
 static boolean
 DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd),
      struct external_nlist *sym_pointer AND
@@ -1384,6 +1391,11 @@ DEFUN(NAME(aout,make_empty_symbol),(abfd),
 {
   aout_symbol_type  *new =
     (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
+  if (!new)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   new->symbol.the_bfd = abfd;
 
   return &new->symbol;
@@ -1429,7 +1441,8 @@ translate_symbol_table (abfd, in, ext, count, str, strsize, dynamic)
       in->type = bfd_h_get_8 (abfd,  ext->e_type);
       in->symbol.udata = 0;
 
-      translate_from_native_sym_flags (ext, in, abfd);
+      if (!translate_from_native_sym_flags (ext, in, abfd))
+       return false;
 
       if (dynamic)
        in->symbol.flags |= BSF_DYNAMIC;
@@ -1489,7 +1502,12 @@ DEFUN(NAME(aout,slurp_symbol_table),(abfd),
                         * sizeof (aout_symbol_type))));
 
   /* Don't allocate on the obstack, so we can free it easily.  */
-  syms = (struct external_nlist *) bfd_xmalloc(symbol_size);
+  syms = (struct external_nlist *) malloc(symbol_size);
+  if (!strings || !cached || !syms)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
   if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size)
     {
@@ -1823,6 +1841,11 @@ add_to_stringtab (abfd, str, tab)
  add_it:
   entry = (struct stringtab_entry *)
     bfd_alloc_by_size_t (abfd, sizeof (struct stringtab_entry));
+  if (!entry)
+    {
+      bfd_error = no_memory;
+      abort();                 /* FIXME */
+    }
 
   entry->less = entry->greater = 0;
   entry->hash = hashval;
@@ -2806,14 +2829,19 @@ aout_link_hash_newfunc (entry, table, string)
   if (ret == (struct aout_link_hash_entry *) NULL)
     ret = ((struct aout_link_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct aout_link_hash_entry)));
+  if (ret == (struct aout_link_hash_entry *) NULL)
+    {
+      bfd_error = no_memory;
+      return (struct bfd_hash_entry *) ret;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct aout_link_hash_entry *)
         _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
                                 table, string));
-
-  /* Set local fields.  */
-  ret->indx = -1;
+  if (ret)
+    /* Set local fields.  */
+    ret->indx = -1;
 
   return (struct bfd_hash_entry *) ret;
 }
@@ -2827,7 +2855,12 @@ NAME(aout,link_hash_table_create) (abfd)
   struct aout_link_hash_table *ret;
 
   ret = ((struct aout_link_hash_table *)
-        bfd_xmalloc (sizeof (struct aout_link_hash_table)));
+        malloc (sizeof (struct aout_link_hash_table)));
+  if (ret == (struct aout_link_hash_table *) NULL)
+      {
+       bfd_error = no_memory;
+       return (struct bfd_link_hash_table *) NULL;
+      }
   if (! _bfd_link_hash_table_init (&ret->root, abfd,
                                   aout_link_hash_newfunc))
     {
@@ -2952,11 +2985,16 @@ aout_link_get_symbols (abfd)
 
   count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
 
-  /* We allocate using bfd_xmalloc to make the values easy to free
+  /* We allocate using malloc to make the values easy to free
      later on.  If we put them on the obstack it might not be possible
      to free them.  */
   syms = ((struct external_nlist *)
-         bfd_xmalloc ((size_t) count * EXTERNAL_NLIST_SIZE));
+         malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
+  if (syms == (struct external_nlist *) NULL)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
       || (bfd_read ((PTR) syms, 1, exec_hdr (abfd)->a_syms, abfd)
@@ -2969,7 +3007,12 @@ aout_link_get_symbols (abfd)
          != BYTES_IN_WORD))
     return false;
   stringsize = GET_WORD (abfd, string_chars);
-  strings = (char *) bfd_xmalloc ((size_t) stringsize);
+  strings = (char *) malloc ((size_t) stringsize);
+  if (strings == NULL)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   /* Skip space for the string count in the buffer for convenience
      when using indexes.  */
@@ -3155,6 +3198,11 @@ aout_link_add_symbols (abfd, info)
              bfd_alloc (abfd,
                         ((size_t) sym_count
                          * sizeof (struct aout_link_hash_entry *))));
+  if (!sym_hash)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   obj_aout_sym_hashes (abfd) = sym_hash;
 
   p = obj_aout_external_syms (abfd);
@@ -3857,6 +3905,14 @@ aout_link_write_other_symbol (h, data)
   if (h->root.written)
     return true;
 
+  h->root.written = true;
+
+  if (finfo->info->strip == strip_all
+      || (finfo->info->strip == strip_some
+         && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
+                             false, false) == NULL))
+    return true;
+
   output_bfd = finfo->output_bfd;
 
   switch (h->root.type)
index a155aafaedc07bbb644b19e97b92547813375e41..852124a3ea4b781ce6fe70fb33120e45b9dadeff 100644 (file)
@@ -754,6 +754,11 @@ do_slurp_bsd_armap (abfd)
   ardata->symdefs = (carsym *) bfd_alloc (abfd,
                                          (ardata->symdef_count
                                           * sizeof (carsym)));
+  if (!ardata->symdefs)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   for (counter = 0, set = ardata->symdefs;
        counter < ardata->symdef_count;
@@ -985,6 +990,11 @@ bfd_slurp_bsd_armap_f2 (abfd)
   ardata->symdefs = (carsym *) bfd_alloc (abfd,
                                          (ardata->symdef_count
                                           * BSD_SYMDEF_SIZE));
+  if (!ardata->symdefs)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   for (counter = 0, set = ardata->symdefs;
        counter < ardata->symdef_count;
index e670a8bb2b6b5c4cac48f1daf3b7bf34d18c9f1e..2d3ce215f7f0ee119e5f00f0b40f85952bed51ba 100644 (file)
@@ -1323,6 +1323,11 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
                           bfd_alloc (input_bfd,
                                      (NUM_RELOC_SECTIONS
                                       * sizeof (asection *))));
+      if (!symndx_to_section)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
 
       symndx_to_section[RELOC_SECTION_NONE] = NULL;
       symndx_to_section[RELOC_SECTION_TEXT] =
@@ -1456,12 +1461,15 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
             not currently implemented.  */
 
          /* I believe that the LITERAL reloc will only apply to a ldq
-            instruction, so check my assumption.  */
-         BFD_ASSERT (((bfd_get_32 (input_bfd,
-                                   contents + r_vaddr - input_section->vma)
-                       >> 26)
-                      & 0x3f)
-                     == 0x29);
+            or ldl instruction, so check my assumption.  */
+         {
+           unsigned long insn;
+
+           insn = bfd_get_32 (input_bfd,
+                              contents + r_vaddr - input_section->vma);
+           BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29
+                       || ((insn >> 26) & 0x3f) == 0x28);
+         }
 
          relocatep = true;
          addend = ecoff_data (input_bfd)->gp - gp;
index c4a793a275c1ecfa68ce5dff5712e8b0a3c9fa27..a9939c80eaedec1a126fcfa46a423fc275c35fe2 100644 (file)
@@ -796,6 +796,11 @@ mips_relocate_section (output_bfd, info, input_bfd, input_section,
                           bfd_alloc (input_bfd,
                                      (NUM_RELOC_SECTIONS
                                       * sizeof (asection *))));
+      if (!symndx_to_section)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
 
       symndx_to_section[RELOC_SECTION_NONE] = NULL;
       symndx_to_section[RELOC_SECTION_TEXT] =
@@ -1166,10 +1171,10 @@ static const struct ecoff_backend_data mips_ecoff_backend_data =
 {
   /* COFF backend structure.  */
   {
-    (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
+    (void (*) PARAMS ((bfd *,PTR,int,int,int,int,PTR))) bfd_void, /* aux_in */
     (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
     (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
-    (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
+    (unsigned (*) PARAMS ((bfd *,PTR,int,int,int,int,PTR)))bfd_void,/*aux_out*/
     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* reloc_out */
index 5c9b576218f3e659dd82f77a570ea42e351c2c08..8f4e25e584d99652eff0e6236718b15d7cc0d9e4 100644 (file)
@@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-/* 
+/*
 Most of this hacked by  Steve Chamberlain,
-                       sac@cygnus.com 
+                       sac@cygnus.com
 */
 /*
 
@@ -30,7 +30,7 @@ SECTION
        BFD supports a number of different flavours of coff format.
        The major differences between formats are the sizes and
        alignments of fields in structures on disk, and the occasional
-       extra field.  
+       extra field.
 
        Coff in all its varieties is implemented with a few common
        files and a number of implementation specific files. For
@@ -45,7 +45,7 @@ SECTION
        The Intel i960 processor version of coff is implemented in
        @file{coff-i960.c}. This file has the same structure as
        @file{coff-m88k.c}, except that it includes @file{coff/i960.h}
-       rather than @file{coff-m88k.h}. 
+       rather than @file{coff-m88k.h}.
 
 SUBSECTION
        Porting to a new version of coff
@@ -61,7 +61,7 @@ SUBSECTION
        structures in @file{../include/coff/foo.h} so that they match
        what you need. You will probably also have to add
        @code{#ifdef}s to the code in @file{coff/internal.h} and
-       @file{coffcode.h} if your version of coff is too wild. 
+       @file{coffcode.h} if your version of coff is too wild.
 
        You can verify that your new BFD backend works quite simply by
        building @file{objdump} from the @file{binutils} directory,
@@ -127,7 +127,7 @@ SUBSUBSECTION
        @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
        correct one. No doubt, some day someone will find a version of
        coff which has a varying field size not catered to at the
-       moment. To port BFD, that person will have to add more @code{#defines}.  
+       moment. To port BFD, that person will have to add more @code{#defines}.
        Three of the bit twiddling routines are exported to
        @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
        and @code{coff_swap_linno_in}. @code{GDB} reads the symbol
@@ -149,7 +149,7 @@ SUBSUBSECTION
        The simple canonical form for symbols used by BFD is not rich
        enough to keep all the information available in a coff symbol
        table. The back end gets around this problem by keeping the original
-       symbol table around, "behind the scenes". 
+       symbol table around, "behind the scenes".
 
        When a symbol table is requested (through a call to
        @code{bfd_canonicalize_symtab}), a request gets through to
@@ -166,7 +166,7 @@ SUBSUBSECTION
        (<<C_FILE>> symbols) are modified so that the internal
        string points to the value in the auxent (the real filename)
        rather than the normal text associated with the symbol
-       (@code{".file"}). 
+       (@code{".file"}).
 
        At this time the symbol names are moved around. Coff stores
        all symbols less than nine characters long physically
@@ -180,10 +180,10 @@ SUBSUBSECTION
        is inspected in turn, and a decision made (using the
        @code{sclass} field) about the various flags to set in the
        @code{asymbol}.  @xref{Symbols}. The generated canonical table
-       shares strings with the hidden internal symbol table. 
+       shares strings with the hidden internal symbol table.
 
        Any linenumbers are read from the coff file too, and attached
-       to the symbols which own the functions the linenumbers belong to. 
+       to the symbols which own the functions the linenumbers belong to.
 
 SUBSUBSECTION
        Symbol writing
@@ -217,7 +217,7 @@ SUBSUBSECTION
        changed at this point to reflect their sum with their owning
        section.  This transformation uses the
        <<output_section>> field of the @code{asymbol}'s
-       @code{asection} @xref{Sections}. 
+       @code{asection} @xref{Sections}.
 
        o <<coff_mangle_symbols>>
 
@@ -231,7 +231,7 @@ SUBSUBSECTION
 
        This routine runs through the symbol table and patches up the
        symbols from their internal form into the coff way, calls the
-       bit twiddlers, and writes out the table to the file. 
+       bit twiddlers, and writes out the table to the file.
 
 */
 
@@ -245,20 +245,28 @@ DESCRIPTION
 
 CODE_FRAGMENT
 .
-.typedef struct coff_ptr_struct 
+.typedef struct coff_ptr_struct
 .{
 .
 .       {* Remembers the offset from the first symbol in the file for
 .          this symbol. Generated by coff_renumber_symbols. *}
 .unsigned int offset;
 .
+.       {* Should the value of this symbol be renumbered.  Used for
+.          XCOFF C_BSTAT symbols.  Set by coff_slurp_symbol_table.  *}
+.unsigned int fix_value : 1;
+.
 .       {* Should the tag field of this symbol be renumbered.
 .          Created by coff_pointerize_aux. *}
-.char fix_tag;
+.unsigned int fix_tag : 1;
 .
 .       {* Should the endidx field of this symbol be renumbered.
 .          Created by coff_pointerize_aux. *}
-.char fix_end;
+.unsigned int fix_end : 1;
+.
+.       {* Should the x_csect.x_scnlen field be renumbered.
+.          Created by coff_slurp_symbol_table. *}
+.unsigned int fix_scnlen : 1;
 .
 .       {* The container for the symbol structure as read and translated
 .           from the file. *}
@@ -307,35 +315,35 @@ sec_to_styp_flags (sec_name, sec_flags)
 {
   long styp_flags = 0;
 
-  if (!strcmp(sec_name, _TEXT)) 
+  if (!strcmp (sec_name, _TEXT))
     {
       styp_flags = STYP_TEXT;
     }
-  else if (!strcmp(sec_name, _DATA)) 
+  else if (!strcmp (sec_name, _DATA))
     {
       styp_flags = STYP_DATA;
 #ifdef TWO_DATA_SECS
     }
-  else if (!strcmp(sec_name, ".data2")) 
+  else if (!strcmp (sec_name, ".data2"))
     {
       styp_flags = STYP_DATA;
-#endif                         /* TWO_DATA_SECS */
+#endif /* TWO_DATA_SECS */
     }
-  else if (!strcmp(sec_name, _BSS)) 
+  else if (!strcmp (sec_name, _BSS))
     {
       styp_flags = STYP_BSS;
 #ifdef _COMMENT
-    } 
-  else if (!strcmp(sec_name, _COMMENT)) 
+    }
+  else if (!strcmp (sec_name, _COMMENT))
     {
       styp_flags = STYP_INFO;
-#endif                         /* _COMMENT */
+#endif /* _COMMENT */
 #ifdef _LIB
     }
-  else if (!strcmp(sec_name, _LIB)) 
+  else if (!strcmp (sec_name, _LIB))
     {
       styp_flags = STYP_LIB;
-#endif                         /* _LIB */
+#endif /* _LIB */
 #ifdef _LIT
     }
   else if (!strcmp (sec_name, _LIT))
@@ -343,21 +351,25 @@ sec_to_styp_flags (sec_name, sec_flags)
       styp_flags = STYP_LIT;
 #endif /* _LIT */
     }
-  else if (!strcmp(sec_name, ".debug"))
+  else if (!strcmp (sec_name, ".debug"))
     {
+#ifdef STYP_DEBUG
+      styp_flags = STYP_DEBUG;
+#else
       styp_flags = STYP_INFO;
+#endif
     }
-  else if (!strcmp(sec_name, ".stab")
-          || !strncmp(sec_name, ".stabstr", 8))
+  else if (!strcmp (sec_name, ".stab")
+          || !strncmp (sec_name, ".stabstr", 8))
     {
       styp_flags = STYP_INFO;
     }
   /* Try and figure out what it should be */
-  else if (sec_flags & SEC_CODE) 
+  else if (sec_flags & SEC_CODE)
     {
       styp_flags = STYP_TEXT;
     }
-  else  if (sec_flags & SEC_DATA) 
+  else if (sec_flags & SEC_DATA)
     {
       styp_flags = STYP_DATA;
     }
@@ -367,7 +379,7 @@ sec_to_styp_flags (sec_name, sec_flags)
       styp_flags = STYP_LIT;
 #else
       styp_flags = STYP_TEXT;
-#endif                         /* STYP_LIT */
+#endif /* STYP_LIT */
     }
   else if (sec_flags & SEC_LOAD)
     {
@@ -380,10 +392,10 @@ sec_to_styp_flags (sec_name, sec_flags)
 
 #ifdef STYP_NOLOAD
   if (sec_flags & SEC_NEVER_LOAD)
-   styp_flags |= STYP_NOLOAD;
+    styp_flags |= STYP_NOLOAD;
 #endif
 
-  return(styp_flags);
+  return (styp_flags);
 }
 /*
  * Return a word with SEC_* flags set to represent the incoming
@@ -393,47 +405,47 @@ sec_to_styp_flags (sec_name, sec_flags)
  *      in sec_to_styp_flags().
  */
 static flagword
-DEFUN(styp_to_sec_flags, (abfd, hdr),
-      bfd *abfd AND
-      PTR hdr)
+DEFUN (styp_to_sec_flags, (abfd, hdr),
+       bfd * abfd AND
+       PTR hdr)
 {
   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
   long styp_flags = internal_s->s_flags;
-  flagword     sec_flags=0;
+  flagword sec_flags = 0;
 
 #ifdef STYP_NOLOAD
   if (styp_flags & STYP_NOLOAD)
-  {
-    sec_flags |= SEC_NEVER_LOAD;
-  }
+    {
+      sec_flags |= SEC_NEVER_LOAD;
+    }
 #endif /* STYP_NOLOAD */
 
   /* For 386 COFF, at least, an unloadable text or data section is
      actually a shared library section.  */
   if (styp_flags & STYP_TEXT)
-  {
-    if (sec_flags & SEC_NEVER_LOAD)
-      sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
-    else
-      sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
-  }
+    {
+      if (sec_flags & SEC_NEVER_LOAD)
+       sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
+      else
+       sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
+    }
   else if (styp_flags & STYP_DATA)
-  {
-    if (sec_flags & SEC_NEVER_LOAD)
-      sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
-    else
-      sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
-  }
-  else if (styp_flags & STYP_BSS) 
-  {
+    {
+      if (sec_flags & SEC_NEVER_LOAD)
+       sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
+      else
+       sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
+    }
+  else if (styp_flags & STYP_BSS)
+    {
 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
-    if (sec_flags & SEC_NEVER_LOAD)
-      sec_flags |= SEC_ALLOC | SEC_SHARED_LIBRARY;
-    else
+      if (sec_flags & SEC_NEVER_LOAD)
+       sec_flags |= SEC_ALLOC | SEC_SHARED_LIBRARY;
+      else
 #endif
-      sec_flags |= SEC_ALLOC;
-  }
-  else if (styp_flags & STYP_INFO) 
+       sec_flags |= SEC_ALLOC;
+    }
+  else if (styp_flags & STYP_INFO)
     {
       /* This should be marked as SEC_DEBUGGING, but that can't be
         done until we make sure that strip can still work.  strip
@@ -442,24 +454,24 @@ DEFUN(styp_to_sec_flags, (abfd, hdr),
         position.  */
     }
   else
-  {
-    sec_flags |= SEC_ALLOC | SEC_LOAD;
-  }
+    {
+      sec_flags |= SEC_ALLOC | SEC_LOAD;
+    }
 
 #ifdef STYP_LIT                        /* A29k readonly text/data section type */
   if ((styp_flags & STYP_LIT) == STYP_LIT)
-  {
-    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
-  }
-#endif                         /* STYP_LIT */
+    {
+      sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
+    }
+#endif /* STYP_LIT */
 #ifdef STYP_OTHER_LOAD         /* Other loaded sections */
   if (styp_flags & STYP_OTHER_LOAD)
-  {
-    sec_flags = (SEC_LOAD | SEC_ALLOC);
-  }
-#endif                         /* STYP_SDATA */
+    {
+      sec_flags = (SEC_LOAD | SEC_ALLOC);
+    }
+#endif /* STYP_SDATA */
 
-  return(sec_flags);
+  return (sec_flags);
 }
 
 #define        get_index(symbol)       ((long) (symbol)->udata)
@@ -471,7 +483,7 @@ INTERNAL_DEFINITION
 CODE_FRAGMENT
 
 Special entry points for gdb to swap in coff symbol table parts:
-.typedef struct 
+.typedef struct
 .{
 .  void (*_bfd_coff_swap_aux_in) PARAMS ((
 .       bfd            *abfd,
@@ -677,15 +689,15 @@ dependent COFF routines:
 .#define bfd_coff_reloc16_estimate(abfd, section, symbols, reloc, shrink, link_info)\
 .        ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
 .         (section, symbols, reloc, shrink, link_info))
-. 
+.
 */
 
 /* See whether the magic number matches.  */
 
 static boolean
-DEFUN(coff_bad_format_hook, (abfd, filehdr),
-      bfd *abfd AND
-      PTR filehdr)
+DEFUN (coff_bad_format_hook, (abfd, filehdr),
+       bfd * abfd AND
+       PTR filehdr)
 {
   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
 
@@ -711,7 +723,7 @@ DEFUN(coff_bad_format_hook, (abfd, filehdr),
 
 static asection *
 DEFUN (coff_make_section_hook, (abfd, name),
-       bfd *abfd AND
+       bfd * abfd AND
        char *name)
 {
 #ifdef TWO_DATA_SECS
@@ -731,9 +743,9 @@ DEFUN (coff_make_section_hook, (abfd, name),
 */
 
 static boolean
-DEFUN(coff_new_section_hook,(abfd, section),
-      bfd            *abfd AND
-      asection       *section)
+DEFUN (coff_new_section_hook, (abfd, section),
+       bfd * abfd AND
+       asection * section)
 {
   section->alignment_power = abfd->xvec->align_power_min;
   /* Allocate aux records for section symbols, to store size and
@@ -753,8 +765,8 @@ DEFUN(coff_new_section_hook,(abfd, section),
 
 static void
 DEFUN (coff_set_alignment_hook, (abfd, section, scnhdr),
-       bfd *abfd AND
-       asection *section AND
+       bfd * abfd AND
+       asection * section AND
        PTR scnhdr)
 {
   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
@@ -773,17 +785,18 @@ DEFUN (coff_set_alignment_hook, (abfd, section, scnhdr),
 
 #endif /* ! I960 */
 
-static          boolean
-DEFUN(coff_mkobject,(abfd),
-      bfd            *abfd)
+static boolean
+DEFUN (coff_mkobject, (abfd),
+       bfd * abfd)
 {
   coff_data_type *coff;
 
-  abfd->tdata.coff_obj_data = (struct coff_tdata *)bfd_zalloc (abfd,sizeof(coff_data_type));
-  if (abfd->tdata.coff_obj_data == 0){
-    bfd_error = no_memory;
-    return false;
-  }
+  abfd->tdata.coff_obj_data = (struct coff_tdata *) bfd_zalloc (abfd, sizeof (coff_data_type));
+  if (abfd->tdata.coff_obj_data == 0)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   coff = coff_data (abfd);
   coff->symbols = (coff_symbol_type *) NULL;
   coff->conversion_table = (unsigned int *) NULL;
@@ -796,11 +809,11 @@ DEFUN(coff_mkobject,(abfd),
 
 /* Create the COFF backend specific information.  */
 
-static          PTR
-DEFUN(coff_mkobject_hook,(abfd, filehdr, aouthdr),
-      bfd            *abfd AND
-      PTR           filehdr AND
-      PTR           aouthdr)
+static PTR
+DEFUN (coff_mkobject_hook, (abfd, filehdr, aouthdr),
+       bfd * abfd AND
+       PTR filehdr AND
+       PTR aouthdr)
 {
   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
   coff_data_type *coff;
@@ -818,11 +831,11 @@ DEFUN(coff_mkobject_hook,(abfd, filehdr, aouthdr),
      unfortunately vary among coff implementations...  */
   coff->local_n_btmask = N_BTMASK;
   coff->local_n_btshft = N_BTSHFT;
-  coff->local_n_tmask  = N_TMASK;
+  coff->local_n_tmask = N_TMASK;
   coff->local_n_tshift = N_TSHIFT;
-  coff->local_symesz   = SYMESZ;
-  coff->local_auxesz   = AUXESZ;
-  coff->local_linesz   = LINESZ;
+  coff->local_symesz = SYMESZ;
+  coff->local_auxesz = AUXESZ;
+  coff->local_linesz = LINESZ;
 
   return (PTR) coff;
 }
@@ -835,7 +848,7 @@ DEFUN(coff_mkobject_hook,(abfd, filehdr, aouthdr),
    at linking together COFF files for different architectures.  */
 
 static boolean
-coff_set_arch_mach_hook(abfd, filehdr)
+coff_set_arch_mach_hook (abfd, filehdr)
      bfd *abfd;
      PTR filehdr;
 {
@@ -844,71 +857,72 @@ coff_set_arch_mach_hook(abfd, filehdr)
   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
 
   machine = 0;
-  switch (internal_f->f_magic) {
+  switch (internal_f->f_magic)
+    {
 #ifdef I386MAGIC
-  case I386MAGIC:
-  case I386PTXMAGIC:
-  case I386AIXMAGIC:           /* Danbury PS/2 AIX C Compiler */
-  case LYNXCOFFMAGIC:          /* shadows the m68k Lynx number below, sigh */
-    arch = bfd_arch_i386;
-    machine = 0;
-    break;
+    case I386MAGIC:
+    case I386PTXMAGIC:
+    case I386AIXMAGIC:         /* Danbury PS/2 AIX C Compiler */
+    case LYNXCOFFMAGIC:        /* shadows the m68k Lynx number below, sigh */
+      arch = bfd_arch_i386;
+      machine = 0;
+      break;
 #endif
 
 #ifdef A29K_MAGIC_BIG
-  case  A29K_MAGIC_BIG:
-  case  A29K_MAGIC_LITTLE:
-    arch = bfd_arch_a29k;
-    machine = 0;
-    break;
+    case A29K_MAGIC_BIG:
+    case A29K_MAGIC_LITTLE:
+      arch = bfd_arch_a29k;
+      machine = 0;
+      break;
 #endif
 
 #ifdef MC68MAGIC
-  case MC68MAGIC:
-  case M68MAGIC:
+    case MC68MAGIC:
+    case M68MAGIC:
 #ifdef MC68KBCSMAGIC
-  case MC68KBCSMAGIC:
+    case MC68KBCSMAGIC:
 #endif
 #ifdef APOLLOM68KMAGIC
-  case APOLLOM68KMAGIC:
+    case APOLLOM68KMAGIC:
 #endif
 #ifdef LYNXCOFFMAGIC
-  case LYNXCOFFMAGIC:
+    case LYNXCOFFMAGIC:
 #endif
-    arch = bfd_arch_m68k;
-    machine = 68020;
-    break;
+      arch = bfd_arch_m68k;
+      machine = 68020;
+      break;
 #endif
 #ifdef MC88MAGIC
-  case MC88MAGIC:
-  case MC88DMAGIC:
-  case MC88OMAGIC:
-    arch = bfd_arch_m88k;
-    machine = 88100;
-    break;
+    case MC88MAGIC:
+    case MC88DMAGIC:
+    case MC88OMAGIC:
+      arch = bfd_arch_m88k;
+      machine = 88100;
+      break;
 #endif
 #ifdef Z8KMAGIC
-   case Z8KMAGIC:
-    arch = bfd_arch_z8k;
-    switch (internal_f->f_flags & F_MACHMASK) 
-      {
-      case F_Z8001:
-       machine = bfd_mach_z8001;
-       break;
-      case F_Z8002:
-       machine = bfd_mach_z8002;
-       break;
-      default:
-       return false;
-      }
-    break;
+    case Z8KMAGIC:
+      arch = bfd_arch_z8k;
+      switch (internal_f->f_flags & F_MACHMASK)
+       {
+       case F_Z8001:
+         machine = bfd_mach_z8001;
+         break;
+       case F_Z8002:
+         machine = bfd_mach_z8002;
+         break;
+       default:
+         return false;
+       }
+      break;
 #endif
 #ifdef I960
 #ifdef I960ROMAGIC
-  case I960ROMAGIC:
-  case I960RWMAGIC:
-    arch = bfd_arch_i960;
-    switch (F_I960TYPE & internal_f->f_flags)
+    case I960ROMAGIC:
+    case I960RWMAGIC:
+      arch = bfd_arch_i960;
+      switch (F_I960TYPE & internal_f->f_flags)
        {
        default:
        case F_I960CORE:
@@ -917,7 +931,7 @@ coff_set_arch_mach_hook(abfd, filehdr)
        case F_I960KB:
          machine = bfd_mach_i960_kb_sb;
          break;
-       case  F_I960MC:
+       case F_I960MC:
          machine = bfd_mach_i960_mc;
          break;
        case F_I960XA:
@@ -930,71 +944,71 @@ coff_set_arch_mach_hook(abfd, filehdr)
          machine = bfd_mach_i960_ka_sa;
          break;
        }
-    break;
+      break;
 #endif
 #endif
 
 #ifdef U802ROMAGIC
-  case U802ROMAGIC:
-  case U802WRMAGIC:
-  case U802TOCMAGIC:
-    arch = bfd_arch_rs6000;
-    machine = 6000;
-    break;
+    case U802ROMAGIC:
+    case U802WRMAGIC:
+    case U802TOCMAGIC:
+      arch = bfd_arch_rs6000;
+      machine = 6000;
+      break;
 #endif
 
 #ifdef WE32KMAGIC
-  case WE32KMAGIC:
-    arch = bfd_arch_we32k;
-    machine = 0;
-    break;
+    case WE32KMAGIC:
+      arch = bfd_arch_we32k;
+      machine = 0;
+      break;
 #endif
 
 #ifdef H8300MAGIC
-  case H8300MAGIC:
-    arch = bfd_arch_h8300;
-    machine = bfd_mach_h8300;
-    /* !! FIXME this probably isn't the right place for this */
-    abfd->flags |= BFD_IS_RELAXABLE;
-    break;
+    case H8300MAGIC:
+      arch = bfd_arch_h8300;
+      machine = bfd_mach_h8300;
+      /* !! FIXME this probably isn't the right place for this */
+      abfd->flags |= BFD_IS_RELAXABLE;
+      break;
 #endif
 
 #ifdef H8300HMAGIC
-  case H8300HMAGIC:
-    arch = bfd_arch_h8300;
-    machine = bfd_mach_h8300h;
-    /* !! FIXME this probably isn't the right place for this */
-    abfd->flags |= BFD_IS_RELAXABLE;
-    break;
+    case H8300HMAGIC:
+      arch = bfd_arch_h8300;
+      machine = bfd_mach_h8300h;
+      /* !! FIXME this probably isn't the right place for this */
+      abfd->flags |= BFD_IS_RELAXABLE;
+      break;
 #endif
 
 #ifdef SHMAGIC
-  case SHMAGIC:
-    arch = bfd_arch_sh;
-    machine = 0;
-    break;
+    case SHMAGIC:
+      arch = bfd_arch_sh;
+      machine = 0;
+      break;
 #endif
 
 #ifdef H8500MAGIC
-  case H8500MAGIC:
-    arch = bfd_arch_h8500;
-    machine = 0;
-    break;
+    case H8500MAGIC:
+      arch = bfd_arch_h8500;
+      machine = 0;
+      break;
 #endif
 
 #ifdef SPARCMAGIC
-  case SPARCMAGIC:
-    arch = bfd_arch_sparc;
-    machine = 0;
-    break;
+    case SPARCMAGIC:
+      arch = bfd_arch_sparc;
+      machine = 0;
+      break;
 #endif
 
-  default:                     /* Unreadable input file type */
-    arch = bfd_arch_obscure;
-break;
-  }
+    default:                   /* Unreadable input file type */
+      arch = bfd_arch_obscure;
+      break;
+    }
 
-  bfd_default_set_arch_mach(abfd, arch, machine);
+  bfd_default_set_arch_mach (abfd, arch, machine);
   return true;
 }
 
@@ -1002,7 +1016,7 @@ break;
 
 static boolean
 DEFUN (symname_in_debug_hook, (abfd, sym),
-       bfd *abfd AND
+       bfd * abfd AND
        struct internal_syment *sym)
 {
   return SYMNAME_IN_DEBUG (sym) ? true : false;
@@ -1027,155 +1041,159 @@ SUBSUBSECTION
        address and the relocation offset; the type is dug directly
        from the howto field.  Then the @code{internal_reloc} is
        swapped into the shape of an @code{external_reloc} and written
-       out to disk. 
+       out to disk.
 
 */
 
 static void
-DEFUN(coff_write_relocs,(abfd),
-      bfd            *abfd)
+DEFUN (coff_write_relocs, (abfd),
+       bfd * abfd)
 {
-  asection       *s;
-  for (s = abfd->sections; s != (asection *) NULL; s = s->next) {
-    unsigned int i;
-    struct external_reloc dst;
-
-    arelent **p = s->orelocation;
-    bfd_seek(abfd, s->rel_filepos, SEEK_SET);
-    for (i = 0; i < s->reloc_count; i++) {
-      struct internal_reloc    n;
-      arelent        *q = p[i];
-      memset((PTR)&n, 0, sizeof(n));
-
-      n.r_vaddr = q->address + s->vma;
-
-#ifdef R_IHCONST                       
-      /* The 29k const/consth reloc pair is a real kludge.  The consth
+  asection *s;
+  for (s = abfd->sections; s != (asection *) NULL; s = s->next)
+    {
+      unsigned int i;
+      struct external_reloc dst;
+
+      arelent **p = s->orelocation;
+      bfd_seek (abfd, s->rel_filepos, SEEK_SET);
+      for (i = 0; i < s->reloc_count; i++)
+       {
+         struct internal_reloc n;
+         arelent *q = p[i];
+         memset ((PTR) & n, 0, sizeof (n));
+
+         n.r_vaddr = q->address + s->vma;
+
+#ifdef R_IHCONST
+         /* The 29k const/consth reloc pair is a real kludge.  The consth
         part doesn't have a symbol; it has an offset.  So rebuilt
         that here.  */
-      if (q->howto->type == R_IHCONST)
-       n.r_symndx = q->addend;
-      else
+         if (q->howto->type == R_IHCONST)
+           n.r_symndx = q->addend;
+         else
 #endif
-       if (q->sym_ptr_ptr) 
-         {
-           if (q->sym_ptr_ptr == bfd_abs_section.symbol_ptr_ptr) 
-             /* This is a relocation relative to the absolute symbol.  */
-             n.r_symndx = -1;
-           else
-             {
-               n.r_symndx = get_index((*(q->sym_ptr_ptr)));
-               /* Take notice if the symbol reloc points to a symbol
+         if (q->sym_ptr_ptr)
+           {
+             if (q->sym_ptr_ptr == bfd_abs_section.symbol_ptr_ptr)
+               /* This is a relocation relative to the absolute symbol.  */
+               n.r_symndx = -1;
+             else
+               {
+                 n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
+                 /* Take notice if the symbol reloc points to a symbol
                   we don't have in our symbol table.  What should we
                   do for this??  */
-               if (n.r_symndx > obj_conv_table_size (abfd))
-                 abort ();
-             }
-         }
+                 if (n.r_symndx > obj_conv_table_size (abfd))
+                   abort ();
+               }
+           }
 
 #ifdef SWAP_OUT_RELOC_OFFSET
-      n.r_offset = q->addend;
+         n.r_offset = q->addend;
 #endif
 
 #ifdef SELECT_RELOC
-      /* Work out reloc type from what is required */
-      SELECT_RELOC(n, q->howto);
+         /* Work out reloc type from what is required */
+         SELECT_RELOC (n, q->howto);
 #else
-      n.r_type = q->howto->type;
+         n.r_type = q->howto->type;
 #endif
-      coff_swap_reloc_out(abfd, &n, &dst);
-      bfd_write((PTR) &dst, 1, RELSZ, abfd);
+         coff_swap_reloc_out (abfd, &n, &dst);
+         bfd_write ((PTR) & dst, 1, RELSZ, abfd);
+       }
     }
-  }
 }
 
 /* Set flags and magic number of a coff file from architecture and machine
    type.  Result is true if we can represent the arch&type, false if not.  */
 
-static          boolean
-DEFUN(coff_set_flags,(abfd, magicp, flagsp),
-      bfd            *abfd AND
-      unsigned       *magicp AND
-      unsigned short *flagsp)
+static boolean
+DEFUN (coff_set_flags, (abfd, magicp, flagsp),
+       bfd * abfd AND
+       unsigned *magicp AND
+       unsigned short *flagsp)
 {
-  switch (bfd_get_arch(abfd)) {
-#ifdef Z8KMAGIC
-   case bfd_arch_z8k:
-    *magicp = Z8KMAGIC;
-    switch (bfd_get_mach(abfd)) 
+  switch (bfd_get_arch (abfd))
     {
-     case bfd_mach_z8001:
-      *flagsp = F_Z8001;
-      break;
-     case bfd_mach_z8002:
-      *flagsp = F_Z8002;
-      break;
-     default:
-      return false;
-    }
-    return true;
+#ifdef Z8KMAGIC
+    case bfd_arch_z8k:
+      *magicp = Z8KMAGIC;
+      switch (bfd_get_mach (abfd))
+       {
+       case bfd_mach_z8001:
+         *flagsp = F_Z8001;
+         break;
+       case bfd_mach_z8002:
+         *flagsp = F_Z8002;
+         break;
+       default:
+         return false;
+       }
+      return true;
 #endif
 #ifdef I960ROMAGIC
 
     case bfd_arch_i960:
 
       {
-       unsigned        flags;
+       unsigned flags;
        *magicp = I960ROMAGIC;
        /*
          ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC :
          I960RWMAGIC);   FIXME???
          */
-       switch (bfd_get_mach(abfd)) {
-       case bfd_mach_i960_core:
-         flags = F_I960CORE;
-         break;
-       case bfd_mach_i960_kb_sb:
-         flags = F_I960KB;
-         break;
-       case bfd_mach_i960_mc:
-         flags = F_I960MC;
-         break;
-       case bfd_mach_i960_xa:
-         flags = F_I960XA;
-         break;
-       case bfd_mach_i960_ca:
-         flags = F_I960CA;
-         break;
-       case bfd_mach_i960_ka_sa:
-         flags = F_I960KA;
-         break;
-       default:
-         return false;
-       }
+       switch (bfd_get_mach (abfd))
+         {
+         case bfd_mach_i960_core:
+           flags = F_I960CORE;
+           break;
+         case bfd_mach_i960_kb_sb:
+           flags = F_I960KB;
+           break;
+         case bfd_mach_i960_mc:
+           flags = F_I960MC;
+           break;
+         case bfd_mach_i960_xa:
+           flags = F_I960XA;
+           break;
+         case bfd_mach_i960_ca:
+           flags = F_I960CA;
+           break;
+         case bfd_mach_i960_ka_sa:
+           flags = F_I960KA;
+           break;
+         default:
+           return false;
+         }
        *flagsp = flags;
        return true;
       }
-    break;
+      break;
 #endif
 #ifdef I386MAGIC
-  case bfd_arch_i386:
-    *magicp = I386MAGIC;
+    case bfd_arch_i386:
+      *magicp = I386MAGIC;
 #ifdef LYNXOS
-    /* Just overwrite the usual value if we're doing Lynx. */
-    *magicp = LYNXCOFFMAGIC;
+      /* Just overwrite the usual value if we're doing Lynx. */
+      *magicp = LYNXCOFFMAGIC;
 #endif
-    return true;
-    break;
+      return true;
+      break;
 #endif
 #ifdef MC68MAGIC
-  case bfd_arch_m68k:
+    case bfd_arch_m68k:
 #ifdef APOLLOM68KMAGIC
-    *magicp = APOLLO_COFF_VERSION_NUMBER;
+      *magicp = APOLLO_COFF_VERSION_NUMBER;
 #else
-    *magicp = MC68MAGIC;
+      *magicp = MC68MAGIC;
 #endif
 #ifdef LYNXOS
-    /* Just overwrite the usual value if we're doing Lynx. */
-    *magicp = LYNXCOFFMAGIC;
+      /* Just overwrite the usual value if we're doing Lynx. */
+      *magicp = LYNXCOFFMAGIC;
 #endif
-    return true;
-    break;
+      return true;
+      break;
 #endif
 
 #ifdef MC88MAGIC
@@ -1186,34 +1204,34 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
 #endif
 #ifdef H8300MAGIC
     case bfd_arch_h8300:
-    switch (bfd_get_mach (abfd)) 
-      {
-      case bfd_mach_h8300:
-       *magicp = H8300MAGIC;
-       return true;
-      case bfd_mach_h8300h:
-       *magicp = H8300HMAGIC;
-       return true;
-      }
+      switch (bfd_get_mach (abfd))
+       {
+       case bfd_mach_h8300:
+         *magicp = H8300MAGIC;
+         return true;
+       case bfd_mach_h8300h:
+         *magicp = H8300HMAGIC;
+         return true;
+       }
       break;
 #endif
 
 #ifdef SHMAGIC
-  case bfd_arch_sh:
+    case bfd_arch_sh:
       *magicp = SHMAGIC;
       return true;
       break;
 #endif
 
 #ifdef SPARCMAGIC
-  case bfd_arch_sparc:
-    *magicp = SPARCMAGIC;
+    case bfd_arch_sparc:
+      *magicp = SPARCMAGIC;
 #ifdef LYNXOS
-    /* Just overwrite the usual value if we're doing Lynx. */
-    *magicp = LYNXCOFFMAGIC;
+      /* Just overwrite the usual value if we're doing Lynx. */
+      *magicp = LYNXCOFFMAGIC;
 #endif
-    return true;
-    break;
+      return true;
+      break;
 #endif
 
 #ifdef H8500MAGIC
@@ -1225,49 +1243,49 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
 #ifdef A29K_MAGIC_BIG
     case bfd_arch_a29k:
       if (abfd->xvec->byteorder_big_p)
-       *magicp = A29K_MAGIC_BIG;
+       *magicp = A29K_MAGIC_BIG;
       else
-       *magicp = A29K_MAGIC_LITTLE;
+       *magicp = A29K_MAGIC_LITTLE;
       return true;
       break;
 #endif
 
 #ifdef WE32KMAGIC
-  case bfd_arch_we32k:
-    *magicp = WE32KMAGIC;
-    return true;
-    break;
+    case bfd_arch_we32k:
+      *magicp = WE32KMAGIC;
+      return true;
+      break;
 #endif
 
 #ifdef U802TOCMAGIC
-  case bfd_arch_rs6000:
-    *magicp = U802TOCMAGIC;
-    return true;
-    break;
+    case bfd_arch_rs6000:
+      *magicp = U802TOCMAGIC;
+      return true;
+      break;
 #endif
 
-  default:                     /* Unknown architecture */
-    /* return false;  -- fall through to "return false" below, to avoid
+    default:                   /* Unknown architecture */
+      /* return false;  -- fall through to "return false" below, to avoid
        "statement never reached" errors on the one below. */
-    break;
-  }
+      break;
+    }
 
   return false;
 }
 
 
-static          boolean
-DEFUN(coff_set_arch_mach,(abfd, arch, machine),
-      bfd            *abfd AND
-      enum bfd_architecture arch AND
-      unsigned long   machine)
+static boolean
+DEFUN (coff_set_arch_mach, (abfd, arch, machine),
+       bfd * abfd AND
+       enum bfd_architecture arch AND
+       unsigned long machine)
 {
-  unsigned        dummy1;
-  unsigned     short dummy2;
-  bfd_default_set_arch_mach(abfd, arch, machine);
+  unsigned dummy1;
+  unsigned short dummy2;
+  bfd_default_set_arch_mach (abfd, arch, machine);
 
   if (arch != bfd_arch_unknown &&
-      coff_set_flags(abfd, &dummy1, &dummy2) != true)
+      coff_set_flags (abfd, &dummy1, &dummy2) != true)
     return false;              /* We can't represent this type */
   return true;                 /* We're easy ... */
 }
@@ -1276,49 +1294,51 @@ DEFUN(coff_set_arch_mach,(abfd, arch, machine),
 /* Calculate the file position for each section. */
 
 static void
-DEFUN(coff_compute_section_file_positions,(abfd),
-      bfd            *abfd)
+DEFUN (coff_compute_section_file_positions, (abfd),
+       bfd * abfd)
 {
-  asection       *current;
-  asection     *previous = (asection *)NULL;
-  file_ptr        sofar = FILHSZ;
+  asection *current;
+  asection *previous = (asection *) NULL;
+  file_ptr sofar = FILHSZ;
 #ifndef I960
-  file_ptr     old_sofar;
+  file_ptr old_sofar;
 #endif
-  if (bfd_get_start_address(abfd)) 
-  {
-    /*  A start address may have been added to the original file. In this
+  if (bfd_get_start_address (abfd))
+    {
+      /*  A start address may have been added to the original file. In this
        case it will need an optional header to record it.  */
-    abfd->flags |= EXEC_P;
-  }
+      abfd->flags |= EXEC_P;
+    }
 
   if (abfd->flags & EXEC_P)
-   sofar += AOUTSZ;
+    sofar += AOUTSZ;
 
   sofar += abfd->section_count * SCNHSZ;
   for (current = abfd->sections;
-       current != (asection *)NULL;
-       current = current->next) {
+       current != (asection *) NULL;
+       current = current->next)
+    {
 
       /* Only deal with sections which have contents */
       if (!(current->flags & SEC_HAS_CONTENTS))
-       continue;
+       continue;
 
       /* Align the sections in the file to the same boundary on
         which they are aligned in virtual memory.  I960 doesn't
         do this (FIXME) so we can stay in sync with Intel.  960
         doesn't yet page from files... */
 #ifndef I960
-    {
-      /* make sure this section is aligned on the right boundary - by
+      {
+       /* make sure this section is aligned on the right boundary - by
         padding the previous section up if necessary */
 
-      old_sofar= sofar;
-      sofar = BFD_ALIGN(sofar, 1 << current->alignment_power);
-      if (previous != (asection *)NULL) {
-         previous->_raw_size += sofar - old_sofar;
-       }
-    }
+       old_sofar = sofar;
+       sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
+       if (previous != (asection *) NULL)
+         {
+           previous->_raw_size += sofar - old_sofar;
+         }
+      }
 
 #endif
       /* FIXME, in demand paged files, the low order bits of the file
@@ -1331,9 +1351,9 @@ DEFUN(coff_compute_section_file_positions,(abfd),
       sofar += current->_raw_size;
 #ifndef I960
       /* make sure that this section is of the right size too */
-      old_sofar =  sofar;
-      sofar = BFD_ALIGN(sofar, 1 << current->alignment_power);
-      current->_raw_size += sofar - old_sofar ;
+      old_sofar = sofar;
+      sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
+      current->_raw_size += sofar - old_sofar;
 #endif
 
 #ifdef _LIB
@@ -1346,13 +1366,15 @@ DEFUN(coff_compute_section_file_positions,(abfd),
 
       previous = current;
     }
-  obj_relocbase(abfd) = sofar;
+  obj_relocbase (abfd) = sofar;
 }
 
+#ifndef RS6000COFF_C
+
 /* If .file, .text, .data, .bss symbols are missing, add them.  */
 /* @@ Should we only be adding missing symbols, or overriding the aux
    values for existing section symbols?  */
-static void
+static boolean
 coff_add_missing_symbols (abfd)
      bfd *abfd;
 {
@@ -1366,38 +1388,43 @@ coff_add_missing_symbols (abfd)
     {
       coff_symbol_type *csym = coff_symbol_from (abfd, sympp[i]);
       CONST char *name;
-      if (csym) 
-      {
-       /* only do this if there is a coff representation of the input
-          symbol */
-       if (csym->native && csym->native->u.syment.n_sclass == C_FILE)
+      if (csym)
        {
-         need_file = 0;
-         continue;
-       }
-       name = csym->symbol.name;
-       if (!name)
-        continue;
-       if (!strcmp (name, _TEXT))
-        need_text = 0;
+         /* only do this if there is a coff representation of the input
+          symbol */
+         if (csym->native && csym->native->u.syment.n_sclass == C_FILE)
+           {
+             need_file = 0;
+             continue;
+           }
+         name = csym->symbol.name;
+         if (!name)
+           continue;
+         if (!strcmp (name, _TEXT))
+           need_text = 0;
 #ifdef APOLLO_M68
-       else if (!strcmp(name, ".wtext"))
-         need_text = 0;
+         else if (!strcmp (name, ".wtext"))
+           need_text = 0;
 #endif
-       else if (!strcmp (name, _DATA))
-        need_data = 0;
-       else if (!strcmp (name, _BSS))
-        need_bss = 0;
-      }
+         else if (!strcmp (name, _DATA))
+           need_data = 0;
+         else if (!strcmp (name, _BSS))
+           need_bss = 0;
+       }
     }
   /* Now i == bfd_get_symcount (abfd).  */
   /* @@ For now, don't deal with .file symbol.  */
   need_file = 0;
 
   if (!need_text && !need_data && !need_bss && !need_file)
-    return;
+    return true;
   nsyms += need_text + need_data + need_bss + need_file;
-  sympp2 = (asymbol**) bfd_alloc_by_size_t (abfd, nsyms * sizeof (asymbol *));
+  sympp2 = (asymbol **) bfd_alloc_by_size_t (abfd, nsyms * sizeof (asymbol *));
+  if (!sympp2)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   memcpy (sympp2, sympp, i * sizeof (asymbol *));
   if (need_file)
     {
@@ -1412,29 +1439,32 @@ coff_add_missing_symbols (abfd)
     sympp2[i++] = coff_section_symbol (abfd, _BSS);
   BFD_ASSERT (i == nsyms);
   bfd_set_symtab (abfd, sympp2, nsyms);
+  return true;
 }
 
+#endif /* ! defined (RS6000COFF_C) */
+
 /* SUPPRESS 558 */
 /* SUPPRESS 529 */
-static          boolean
-DEFUN(coff_write_object_contents,(abfd),
-      bfd            *abfd)
+static boolean
+DEFUN (coff_write_object_contents, (abfd),
+       bfd * abfd)
 {
-  asection       *current;
+  asection *current;
   unsigned int count;
-  
-  boolean         hasrelocs = false;
-  boolean         haslinno = false;
-  file_ptr        reloc_base;
-  file_ptr        lineno_base;
-  file_ptr        sym_base;
-  file_ptr        scn_base;
-  file_ptr        data_base;
-  unsigned long   reloc_size = 0;
-  unsigned long   lnno_size = 0;
-  asection       *text_sec = NULL;
-  asection       *data_sec = NULL;
-  asection       *bss_sec = NULL;
+
+  boolean hasrelocs = false;
+  boolean haslinno = false;
+  file_ptr reloc_base;
+  file_ptr lineno_base;
+  file_ptr sym_base;
+  file_ptr scn_base;
+  file_ptr data_base;
+  unsigned long reloc_size = 0;
+  unsigned long lnno_size = 0;
+  asection *text_sec = NULL;
+  asection *data_sec = NULL;
+  asection *bss_sec = NULL;
 
   struct internal_filehdr internal_f;
   struct internal_aouthdr internal_a;
@@ -1446,161 +1476,178 @@ DEFUN(coff_write_object_contents,(abfd),
      @@ The code doesn't make this check.  Is it supposed to be done,
      or isn't it??  */
   count = 1;
-  for (current = abfd->sections; current != (asection *)NULL; 
-       current = current->next) 
-  {
+  for (current = abfd->sections; current != (asection *) NULL;
+       current = current->next)
+    {
       current->target_index = count;
       count++;
-  }
+    }
 
-  if(abfd->output_has_begun == false) {
-      coff_compute_section_file_positions(abfd);
+  if (abfd->output_has_begun == false)
+    {
+      coff_compute_section_file_positions (abfd);
     }
 
-  if (abfd->sections != (asection *)NULL) {
+  if (abfd->sections != (asection *) NULL)
+    {
       scn_base = abfd->sections->filepos;
     }
-  else {
+  else
+    {
       scn_base = 0;
     }
-  if (bfd_seek(abfd, scn_base, SEEK_SET) != 0)
-   return false;
-  reloc_base = obj_relocbase(abfd);
+  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
+    return false;
+  reloc_base = obj_relocbase (abfd);
 
   /* Make a pass through the symbol table to count line number entries and
      put them into the correct asections */
 
-  lnno_size =  coff_count_linenumbers(abfd) * LINESZ;
+  lnno_size = coff_count_linenumbers (abfd) * LINESZ;
   data_base = scn_base;
 
   /* Work out the size of the reloc and linno areas */
 
   for (current = abfd->sections; current != NULL; current =
-       current->next) 
-  {
-    /* We give section headers to +ve indexes */
-    if (current->target_index > 0) 
+       current->next)
     {
-       
-      reloc_size += current->reloc_count * RELSZ;
-      data_base += SCNHSZ;
+      /* We give section headers to +ve indexes */
+      if (current->target_index > 0)
+       {
+
+         reloc_size += current->reloc_count * RELSZ;
+         data_base += SCNHSZ;
+       }
+
     }
-      
-  }
 
   lineno_base = reloc_base + reloc_size;
   sym_base = lineno_base + lnno_size;
 
   /* Indicate in each section->line_filepos its actual file address */
   for (current = abfd->sections; current != NULL; current =
-       current->next) 
-  {
-    if (current->target_index > 0) 
+       current->next)
     {
-       
-      if (current->lineno_count) {
-         current->line_filepos = lineno_base;
-         current->moving_line_filepos = lineno_base;
-         lineno_base += current->lineno_count * LINESZ;
-       }
-      else {
-         current->line_filepos = 0;
-       }
-      if (current->reloc_count) {
-         current->rel_filepos = reloc_base;
-         reloc_base += current->reloc_count * RELSZ;
-       }
-      else {
-         current->rel_filepos = 0;
+      if (current->target_index > 0)
+       {
+
+         if (current->lineno_count)
+           {
+             current->line_filepos = lineno_base;
+             current->moving_line_filepos = lineno_base;
+             lineno_base += current->lineno_count * LINESZ;
+           }
+         else
+           {
+             current->line_filepos = 0;
+           }
+         if (current->reloc_count)
+           {
+             current->rel_filepos = reloc_base;
+             reloc_base += current->reloc_count * RELSZ;
+           }
+         else
+           {
+             current->rel_filepos = 0;
+           }
        }
     }
-  }    
-      
+
 
 
   /* Write section headers to the file.  */
   internal_f.f_nscns = 0;
-  bfd_seek(abfd,
-          (file_ptr) ((abfd->flags & EXEC_P) ?
-                      (FILHSZ + AOUTSZ) : FILHSZ),
-          SEEK_SET);
+  bfd_seek (abfd,
+           (file_ptr) ((abfd->flags & EXEC_P) ?
+                       (FILHSZ + AOUTSZ) : FILHSZ),
+           SEEK_SET);
 
-{
+  {
 #if 0
-  unsigned int    pad = abfd->flags & D_PAGED ? data_base : 0;
+    unsigned int pad = abfd->flags & D_PAGED ? data_base : 0;
 #endif
-  unsigned int    pad = 0;
+    unsigned int pad = 0;
 
-  for (current = abfd->sections;
-       current != NULL;
-       current = current->next) {
-      struct internal_scnhdr section;
-      if (current->target_index > 0) 
+    for (current = abfd->sections;
+        current != NULL;
+        current = current->next)
       {
-       internal_f.f_nscns ++;
-       strncpy(&(section.s_name[0]), current->name, 8);
+       struct internal_scnhdr section;
+       if (current->target_index > 0)
+         {
+           internal_f.f_nscns++;
+           strncpy (&(section.s_name[0]), current->name, 8);
 #ifdef _LIB
-       /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
+           /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
           Ian Taylor <ian@cygnus.com>.  */
-       if (strcmp (current->name, _LIB) == 0)
-         section.s_vaddr = 0;
-       else
+           if (strcmp (current->name, _LIB) == 0)
+             section.s_vaddr = 0;
+           else
 #endif
-       section.s_vaddr = current->lma + pad;
-       section.s_paddr = current->lma + pad;
-       section.s_size = current->_raw_size - pad;
-       /*
+             section.s_vaddr = current->lma + pad;
+           section.s_paddr = current->lma + pad;
+           section.s_size = current->_raw_size - pad;
+           /*
          If this section has no size or is unloadable then the scnptr
          will be 0 too
          */
-       if (current->_raw_size - pad == 0 ||
-           (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) {
-           section.s_scnptr = 0;
-         }
-       else {
-           section.s_scnptr = current->filepos;
-         }
-       section.s_relptr = current->rel_filepos;
-       section.s_lnnoptr = current->line_filepos;
-       section.s_nreloc = current->reloc_count;
-       section.s_nlnno = current->lineno_count;
-       if (current->reloc_count != 0)
-        hasrelocs = true;
-       if (current->lineno_count != 0)
-        haslinno = true;
-
-       section.s_flags = sec_to_styp_flags(current->name,current->flags);
-
-       if (!strcmp(current->name, _TEXT)) {
-           text_sec = current;
-         } else if (!strcmp(current->name, _DATA)) {
-             data_sec = current;
+           if (current->_raw_size - pad == 0 ||
+               (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+             {
+               section.s_scnptr = 0;
+             }
+           else
+             {
+               section.s_scnptr = current->filepos;
+             }
+           section.s_relptr = current->rel_filepos;
+           section.s_lnnoptr = current->line_filepos;
+           section.s_nreloc = current->reloc_count;
+           section.s_nlnno = current->lineno_count;
+           if (current->reloc_count != 0)
+             hasrelocs = true;
+           if (current->lineno_count != 0)
+             haslinno = true;
+
+           section.s_flags = sec_to_styp_flags (current->name, current->flags);
+
+           if (!strcmp (current->name, _TEXT))
+             {
+               text_sec = current;
+             }
+           else if (!strcmp (current->name, _DATA))
+             {
+               data_sec = current;
 #ifdef TWO_DATA_SECS
-           } else if (!strcmp(current->name, ".data2")) {
-             data_sec = current;
+             }
+           else if (!strcmp (current->name, ".data2"))
+             {
+               data_sec = current;
 #endif /* TWO_DATA_SECS */
-           } else if (!strcmp(current->name, _BSS)) {
+             }
+           else if (!strcmp (current->name, _BSS))
+             {
                bss_sec = current;
              }
 
 #ifdef I960
-       section.s_align = (current->alignment_power
-                          ? 1 << current->alignment_power
-                          : 0);
+           section.s_align = (current->alignment_power
+                              ? 1 << current->alignment_power
+                              : 0);
 
 #endif
-      {
-       SCNHDR          buff;
+           {
+             SCNHDR buff;
 
-       coff_swap_scnhdr_out(abfd, &section, &buff);
-       bfd_write((PTR) (&buff), 1, SCNHSZ, abfd);
+             coff_swap_scnhdr_out (abfd, &section, &buff);
+             bfd_write ((PTR) (&buff), 1, SCNHSZ, abfd);
 
-      }
+           }
 
-       pad = 0;
+           pad = 0;
+         }
       }
-    }  
-}
+  }
 
 
   /* OK, now set up the filehdr... */
@@ -1615,31 +1662,31 @@ DEFUN(coff_write_object_contents,(abfd),
     */
   internal_f.f_timdat = 0;
 
-  if (bfd_get_symcount(abfd) != 0)
-   internal_f.f_symptr = sym_base;
+  if (bfd_get_symcount (abfd) != 0)
+    internal_f.f_symptr = sym_base;
   else
-   internal_f.f_symptr = 0;
+    internal_f.f_symptr = 0;
 
   internal_f.f_flags = 0;
 
   if (abfd->flags & EXEC_P)
-   internal_f.f_opthdr = AOUTSZ;
+    internal_f.f_opthdr = AOUTSZ;
   else
-   internal_f.f_opthdr = 0;
+    internal_f.f_opthdr = 0;
 
   if (!hasrelocs)
-   internal_f.f_flags |= F_RELFLG;
+    internal_f.f_flags |= F_RELFLG;
   if (!haslinno)
-   internal_f.f_flags |= F_LNNO;
-  if (0 == bfd_get_symcount(abfd))
-   internal_f.f_flags |= F_LSYMS;
+    internal_f.f_flags |= F_LNNO;
+  if (0 == bfd_get_symcount (abfd))
+    internal_f.f_flags |= F_LSYMS;
   if (abfd->flags & EXEC_P)
-   internal_f.f_flags |= F_EXEC;
+    internal_f.f_flags |= F_EXEC;
 
   if (!abfd->xvec->byteorder_big_p)
-   internal_f.f_flags |= F_AR32WR;
-  else 
-  internal_f.f_flags |= F_AR32W;
+    internal_f.f_flags |= F_AR32WR;
+  else
+    internal_f.f_flags |= F_AR32W;
 
   /*
     FIXME, should do something about the other byte orders and
@@ -1650,156 +1697,169 @@ DEFUN(coff_write_object_contents,(abfd),
 
   /* Set up architecture-dependent stuff */
 
-{ unsigned int   magic = 0;
-  unsigned short    flags = 0;
-  coff_set_flags(abfd, &magic, &flags);
-  internal_f.f_magic = magic;
-  internal_f.f_flags |= flags;
-  /* ...and the "opt"hdr... */
+  {
+    unsigned int magic = 0;
+    unsigned short flags = 0;
+    coff_set_flags (abfd, &magic, &flags);
+    internal_f.f_magic = magic;
+    internal_f.f_flags |= flags;
+    /* ...and the "opt"hdr... */
 
 #ifdef A29K
-# ifdef ULTRA3                 /* NYU's machine */
-  /* FIXME: This is a bogus check.  I really want to see if there
+#ifdef ULTRA3                  /* NYU's machine */
+    /* FIXME: This is a bogus check.  I really want to see if there
    * is a .shbss or a .shdata section, if so then set the magic
    * number to indicate a shared data executable.
    */
-  if (internal_f.f_nscns >= 7)
-   internal_a.magic = SHMAGIC;         /* Shared magic */
-  else
-# endif                                /* ULTRA3 */
-   internal_a.magic = NMAGIC;  /* Assume separate i/d */
+    if (internal_f.f_nscns >= 7)
+      internal_a.magic = SHMAGIC;      /* Shared magic */
+    else
+#endif /* ULTRA3 */
+      internal_a.magic = NMAGIC;/* Assume separate i/d */
 #define __A_MAGIC_SET__
-#endif                         /* A29K */
+#endif /* A29K */
 #ifdef I960
-  internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
+    internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
 #define __A_MAGIC_SET__
-#endif                         /* I960 */
+#endif /* I960 */
 #if M88
 #define __A_MAGIC_SET__
-  internal_a.magic = PAGEMAGICBCS;
-#endif                         /* M88 */
+    internal_a.magic = PAGEMAGICBCS;
+#endif /* M88 */
 
 #if APOLLO_M68
 #define __A_MAGIC_SET__
-  internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
+    internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
 #endif
 
 #if M68 || WE32K
 #define __A_MAGIC_SET__
-  /* Never was anything here for the 68k */
-#endif                         /* M68 || WE32K */
+    /* Never was anything here for the 68k */
+#endif /* M68 || WE32K */
 
 #if I386
-# define __A_MAGIC_SET__
-  internal_a.magic = ZMAGIC;
+#define __A_MAGIC_SET__
+    internal_a.magic = ZMAGIC;
 #endif /* I386 */
 
 #if RS6000COFF_C
 #define __A_MAGIC_SET__
-  internal_a.magic = (abfd->flags & D_PAGED)? RS6K_AOUTHDR_ZMAGIC:
-  (abfd->flags & WP_TEXT)? RS6K_AOUTHDR_NMAGIC:
-  RS6K_AOUTHDR_OMAGIC;
+    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
+      (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
+      RS6K_AOUTHDR_OMAGIC;
 #endif
 
 #ifndef __A_MAGIC_SET__
-# include "Your aouthdr magic number is not being set!"
+#include "Your aouthdr magic number is not being set!"
 #else
-# undef __A_MAGIC_SET__
+#undef __A_MAGIC_SET__
 #endif
-}
+  }
   /* Now should write relocs, strings, syms */
-  obj_sym_filepos(abfd) = sym_base;
-
-  if (bfd_get_symcount(abfd) != 0) {
-      coff_add_missing_symbols (abfd);
-      coff_renumber_symbols(abfd);
-      coff_mangle_symbols(abfd);
-      coff_write_symbols(abfd);
-      coff_write_linenumbers(abfd);
-      coff_write_relocs(abfd);
+  obj_sym_filepos (abfd) = sym_base;
+
+  if (bfd_get_symcount (abfd) != 0)
+    {
+#ifndef RS6000COFF_C
+      if (!coff_add_missing_symbols (abfd))
+       return false;
+#endif
+      if (!coff_renumber_symbols (abfd))
+       return false;
+      coff_mangle_symbols (abfd);
+      coff_write_symbols (abfd);
+      if (!coff_write_linenumbers (abfd))
+       return false;
+      coff_write_relocs (abfd);
     }
-  if (text_sec) {
-      internal_a.tsize = bfd_get_section_size_before_reloc(text_sec);
+  if (text_sec)
+    {
+      internal_a.tsize = bfd_get_section_size_before_reloc (text_sec);
       internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
     }
-  if (data_sec) {
-      internal_a.dsize = bfd_get_section_size_before_reloc(data_sec);
-      internal_a.data_start = internal_a.dsize ? data_sec->vma      : 0;
+  if (data_sec)
+    {
+      internal_a.dsize = bfd_get_section_size_before_reloc (data_sec);
+      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
     }
-  if (bss_sec) {
-      internal_a.bsize = bfd_get_section_size_before_reloc(bss_sec);
+  if (bss_sec)
+    {
+      internal_a.bsize = bfd_get_section_size_before_reloc (bss_sec);
     }
 
-  internal_a.entry = bfd_get_start_address(abfd);
-  internal_f.f_nsyms =  bfd_get_symcount(abfd);
+  internal_a.entry = bfd_get_start_address (abfd);
+  internal_f.f_nsyms = bfd_get_symcount (abfd);
 
   /* now write them */
-  if (bfd_seek(abfd, (file_ptr) 0, SEEK_SET) != 0)
-   return false;
-{
-  FILHDR buff;
-  coff_swap_filehdr_out(abfd, (PTR)&internal_f, (PTR)&buff);
-  bfd_write((PTR) &buff, 1, FILHSZ, abfd);
-}
-  if (abfd->flags & EXEC_P) {
+  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
+    return false;
+  {
+    FILHDR buff;
+    coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) & buff);
+    bfd_write ((PTR) & buff, 1, FILHSZ, abfd);
+  }
+  if (abfd->flags & EXEC_P)
+    {
       AOUTHDR buff;
-      coff_swap_aouthdr_out(abfd, (PTR)&internal_a, (PTR)&buff);
-      bfd_write((PTR) &buff, 1, AOUTSZ, abfd);
+      coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) & buff);
+      bfd_write ((PTR) & buff, 1, AOUTSZ, abfd);
     }
   return true;
 }
 
-static          boolean
-DEFUN(coff_set_section_contents,(abfd, section, location, offset, count),
-      bfd            *abfd AND
-      sec_ptr         section AND
-      PTR             location AND
-      file_ptr        offset AND
-      bfd_size_type   count)
+static boolean
+DEFUN (coff_set_section_contents, (abfd, section, location, offset, count),
+       bfd * abfd AND
+       sec_ptr section AND
+       PTR location AND
+       file_ptr offset AND
+       bfd_size_type count)
 {
-    if (abfd->output_has_begun == false)       /* set by bfd.c handler */
-       coff_compute_section_file_positions(abfd);
+  if (abfd->output_has_begun == false) /* set by bfd.c handler */
+    coff_compute_section_file_positions (abfd);
 
 #ifdef _LIB
-    /* If this is a .lib section, bump the vma address so that it
+  /* If this is a .lib section, bump the vma address so that it
        winds up being the number of .lib sections output.  This is
        right for SVR3.2.  Shared libraries should probably get more
        generic support.  Ian Taylor <ian@cygnus.com>.  */
-    if (strcmp (section->name, _LIB) == 0)
-      ++section->lma;
+  if (strcmp (section->name, _LIB) == 0)
+    ++section->lma;
 #endif
 
-    /* Don't write out bss sections - one way to do this is to 
-       see if the filepos has not been set. */ 
-    if (section->filepos == 0)
-      return true;
+  /* Don't write out bss sections - one way to do this is to
+       see if the filepos has not been set. */
+  if (section->filepos == 0)
+    return true;
 
-    bfd_seek(abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
+  bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
 
-    if (count != 0) {
-       return (bfd_write(location, 1, count, abfd) == count) ? true : false;
+  if (count != 0)
+    {
+      return (bfd_write (location, 1, count, abfd) == count) ? true : false;
     }
-    return true;
+  return true;
 }
 #if 0
-static          boolean
-coff_close_and_cleanup(abfd)
-    bfd            *abfd;
+static boolean
+coff_close_and_cleanup (abfd)
+     bfd *abfd;
 {
-  if (!bfd_read_p(abfd))
-    switch (abfd->format) {
-    case bfd_archive:
-      if (!_bfd_write_archive_contents(abfd))
-       return false;
-      break;
-    case bfd_object:
-      if (!coff_write_object_contents(abfd))
+  if (!bfd_read_p (abfd))
+    switch (abfd->format)
+      {
+      case bfd_archive:
+       if (!_bfd_write_archive_contents (abfd))
+         return false;
+       break;
+      case bfd_object:
+       if (!coff_write_object_contents (abfd))
+         return false;
+       break;
+      default:
+       bfd_error = invalid_operation;
        return false;
-      break;
-    default:
-      bfd_error = invalid_operation;
-      return false;
-    }
+      }
 
   /* We depend on bfd_close to free all the memory on the obstack.  */
   /* FIXME if bfd_release is not using obstacks! */
@@ -1809,27 +1869,29 @@ coff_close_and_cleanup(abfd)
 #endif
 
 static PTR
-buy_and_read(abfd, where, seek_direction, size)
-    bfd            *abfd;
-    file_ptr        where;
-    int             seek_direction;
-    size_t          size;
+buy_and_read (abfd, where, seek_direction, size)
+     bfd *abfd;
+     file_ptr where;
+     int seek_direction;
+     size_t size;
 {
-    PTR             area = (PTR) bfd_alloc(abfd, size);
-    if (!area) {
-       bfd_error = no_memory;
-       return (NULL);
+  PTR area = (PTR) bfd_alloc (abfd, size);
+  if (!area)
+    {
+      bfd_error = no_memory;
+      return (NULL);
     }
-    bfd_seek(abfd, where, seek_direction);
-    if (bfd_read(area, 1, size, abfd) != size) {
-       bfd_error = system_call_error;
-       return (NULL);
+  bfd_seek (abfd, where, seek_direction);
+  if (bfd_read (area, 1, size, abfd) != size)
+    {
+      bfd_error = system_call_error;
+      return (NULL);
     }                          /* on error */
-    return (area);
+  return (area);
 }                              /* buy_and_read() */
 
 /*
-SUBSUBSECTION 
+SUBSUBSECTION
        Reading linenumbers
 
        Creating the linenumber table is done by reading in the entire
@@ -1839,7 +1901,7 @@ SUBSUBSECTION
        is marked as having a line number of 0. Each line within the
        function is an offset from the first line in the function. The
        base of the line number information for the table is stored in
-       the symbol associated with the function. 
+       the symbol associated with the function.
 
        The information is copied from the external to the internal
        table, and each symbol which marks a function is marked by
@@ -1850,22 +1912,22 @@ SUBSUBSECTION
 */
 
 static boolean
-coff_slurp_line_table(abfd, asect)
+coff_slurp_line_table (abfd, asect)
      bfd *abfd;
      asection *asect;
 {
-  LINENO  *native_lineno;
+  LINENO *native_lineno;
   alent *lineno_cache;
 
-  BFD_ASSERT(asect->lineno == (alent *) NULL);
+  BFD_ASSERT (asect->lineno == (alent *) NULL);
 
-  native_lineno = (LINENO *) buy_and_read(abfd,
-                                         asect->line_filepos,
-                                         SEEK_SET,
-                                         (size_t) (LINESZ *
-                                                   asect->lineno_count));
+  native_lineno = (LINENO *) buy_and_read (abfd,
+                                          asect->line_filepos,
+                                          SEEK_SET,
+                                          (size_t) (LINESZ *
+                                                    asect->lineno_count));
   lineno_cache =
-    (alent *) bfd_alloc(abfd, (size_t) ((asect->lineno_count + 1) * sizeof(alent)));
+    (alent *) bfd_alloc (abfd, (size_t) ((asect->lineno_count + 1) * sizeof (alent)));
   if (lineno_cache == NULL)
     {
       bfd_error = no_memory;
@@ -1873,29 +1935,29 @@ coff_slurp_line_table(abfd, asect)
     }
   else
     {
-      unsigned int    counter = 0;
-      alent          *cache_ptr = lineno_cache;
-      LINENO  *src = native_lineno;
+      unsigned int counter = 0;
+      alent *cache_ptr = lineno_cache;
+      LINENO *src = native_lineno;
 
       while (counter < asect->lineno_count)
        {
          struct internal_lineno dst;
-         coff_swap_lineno_in(abfd, src, &dst);
+         coff_swap_lineno_in (abfd, src, &dst);
          cache_ptr->line_number = dst.l_lnno;
 
          if (cache_ptr->line_number == 0)
            {
              coff_symbol_type *sym =
-               (coff_symbol_type *) (dst.l_addr.l_symndx
-                                     + obj_raw_syments(abfd))->u.syment._n._n_n._n_zeroes;
+             (coff_symbol_type *) (dst.l_addr.l_symndx
+                     + obj_raw_syments (abfd))->u.syment._n._n_n._n_zeroes;
              cache_ptr->u.sym = (asymbol *) sym;
              sym->lineno = cache_ptr;
            }
          else
            {
              cache_ptr->u.offset = dst.l_addr.l_paddr
-               - bfd_section_vma(abfd, asect);
-           } /* If no linenumber expect a symbol index */
+               - bfd_section_vma (abfd, asect);
+           }                   /* If no linenumber expect a symbol index */
 
          cache_ptr++;
          src++;
@@ -1910,229 +1972,270 @@ coff_slurp_line_table(abfd, asect)
 }
 
 static boolean
-DEFUN(coff_slurp_symbol_table,(abfd),
-      bfd            *abfd)
+DEFUN (coff_slurp_symbol_table, (abfd),
+       bfd * abfd)
 {
-  combined_entry_type         *native_symbols;
+  combined_entry_type *native_symbols;
   coff_symbol_type *cached_area;
-  unsigned int   *table_ptr;
+  unsigned int *table_ptr;
 
-  unsigned int    number_of_symbols = 0;
-  if (obj_symbols(abfd))
+  unsigned int number_of_symbols = 0;
+  if (obj_symbols (abfd))
     return true;
-  bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET);
+  bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
 
   /* Read in the symbol table */
-  if ((native_symbols = coff_get_normalized_symtab(abfd)) == NULL) {
-    return (false);
-  }                            /* on error */
+  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
+    {
+      return (false);
+    }                          /* on error */
 
   /* Allocate enough room for all the symbols in cached form */
   cached_area =
     (coff_symbol_type *)
-      bfd_alloc(abfd, (size_t) (bfd_get_symcount(abfd) * sizeof(coff_symbol_type)));
+    bfd_alloc (abfd, (size_t) (bfd_get_symcount (abfd) * sizeof (coff_symbol_type)));
 
-  if (cached_area == NULL) {
-    bfd_error = no_memory;
-    return false;
-  }                            /* on error */
+  if (cached_area == NULL)
+    {
+      bfd_error = no_memory;
+      return false;
+    }                          /* on error */
   table_ptr =
     (unsigned int *)
-      bfd_alloc(abfd, (size_t) (bfd_get_symcount(abfd) * sizeof(unsigned int)));
+    bfd_alloc (abfd, (size_t) (bfd_get_symcount (abfd) * sizeof (unsigned int)));
 
-  if (table_ptr == NULL) {
-    bfd_error = no_memory;
-    return false;
-  } 
-  else 
-  {
-    coff_symbol_type *dst = cached_area;
-    unsigned int    last_native_index = bfd_get_symcount(abfd);
-    unsigned int    this_index = 0;
-    while (this_index < last_native_index) {
-      combined_entry_type         *src = native_symbols + this_index;
-      table_ptr[this_index] = number_of_symbols;
-      dst->symbol.the_bfd = abfd;
-
-      dst->symbol.name = (char *)(src->u.syment._n._n_n._n_offset);
-      /* We use the native name field to point to the cached field.  */
-      src->u.syment._n._n_n._n_zeroes = (long) dst;
-      dst->symbol.section = coff_section_from_bfd_index(abfd,
-                                                       src->u.syment.n_scnum);
-      dst->symbol.flags = 0;
-      dst->done_lineno = false;
-      
-      switch (src->u.syment.n_sclass) {
+  if (table_ptr == NULL)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
+  else
+    {
+      coff_symbol_type *dst = cached_area;
+      unsigned int last_native_index = bfd_get_symcount (abfd);
+      unsigned int this_index = 0;
+      while (this_index < last_native_index)
+       {
+         combined_entry_type *src = native_symbols + this_index;
+         table_ptr[this_index] = number_of_symbols;
+         dst->symbol.the_bfd = abfd;
+
+         dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
+         /* We use the native name field to point to the cached field.  */
+         src->u.syment._n._n_n._n_zeroes = (long) dst;
+         dst->symbol.section = coff_section_from_bfd_index (abfd,
+                                                    src->u.syment.n_scnum);
+         dst->symbol.flags = 0;
+         dst->done_lineno = false;
+
+         switch (src->u.syment.n_sclass)
+           {
 #ifdef I960
-      case C_LEAFEXT:
+           case C_LEAFEXT:
 #if 0
-       dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
-       dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
-       dst->symbol.flags |= BSF_NOT_AT_END;
+             dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
+             dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
+             dst->symbol.flags |= BSF_NOT_AT_END;
 #endif
-       /* Fall through to next case */
+             /* Fall through to next case */
 
 #endif
 
-      case C_EXT:
+           case C_EXT:
 #ifdef RS6000COFF_C
-      case C_HIDEXT:
-#endif
-       if ((src->u.syment.n_scnum) == 0) {
-         if ((src->u.syment.n_value) == 0) {
-           dst->symbol.section = &bfd_und_section;
-           dst->symbol.value= 0;
-         }
-         else {
-           dst->symbol.section = &bfd_com_section;
-           dst->symbol.value = (src->u.syment.n_value);
-         }
-       }
-       else {
-         /*
+           case C_HIDEXT:
+#endif
+             if ((src->u.syment.n_scnum) == 0)
+               {
+                 if ((src->u.syment.n_value) == 0)
+                   {
+                     dst->symbol.section = &bfd_und_section;
+                     dst->symbol.value = 0;
+                   }
+                 else
+                   {
+                     dst->symbol.section = &bfd_com_section;
+                     dst->symbol.value = (src->u.syment.n_value);
+                   }
+               }
+             else
+               {
+                 /*
            Base the value as an index from the base of the
            section
            */
 
-           dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
-           dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
+                 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
+                 dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
 
-         if (ISFCN((src->u.syment.n_type))) {
-           /*
+                 if (ISFCN ((src->u.syment.n_type)))
+                   {
+                     /*
              A function ext does not go at the end of a file
              */
-           dst->symbol.flags |= BSF_NOT_AT_END;
-         }
-       }
-
+                     dst->symbol.flags |= BSF_NOT_AT_END;
+                   }
+               }
 
-       break;
-
-      case C_STAT:             /* static                        */
+#ifdef RS6000COFF_C
+             /* If this symbol has a csect aux of type LD, the scnlen field
+          is actually the index of the containing csect symbol.  We
+          need to pointerize it.  */
+             if (src->u.syment.n_numaux > 0)
+               {
+                 combined_entry_type *aux;
+
+                 aux = src + src->u.syment.n_numaux - 1;
+                 if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD)
+                   {
+                     aux->u.auxent.x_csect.x_scnlen.p =
+                       native_symbols + aux->u.auxent.x_csect.x_scnlen.l;
+                     aux->fix_scnlen = 1;
+                   }
+               }
+#endif
+
+             break;
+
+           case C_STAT:        /* static                        */
 #ifdef I960
-      case C_LEAFSTAT:         /* static leaf procedure        */
-#endif
-      case C_LABEL:            /* label                         */
-       if (src->u.syment.n_scnum == -2)
-         dst->symbol.flags = BSF_DEBUGGING;
-       else
-         dst->symbol.flags = BSF_LOCAL;
-       /*
+           case C_LEAFSTAT:    /* static leaf procedure        */
+#endif
+           case C_LABEL:       /* label                         */
+             if (src->u.syment.n_scnum == -2)
+               dst->symbol.flags = BSF_DEBUGGING;
+             else
+               dst->symbol.flags = BSF_LOCAL;
+             /*
          Base the value as an index from the base of the section, if
          there is one
          */
-       if (dst->symbol.section)
-         dst->symbol.value = (src->u.syment.n_value) -
-           dst->symbol.section->vma;
-       else
-         dst->symbol.value = (src->u.syment.n_value) ;
-       break;
-
-      case C_MOS:              /* member of structure   */
-      case C_EOS:              /* end of structure              */
-#ifdef NOTDEF  /* C_AUTOARG has the same value */
+             if (dst->symbol.section)
+               dst->symbol.value = (src->u.syment.n_value) -
+                 dst->symbol.section->vma;
+             else
+               dst->symbol.value = (src->u.syment.n_value);
+             break;
+
+           case C_MOS: /* member of structure   */
+           case C_EOS: /* end of structure              */
+#ifdef NOTDEF                  /* C_AUTOARG has the same value */
 #ifdef C_GLBLREG
-      case C_GLBLREG:          /* A29k-specific storage class */
+           case C_GLBLREG:     /* A29k-specific storage class */
 #endif
 #endif
-      case C_REGPARM:          /* register parameter            */
-      case C_REG:              /* register variable             */
+           case C_REGPARM:     /* register parameter            */
+           case C_REG: /* register variable             */
 #ifdef C_AUTOARG
-      case C_AUTOARG:          /* 960-specific storage class */
-#endif
-      case C_TPDEF:            /* type definition               */
-      case C_ARG:
-      case C_AUTO:             /* automatic variable */
-      case C_FIELD:            /* bit field */
-      case C_ENTAG:            /* enumeration tag               */
-      case C_MOE:              /* member of enumeration         */
-      case C_MOU:              /* member of union               */
-      case C_UNTAG:            /* union tag                     */
-       dst->symbol.flags = BSF_DEBUGGING;
-       dst->symbol.value = (src->u.syment.n_value);
-       break;
-
-      case C_FILE:             /* file name                     */
-      case C_STRTAG:           /* structure tag                 */
+           case C_AUTOARG:     /* 960-specific storage class */
+#endif
+           case C_TPDEF:       /* type definition               */
+           case C_ARG:
+           case C_AUTO:        /* automatic variable */
+           case C_FIELD:       /* bit field */
+           case C_ENTAG:       /* enumeration tag               */
+           case C_MOE: /* member of enumeration         */
+           case C_MOU: /* member of union               */
+           case C_UNTAG:       /* union tag                     */
+             dst->symbol.flags = BSF_DEBUGGING;
+             dst->symbol.value = (src->u.syment.n_value);
+             break;
+
+           case C_FILE:        /* file name                     */
+           case C_STRTAG:      /* structure tag                 */
 #ifdef RS6000COFF_C
-      case C_BINCL:            /* beginning of include file     */
-      case C_EINCL:            /* ending of include file        */
-      case C_GSYM:
-      case C_LSYM:
-      case C_PSYM:
-      case C_RSYM:
-      case C_RPSYM:
-      case C_STSYM:
-      case C_DECL:
-      case C_ENTRY:
-      case C_FUN:
-      case C_BSTAT:
-      case C_ESTAT:
-#endif
-       dst->symbol.flags = BSF_DEBUGGING;
-       dst->symbol.value = (src->u.syment.n_value);
-       break;
+           case C_BINCL:       /* beginning of include file     */
+           case C_EINCL:       /* ending of include file        */
+           case C_GSYM:
+           case C_LSYM:
+           case C_PSYM:
+           case C_RSYM:
+           case C_RPSYM:
+           case C_STSYM:
+           case C_DECL:
+           case C_ENTRY:
+           case C_FUN:
+           case C_ESTAT:
+#endif
+             dst->symbol.flags = BSF_DEBUGGING;
+             dst->symbol.value = (src->u.syment.n_value);
+             break;
 
-      case C_BLOCK:            /* ".bb" or ".eb"                */
-      case C_FCN:              /* ".bf" or ".ef"                */
-      case C_EFCN:             /* physical end of function      */
-       dst->symbol.flags = BSF_LOCAL;
-       /*
+#ifdef RS6000COFF_C
+           case C_BSTAT:
+             dst->symbol.flags = BSF_DEBUGGING;
+             dst->symbol.value = src->u.syment.n_value;
+
+             /* The value is actually a symbol index.  Save a pointer to
+          the symbol instead of the index.  FIXME: This should use a
+          union.  */
+             src->u.syment.n_value =
+               (long) (native_symbols + src->u.syment.n_value);
+             src->fix_value = 1;
+             break;
+#endif
+
+           case C_BLOCK:       /* ".bb" or ".eb"                */
+           case C_FCN: /* ".bf" or ".ef"                */
+           case C_EFCN:        /* physical end of function      */
+             dst->symbol.flags = BSF_LOCAL;
+             /*
          Base the value as an index from the base of the section
          */
-       dst->symbol.value = (src->u.syment.n_value) - dst->symbol.section->vma;
-       break;
-
-      case C_NULL:
-      case C_EXTDEF:           /* external definition           */
-      case C_ULABEL:           /* undefined label               */
-      case C_USTATIC:          /* undefined static              */
-      case C_LINE:             /* line # reformatted as symbol table entry */
-      case C_ALIAS:            /* duplicate tag                 */
-      case C_HIDDEN:           /* ext symbol in dmert public lib */
-      default:
-
-       fprintf(stderr,"Unrecognized storage class %d (assuming debugging)\n  for %s symbol `%s'\n",
-               src->u.syment.n_sclass, dst->symbol.section->name,
-               dst->symbol.name);
+             dst->symbol.value = (src->u.syment.n_value) - dst->symbol.section->vma;
+             break;
+
+           case C_NULL:
+           case C_EXTDEF:      /* external definition           */
+           case C_ULABEL:      /* undefined label               */
+           case C_USTATIC:     /* undefined static              */
+           case C_LINE:        /* line # reformatted as symbol table entry */
+           case C_ALIAS:       /* duplicate tag                 */
+           case C_HIDDEN:      /* ext symbol in dmert public lib */
+           default:
+
+             fprintf (stderr, "Unrecognized storage class %d (assuming debugging)\n  for %s symbol `%s'\n",
+                      src->u.syment.n_sclass, dst->symbol.section->name,
+                      dst->symbol.name);
 /*     abort();*/
-       dst->symbol.flags = BSF_DEBUGGING;
-       dst->symbol.value = (src->u.syment.n_value);
-       break;
-      }
+             dst->symbol.flags = BSF_DEBUGGING;
+             dst->symbol.value = (src->u.syment.n_value);
+             break;
+           }
 
 /*      BFD_ASSERT(dst->symbol.flags != 0);*/
 
-      dst->native = src;
+         dst->native = src;
 
-      dst->symbol.udata = 0;
-      dst->lineno = (alent *) NULL;
-      this_index += (src->u.syment.n_numaux) + 1;
-      dst++;
-      number_of_symbols++;
-    }                          /* walk the native symtab */
-  }                            /* bfdize the native symtab */
+         dst->symbol.udata = 0;
+         dst->lineno = (alent *) NULL;
+         this_index += (src->u.syment.n_numaux) + 1;
+         dst++;
+         number_of_symbols++;
+       }                       /* walk the native symtab */
+    }                          /* bfdize the native symtab */
 
-  obj_symbols(abfd) = cached_area;
-  obj_raw_syments(abfd) = native_symbols;
+  obj_symbols (abfd) = cached_area;
+  obj_raw_syments (abfd) = native_symbols;
 
   obj_conv_table_size (abfd) = bfd_get_symcount (abfd);
-  bfd_get_symcount(abfd) = number_of_symbols;
-  obj_convert(abfd) = table_ptr;
+  bfd_get_symcount (abfd) = number_of_symbols;
+  obj_convert (abfd) = table_ptr;
   /* Slurp the line tables for each section too */
-    {
-      asection       *p;
-      p = abfd->sections;
-      while (p) {
-       coff_slurp_line_table(abfd, p);
+  {
+    asection *p;
+    p = abfd->sections;
+    while (p)
+      {
+       coff_slurp_line_table (abfd, p);
        p = p->next;
       }
-    }
+  }
   return true;
 }                              /* coff_slurp_symbol_table() */
 
 /*
-SUBSUBSECTION 
+SUBSUBSECTION
        Reading relocations
 
        Coff relocations are easily transformed into the internal BFD form
@@ -2170,79 +2273,80 @@ SUBSUBSECTION
            }                                           \
            else {                                      \
                cache_ptr->addend = 0;                  \
-           }                   
+           }
 #endif
 
-static          boolean
-DEFUN(coff_slurp_reloc_table,(abfd, asect, symbols),
-      bfd            *abfd AND
-      sec_ptr         asect AND
-      asymbol       **symbols)
+static boolean
+DEFUN (coff_slurp_reloc_table, (abfd, asect, symbols),
+       bfd * abfd AND
+       sec_ptr asect AND
+       asymbol ** symbols)
 {
-  RELOC   *native_relocs;
-  arelent        *reloc_cache;
-  arelent        *cache_ptr;
+  RELOC *native_relocs;
+  arelent *reloc_cache;
+  arelent *cache_ptr;
 
   unsigned int idx;
-  
+
   if (asect->relocation)
-   return true;
+    return true;
   if (asect->reloc_count == 0)
-   return true;
+    return true;
   if (asect->flags & SEC_CONSTRUCTOR)
-   return true;
-  if (!coff_slurp_symbol_table(abfd))
-   return false;
+    return true;
+  if (!coff_slurp_symbol_table (abfd))
+    return false;
   native_relocs =
-   (RELOC *) buy_and_read(abfd,
-                         asect->rel_filepos,
-                         SEEK_SET,
-                         (size_t) (RELSZ *
-                                   asect->reloc_count));
+    (RELOC *) buy_and_read (abfd,
+                           asect->rel_filepos,
+                           SEEK_SET,
+                           (size_t) (RELSZ *
+                                     asect->reloc_count));
   reloc_cache = (arelent *)
-   bfd_alloc(abfd, (size_t) (asect->reloc_count * sizeof(arelent)));
+    bfd_alloc (abfd, (size_t) (asect->reloc_count * sizeof (arelent)));
 
-  if (reloc_cache == NULL) {
+  if (reloc_cache == NULL)
+    {
       bfd_error = no_memory;
       return false;
-    } 
+    }
 
-  
-  for (idx = 0; idx < asect->reloc_count; idx ++) 
-  {
+
+  for (idx = 0; idx < asect->reloc_count; idx++)
+    {
 #ifdef RELOC_PROCESSING
       struct internal_reloc dst;
-      struct external_reloc  *src;
+      struct external_reloc *src;
 
       cache_ptr = reloc_cache + idx;
       src = native_relocs + idx;
-      bfd_swap_reloc_in(abfd, src, &dst);
+      bfd_swap_reloc_in (abfd, src, &dst);
 
-      RELOC_PROCESSING(cache_ptr, &dst, symbols, abfd, asect);
+      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
 #else
       struct internal_reloc dst;
-      asymbol        *ptr;
-      struct external_reloc  *src;
+      asymbol *ptr;
+      struct external_reloc *src;
 
       cache_ptr = reloc_cache + idx;
       src = native_relocs + idx;
 
-      bfd_swap_reloc_in(abfd, src, &dst);
+      bfd_swap_reloc_in (abfd, src, &dst);
 
 
       cache_ptr->address = dst.r_vaddr;
 
-      if (dst.r_symndx != -1) 
+      if (dst.r_symndx != -1)
        {
          /* @@ Should never be greater than count of symbols!  */
          if (dst.r_symndx >= obj_conv_table_size (abfd))
            abort ();
-         cache_ptr->sym_ptr_ptr = symbols + obj_convert(abfd)[dst.r_symndx];
+         cache_ptr->sym_ptr_ptr = symbols + obj_convert (abfd)[dst.r_symndx];
          ptr = *(cache_ptr->sym_ptr_ptr);
        }
-      else 
+      else
        {
-         cache_ptr->sym_ptr_ptr= bfd_abs_section.symbol_ptr_ptr;
+         cache_ptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
          ptr = 0;
        }
 
@@ -2254,16 +2358,16 @@ DEFUN(coff_slurp_reloc_table,(abfd, asect, symbols),
         Note that symbols which used to be common must be left alone */
 
       /* Calculate any reloc addend by looking at the symbol */
-      CALC_ADDEND(abfd, ptr, dst, cache_ptr);
+      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
 
       cache_ptr->address -= asect->vma;
 /* !!     cache_ptr->section = (asection *) NULL;*/
 
       /* Fill in the cache_ptr->howto field from dst.r_type */
-      RTYPE2HOWTO(cache_ptr, &dst);
+      RTYPE2HOWTO (cache_ptr, &dst);
 #endif
 
-  }
+    }
 
   asect->relocation = reloc_cache;
   return true;
@@ -2272,54 +2376,54 @@ DEFUN(coff_slurp_reloc_table,(abfd, asect, symbols),
 
 /* This is stupid.  This function should be a boolean predicate.  */
 static unsigned int
-DEFUN(coff_canonicalize_reloc, (abfd, section, relptr, symbols),
-bfd            *abfd AND
-sec_ptr         section AND
-arelent       **relptr AND
-asymbol       **symbols)
+DEFUN (coff_canonicalize_reloc, (abfd, section, relptr, symbols),
+       bfd * abfd AND
+       sec_ptr section AND
+       arelent ** relptr AND
+       asymbol ** symbols)
 {
-  arelent        *tblptr = section->relocation;
-  unsigned int    count = 0;
+  arelent *tblptr = section->relocation;
+  unsigned int count = 0;
 
 
-  if (section->flags & SEC_CONSTRUCTOR) 
-  {
-    /* this section has relocs made up by us, they are not in the
+  if (section->flags & SEC_CONSTRUCTOR)
+    {
+      /* this section has relocs made up by us, they are not in the
        file, so take them out of their chain and place them into
        the data area provided */
-    arelent_chain *chain = section->constructor_chain;
-    for (count = 0; count < section->reloc_count; count ++) 
-    {
-      *relptr ++ = &chain->relent;
-      chain = chain->next;
-    }
+      arelent_chain *chain = section->constructor_chain;
+      for (count = 0; count < section->reloc_count; count++)
+       {
+         *relptr++ = &chain->relent;
+         chain = chain->next;
+       }
 
-  }
-  else 
-  { 
-    coff_slurp_reloc_table(abfd, section, symbols);
+    }
+  else
+    {
+      coff_slurp_reloc_table (abfd, section, symbols);
 
 
-    tblptr = section->relocation;
-    if (!tblptr)
-     return 0;
+      tblptr = section->relocation;
+      if (!tblptr)
+       return 0;
 
-    for (; count++ < section->reloc_count;)
-     *relptr++ = tblptr++;
+      for (; count++ < section->reloc_count;)
+       *relptr++ = tblptr++;
 
 
-  }
+    }
   *relptr = 0;
   return section->reloc_count;
 }
 
 #ifdef GNU960
 file_ptr
-coff_sym_filepos(abfd)
-bfd *abfd;
-  {
-    return obj_sym_filepos(abfd);
-  }
+coff_sym_filepos (abfd)
+     bfd *abfd;
+{
+  return obj_sym_filepos (abfd);
+}
 #endif
 
 #ifndef coff_reloc16_estimate
@@ -2352,28 +2456,29 @@ dummy_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
      unsigned int *src_ptr;
      unsigned int *dst_ptr;
 {
-  fprintf(stderr, "%s\n", reloc->howto->name);
+  fprintf (stderr, "%s\n", reloc->howto->name);
   abort ();
 }
 #endif
 
-static CONST bfd_coff_backend_data bfd_coff_std_swap_table = {
- coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in,
- coff_swap_aux_out, coff_swap_sym_out,
- coff_swap_lineno_out, coff_swap_reloc_out,
- coff_swap_filehdr_out, coff_swap_aouthdr_out,
- coff_swap_scnhdr_out,
- FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, LINESZ,
+static CONST bfd_coff_backend_data bfd_coff_std_swap_table =
+{
+  coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in,
+  coff_swap_aux_out, coff_swap_sym_out,
+  coff_swap_lineno_out, coff_swap_reloc_out,
+  coff_swap_filehdr_out, coff_swap_aouthdr_out,
+  coff_swap_scnhdr_out,
+  FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, LINESZ,
 #ifdef COFF_LONG_FILENAMES
- true,
 true,
 #else
- false,
 false,
 #endif
- coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
- coff_bad_format_hook, coff_set_arch_mach_hook, coff_mkobject_hook,
- styp_to_sec_flags, coff_make_section_hook, coff_set_alignment_hook,
- coff_slurp_symbol_table, symname_in_debug_hook, 
- coff_reloc16_extra_cases, coff_reloc16_estimate
 coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
 coff_bad_format_hook, coff_set_arch_mach_hook, coff_mkobject_hook,
 styp_to_sec_flags, coff_make_section_hook, coff_set_alignment_hook,
+  coff_slurp_symbol_table, symname_in_debug_hook,
 coff_reloc16_extra_cases, coff_reloc16_estimate
 };
 
 #define coff_core_file_failing_command _bfd_dummy_core_file_failing_command
index c9a570fab90353b0c4fc55ccaa5505a12a0637e6..d3a3582f83c59941495fe695c7337b0b6ff38ee3 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for the generic parts of COFF, for BFD.
-   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -132,6 +132,11 @@ DEFUN(coff_real_object_p,(abfd, nscns, internal_f, internal_a),
   scnhsz = bfd_coff_scnhsz (abfd);
   readsize = nscns * scnhsz;
   external_sections = (char *)bfd_alloc(abfd, readsize);
+  if (!external_sections)
+    {
+      bfd_error = no_memory;
+      goto fail;
+    }
 
   if (bfd_read((PTR)external_sections, 1, readsize, abfd) != readsize) {
     goto fail;
@@ -420,7 +425,7 @@ struct internal_syment *syment)
  do that here too.
 
 */
-void
+boolean
 DEFUN(coff_renumber_symbols,(bfd_ptr),
       bfd *bfd_ptr)
 {
@@ -444,6 +449,11 @@ DEFUN(coff_renumber_symbols,(bfd_ptr),
     newsyms = (asymbol **) bfd_alloc_by_size_t (bfd_ptr,
                                                sizeof (asymbol *)
                                                * (symbol_count + 1));
+    if (!newsyms)
+      {
+       bfd_error = no_memory;
+       return false;
+      }
     bfd_ptr->outsymbols = newsyms;
     for (i = 0; i < symbol_count; i++)
       if (symbol_ptr_ptr[i]->section != &bfd_und_section)
@@ -485,6 +495,7 @@ DEFUN(coff_renumber_symbols,(bfd_ptr),
        }
       }
   obj_conv_table_size (bfd_ptr) = native_index;
+  return true;
 }
 
 /*
@@ -493,42 +504,59 @@ DEFUN(coff_renumber_symbols,(bfd_ptr),
 
 */
 void
-DEFUN(coff_mangle_symbols,(bfd_ptr),
-      bfd *bfd_ptr)
+coff_mangle_symbols (bfd_ptr)
+     bfd *bfd_ptr;
 {
-  unsigned int symbol_count = bfd_get_symcount(bfd_ptr);
+  unsigned int symbol_count = bfd_get_symcount (bfd_ptr);
   asymbol **symbol_ptr_ptr = bfd_ptr->outsymbols;
   unsigned int symbol_index;
 
   for (symbol_index = 0; symbol_index < symbol_count; symbol_index++)
-      {
-       coff_symbol_type *coff_symbol_ptr =
-         coff_symbol_from(bfd_ptr, symbol_ptr_ptr[symbol_index]);
+    {
+      coff_symbol_type *coff_symbol_ptr =
+       coff_symbol_from (bfd_ptr, symbol_ptr_ptr[symbol_index]);
 
-       if (coff_symbol_ptr && coff_symbol_ptr->native) {
+      if (coff_symbol_ptr && coff_symbol_ptr->native)
+       {
          int i;
          combined_entry_type *s = coff_symbol_ptr->native;
 
-         for (i = 0; i < s->u.syment.n_numaux ; i++) {
-           combined_entry_type *a = s + i + 1;
-           if (a->fix_tag) {
-             a->u.auxent.x_sym.x_tagndx.l =
-               a->u.auxent.x_sym.x_tagndx.p->offset;
-             a->fix_tag = 0;
+         if (s->fix_value)
+           {
+             /* FIXME: We should use a union here.  */
+             s->u.syment.n_value =
+               ((combined_entry_type *) s->u.syment.n_value)->offset;
+             s->fix_value = 0;
            }
-           if (a->fix_end) {
-             a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l =
-               a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p->offset;
-             a->fix_end = 0;
-             
+         for (i = 0; i < s->u.syment.n_numaux ; i++)
+           {
+             combined_entry_type *a = s + i + 1;
+             if (a->fix_tag)
+               {
+                 a->u.auxent.x_sym.x_tagndx.l =
+                   a->u.auxent.x_sym.x_tagndx.p->offset;
+                 a->fix_tag = 0;
+               }
+             if (a->fix_end)
+               {
+                 a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l =
+                   a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p->offset;
+                 a->fix_end = 0;
+               }
+             if (a->fix_scnlen)
+               {
+                 a->u.auxent.x_csect.x_scnlen.l =
+                   a->u.auxent.x_csect.x_scnlen.p->offset;
+                 a->fix_scnlen = 0;
+               }
            }
-
-         }
        }
-      }
+    }
 }
 
-static int string_size;
+static bfd_size_type string_size;
+static bfd_size_type debug_string_size;
+static asection *debug_string_section;
 
 static void
 DEFUN(coff_fix_symbol_name,(abfd, symbol, native),
@@ -569,17 +597,50 @@ DEFUN(coff_fix_symbol_name,(abfd, symbol, native),
     }
   }
   else
-      {                                /* NOT A C_FILE SYMBOL */
-       if (name_length <= SYMNMLEN) {
+    {                          /* NOT A C_FILE SYMBOL */
+      if (name_length <= SYMNMLEN)
+       {
          /* This name will fit into the symbol neatly */
          strncpy(native->u.syment._n._n_name, symbol->name, SYMNMLEN);
        }
-       else {
+      else if (! bfd_coff_symname_in_debug (abfd, &native->u.syment))
+       {
          native->u.syment._n._n_n._n_offset =  string_size + 4;
          native->u.syment._n._n_n._n_zeroes = 0;
          string_size += name_length + 1;
        }
-      }
+      else
+       {
+         long filepos;
+         bfd_byte buf[2];
+
+         /* This name should be written into the .debug section.  For
+            some reason each name is preceded by a two byte length
+            and also followed by a null byte.  FIXME: We assume that
+            the .debug section has already been created, and that it
+            is large enough.  */
+         if (debug_string_section == (asection *) NULL)
+           debug_string_section = bfd_get_section_by_name (abfd, ".debug");
+         filepos = bfd_tell (abfd);
+         bfd_put_16 (abfd, name_length + 1, buf);
+         if (! bfd_set_section_contents (abfd,
+                                         debug_string_section,
+                                         (PTR) buf,
+                                         (file_ptr) debug_string_size,
+                                         (bfd_size_type) 2)
+             || ! bfd_set_section_contents (abfd,
+                                            debug_string_section,
+                                            (PTR) symbol->name,
+                                            (file_ptr) debug_string_size + 2,
+                                            (bfd_size_type) name_length + 1))
+           abort ();
+         if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
+           abort ();
+         native->u.syment._n._n_n._n_offset = debug_string_size + 2;
+         native->u.syment._n._n_n._n_zeroes = 0;
+         debug_string_size += name_length + 3;
+       }
+    }
 }
 
 #define        set_index(symbol, idx)  ((symbol)->udata =(PTR) (idx))
@@ -625,6 +686,11 @@ unsigned int written)
 
   symesz = bfd_coff_symesz (abfd);
   buf = bfd_alloc (abfd, symesz);
+  if (!buf)
+    {
+      bfd_error = no_memory;
+      abort();                 /* FIXME */
+    }
   bfd_coff_swap_sym_out(abfd, &native->u.syment, buf);
   bfd_write(buf, 1, symesz, abfd);
   bfd_release (abfd, buf);
@@ -636,6 +702,11 @@ unsigned int written)
 
       auxesz = bfd_coff_auxesz (abfd);
       buf = bfd_alloc (abfd, auxesz);
+      if (!buf)
+       {
+         bfd_error = no_memory;
+         abort();              /* FIXME */
+       }
       for (j = 0; j < native->u.syment.n_numaux;  j++)
        {
          bfd_coff_swap_aux_out(abfd,
@@ -785,7 +856,7 @@ DEFUN(coff_write_symbols,(abfd),
   asymbol       **p;
 
   string_size = 0;
-
+  debug_string_size = 0;
 
   /* Seek to the right place */
   bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET);
@@ -833,9 +904,10 @@ DEFUN(coff_write_symbols,(abfd),
                     (c_symbol->native->u.syment.n_sclass == C_FILE)) ?
             FILNMLEN : SYMNMLEN;
 
-          if (name_length > maxlen) {
+          if (name_length > maxlen
+              && ! bfd_coff_symname_in_debug (abfd,
+                                              &c_symbol->native->u.syment))
             bfd_write((PTR) (q->name), 1, name_length + 1, abfd);
-          }
         }
    }
   else {
@@ -848,9 +920,15 @@ DEFUN(coff_write_symbols,(abfd),
     bfd_h_put_32 (abfd, size, buffer);
     bfd_write((PTR) buffer, 1, sizeof (buffer), abfd);
   }
+
+  BFD_ASSERT (debug_string_size == 0
+             || (debug_string_section != (asection *) NULL
+                 && (BFD_ALIGN (debug_string_size,
+                                1 << debug_string_section->alignment_power)
+                     == bfd_section_size (abfd, debug_string_section))));
 }
 
-void
+boolean
 DEFUN(coff_write_linenumbers,(abfd),
       bfd            *abfd)
 {
@@ -860,6 +938,11 @@ DEFUN(coff_write_linenumbers,(abfd),
 
   linesz = bfd_coff_linesz (abfd);
   buff = bfd_alloc (abfd, linesz);
+  if (!buff)
+    {
+      bfd_error = no_memory;
+      return;
+    }
   for (s = abfd->sections; s != (asection *) NULL; s = s->next) {
     if (s->lineno_count) {
       asymbol       **q = abfd->outsymbols;
@@ -893,6 +976,7 @@ DEFUN(coff_write_linenumbers,(abfd),
     }
   }
   bfd_release (abfd, buff);
+  return true;
 }
 
 /*ARGSUSED*/
@@ -925,6 +1009,11 @@ coff_section_symbol (abfd, name)
       };
       struct foo *f;
       f = (struct foo *) bfd_alloc_by_size_t (abfd, sizeof (*f));
+      if (!f)
+       {
+         bfd_error = no_error;
+         return NULL;
+       }
       memset ((char *) f, 0, sizeof (*f));
       coff_symbol_from (abfd, sym)->native = csym = f->e;
     }
@@ -1106,11 +1195,21 @@ bfd            *abfd)
     }
 
   internal = (combined_entry_type *)bfd_alloc(abfd, size);
+  if (!internal)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   internal_end = internal + bfd_get_symcount(abfd);
 
   symesz = bfd_coff_symesz (abfd);
   raw_size =      bfd_get_symcount(abfd) * symesz;
   raw = bfd_alloc(abfd,raw_size);
+  if (!raw)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   if (bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET) == -1
       || bfd_read(raw, raw_size, 1, abfd) != raw_size) {
@@ -1131,8 +1230,10 @@ bfd            *abfd)
 
       unsigned int i;
       bfd_coff_swap_sym_in(abfd, (PTR)raw_src, (PTR)&internal_ptr->u.syment);
+      internal_ptr->fix_value = 0;
       internal_ptr->fix_tag = 0;
       internal_ptr->fix_end = 0;
+      internal_ptr->fix_scnlen = 0;
       symbol_ptr = internal_ptr;
 
       for (i = 0;
@@ -1142,8 +1243,10 @@ bfd            *abfd)
        internal_ptr++;
        raw_src += symesz;
       
+       internal_ptr->fix_value = 0;
        internal_ptr->fix_tag = 0;
        internal_ptr->fix_end = 0;
+       internal_ptr->fix_scnlen = 0;
        bfd_coff_swap_aux_in(abfd, (PTR) raw_src,
                             symbol_ptr->u.syment.n_type,
                             symbol_ptr->u.syment.n_sclass,
@@ -1212,6 +1315,8 @@ bfd            *abfd)
            internal_ptr->u.syment._n._n_n._n_offset =  (long int) newstring;
            internal_ptr->u.syment._n._n_n._n_zeroes = 0;
          }
+       else if (internal_ptr->u.syment._n._n_n._n_offset == 0)
+         internal_ptr->u.syment._n._n_n._n_offset = (long int) "";
        else if (!bfd_coff_symname_in_debug(abfd, &internal_ptr->u.syment)) {
            /* Long name already.  Point symbol at the string in the table.  */
            if (string_table == NULL) {
@@ -1259,6 +1364,7 @@ DEFUN (coff_make_empty_symbol, (abfd),
     bfd_error = no_memory;
     return (NULL);
   }                            /* on error */
+  memset (new, 0, sizeof *new);
   new->symbol.section = 0;
   new->native = 0;
   new->lineno = (alent *) NULL;
@@ -1282,6 +1388,11 @@ coff_bfd_make_debug_symbol (abfd, ptr, sz)
   }                            /* on error */
   /* @@ This shouldn't be using a constant multiplier.  */
   new->native = (combined_entry_type *) bfd_zalloc (abfd, sizeof (combined_entry_type) * 10);
+  if (!new->native)
+    {
+      bfd_error = no_memory;
+      return (NULL);
+    }                          /* on error */
   new->symbol.section = &bfd_debug_section;
   new->lineno = (alent *) NULL;
   new->done_lineno = false;
index 702ddc038262d7160a02bd1f3d7378efda30e1d9..7c21b7421b38a7639d925c91019955094bcfb913 100644 (file)
@@ -95,7 +95,7 @@ INTERNAL_FUNCTION
        bfd_constructor_entry 
 
 SYNOPSIS
-       void bfd_constructor_entry(bfd *abfd, 
+       boolean bfd_constructor_entry(bfd *abfd, 
                asymbol **symbol_ptr_ptr,
                CONST char*type);
 
@@ -109,10 +109,13 @@ DESCRIPTION
        have one, and grow a relocation table for the entry points as
        they accumulate.
 
+       Return <<true>> if successful, <<false>> if out of memory.
+
 */
 
  
-void DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type),
+boolean
+DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type),
           bfd *abfd AND
           asymbol **symbol_ptr_ptr AND
           CONST char *type)
@@ -130,6 +133,11 @@ void DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type),
    {
        arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd,
                                                         sizeof(arelent_chain));
+       if (!reloc)
+        {
+          bfd_error = no_memory;
+          return false;
+        }
 
 /*       reloc->relent.section = (asection *)NULL;*/
        reloc->relent.addend = 0;
@@ -143,5 +151,5 @@ void DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type),
        rel_section->_cooked_size += sizeof(int *);
        rel_section->reloc_count++;
    }
-
+    return true;
 }
index 3ff608486b242590d15ac5c0e023f04d06fa946b..735ab26e857c4d96dc3fbfac1fee4145d62d6a27 100644 (file)
@@ -46,7 +46,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 static int ecoff_get_magic PARAMS ((bfd *abfd));
 static boolean ecoff_slurp_symbolic_header PARAMS ((bfd *abfd));
-static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
+static boolean ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
                                           asymbol *asym, int ext,
                                           asymbol **indirect_ptr_ptr));
 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
@@ -831,7 +831,7 @@ ecoff_make_empty_symbol (abfd)
 
 /* Set the BFD flags and section for an ECOFF symbol.  */
 
-static void
+static boolean
 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
      bfd *abfd;
      SYMR *ecoff_sym;
@@ -859,7 +859,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       asym->flags = BSF_DEBUGGING;
       asym->section = &bfd_und_section;
       *indirect_ptr_ptr = NULL;
-      return;
+      return true;
     }
 
   if (ECOFF_IS_STAB (ecoff_sym)
@@ -869,7 +869,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       asym->section = &bfd_ind_section;
       /* Pass this symbol on to the next call to this function.  */
       *indirect_ptr_ptr = asym;
-      return;
+      return true;
     }
 
   /* Most symbol types are just for debugging.  */
@@ -885,12 +885,12 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       if (ECOFF_IS_STAB (ecoff_sym))
        {
          asym->flags = BSF_DEBUGGING;
-         return;
+         return true;
        }
       break;
     default:
       asym->flags = BSF_DEBUGGING;
-      return;
+      return true;
     }
 
   if (ext)
@@ -1042,6 +1042,11 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
                char *copy;
 
                copy = (char *) bfd_alloc (abfd, strlen (name) + 1);
+               if (!copy)
+                 {
+                   bfd_error = no_memory;
+                   return false;
+                 }
                strcpy (copy, name);
                section = bfd_make_section (abfd, copy);
              }
@@ -1049,6 +1054,11 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
            /* Build a reloc pointing to this constructor.  */
            reloc_chain =
              (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
+           if (!reloc_chain)
+             {
+               bfd_error = no_memory;
+               return false;
+             }
            reloc_chain->relent.sym_ptr_ptr =
              bfd_get_section (asym)->symbol_ptr_ptr;
            reloc_chain->relent.address = section->_raw_size;
@@ -1079,6 +1089,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
          break;
        }
     }
+  return true;
 }
 
 /* Read an ECOFF symbol table.  */
@@ -1136,8 +1147,9 @@ ecoff_slurp_symbol_table (abfd)
       (*swap_ext_in) (abfd, (PTR) eraw_src, &internal_esym);
       internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
                                   + internal_esym.asym.iss);
-      ecoff_set_symbol_info (abfd, &internal_esym.asym,
-                            &internal_ptr->symbol, 1, &indirect_ptr);
+      if (!ecoff_set_symbol_info (abfd, &internal_esym.asym,
+                            &internal_ptr->symbol, 1, &indirect_ptr))
+       return false;
       /* The alpha uses a negative ifd field for section symbols.  */
       if (internal_esym.ifd >= 0)
        internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
@@ -1171,8 +1183,9 @@ ecoff_slurp_symbol_table (abfd)
          internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ss
                                       + fdr_ptr->issBase
                                       + internal_sym.iss);
-         ecoff_set_symbol_info (abfd, &internal_sym,
-                                &internal_ptr->symbol, 0, &indirect_ptr);
+         if (!ecoff_set_symbol_info (abfd, &internal_sym,
+                                     &internal_ptr->symbol, 0, &indirect_ptr))
+           return false;
          internal_ptr->fdr = fdr_ptr;
          internal_ptr->local = true;
          internal_ptr->native = (PTR) lraw_src;
@@ -3047,6 +3060,12 @@ ecoff_slurp_armap (abfd)
   symdef_ptr = ((struct symdef *)
                bfd_alloc (abfd,
                           ardata->symdef_count * sizeof (struct symdef)));
+  if (!symdef_ptr)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
+
   ardata->symdefs = (carsym *) symdef_ptr;
 
   raw_ptr = raw_armap + 4;
@@ -3158,6 +3177,11 @@ ecoff_write_armap (abfd, elength, map, orl_count, stridx)
     return false;
   
   hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
+  if (!hashtable)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   current = abfd->archive_head;
   last_elt = current;
@@ -3308,15 +3332,23 @@ ecoff_link_hash_newfunc (entry, table, string)
   if (ret == (struct ecoff_link_hash_entry *) NULL)
     ret = ((struct ecoff_link_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct ecoff_link_hash_entry)));
+  if (ret == (struct ecoff_link_hash_entry *) NULL)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct ecoff_link_hash_entry *)
         _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
                                 table, string));
 
-  /* Set local fields.  */
-  ret->indx = -1;
-  ret->abfd = NULL;
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->indx = -1;
+      ret->abfd = NULL;
+    }
   memset (&ret->esym, 0, sizeof ret->esym);
 
   return (struct bfd_hash_entry *) ret;
@@ -3710,6 +3742,11 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
   sym_hash = ((struct ecoff_link_hash_entry **)
              bfd_alloc (abfd,
                         ext_count * sizeof (struct bfd_link_hash_entry *)));
+  if (!sym_hash)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   ecoff_data (abfd)->sym_hashes = sym_hash;
 
   ext_ptr = (char *) external_ext;
index 306f028e11637e0a9e25b7a2c8fcf57f46d4e000..7fd34cb6ff6031bf1457b4a408a29ebda3843f30 100644 (file)
@@ -41,7 +41,7 @@ static boolean ecoff_write_symhdr PARAMS ((bfd *, struct ecoff_debug_info *,
                                           file_ptr where));
 
 /* Obstack allocation and deallocation routines.  */
-#define obstack_chunk_alloc bfd_xmalloc_by_size_t
+#define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
 \f
 /* The minimum amount of data to allocate.  */
@@ -115,14 +115,22 @@ string_hash_newfunc (entry, table, string)
   if (ret == (struct string_hash_entry *) NULL)
     ret = ((struct string_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct string_hash_entry)));
+  if (ret == (struct string_hash_entry *) NULL)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct string_hash_entry *)
         bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
 
-  /* Initialize the local fields.  */
-  ret->val = -1;
-  ret->next = NULL;
+  if (ret)
+    {
+      /* Initialize the local fields.  */
+      ret->val = -1;
+      ret->next = NULL;
+    }
 
   return (struct bfd_hash_entry *) ret;
 }
@@ -197,12 +205,12 @@ struct accumulate
 
 /* Add a file entry to a shuffle list.  */
 
-static void add_file_shuffle PARAMS ((struct accumulate *,
+static boolean add_file_shuffle PARAMS ((struct accumulate *,
                                      struct shuffle **,
                                      struct shuffle **, bfd *, file_ptr,
                                      unsigned long));
 
-static void
+static boolean
 add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
      struct accumulate *ainfo;
      struct shuffle **head;
@@ -222,11 +230,16 @@ add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
       (*tail)->size += size;
       if ((*tail)->size > ainfo->largest_file_shuffle)
        ainfo->largest_file_shuffle = (*tail)->size;
-      return;
+      return true;
     }
 
   n = (struct shuffle *) obstack_alloc (&ainfo->memory,
                                        sizeof (struct shuffle));
+  if (!n)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   n->next = NULL;
   n->size = size;
   n->filep = true;
@@ -239,16 +252,17 @@ add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
   *tail = n;
   if (size > ainfo->largest_file_shuffle)
     ainfo->largest_file_shuffle = size;
+  return true;
 }
 
 /* Add a memory entry to a shuffle list.  */
 
-static void add_memory_shuffle PARAMS ((struct accumulate *,
-                                       struct shuffle **head,
-                                       struct shuffle **tail,
-                                       bfd_byte *data, unsigned long size));
+static boolean add_memory_shuffle PARAMS ((struct accumulate *,
+                                          struct shuffle **head,
+                                          struct shuffle **tail,
+                                          bfd_byte *data, unsigned long size));
 
-static void
+static boolean
 add_memory_shuffle (ainfo, head, tail, data, size)
      struct accumulate *ainfo;
      struct shuffle **head;
@@ -260,6 +274,11 @@ add_memory_shuffle (ainfo, head, tail, data, size)
      
   n = (struct shuffle *) obstack_alloc (&ainfo->memory,
                                        sizeof (struct shuffle));
+  if (!n)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   n->next = NULL;
   n->size = size;
   n->filep = false;
@@ -269,6 +288,7 @@ add_memory_shuffle (ainfo, head, tail, data, size)
   if (*tail != (struct shuffle *) NULL)
     (*tail)->next = n;
   *tail = n;
+  return true;
 }
 
 /* Initialize the FDR hash table.  This returns a handle which is then
@@ -284,7 +304,12 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
 {
   struct accumulate *ainfo;
 
-  ainfo = (struct accumulate *) bfd_xmalloc (sizeof (struct accumulate));
+  ainfo = (struct accumulate *) malloc (sizeof (struct accumulate));
+  if (!ainfo)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   if (! bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
                               1021))
     return NULL;
@@ -319,7 +344,11 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
       output_debug->symbolic_header.issMax = 1;
     }
 
-  obstack_begin (&ainfo->memory, 4050);
+  if (!obstack_begin (&ainfo->memory, 4050))
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   return (PTR) ainfo;
 }
@@ -447,7 +476,13 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
 
   sz = (input_symhdr->crfd + input_symhdr->ifdMax) * external_rfd_size;
   rfd_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
-  add_memory_shuffle (ainfo, &ainfo->rfd, &ainfo->rfd_end, rfd_out, sz);
+  if (!input_debug->ifdmap || !rfd_out)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
+  if (!add_memory_shuffle (ainfo, &ainfo->rfd, &ainfo->rfd_end, rfd_out, sz))
+    return false;
 
   copied = 0;
 
@@ -537,7 +572,13 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
      information.  */
   sz = copied * external_fdr_size;
   fdr_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
-  add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end, fdr_out, sz);
+  if (!fdr_out)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
+  if (!add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end, fdr_out, sz))
+    return false;
   for (fdr_ptr = fdr_start, i = 0;
        fdr_ptr < fdr_end;
        fdr_ptr += fdr_add, i++)
@@ -569,7 +610,13 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
       fgotfilename = false;
       sz = fdr.csym * external_sym_size;
       sym_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
-      add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end, sym_out, sz);
+      if (!sym_out)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
+      if (!add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end, sym_out, sz))
+       return false;
       lraw_src = ((bfd_byte *) input_debug->external_sym
                  + fdr.isymBase * input_swap->external_sym_size);
       lraw_end = lraw_src + fdr.csym * input_swap->external_sym_size;
@@ -658,10 +705,11 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
       /* Copy the information that does not need swapping.  */
       if (fdr.cbLine > 0)
        {
-         add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
+         if (!add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
                            input_bfd,
                            input_symhdr->cbLineOffset + fdr.cbLineOffset,
-                           fdr.cbLine);
+                           fdr.cbLine))
+           return false;
          fdr.ilineBase = output_symhdr->ilineMax;
          fdr.cbLineOffset = output_symhdr->cbLine;
          output_symhdr->ilineMax += fdr.cline;
@@ -669,11 +717,12 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
        }
       if (fdr.caux > 0)
        {
-         add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
+         if (!add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
                            input_bfd,
                            (input_symhdr->cbAuxOffset
                             + fdr.iauxBase * sizeof (union aux_ext)),
-                           fdr.caux * sizeof (union aux_ext));
+                           fdr.caux * sizeof (union aux_ext)))
+           return false;
          fdr.iauxBase = output_symhdr->iauxMax;
          output_symhdr->iauxMax += fdr.caux;
        }
@@ -689,10 +738,11 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
        }
       else if (fdr.cbSs > 0)
        {
-         add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
+         if (!add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
                            input_bfd,
                            input_symhdr->cbSsOffset + fdr.issBase,
-                           fdr.cbSs);
+                           fdr.cbSs))
+           return false;
          fdr.issBase = output_symhdr->issMax;
          output_symhdr->issMax += fdr.cbSs;
        }
@@ -704,18 +754,24 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
             the information will suffice.  */
          BFD_ASSERT (external_pdr_size == input_swap->external_pdr_size);
          if (fdr.cpd > 0)
-           add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
-                             input_bfd,
-                             (input_symhdr->cbPdOffset
-                              + fdr.ipdFirst * external_pdr_size),
-                             fdr.cpd * external_pdr_size);
+           {
+             if (!add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
+                                    input_bfd,
+                                    (input_symhdr->cbPdOffset
+                                     + fdr.ipdFirst * external_pdr_size),
+                                    fdr.cpd * external_pdr_size))
+               return false;
+           }
          BFD_ASSERT (external_opt_size == input_swap->external_opt_size);
          if (fdr.copt > 0)
-           add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
-                             input_bfd,
-                             (input_symhdr->cbOptOffset
-                              + fdr.ioptBase * external_opt_size),
-                             fdr.copt * external_opt_size);
+           {
+             if (!add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
+                                    input_bfd,
+                                    (input_symhdr->cbOptOffset
+                                     + fdr.ioptBase * external_opt_size),
+                                    fdr.copt * external_opt_size))
+               return false;
+           }
        }
       else
        {
@@ -734,7 +790,13 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          end = in + fdr.cpd * insz;
          sz = fdr.cpd * outsz;
          out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
-         add_memory_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end, out, sz);
+         if (!out)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
+         if (!add_memory_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end, out, sz))
+           return false;
          for (; in < end; in += insz, out += outsz)
            {
              PDR pdr;
@@ -751,7 +813,13 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          end = in + fdr.copt * insz;
          sz = fdr.copt * outsz;
          out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
-         add_memory_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end, out, sz);
+         if (!out)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
+         if (!add_memory_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end, out, sz))
+           return false;
          for (; in < end; in += insz, out += outsz)
            {
              OPTR opt;
@@ -810,8 +878,9 @@ ecoff_add_string (ainfo, info, debug, fdr, string)
   len = strlen (string);
   if (info->relocateable)
     {
-      add_memory_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end, (PTR) string,
-                         len + 1);
+      if (!add_memory_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end, (PTR) string,
+                              len + 1))
+       return -1;
       ret = symhdr->issMax;
       symhdr->issMax += len + 1;
       fdr->cbSs += len + 1;
@@ -921,6 +990,11 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
 
       external_sym = (PTR) obstack_alloc (&ainfo->memory,
                                          output_swap->external_sym_size);
+      if (!external_sym)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
       (*swap_sym_out) (output_bfd, &internal_sym, external_sym);
       add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end,
                          external_sym, output_swap->external_sym_size);
@@ -936,6 +1010,11 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
      it only applies to aux fields and there are none.  */
   external_fdr = (PTR) obstack_alloc (&ainfo->memory,
                                      output_swap->external_fdr_size);
+  if (!external_fdr)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   (*output_swap->swap_fdr_out) (output_bfd, &fdr, external_fdr);
   add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end,
                      external_fdr, output_swap->external_fdr_size);
index 14c520a1e65d7aad3ca278c060f07bfa32465929..cb5c9e5b36183201e95b1f457edbbae1097fe3bd 100644 (file)
@@ -485,10 +485,10 @@ hppa_elf_gen_reloc_type (abfd, base_type, format, field)
   int i;
 
   final_types = (elf32_hppa_reloc_type **) bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type *) * 2);
-  BFD_ASSERT (final_types != 0);
+  BFD_ASSERT (final_types != 0); /* FIXME */
 
   finaltype = (elf32_hppa_reloc_type *) bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type));
-  BFD_ASSERT (finaltype != 0);
+  BFD_ASSERT (finaltype != 0); /* FIXME */
 
   final_types[0] = finaltype;
   final_types[1] = NULL;
@@ -1090,10 +1090,10 @@ hppa_elf_gen_reloc_type (abfd, base_type, format, field)
     case R_HPPA_COMPLEX_PCREL_CALL:
     case R_HPPA_COMPLEX_ABS_CALL:
       final_types = (elf32_hppa_reloc_type **) bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type *) * 6);
-      BFD_ASSERT (final_types != 0);
+      BFD_ASSERT (final_types != 0); /* FIXME */
 
       finaltype = (elf32_hppa_reloc_type *) bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type) * 5);
-      BFD_ASSERT (finaltype != 0);
+      BFD_ASSERT (finaltype != 0); /* FIXME */
 
       for (i = 0; i < 5; i++)
        final_types[i] = &finaltype[i];
@@ -1747,6 +1747,11 @@ elf_hppa_tc_symbol (abfd, symbolP, sym_idx)
     return;
 
   symextP = (symext_chainS *) bfd_alloc (abfd, sizeof (symext_chainS) * 2);
+  if (!symextP)
+    {
+      bfd_error = no_memory;
+      abort();                 /* FIXME */
+    }
 
   symextP[0].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX, sym_idx);
   symextP[0].next = &symextP[1];
@@ -1808,6 +1813,11 @@ elf_hppa_tc_make_sections (abfd, ignored)
       bfd_set_section_alignment (abfd, symextn_sec, 2);
     }
   symextn_contents = (symext_entryS *) bfd_alloc (abfd, size);
+  if (!symextn_contents)
+    {
+      bfd_error = no_memory;
+      abort();                 /* FIXME */
+    }
 
   for (i = 0, symextP = symext_rootP; symextP; symextP = symextP->next, ++i)
     symextn_contents[i] = symextP->entry;
@@ -1965,7 +1975,7 @@ new_stub (abfd, stub_sec, link_info)
   else
     {
       bfd_error = no_memory;
-      bfd_perror ("new_stub");
+      abort();                 /* FIXME */
     }
 
   return stub;
@@ -2031,7 +2041,7 @@ add_stub_by_name(abfd, stub_sec, sym, link_info)
       else
        {
          bfd_error = no_memory;
-         bfd_perror("add_stub_by_name");
+         abort();              /* FIXME */
        }
     }
 
@@ -2141,8 +2151,8 @@ type_of_mismatch (caller_bits, callee_bits, type)
 }
 
 #define CURRENT_STUB_OFFSET(entry)     \
-  ((int)(entry)->stub_desc->stub_secp \
-   - (int)(entry)->stub_desc->stub_contents - 4)
+  ((char *)(entry)->stub_desc->stub_secp \
+   - (char *)(entry)->stub_desc->stub_contents - 4)
 
 static boolean stubs_finished = false;
 
@@ -2275,13 +2285,18 @@ hppa_elf_stub_branch_reloc (stub_desc,  /* the bfd */
          stub_desc->stub_sec->relocation = (arelent *) realloc (stub_desc->stub_sec->relocation,
                                                                 size);
        }
+      if (!stub_desc->stub_sec->relocation)
+       {
+         bfd_error = no_memory;
+         abort();              /* FIXME */
+       }
     }
 
   /* Fill in the details. */
   relent.address = offset;
   relent.addend = 0;
   relent.sym_ptr_ptr = (asymbol **) bfd_zalloc (stub_desc->this_bfd, sizeof (asymbol *));
-  BFD_ASSERT (relent.sym_ptr_ptr);
+  BFD_ASSERT (relent.sym_ptr_ptr); /* FIXME */
 
   relent.sym_ptr_ptr[0] = target_sym;
   relent.howto = bfd_reloc_type_lookup (stub_desc->this_bfd, R_HPPA_PCREL_CALL_17);
@@ -2325,6 +2340,11 @@ hppa_elf_stub_reloc (stub_desc,  /* the bfd */
          stub_desc->stub_sec->relocation = (arelent *) realloc (stub_desc->stub_sec->relocation,
                                                                 size);
        }
+      if (!stub_desc->stub_sec->relocation)
+       {
+         bfd_error = no_memory;
+         abort();              /* FIXME */
+       }
     }
 
   rela_hdr = &elf_section_data(stub_desc->stub_sec)->rel_hdr;
@@ -2334,7 +2354,7 @@ hppa_elf_stub_reloc (stub_desc,   /* the bfd */
   relent.address = offset;
   relent.addend = 0;
   relent.sym_ptr_ptr = (asymbol **) bfd_zalloc (stub_desc->this_bfd, sizeof (asymbol *));
-  BFD_ASSERT (relent.sym_ptr_ptr);
+  BFD_ASSERT (relent.sym_ptr_ptr); /* FIXME */
 
   relent.sym_ptr_ptr[0] = target_sym;
   relent.howto = bfd_reloc_type_lookup (stub_desc->this_bfd, type);
@@ -2407,7 +2427,12 @@ hppa_elf_build_arg_reloc_stub (abfd, output_bfd, link_info, reloc_entry,
   if (!stub_desc->stub_contents)
     {
       stub_desc->allocated_size = STUB_BUFFER_INCR;
-      stub_desc->stub_contents = (char *) bfd_xmalloc (STUB_BUFFER_INCR);
+      stub_desc->stub_contents = (char *) malloc (STUB_BUFFER_INCR);
+      if (!stub_desc->stub_contents)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
     }
   else if ((stub_desc->allocated_size - stub_desc->real_size) < STUB_MAX_SIZE)
     {
@@ -2435,6 +2460,11 @@ hppa_elf_build_arg_reloc_stub (abfd, output_bfd, link_info, reloc_entry,
         change the relocation type?  */
       reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (stub_desc->this_bfd,
                                                          sizeof (asymbol *));
+      if (!reloc_entry->sym_ptr_ptr)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       reloc_entry->sym_ptr_ptr[0] = stub_sym;
       if (reloc_entry->howto->type != R_HPPA_PLABEL_32
          && (get_opcode(insn) == BLE
@@ -2446,10 +2476,20 @@ hppa_elf_build_arg_reloc_stub (abfd, output_bfd, link_info, reloc_entry,
     {
       /* Create a new symbol to point to this stub.  */
       stub_sym = bfd_make_empty_symbol (abfd);
+      if (!stub_sym)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       stub_sym->name = bfd_zalloc (abfd, strlen (stub_sym_name) + 1);
+      if (!stub_sym->name)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       strcpy ((char *) stub_sym->name, stub_sym_name);
       stub_sym->value
-       = (int) stub_desc->stub_secp - (int) stub_desc->stub_contents;
+       = (char *) stub_desc->stub_secp - (char *) stub_desc->stub_contents;
       stub_sym->section = stub_sec;
       stub_sym->flags = BSF_LOCAL | BSF_FUNCTION;
       stub_entry = add_stub_by_name (abfd, stub_sec, stub_sym, link_info);
@@ -2459,6 +2499,11 @@ hppa_elf_build_arg_reloc_stub (abfd, output_bfd, link_info, reloc_entry,
         relocation to be the internal use only stub R_HPPA_STUB_CALL_17.  */
       reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (stub_desc->this_bfd,
                                                          sizeof (asymbol *));
+      if (!reloc_entry->sym_ptr_ptr)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       reloc_entry->sym_ptr_ptr[0] = stub_sym;
       if (reloc_entry->howto->type != R_HPPA_PLABEL_32
          && (get_opcode (insn) == BLE
@@ -2929,6 +2974,11 @@ hppa_elf_build_long_branch_stub (abfd, output_bfd, link_info, reloc_entry,
         FIXME.  Is there a need to change the relocation type too?  */
       reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (stub_desc->this_bfd,
                                                          sizeof (asymbol *));
+      if (!reloc_entry->sym_ptr_ptr)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       reloc_entry->sym_ptr_ptr[0] = stub_sym;
       reloc_entry->howto = bfd_reloc_type_lookup (abfd, R_HPPA_STUB_CALL_17);
     }
@@ -2936,10 +2986,20 @@ hppa_elf_build_long_branch_stub (abfd, output_bfd, link_info, reloc_entry,
     {
       /* We will need to allocate a new stub.  */
       stub_sym = bfd_make_empty_symbol (abfd);
+      if (!stub_sym)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       stub_sym->name = bfd_zalloc (abfd, strlen (stub_sym_name) + 1);
+      if (!stub_sym->name)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       strcpy ((char *) stub_sym->name, stub_sym_name);
       stub_sym->value
-       = (int) stub_desc->stub_secp - (int) stub_desc->stub_contents;
+       = (char *) stub_desc->stub_secp - (char *) stub_desc->stub_contents;
       stub_sym->section = stub_sec;
       stub_sym->flags = BSF_LOCAL | BSF_FUNCTION;
       stub_entry = add_stub_by_name (abfd, stub_sec, stub_sym, link_info);
@@ -2950,6 +3010,11 @@ hppa_elf_build_long_branch_stub (abfd, output_bfd, link_info, reloc_entry,
         FIXME.  Is there a need to change the relocation type too?  */
       reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (stub_desc->this_bfd,
                                                          sizeof (asymbol *));
+      if (!reloc_entry->sym_ptr_ptr)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
       reloc_entry->sym_ptr_ptr[0] = stub_sym;
       reloc_entry->howto = bfd_reloc_type_lookup (abfd, R_HPPA_STUB_CALL_17);
       
@@ -3458,6 +3523,11 @@ elf32_hppa_backend_symbol_table_processing (abfd, esyms,symcnt)
   /* allocate a buffer of the appropriate size for the symextn section */
 
   symextn_hdr->contents = bfd_zalloc(abfd,symextn_hdr->sh_size);
+  if (!symextn_hdr->contents)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   symextn_hdr->size = symextn_hdr->sh_size;
        
   /* read in the symextn section */
index 585187af0870c7668d58bce75b55df85dc914e12..57734bc5e88df5c28c8b16dc8bb15a132e6d25b8 100644 (file)
@@ -1,5 +1,5 @@
 /* MIPS-specific support for 32-bit ELF
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright 1993, 1994 Free Software Foundation, Inc.
 
    Most of the information added by Ian Lance Taylor, Cygnus Support,
    <ian@cygnus.com>.
@@ -1061,6 +1061,7 @@ mips_elf_read_ecoff_info (abfd, section, debug)
        return false;                                                   \
     }
 
+  READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
   READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
   READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
   READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
@@ -1072,7 +1073,8 @@ mips_elf_read_ecoff_info (abfd, section, debug)
   READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
   READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
   READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
-  READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
+
+  debug->fdr = NULL;
 
   return true;
 }
@@ -1084,6 +1086,8 @@ mips_elf_get_extr (sym, esym)
      asymbol *sym;
      EXTR *esym;
 {
+  const struct ecoff_debug_swap *swap;
+
   if (sym->flags & BSF_SECTION_SYM)
     return false;
 
@@ -1103,7 +1107,11 @@ mips_elf_get_extr (sym, esym)
       return true;
     }
 
-  *esym = *((elf_symbol_type *) sym)->tc_data.mips_extr;
+  swap = (get_elf_backend_data (bfd_asymbol_bfd (sym))
+         ->elf_backend_ecoff_debug_swap);
+  (*swap->swap_ext_in) (bfd_asymbol_bfd (sym),
+                       ((elf_symbol_type *) sym)->tc_data.mips_extr,
+                       esym);
 
   return true;
 }
@@ -1140,6 +1148,7 @@ mips_elf_final_link (abfd, info)
   const struct ecoff_debug_swap *swap
     = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
   HDRR *symhdr = &debug.symbolic_header;
+  PTR mdebug_handle = NULL;
 
   abfd->outsymbols = (asymbol **) NULL;
   abfd->symcount = 0;
@@ -1152,6 +1161,7 @@ mips_elf_final_link (abfd, info)
       return false;
 
   /* Accumulate the global symbols.  */
+  wginfo.info = info;
   wginfo.output_bfd = abfd;
   wginfo.psymalloc = &outsymalloc;
   _bfd_generic_link_hash_traverse (_bfd_generic_hash_table (info),
@@ -1167,7 +1177,10 @@ mips_elf_final_link (abfd, info)
   secpp = &abfd->sections;
   while (*secpp != NULL)
     {
-      if ((*secpp)->_raw_size == 0
+      if (((*secpp)->_raw_size == 0
+          && strcmp ((*secpp)->name, ".data") != 0
+          && strcmp ((*secpp)->name, ".text") != 0
+          && strcmp ((*secpp)->name, ".bss") != 0)
          || strcmp ((*secpp)->name, ".options") == 0
          || strncmp ((*secpp)->name, ".gptab", 6) == 0)
        {
@@ -1182,6 +1195,8 @@ mips_elf_final_link (abfd, info)
      information.  We don't write out the information until we have
      set the section sizes, because the ELF backend only assigns space
      in the file once.  */
+  reginfo_sec = NULL;
+  mdebug_sec = NULL;
   for (o = abfd->sections; o != (asection *) NULL; o = o->next)
     {
       if (strcmp (o->name, ".reginfo") == 0)
@@ -1258,18 +1273,22 @@ mips_elf_final_link (abfd, info)
 
          /* We accumulate the debugging information itself in the
             debug_info structure.  */
-         debug.line = debug.line_end = NULL;
-         debug.external_dnr = debug.external_dnr_end = NULL;
-         debug.external_pdr = debug.external_pdr_end = NULL;
-         debug.external_sym = debug.external_sym_end = NULL;
-         debug.external_opt = debug.external_opt_end = NULL;
-         debug.external_aux = debug.external_aux_end = NULL;
-         debug.ss = debug.ss_end = NULL;
+         debug.line = NULL;
+         debug.external_dnr = NULL;
+         debug.external_pdr = NULL;
+         debug.external_sym = NULL;
+         debug.external_opt = NULL;
+         debug.external_aux = NULL;
+         debug.ss = NULL;
          debug.ssext = debug.ssext_end = NULL;
-         debug.external_fdr = debug.external_fdr_end = NULL;
-         debug.external_rfd = debug.external_rfd_end = NULL;
+         debug.external_fdr = NULL;
+         debug.external_rfd = NULL;
          debug.external_ext = debug.external_ext_end = NULL;
 
+         mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
+         if (mdebug_handle == (PTR) NULL)
+           return false;
+
          for (p = o->link_order_head;
               p != (struct bfd_link_order *) NULL;
               p = p->next)
@@ -1282,6 +1301,10 @@ mips_elf_final_link (abfd, info)
              if (p->type != bfd_indirect_link_order)
                continue;
 
+#ifndef alloca
+             alloca (0);
+#endif
+
              input_section = p->u.indirect.section;
              input_bfd = input_section->owner;
 
@@ -1308,9 +1331,8 @@ mips_elf_final_link (abfd, info)
                return false;
 
              if (! (bfd_ecoff_debug_accumulate
-                    (abfd, &debug, swap,
-                     input_bfd, &input_debug, input_swap,
-                     info->relocateable)))
+                    (mdebug_handle, abfd, &debug, swap, input_bfd,
+                     &input_debug, input_swap, info)))
                return false;
 
              /* Loop through the external symbols.  For each one with
@@ -1355,15 +1377,21 @@ mips_elf_final_link (abfd, info)
                      if (elf_sym->tc_data.mips_extr != NULL)
                        continue;
 
-                     elf_sym->tc_data.mips_extr =
-                       (EXTR *) bfd_alloc (abfd, sizeof (EXTR));
+                     if (ext.ifd != -1)
+                       {
+                         BFD_ASSERT (ext.ifd
+                                     < input_debug.symbolic_header.ifdMax);
+                         ext.ifd = input_debug.ifdmap[ext.ifd];
+                       }
 
-                     ext.ifd += input_debug.ifdbase;
-                     *elf_sym->tc_data.mips_extr = ext;
+                     (*input_swap->swap_ext_out) (input_bfd, &ext,
+                                                  (PTR) eraw_src);
+                     elf_sym->tc_data.mips_extr = (PTR) eraw_src;
                    }
                }
 
-             /* Free up the information we just read.  */
+             /* Free up the information we just read, except for the
+                external symbols which we may have pointers to.  */
              free (input_debug.line);
              free (input_debug.external_dnr);
              free (input_debug.external_pdr);
@@ -1374,7 +1402,6 @@ mips_elf_final_link (abfd, info)
              free (input_debug.ssext);
              free (input_debug.external_fdr);
              free (input_debug.external_rfd);
-             free (input_debug.external_ext);
            }
 
          /* Build the external symbol information.  */
@@ -1418,7 +1445,12 @@ mips_elf_final_link (abfd, info)
                  input_bfd = input_section->owner;
                  relsize = bfd_get_reloc_upper_bound (input_bfd,
                                                       input_section);
-                 relocs = (arelent **) bfd_xmalloc (relsize);
+                 relocs = (arelent **) malloc (relsize);
+                 if (!relocs)
+                   {
+                     bfd_error = no_memory;
+                     return false;
+                   }
                  reloc_count =
                    bfd_canonicalize_reloc (input_bfd, input_section,
                                            relocs,
@@ -1434,6 +1466,11 @@ mips_elf_final_link (abfd, info)
                                bfd_alloc (abfd,
                                           (o->reloc_count
                                            * sizeof (arelent *))));
+             if (!o->orelocation)
+               {
+                 bfd_error = no_memory;
+                 return false;
+               }
              /* Reset the count so that it can be used as an index
                 when putting in the output relocs.  */
              o->reloc_count = 0;
@@ -1461,8 +1498,12 @@ mips_elf_final_link (abfd, info)
                                    (file_ptr) 0, (bfd_size_type) 0);
          BFD_ASSERT (abfd->output_has_begun);
        }
-      if (! bfd_ecoff_write_debug (abfd, &debug, swap, mdebug_sec->filepos))
+      if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
+                                              swap, info,
+                                              mdebug_sec->filepos))
        return false;
+
+      bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
     }
 
   /* Handle all the link order information for the sections.  */
index b2b99d34b43c832ae073b183009efa3bdb718860..b5c8d0b6b9265f53f68fc36b376043f820cca014 100644 (file)
@@ -132,7 +132,7 @@ static boolean elf_slurp_symbol_table PARAMS ((bfd *, asymbol **));
 static int elf_symbol_from_bfd_symbol PARAMS ((bfd *,
                                               struct symbol_cache_entry **));
 
-static void elf_map_symbols PARAMS ((bfd *));
+static boolean elf_map_symbols PARAMS ((bfd *));
 static boolean swap_out_syms PARAMS ((bfd *));
 
 #ifdef DEBUG
@@ -412,7 +412,7 @@ DEFUN (bfd_add_to_strtab, (abfd, ss, str),
   /* should this be using obstacks? */
   ss->tab = realloc (ss->tab, ss->length + ln);
 
-  BFD_ASSERT (ss->tab != 0);
+  BFD_ASSERT (ss->tab != 0);   /* FIXME */
   strcpy (ss->tab + ss->length, str);
   ss->nentries++;
   ss->length += ln;
@@ -437,7 +437,7 @@ DEFUN (bfd_add_2_to_strtab, (abfd, ss, str, str2),
   else
     ss->tab = malloc (ln);
 
-  BFD_ASSERT (ss->tab != 0);
+  BFD_ASSERT (ss->tab != 0);   /* FIXME */
   strcpy (ss->tab + ss->length, str);
   strcpy (ss->tab + ss->length + strlen (str), str2);
   ss->nentries++;
@@ -596,8 +596,8 @@ DEFUN (bfd_section_from_shdr, (abfd, shindex),
          newsect->flags = SEC_HAS_CONTENTS;
          hdr->rawdata = (PTR) newsect;
          newsect->_raw_size = hdr->sh_size;
-         newsect->alignment_power = 0;
-         newsect->vma = 0;
+         newsect->alignment_power = bfd_log2 (hdr->sh_addralign);
+         newsect->vma = hdr->sh_addr;
          newsect->filepos = hdr->sh_offset;
 
          if (hdr->sh_flags & SHF_ALLOC)
@@ -710,6 +710,11 @@ DEFUN (elf_new_section_hook, (abfd, sec),
   struct bfd_elf_section_data *sdata;
 
   sdata = (struct bfd_elf_section_data *) bfd_alloc (abfd, sizeof (*sdata));
+  if (!sdata)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   sec->used_by_bfd = (PTR) sdata;
   memset (sdata, 0, sizeof (*sdata));
   return true;
@@ -753,6 +758,11 @@ DEFUN (bfd_section_from_phdr, (abfd, hdr, index),
           (hdr->p_memsz > hdr->p_filesz));
   sprintf (namebuf, split ? "segment%da" : "segment%d", index);
   name = bfd_alloc (abfd, strlen (namebuf) + 1);
+  if (!name)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   strcpy (name, namebuf);
   newsect = bfd_make_section (abfd, name);
   newsect->vma = hdr->p_vaddr;
@@ -779,6 +789,11 @@ DEFUN (bfd_section_from_phdr, (abfd, hdr, index),
     {
       sprintf (namebuf, "segment%db", index);
       name = bfd_alloc (abfd, strlen (namebuf) + 1);
+      if (!name)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
       strcpy (name, namebuf);
       newsect = bfd_make_section (abfd, name);
       newsect->vma = hdr->p_vaddr + hdr->p_filesz;
@@ -1149,6 +1164,11 @@ write_relocs (abfd, sec, xxx)
 
   rela_hdr->sh_size = rela_hdr->sh_entsize * sec->reloc_count;
   rela_hdr->contents = (void *) bfd_alloc (abfd, rela_hdr->sh_size);
+  if (!rela_hdr->contents)
+    {
+      bfd_error = no_memory;
+      abort();                 /* FIXME */
+    }
 
   /* orelocation has the data, reloc_count has the count... */
   if (use_rela_p)
@@ -1378,7 +1398,7 @@ sym_is_global (abfd, sym)
   return 0;
 }
 
-static void
+static boolean
 DEFUN (elf_map_symbols, (abfd), bfd * abfd)
 {
   int symcount = bfd_get_symcount (abfd);
@@ -1414,11 +1434,20 @@ DEFUN (elf_map_symbols, (abfd), bfd * abfd)
   sect_syms = (asymbol **) bfd_zalloc (abfd, max_index * sizeof (asymbol *));
   elf_section_syms (abfd) = sect_syms;
 
-  BFD_ASSERT (sect_syms != 0);
+  if (sect_syms != 0)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   for (asect = abfd->sections; asect; asect = asect->next)
     {
       asymbol *sym = bfd_make_empty_symbol (abfd);
+      if (!sym)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
       sym->the_bfd = abfd;
       sym->name = asect->name;
       sym->value = asect->vma;
@@ -1442,6 +1471,11 @@ DEFUN (elf_map_symbols, (abfd), bfd * abfd)
       else
        syms = (asymbol **) bfd_alloc (abfd,
                                       (num_sections + 1) * sizeof (asymbol *));
+      if (!syms)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
 
       for (asect = abfd->sections; asect; asect = asect->next)
        {
@@ -1455,6 +1489,11 @@ DEFUN (elf_map_symbols, (abfd), bfd * abfd)
 
   elf_sym_extra (abfd) = sym_extra
     = (Elf_Sym_Extra *) bfd_alloc (abfd, symcount * sizeof (Elf_Sym_Extra));
+  if (!sym_extra)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   /* Identify and classify all of the symbols.  */
   for (idx = 0; idx < symcount; idx++)
@@ -1478,17 +1517,19 @@ DEFUN (elf_map_symbols, (abfd), bfd * abfd)
 
   elf_num_locals (abfd) = num_locals;
   elf_num_globals (abfd) = num_globals;
+  return true;
 }
 
-static void assign_section_numbers ();
-static void assign_file_positions_except_relocs ();
+static boolean assign_section_numbers ();
+static boolean assign_file_positions_except_relocs ();
 
 static boolean
 DEFUN (elf_compute_section_file_positions, (abfd), bfd * abfd)
 {
   bfd_map_over_sections (abfd, elf_fake_sections, 0);
 
-  assign_section_numbers (abfd);
+  if (!assign_section_numbers (abfd))
+    return false;
 
   bfd_map_over_sections (abfd, elf_make_sections, 0);
 
@@ -1497,7 +1538,8 @@ DEFUN (elf_compute_section_file_positions, (abfd), bfd * abfd)
   if (swap_out_syms (abfd) == false)
     return false;
 
-  assign_file_positions_except_relocs (abfd);
+  if (!assign_file_positions_except_relocs (abfd))
+    return false;
 
   return true;
 }
@@ -1531,7 +1573,7 @@ static const Elf_Internal_Shdr null_shdr;
    too.  The link/info pointers for the standard section types are filled
    in here too, while we're at it.  (Link pointers for .stab sections are
    not filled in here.)  */
-static void
+static boolean
 assign_section_numbers (abfd)
      bfd *abfd;
 {
@@ -1573,6 +1615,11 @@ assign_section_numbers (abfd)
      indices.  */
   i_shdrp = (Elf_Internal_Shdr **)
     bfd_alloc (abfd, section_number * sizeof (Elf_Internal_Shdr *));
+  if (!i_shdrp)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   elf_elfsections(abfd) = i_shdrp;
   for (i = 0; i < section_number; i++)
     i_shdrp[i] = 0;
@@ -1595,6 +1642,7 @@ assign_section_numbers (abfd)
   for (i = 0; i < section_number; i++)
     if (i_shdrp[i] == 0)
       abort ();
+  return true;
 }
 
 static INLINE file_ptr
@@ -1645,7 +1693,7 @@ struct seg_info {
   struct seg_info *next;
 };
 
-static void
+static boolean
 map_program_segments (abfd)
      bfd *abfd;
 {
@@ -1708,6 +1756,11 @@ map_program_segments (abfd)
       {
        struct seg_info *s;
        s = (struct seg_info *) bfd_alloc (abfd, sizeof (struct seg_info));
+       if (!s)
+         {
+           bfd_error = no_memory;
+           return false;
+         }
        s->next = seg;
        seg = s;
       }
@@ -1787,6 +1840,11 @@ map_program_segments (abfd)
       }
     phdr = (Elf_Internal_Phdr*) bfd_alloc (abfd,
                                           n_segs * sizeof (Elf_Internal_Phdr));
+    if (!phdr)
+      {
+       bfd_error = no_memory;
+       abort();                /* FIXME */
+      }
     elf_tdata (abfd)->phdr = phdr;
     while (seg)
       {
@@ -1810,9 +1868,10 @@ map_program_segments (abfd)
     i_ehdrp->e_phnum = n_segs;
   }
   elf_write_phdrs (abfd, i_ehdrp, elf_tdata (abfd)->phdr, i_ehdrp->e_phnum);
+  return true;
 }
 
-static void
+static boolean
 assign_file_positions_except_relocs (abfd)
      bfd *abfd;
 {
@@ -1912,7 +1971,8 @@ assign_file_positions_except_relocs (abfd)
   if (exec_p)
     {
       elf_tdata (abfd)->next_file_pos = off;
-      map_program_segments (abfd);
+      if (!map_program_segments (abfd))
+       return false;
       off = elf_tdata (abfd)->next_file_pos;
 
       /* Section headers.  */
@@ -1932,6 +1992,7 @@ assign_file_positions_except_relocs (abfd)
        }
     }
   elf_tdata (abfd)->next_file_pos = off;
+  return true;
 }
 
 static boolean
@@ -2048,7 +2109,8 @@ static boolean
 swap_out_syms (abfd)
      bfd *abfd;
 {
-  elf_map_symbols (abfd);
+  if (!elf_map_symbols (abfd))
+    return false;
 
   /* Dump out the symtabs. */
   {
@@ -2079,6 +2141,11 @@ swap_out_syms (abfd)
 
     outbound_syms = (Elf_External_Sym *)
       bfd_alloc (abfd, (1 + symcount) * sizeof (Elf_External_Sym));
+    if (!outbound_syms)
+      {
+       bfd_error = no_memory;
+       return false;
+      }
     /* now generate the data (for "contents") */
     {
       /* Fill in zeroth symbol and swap it out.  */
@@ -2527,7 +2594,7 @@ DEFUN (elf_slurp_symbol_table, (abfd, symptrs),
 
   /* Temporarily allocate room for the raw ELF symbols.  */
   x_symp = (Elf_External_Sym *) malloc (symcount * sizeof (Elf_External_Sym));
-  if (!x_symp)
+  if (!symbase || !x_symp)
     {
       bfd_error = no_memory;
       return false;
@@ -2705,6 +2772,12 @@ DEFUN (elf_slurp_reloca_table, (abfd, asect, symbols),
   bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
   native_relocs = (Elf_External_Rela *)
     bfd_alloc (abfd, asect->reloc_count * sizeof (Elf_External_Rela));
+  if (!native_relocs)
+  if (!reloc_cache)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   bfd_read ((PTR) native_relocs,
            sizeof (Elf_External_Rela), asect->reloc_count, abfd);
 
@@ -2847,6 +2920,11 @@ DEFUN (elf_slurp_reloc_table, (abfd, asect, symbols),
   bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
   native_relocs = (Elf_External_Rel *)
     bfd_alloc (abfd, asect->reloc_count * sizeof (Elf_External_Rel));
+  if (!native_relocs)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   bfd_read ((PTR) native_relocs,
            sizeof (Elf_External_Rel), asect->reloc_count, abfd);
 
index bccc97dcd5eb97b32f917d80da813dca7ceb433e..987c259d01c015755ccbaa646483135744602206 100644 (file)
@@ -1,22 +1,22 @@
 /* hash.c -- hash table routines for BFD
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright (C) 1993, 94 Free Software Foundation, Inc.
    Written by Steve Chamberlain <sac@cygnus.com>
 
-This file is part of GLD, the Gnu Linker.
+This file is part of BFD, the Binary File Descriptor library.
 
-GLD is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GLD is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GLD; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -290,7 +290,7 @@ SUBSUBSECTION
 */
 
 /* Obstack allocation and deallocation routines.  */
-#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
 
 /* The default number of entries to use when creating a hash table.  */
@@ -309,9 +309,18 @@ bfd_hash_table_init_n (table, newfunc, size)
   unsigned int alloc;
 
   alloc = size * sizeof (struct bfd_hash_entry *);
-  obstack_begin (&table->memory, alloc);
+  if (!obstack_begin (&table->memory, alloc))
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   table->table = ((struct bfd_hash_entry **)
                  obstack_alloc (&table->memory, alloc));
+  if (!table->table)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   memset ((PTR) table->table, 0, alloc);
   table->size = size;
   table->newfunc = newfunc;
@@ -388,6 +397,11 @@ bfd_hash_lookup (table, string, create, copy)
       char *new;
 
       new = (char *) obstack_alloc (&table->memory, len + 1);
+      if (!new)
+       {
+         bfd_error = no_memory;
+         return (struct bfd_hash_entry *) NULL;
+       }
       strcpy (new, string);
       string = new;
     }
index 410d639d741bf9b7f4b6951147304344931f87d9..08f74739c2f43eb9e817e3e13b90087b5bb89001 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD backend for hp-ux 9000/300
-   Copyright (C) 1990-1991 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1991, 1994 Free Software Foundation, Inc.
    Written by Glenn Engel.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -28,7 +28,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
     Support for the 9000/[34]00 has several limitations.
       1. Shared libraries are not supported.
       2. The output format from this bfd is not usable by native tools.
-      3. Core files are not supported (yet).
 
     The primary motivation for writing this bfd was to allow use of
     gdb and gcc for host based debugging and not to mimic the hp-ux tools
@@ -126,10 +125,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /***********************************************/
 /* provide overrides for routines in this file */
 /***********************************************/
-#define MY_get_symtab MY(get_symtab)
-#define MY_get_symtab_upper_bound MY(get_symtab_upper_bound)
-#define MY_canonicalize_reloc MY(canonicalize_reloc)
-#define MY_write_object_contents MY(write_object_contents)
+/* these don't use MY because that causes problems within JUMP_TABLE
+   (CAT winds up being expanded recursively, which ANSI C compilers
+   will not do).  */
+#define MY_get_symtab hp300hpux_get_symtab
+#define MY_get_symtab_upper_bound hp300hpux_get_symtab_upper_bound
+#define MY_canonicalize_reloc hp300hpux_canonicalize_reloc
+#define MY_write_object_contents hp300hpux_write_object_contents
+
+#define MY_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
+#define MY_bfd_link_add_symbols _bfd_generic_link_add_symbols
+#define MY_bfd_final_link _bfd_generic_final_link
 
 #define hp300hpux_write_syms aout_32_write_syms
 
@@ -167,6 +173,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define HP_RLENGTH_ALIGN       0x03
 
 #define NAME(x,y) CAT3(hp300hpux,_32_,y)
+#define ARCH_SIZE 32
 #include "aoutx.h"
 
 /* Since the hpux symbol table has nlist elements interspersed with
@@ -232,6 +239,8 @@ DEFUN(MY(callback),(abfd),
   return abfd->xvec;
 }
 
+extern boolean aout_32_write_syms PARAMS ((bfd *abfd));
+
 static boolean
 DEFUN(MY(write_object_contents),(abfd),
       bfd *abfd)
@@ -272,7 +281,19 @@ DEFUN(MY(write_object_contents),(abfd),
     bfd_seek (abfd, 0L, false);                                        
     bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd);
 
-    /* Now write out reloc info, followed by syms and strings */       
+    /* Write out the symbols, and then the relocs.  We must write out
+       the symbols first so that we know the symbol indices.  */
+
+    if (bfd_get_symcount (abfd) != 0)
+      {
+       /* Skip the relocs to where we want to put the symbols.  */
+       if (bfd_seek (abfd, (file_ptr) N_DRELOFF (*execp) + execp->a_drsize,
+                     SEEK_SET) != 0)
+         return false;
+      }
+
+    if (! MY(write_syms) (abfd))
+      return false;
 
     if (bfd_get_symcount (abfd) != 0)                          
     {                                                          
@@ -284,7 +305,6 @@ DEFUN(MY(write_object_contents),(abfd),
         if (!NAME(aout,squirt_out_relocs)(abfd, obj_datasec (abfd))) return false;
     }
 
-    MY(write_syms)(abfd);
     return true;
 }                                                                      
 
@@ -340,7 +360,7 @@ DEFUN(convert_sym_type,(sym_pointer, cache_ptr, abfd),
            break;
 
          default:
-           printf ("unknown symbol type encountered: %x", name_type);
+           fprintf (stderr, "unknown symbol type encountered: %x", name_type);
          }
        if (name_type & HP_SYMTYPE_EXTERNAL)
          new_type |= N_EXT;
@@ -462,6 +482,11 @@ DEFUN(MY(slurp_symbol_table),(abfd),
 
   strings = (char *) bfd_alloc(abfd,
                                symbol_bytes + SYM_EXTRA_BYTES);
+  if (!strings)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   syms = (struct external_nlist *) (strings + SYM_EXTRA_BYTES);
   bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
   if (bfd_read ((PTR)syms, symbol_bytes, 1, abfd) != symbol_bytes)
@@ -489,6 +514,11 @@ DEFUN(MY(slurp_symbol_table),(abfd),
   cached = (aout_symbol_type *)
     bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) *
                                      sizeof(aout_symbol_type)));
+  if (!cached)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   /* as we march thru the hp symbol table, convert it into a list of
      null terminated strings to hold the symbol names.  Make sure any
@@ -515,7 +545,8 @@ DEFUN(MY(slurp_symbol_table),(abfd),
 
             cache_save = *cache_ptr;
             convert_sym_type(sym_pointer, cache_ptr, abfd);
-           translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd);
+           if (!translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd))
+             return false;
 
             /********************************************************/
             /* for hpux, the 'lenght' value indicates the length of */
@@ -560,8 +591,9 @@ DEFUN(MY(slurp_symbol_table),(abfd),
                 strings += length+10;
                 cache_ptr2->type &= ~HP_SECONDARY_SYMBOL;  /* clear secondary */
                 convert_sym_type(sym_pointer, cache_ptr2, abfd);
-                translate_from_native_sym_flags (sym_pointer, cache_ptr2,
-                                                abfd);
+                if (!translate_from_native_sym_flags (sym_pointer, cache_ptr2,
+                                                     abfd))
+                 return false;
             }
 
             /* skip over the embedded symbol. */
@@ -618,8 +650,8 @@ DEFUN(MY(swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
   case HP_RSEGMENT_NOOP:
       break;
   default:
-      printf
-          ("illegal relocation segment type: %x\n", (bytes->r_type[0]));
+      fprintf (stderr, "illegal relocation segment type: %x\n",
+              (bytes->r_type[0]));
   }
 
   switch (bytes->r_length[0])
@@ -634,7 +666,7 @@ DEFUN(MY(swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
       r_length = 2;
       break;
     default:
-      printf("illegal relocation length: %x\n",bytes->r_length[0] );
+      fprintf (stderr, "illegal relocation length: %x\n",bytes->r_length[0] );
       r_length = 0;
     }
 
index b6ecc30fbef435f791219a0f913acf240f396cc1..04ba4ba1a71712118a090c7f989354d7dbb78c23 100644 (file)
@@ -111,7 +111,8 @@ hppabsd_core_make_empty_symbol (abfd)
      bfd *abfd;
 {
   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
-  new->the_bfd = abfd;
+  if (new)
+    new->the_bfd = abfd;
   return new;
 }
 
@@ -165,6 +166,11 @@ hppabsd_core_core_file_p (abfd)
 
   coredata = (struct hppabsd_core_struct *)
     bfd_zalloc (abfd, sizeof (struct hppabsd_core_struct));
+  if (!coredata)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* Make the core data and available via the tdata part of the BFD.  */
   abfd->tdata.hppabsd_core_data = coredata;
@@ -234,7 +240,7 @@ hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
 #define        hppabsd_core_close_and_cleanup          bfd_generic_close_and_cleanup
 #define        hppabsd_core_set_section_contents       (boolean (*) PARAMS     \
         ((bfd *abfd, asection *section, PTR data, file_ptr offset,     \
-        bfd_size_type count))) bfd_false
+        bfd_size_type count))) bfd_generic_set_section_contents
 #define        hppabsd_core_get_section_contents \
        bfd_generic_get_section_contents
 #define        hppabsd_core_new_section_hook           (boolean (*) PARAMS     \
@@ -288,9 +294,10 @@ swap_abort ()
   abort ();    
 }
 
-#define        NO_GET  ((bfd_vma (*) PARAMS ((         bfd_byte *))) swap_abort )
+#define        NO_GET  ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
 #define        NO_PUT  ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
-#define        NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort )
+#define        NO_SIGNED_GET \
+  ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
 
 bfd_target hppabsd_core_vec =
   {
index e179114fdc50a987a125061128d82c4ed49dc358..005581bf5febdd429733cc242903659da66ae783 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for ieee-695 objects.
-   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -29,255 +29,259 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "libbfd.h"
 #include "ieee.h"
 #include "libieee.h"
-
-
 #include "obstack.h"
-#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
 
 /* Functions for writing to ieee files in the strange way that the
    standard requires. */
 
 static void
-DEFUN(ieee_write_byte,(abfd, byte),
-      bfd *abfd AND
-      bfd_byte byte)
+DEFUN (ieee_write_byte, (abfd, byte),
+       bfd * abfd AND
+       bfd_byte byte)
 {
-  bfd_write((PTR)&byte, 1, 1, abfd);
+  bfd_write ((PTR) & byte, 1, 1, abfd);
 }
 
-
 static void
-DEFUN(ieee_write_twobyte,(abfd, twobyte),
-      bfd *abfd AND
-      int twobyte)
+DEFUN (ieee_write_twobyte, (abfd, twobyte),
+       bfd * abfd AND
+       int twobyte)
 {
   bfd_byte b[2];
   b[1] = twobyte & 0xff;
   b[0] = twobyte >> 8;
-  bfd_write((PTR)&b[0], 1, 2, abfd);
+  bfd_write ((PTR) & b[0], 1, 2, abfd);
 }
 
-
-
 static void
-DEFUN(ieee_write_2bytes,(abfd, bytes),
-      bfd *abfd AND
-      int bytes)
+DEFUN (ieee_write_2bytes, (abfd, bytes),
+       bfd * abfd AND
+       int bytes)
 {
   bfd_byte buffer[2];
   buffer[0] = bytes >> 8;
   buffer[1] = bytes & 0xff;
 
-  bfd_write((PTR)buffer, 1, 2, abfd);
+  bfd_write ((PTR) buffer, 1, 2, abfd);
 }
 
 static void
-DEFUN(ieee_write_int,(abfd, value),
-      bfd *abfd AND
-      bfd_vma value)
+DEFUN (ieee_write_int, (abfd, value),
+       bfd * abfd AND
+       bfd_vma value)
 {
-  if (((unsigned)value) <= 127) {
-    ieee_write_byte(abfd, (bfd_byte)value);
-  }
-  else {
-    unsigned int length;
-    /* How many significant bytes ? */
-    /* FIXME FOR LONGER INTS */
-    if (value & 0xff000000) {
-      length = 4;
-    }
-    else if (value & 0x00ff0000) {
-      length  = 3;
-    }
-    else if (value & 0x0000ff00) {
-      length = 2;
-    }
-    else length = 1;
-
-    ieee_write_byte(abfd,
-                   (bfd_byte)((int)ieee_number_repeat_start_enum + length));
-    switch (length) {
-    case 4:
-      ieee_write_byte(abfd, (bfd_byte)(value >> 24));
-    case 3:
-      ieee_write_byte(abfd, (bfd_byte)(value >> 16));
-    case 2:
-      ieee_write_byte(abfd, (bfd_byte)(value >> 8));
-    case 1:
-      ieee_write_byte(abfd, (bfd_byte)(value));
+  if (((unsigned) value) <= 127)
+    {
+      ieee_write_byte (abfd, (bfd_byte) value);
+    }
+  else
+    {
+      unsigned int length;
+      /* How many significant bytes ? */
+      /* FIXME FOR LONGER INTS */
+      if (value & 0xff000000)
+       {
+         length = 4;
+       }
+      else if (value & 0x00ff0000)
+       {
+         length = 3;
+       }
+      else if (value & 0x0000ff00)
+       {
+         length = 2;
+       }
+      else
+       length = 1;
+
+      ieee_write_byte (abfd,
+                (bfd_byte) ((int) ieee_number_repeat_start_enum + length));
+      switch (length)
+       {
+       case 4:
+         ieee_write_byte (abfd, (bfd_byte) (value >> 24));
+       case 3:
+         ieee_write_byte (abfd, (bfd_byte) (value >> 16));
+       case 2:
+         ieee_write_byte (abfd, (bfd_byte) (value >> 8));
+       case 1:
+         ieee_write_byte (abfd, (bfd_byte) (value));
+       }
     }
-  }
 }
 
 static void
-DEFUN(ieee_write_id,(abfd, id),
-      bfd *abfd AND
-      CONST char *id)
+DEFUN (ieee_write_id, (abfd, id),
+       bfd * abfd AND
+       CONST char *id)
 {
-  size_t length = strlen(id);
-  if (length <= 127) {
-    ieee_write_byte(abfd, (bfd_byte)length);
-  }
-  else if (length < 255) {
-    ieee_write_byte(abfd, ieee_extension_length_1_enum);
-    ieee_write_byte(abfd, (bfd_byte)length);
-  }
-  else if (length < 65535) {
-    ieee_write_byte(abfd, ieee_extension_length_2_enum);
-    ieee_write_byte(abfd, (bfd_byte)(length >> 8));
-    ieee_write_byte(abfd, (bfd_byte)(length & 0xff));  
-  }
-  else {
-    BFD_FAIL();
-  }
-  bfd_write((PTR)id, 1, length, abfd);
+  size_t length = strlen (id);
+  if (length <= 127)
+    {
+      ieee_write_byte (abfd, (bfd_byte) length);
+    }
+  else if (length < 255)
+    {
+      ieee_write_byte (abfd, ieee_extension_length_1_enum);
+      ieee_write_byte (abfd, (bfd_byte) length);
+    }
+  else if (length < 65535)
+    {
+      ieee_write_byte (abfd, ieee_extension_length_2_enum);
+      ieee_write_byte (abfd, (bfd_byte) (length >> 8));
+      ieee_write_byte (abfd, (bfd_byte) (length & 0xff));
+    }
+  else
+    {
+      BFD_FAIL ();
+    }
+  bfd_write ((PTR) id, 1, length, abfd);
 }
+\f
+
 /***************************************************************************
 Functions for reading from ieee files in the strange way that the
 standard requires:
 */
 
-
 #define this_byte(ieee) *((ieee)->input_p)
 #define next_byte(ieee) ((ieee)->input_p++)
 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
 
-
-static unsigned short 
-DEFUN(read_2bytes,(ieee),
-   common_header_type *ieee)
+static unsigned short
+DEFUN (read_2bytes, (ieee),
+       common_header_type * ieee)
 {
-  unsigned  char c1 = this_byte_and_next(ieee);
-  unsigned  char c2 = this_byte_and_next(ieee);
-  return (c1<<8 ) | c2;
-
+  unsigned char c1 = this_byte_and_next (ieee);
+  unsigned char c2 = this_byte_and_next (ieee);
+  return (c1 << 8) | c2;
 }
 
 static void
-DEFUN(bfd_get_string,(ieee, string, length),
-    common_header_type *ieee AND
-      char *string AND
-      size_t length)
+DEFUN (bfd_get_string, (ieee, string, length),
+       common_header_type * ieee AND
+       char *string AND
+       size_t length)
 {
   size_t i;
-  for (i= 0; i < length; i++) {
-    string[i] = this_byte_and_next(ieee);
-  }
+  for (i = 0; i < length; i++)
+    {
+      string[i] = this_byte_and_next (ieee);
+    }
 }
 
 static char *
-DEFUN(read_id,(ieee),
-  common_header_type *ieee)
+DEFUN (read_id, (ieee),
+       common_header_type * ieee)
 {
   size_t length;
   char *string;
-  length = this_byte_and_next(ieee);
-  if (length <= 0x7f) {
-    /* Simple string of length 0 to 127 */
-  }
-  else if (length == 0xde) {
-    /* Length is next byte, allowing 0..255 */
-    length = this_byte_and_next(ieee);
-  }
-  else if (length == 0xdf) {
-    /* Length is next two bytes, allowing 0..65535 */
-    length = this_byte_and_next(ieee) ;
-    length = (length * 256) + this_byte_and_next(ieee);
-  }
+  length = this_byte_and_next (ieee);
+  if (length <= 0x7f)
+    {
+      /* Simple string of length 0 to 127 */
+    }
+  else if (length == 0xde)
+    {
+      /* Length is next byte, allowing 0..255 */
+      length = this_byte_and_next (ieee);
+    }
+  else if (length == 0xdf)
+    {
+      /* Length is next two bytes, allowing 0..65535 */
+      length = this_byte_and_next (ieee);
+      length = (length * 256) + this_byte_and_next (ieee);
+    }
   /* Buy memory and read string */
-  string = bfd_alloc(ieee->abfd, length+1);
-  bfd_get_string(ieee, string, length);
+  string = bfd_alloc (ieee->abfd, length + 1);
+  if (!string)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
+  bfd_get_string (ieee, string, length);
   string[length] = 0;
   return string;
 }
 
 static void
-DEFUN(ieee_write_expression,(abfd, value, symbol, pcrel, index),
-      bfd*abfd AND
-      bfd_vma value AND
-      asymbol *symbol AND
-      boolean pcrel AND
-    unsigned int index)
+DEFUN (ieee_write_expression, (abfd, value, symbol, pcrel, index),
+       bfd * abfd AND
+       bfd_vma value AND
+       asymbol * symbol AND
+       boolean pcrel AND
+       unsigned int index)
 {
   unsigned int term_count = 0;
 
-  if (value != 0) 
-  {
-    ieee_write_int(abfd, value);
-    term_count++;
-  }
-  
-     
+  if (value != 0)
+    {
+      ieee_write_int (abfd, value);
+      term_count++;
+    }
 
   if (bfd_is_com_section (symbol->section)
-      || symbol->section == &bfd_und_section) 
-  {
-    /* Def of a common symbol */
-    ieee_write_byte(abfd, ieee_variable_X_enum);
-    ieee_write_int(abfd, symbol->value);
-    term_count++;
-  }
-  else  if (symbol->section != &bfd_abs_section) 
-  {
-    /* Ref to defined symbol - */
-  
-    ieee_write_byte(abfd, ieee_variable_R_enum);
-    ieee_write_byte(abfd, 
-       (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
-    term_count++;
-    if (symbol->flags & BSF_GLOBAL) 
-    {
-      ieee_write_byte(abfd, ieee_variable_I_enum);
-      ieee_write_int(abfd, symbol->value);
+      || symbol->section == &bfd_und_section)
+    {
+      /* Def of a common symbol */
+      ieee_write_byte (abfd, ieee_variable_X_enum);
+      ieee_write_int (abfd, symbol->value);
       term_count++;
     }
-    else if (symbol->flags & ( BSF_LOCAL | BSF_SECTION_SYM))
+  else if (symbol->section != &bfd_abs_section)
     {
-      /* This is a reference to a defined local symbol, 
-        We can easily do a local as a section+offset */
-      ieee_write_byte(abfd, ieee_variable_R_enum); /* or L */
-      ieee_write_byte(abfd, 
-         (bfd_byte)(symbol->section->index + IEEE_SECTION_NUMBER_BASE));
-      ieee_write_int(abfd, symbol->value);
-      term_count++;
+      /* Ref to defined symbol - */
 
+      ieee_write_byte (abfd, ieee_variable_R_enum);
+      ieee_write_byte (abfd,
+           (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
+      term_count++;
+      if (symbol->flags & BSF_GLOBAL)
+       {
+         ieee_write_byte (abfd, ieee_variable_I_enum);
+         ieee_write_int (abfd, symbol->value);
+         term_count++;
+       }
+      else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
+       {
+         /* This is a reference to a defined local symbol,
+        We can easily do a local as a section+offset */
+         ieee_write_byte (abfd, ieee_variable_R_enum); /* or L */
+         ieee_write_byte (abfd,
+           (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
+         ieee_write_int (abfd, symbol->value);
+         term_count++;
+       }
+      else
+       {
+         BFD_FAIL ();
+       }
     }
-    else   {
-       BFD_FAIL();
-      }
-
-  }
 
-  
-  if(pcrel) {
+  if (pcrel)
+    {
       /* subtract the pc from here by asking for PC of this section*/
-      ieee_write_byte(abfd, ieee_variable_P_enum);
-      ieee_write_byte(abfd, (bfd_byte)(index+IEEE_SECTION_NUMBER_BASE));
-      ieee_write_byte(abfd, ieee_function_minus_enum);
+      ieee_write_byte (abfd, ieee_variable_P_enum);
+      ieee_write_byte (abfd, (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE));
+      ieee_write_byte (abfd, ieee_function_minus_enum);
     }
 
-  if (term_count == 1) 
-  {
-    ieee_write_byte(abfd,0);
-  }
-  else {    
-      while (term_count > 1) {
-         ieee_write_byte(abfd, ieee_function_plus_enum);
+  if (term_count == 1)
+    {
+      ieee_write_byte (abfd, 0);
+    }
+  else
+    {
+      while (term_count > 1)
+       {
+         ieee_write_byte (abfd, ieee_function_plus_enum);
          term_count--;
        }
-
     }
-
 }
-
-
-
-
-
-
-
+\f
 
 /*****************************************************************************/
 
@@ -285,72 +289,76 @@ DEFUN(ieee_write_expression,(abfd, value, symbol, pcrel, index),
 writes any integer into the buffer supplied and always takes 5 bytes
 */
 static void
-DEFUN(ieee_write_int5,(buffer, value),
-      bfd_byte*buffer AND
-      bfd_vma value )
+DEFUN (ieee_write_int5, (buffer, value),
+       bfd_byte * buffer AND
+       bfd_vma value)
 {
-  buffer[0] = (bfd_byte)ieee_number_repeat_4_enum;
-  buffer[1] = (value >> 24 ) & 0xff;
-  buffer[2] = (value >> 16 ) & 0xff;
-  buffer[3] = (value >> 8 ) & 0xff;
-  buffer[4] = (value >> 0 ) & 0xff;
+  buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
+  buffer[1] = (value >> 24) & 0xff;
+  buffer[2] = (value >> 16) & 0xff;
+  buffer[3] = (value >> 8) & 0xff;
+  buffer[4] = (value >> 0) & 0xff;
 }
+
 static void
-DEFUN(ieee_write_int5_out, (abfd, value),
-      bfd *abfd AND
-      bfd_vma value)
+DEFUN (ieee_write_int5_out, (abfd, value),
+       bfd * abfd AND
+       bfd_vma value)
 {
   bfd_byte b[5];
-  ieee_write_int5(b, value);
-  bfd_write((PTR)b,1,5,abfd);
+  ieee_write_int5 (b, value);
+  bfd_write ((PTR) b, 1, 5, abfd);
 }
 
-
-static boolean 
-DEFUN(parse_int,(ieee, value_ptr),
-      common_header_type  *ieee AND
-      bfd_vma *value_ptr)
+static boolean
+DEFUN (parse_int, (ieee, value_ptr),
+       common_header_type * ieee AND
+       bfd_vma * value_ptr)
 {
-  int value = this_byte(ieee);
+  int value = this_byte (ieee);
   int result;
-  if (value >= 0 && value <= 127) {
-    *value_ptr = value;
-    next_byte(ieee);
-    return true;
-  } 
-  else if (value >= 0x80 && value <= 0x88) {
-    unsigned int count = value & 0xf;
-    result = 0;
-    next_byte(ieee);
-    while (count) {
-      result =(result << 8) | this_byte_and_next(ieee);
-      count--;
-    }
-    *value_ptr = result;
-    return true;
-  } 
+  if (value >= 0 && value <= 127)
+    {
+      *value_ptr = value;
+      next_byte (ieee);
+      return true;
+    }
+  else if (value >= 0x80 && value <= 0x88)
+    {
+      unsigned int count = value & 0xf;
+      result = 0;
+      next_byte (ieee);
+      while (count)
+       {
+         result = (result << 8) | this_byte_and_next (ieee);
+         count--;
+       }
+      *value_ptr = result;
+      return true;
+    }
   return false;
 }
+
 static int
-DEFUN(parse_i,(ieee, ok),
-   common_header_type *ieee AND
-      boolean *ok)
+DEFUN (parse_i, (ieee, ok),
+       common_header_type * ieee AND
+       boolean * ok)
 {
   bfd_vma x;
-  *ok = parse_int(ieee, &x);
+  *ok = parse_int (ieee, &x);
   return x;
 }
 
-static bfd_vma 
-DEFUN(must_parse_int,(ieee),
-     common_header_type *ieee)
+static bfd_vma
+DEFUN (must_parse_int, (ieee),
+       common_header_type * ieee)
 {
   bfd_vma result;
-  BFD_ASSERT(parse_int(ieee, &result) == true);
+  BFD_ASSERT (parse_int (ieee, &result) == true);
   return result;
 }
 
-typedef struct 
+typedef struct
 {
   bfd_vma value;
   asection *section;
@@ -358,42 +366,43 @@ typedef struct
 } ieee_value_type;
 
 
-static 
-reloc_howto_type abs32_howto 
- = HOWTO(1,0,2,32,false,0,complain_overflow_bitfield,0,"abs32",true,0xffffffff, 0xffffffff,false);
 static
-reloc_howto_type abs16_howto 
- = HOWTO(1,0,1,16,false,0,complain_overflow_bitfield,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
+reloc_howto_type abs32_howto
+= HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
+static
+reloc_howto_type abs16_howto
+= HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
 
 static
-reloc_howto_type abs8_howto 
- = HOWTO(1,0,0,8,false,0,complain_overflow_bitfield,0,"abs8",true,0x000000ff, 0x000000ff,false);
+reloc_howto_type abs8_howto
+= HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
 
-static 
-reloc_howto_type rel32_howto 
- = HOWTO(1,0,2,32,true,0,complain_overflow_signed,0,"rel32",true,0xffffffff,
-        0xffffffff,false);
+static
+reloc_howto_type rel32_howto
+= HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
+        0xffffffff, false);
 
 static
-reloc_howto_type rel16_howto 
- = HOWTO(1,0,1,16,true,0,complain_overflow_signed,0,"rel16",true,0x0000ffff, 0x0000ffff,false);
+reloc_howto_type rel16_howto
+= HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
 
 static
-reloc_howto_type rel8_howto 
- = HOWTO(1,0,0,8,true,0,complain_overflow_signed,0,"rel8",true,0x000000ff, 0x000000ff,false);
+reloc_howto_type rel8_howto
+= HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
 
 
-static ieee_symbol_index_type NOSYMBOL = {  0, 0};
+static ieee_symbol_index_type NOSYMBOL =
+{0, 0};
 
 
 static void
-DEFUN(parse_expression,(ieee, value, symbol, pcrel, extra, section),
-      ieee_data_type *ieee AND
-      bfd_vma *value AND
-      ieee_symbol_index_type *symbol AND
-      boolean *pcrel AND
-      unsigned int *extra AND
-      asection **section)
+DEFUN (parse_expression, (ieee, value, symbol, pcrel, extra, section),
+       ieee_data_type * ieee AND
+       bfd_vma * value AND
+       ieee_symbol_index_type * symbol AND
+       boolean * pcrel AND
+       unsigned int *extra AND
+       asection ** section)
 
 {
 #define POS sp[1]
@@ -402,7 +411,6 @@ DEFUN(parse_expression,(ieee, value, symbol, pcrel, extra, section),
 #define INC sp++;
 #define DEC sp--;
 
-  
   boolean loop = true;
   ieee_value_type stack[10];
 
@@ -411,594 +419,628 @@ DEFUN(parse_expression,(ieee, value, symbol, pcrel, extra, section),
 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
   ieee_value_type *sp = stack;
 
-  while (loop) {
-    switch (this_byte(&(ieee->h))) 
+  while (loop)
+    {
+      switch (this_byte (&(ieee->h)))
        {
        case ieee_variable_P_enum:
          /* P variable, current program counter for section n */
-           {
-             int section_n ;
-             next_byte(&(ieee->h));
-             *pcrel = true;
-             section_n  = must_parse_int(&(ieee->h));
-             PUSH(NOSYMBOL, &bfd_abs_section,
-                  TOS.value = ieee->section_table[section_n]->vma +
-                  ieee_per_section(ieee->section_table[section_n])->pc);
-             break;
-           }
+         {
+           int section_n;
+           next_byte (&(ieee->h));
+           *pcrel = true;
+           section_n = must_parse_int (&(ieee->h));
+           PUSH (NOSYMBOL, &bfd_abs_section,
+                 TOS.value = ieee->section_table[section_n]->vma +
+                 ieee_per_section (ieee->section_table[section_n])->pc);
+           break;
+         }
        case ieee_variable_L_enum:
          /* L variable  address of section N */
-         next_byte(&(ieee->h));
-         PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
+         next_byte (&(ieee->h));
+         PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
          break;
        case ieee_variable_R_enum:
          /* R variable, logical address of section module */
          /* FIXME, this should be different to L */
-         next_byte(&(ieee->h));
-         PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
+         next_byte (&(ieee->h));
+         PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
          break;
        case ieee_variable_S_enum:
          /* S variable, size in MAUS of section module */
-         next_byte(&(ieee->h));
-         PUSH(NOSYMBOL,
-              0,
-              ieee->section_table[must_parse_int(&(ieee->h))]->_raw_size);
+         next_byte (&(ieee->h));
+         PUSH (NOSYMBOL,
+               0,
+               ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
          break;
-         case ieee_variable_I_enum:
+       case ieee_variable_I_enum:
        case ieee_variable_X_enum:
          /* Push the address of external variable n */
-           {
-             ieee_symbol_index_type sy;
-             next_byte(&(ieee->h));
-             sy.index  = (int)(must_parse_int(&(ieee->h))) ;
-             sy.letter = 'X';
+         {
+           ieee_symbol_index_type sy;
+           next_byte (&(ieee->h));
+           sy.index = (int) (must_parse_int (&(ieee->h)));
+           sy.letter = 'X';
 
-             PUSH(sy, &bfd_und_section, 0);
-           }   
+           PUSH (sy, &bfd_und_section, 0);
+         }
          break;
        case ieee_function_minus_enum:
-           {
-             bfd_vma value1, value2;
-             asection *section1, *section_dummy;
-             ieee_symbol_index_type sy;
-             next_byte(&(ieee->h));
-
-             POP(sy, section1, value1);
-             POP(sy, section_dummy, value2);
-             PUSH(sy, section1 ? section1 : section_dummy, value1-value2);
-           }
+         {
+           bfd_vma value1, value2;
+           asection *section1, *section_dummy;
+           ieee_symbol_index_type sy;
+           next_byte (&(ieee->h));
+
+           POP (sy, section1, value1);
+           POP (sy, section_dummy, value2);
+           PUSH (sy, section1 ? section1 : section_dummy, value1 - value2);
+         }
          break;
        case ieee_function_plus_enum:
-           {
-             bfd_vma value1, value2;
-             asection *section1;
-             asection *section2;
-             ieee_symbol_index_type sy1;
-             ieee_symbol_index_type sy2;
-             next_byte(&(ieee->h));
-
-             POP(sy1, section1, value1);
-             POP(sy2, section2, value2);
-             PUSH(sy1.letter ? sy1 : sy2, section1!=&bfd_abs_section ? section1: section2, value1+value2);
-           }
+         {
+           bfd_vma value1, value2;
+           asection *section1;
+           asection *section2;
+           ieee_symbol_index_type sy1;
+           ieee_symbol_index_type sy2;
+           next_byte (&(ieee->h));
+
+           POP (sy1, section1, value1);
+           POP (sy2, section2, value2);
+           PUSH (sy1.letter ? sy1 : sy2, section1 != &bfd_abs_section ? section1 : section2, value1 + value2);
+         }
          break;
-       default: 
-           {
-             bfd_vma va;
-             BFD_ASSERT(this_byte(&(ieee->h)) < (int)ieee_variable_A_enum 
-                        || this_byte(&(ieee->h)) > (int)ieee_variable_Z_enum);
-             if (parse_int(&(ieee->h), &va)) 
-                 {
-                   PUSH(NOSYMBOL, &bfd_abs_section, va);
-                 }
-             else {
-               /* 
+       default:
+         {
+           bfd_vma va;
+           BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
+                   || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
+           if (parse_int (&(ieee->h), &va))
+             {
+               PUSH (NOSYMBOL, &bfd_abs_section, va);
+             }
+           else
+             {
+               /*
                  Thats all that we can understand. As far as I can see
                  there is a bug in the Microtec IEEE output which I'm
-                 using to scan, whereby the comma operator is ommited
+                 using to scan, whereby the comma operator is omitted
                  sometimes in an expression, giving expressions with too
                  many terms. We can tell if that's the case by ensuring
                  that sp == stack here. If not, then we've pushed
-                 something too far, so we keep adding
-                 */
+                 something too far, so we keep adding.  */
+
+               while (sp != stack + 1)
+                 {
+                   asection *section1;
+                   ieee_symbol_index_type sy1;
+                   POP (sy1, section1, *extra);
+                 }
+               {
+                 asection *dummy;
 
-               while (sp != stack+1) {
-                 asection *section1;
-                 ieee_symbol_index_type sy1;
-                 POP(sy1, section1, *extra);
+                 POP (*symbol, dummy, *value);
+                 if (section)
+                   *section = dummy;
                }
-             {
-               asection *dummy;
 
-               POP(*symbol, dummy, *value);
-               if (section) *section = dummy;
-             }
-               
                loop = false;
              }
-           }
-
+         }
        }
-  }
+    }
 }
 
 
-
 #define ieee_seek(abfd, offset) \
   IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
 
-#define ieee_pos(abfd)   IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte 
+#define ieee_pos(abfd)   IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte
 
 static unsigned int last_index;
-static char last_type; /* is the index for an X or a D */
+static char last_type;         /* is the index for an X or a D */
+
 static ieee_symbol_type *
-DEFUN(get_symbol,(abfd, 
-                 ieee,  
-                 last_symbol,
-                 symbol_count,
-                 pptr,
-                 max_index,
-                 this_type
-                 ),
-      bfd *abfd AND
-      ieee_data_type *ieee AND
-      ieee_symbol_type *last_symbol AND
-      unsigned int *symbol_count AND
-                 ieee_symbol_type *** pptr AND
-      unsigned int *max_index AND
-      char this_type
-      )
+DEFUN (get_symbol, (abfd,
+                   ieee,
+                   last_symbol,
+                   symbol_count,
+                   pptr,
+                   max_index,
+                   this_type
+       ),
+       bfd * abfd AND
+       ieee_data_type * ieee AND
+       ieee_symbol_type * last_symbol AND
+       unsigned int *symbol_count AND
+       ieee_symbol_type *** pptr AND
+       unsigned int *max_index AND
+       char this_type
+)
 {
   /* Need a new symbol */
-  unsigned int new_index = must_parse_int(&(ieee->h));
-  if (new_index != last_index || this_type != last_type) {
-    ieee_symbol_type  *   new_symbol = (ieee_symbol_type *)bfd_alloc(ieee->h.abfd,
-                                                                    sizeof(ieee_symbol_type));
-
-    new_symbol->index = new_index;
-    last_index = new_index;
-    ( *symbol_count)++;        
-    ** pptr= new_symbol;
-    *pptr = &new_symbol->next;
-    if (new_index > *max_index) {
-      *max_index = new_index;
-    }
-    last_type = this_type;
-    return new_symbol;
-  }
+  unsigned int new_index = must_parse_int (&(ieee->h));
+  if (new_index != last_index || this_type != last_type)
+    {
+      ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd,
+                                                sizeof (ieee_symbol_type));
+      if (!new_symbol)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
+
+      new_symbol->index = new_index;
+      last_index = new_index;
+      (*symbol_count)++;
+      **pptr = new_symbol;
+      *pptr = &new_symbol->next;
+      if (new_index > *max_index)
+       {
+         *max_index = new_index;
+       }
+      last_type = this_type;
+      return new_symbol;
+    }
   return last_symbol;
 }
+
 static void
-DEFUN(ieee_slurp_external_symbols,(abfd),
-      bfd *abfd)
+DEFUN (ieee_slurp_external_symbols, (abfd),
+       bfd * abfd)
 {
-  ieee_data_type *ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
   file_ptr offset = ieee->w.r.external_part;
 
-
   ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
   ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
-  ieee_symbol_type  *symbol = (ieee_symbol_type *)NULL;
+  ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
   unsigned int symbol_count = 0;
   boolean loop = true;
   last_index = 0xffffff;
   ieee->symbol_table_full = true;
 
-  ieee_seek(abfd, offset );
+  ieee_seek (abfd, offset);
 
-  while (loop) {
-    switch (this_byte(&(ieee->h))) {
-    case ieee_nn_record:
-      next_byte(&(ieee->h));
+  while (loop)
+    {
+      switch (this_byte (&(ieee->h)))
+       {
+       case ieee_nn_record:
+         next_byte (&(ieee->h));
 
-      symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
-                         &prev_symbols_ptr, 
-                         &ieee->external_symbol_max_index,'D');
+         symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
+                              &prev_symbols_ptr,
+                              &ieee->external_symbol_max_index, 'D');
 
 
-      symbol->symbol.the_bfd = abfd;
-      symbol->symbol.name = read_id(&(ieee->h));
-      symbol->symbol.udata = (PTR)NULL;
-      symbol->symbol.flags = BSF_NO_FLAGS;
+         symbol->symbol.the_bfd = abfd;
+         symbol->symbol.name = read_id (&(ieee->h));
+         symbol->symbol.udata = (PTR) NULL;
+         symbol->symbol.flags = BSF_NO_FLAGS;
+         break;
+       case ieee_external_symbol_enum:
+         next_byte (&(ieee->h));
 
-      
-      break;
-    case ieee_external_symbol_enum:
-      next_byte(&(ieee->h));
-                                            
-      symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
-                         &prev_symbols_ptr,
-                         &ieee->external_symbol_max_index,'D');
+         symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
+                              &prev_symbols_ptr,
+                              &ieee->external_symbol_max_index, 'D');
 
 
-      BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
+         BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
 
-      symbol->symbol.the_bfd = abfd;
-      symbol->symbol.name = read_id(&(ieee->h));
-      symbol->symbol.udata = (PTR)NULL;
-      symbol->symbol.flags = BSF_NO_FLAGS;
-      break;
-    case ieee_attribute_record_enum >> 8:
-       {
-         unsigned int symbol_name_index;
-         unsigned int symbol_type_index;
-         unsigned int symbol_attribute_def;
-         bfd_vma value;
-         next_byte(&(ieee->h)); /* Skip prefix */
-         next_byte(&(ieee->h));
-         symbol_name_index = must_parse_int(&(ieee->h));
-         symbol_type_index = must_parse_int(&(ieee->h));
-         symbol_attribute_def = must_parse_int(&(ieee->h));
-         switch (symbol_attribute_def) {
-         case 63:
-           /* Module misc; followed by two fields which describe the
+         symbol->symbol.the_bfd = abfd;
+         symbol->symbol.name = read_id (&(ieee->h));
+         symbol->symbol.udata = (PTR) NULL;
+         symbol->symbol.flags = BSF_NO_FLAGS;
+         break;
+       case ieee_attribute_record_enum >> 8:
+         {
+           unsigned int symbol_name_index;
+           unsigned int symbol_type_index;
+           unsigned int symbol_attribute_def;
+           bfd_vma value;
+           next_byte (&(ieee->h));     /* Skip prefix */
+           next_byte (&(ieee->h));
+           symbol_name_index = must_parse_int (&(ieee->h));
+           symbol_type_index = must_parse_int (&(ieee->h));
+           symbol_attribute_def = must_parse_int (&(ieee->h));
+           switch (symbol_attribute_def)
+             {
+             case 63:
+               /* Module misc; followed by two fields which describe the
               current module block. The first fired is the type id
               number, the second is the number of asn records
               associated with the directive */
-           parse_int(&(ieee->h),&value);
-           parse_int(&(ieee->h),&value);
-           break;
+               parse_int (&(ieee->h), &value);
+               parse_int (&(ieee->h), &value);
+               break;
 
-         default:
-           parse_int(&(ieee->h),&value);
-           break;
+             default:
+               parse_int (&(ieee->h), &value);
+               break;
+             }
          }
-       }
-      break;
-    case ieee_value_record_enum >> 8:
-       {
-         unsigned int symbol_name_index;
-         ieee_symbol_index_type symbol_ignore;
-         boolean pcrel_ignore;
-         unsigned int extra;
-         next_byte(&(ieee->h));
-         next_byte(&(ieee->h));
-
-         symbol_name_index = must_parse_int(&(ieee->h));
-         parse_expression(ieee,
-                          &symbol->symbol.value,
-                          &symbol_ignore, 
-                          &pcrel_ignore, 
-                          &extra,
-                          &symbol->symbol.section);
-
-           symbol->symbol.flags  = BSF_GLOBAL | BSF_EXPORT;
+         break;
+       case ieee_value_record_enum >> 8:
+         {
+           unsigned int symbol_name_index;
+           ieee_symbol_index_type symbol_ignore;
+           boolean pcrel_ignore;
+           unsigned int extra;
+           next_byte (&(ieee->h));
+           next_byte (&(ieee->h));
+
+           symbol_name_index = must_parse_int (&(ieee->h));
+           parse_expression (ieee,
+                             &symbol->symbol.value,
+                             &symbol_ignore,
+                             &pcrel_ignore,
+                             &extra,
+                             &symbol->symbol.section);
+
+           symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
 
-       }
-      break;
-    case ieee_weak_external_reference_enum:
-       { bfd_vma size;
-         bfd_vma value ;
-         next_byte(&(ieee->h));
-         /* Throw away the external reference index */
-         (void)must_parse_int(&(ieee->h));
-         /* Fetch the default size if not resolved */
-         size = must_parse_int(&(ieee->h));
-         /* Fetch the defautlt value if available */
-         if (  parse_int(&(ieee->h), &value) == false) {
-           value = 0;
          }
-         /* This turns into a common */
-         symbol->symbol.section = &bfd_com_section;
-         symbol->symbol.value = size;
-       }
-      break;
+         break;
+       case ieee_weak_external_reference_enum:
+         {
+           bfd_vma size;
+           bfd_vma value;
+           next_byte (&(ieee->h));
+           /* Throw away the external reference index */
+           (void) must_parse_int (&(ieee->h));
+           /* Fetch the default size if not resolved */
+           size = must_parse_int (&(ieee->h));
+           /* Fetch the defautlt value if available */
+           if (parse_int (&(ieee->h), &value) == false)
+             {
+               value = 0;
+             }
+           /* This turns into a common */
+           symbol->symbol.section = &bfd_com_section;
+           symbol->symbol.value = size;
+         }
+         break;
 
-    case ieee_external_reference_enum: 
-      next_byte(&(ieee->h));
+       case ieee_external_reference_enum:
+         next_byte (&(ieee->h));
 
-      symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
-                         &prev_reference_ptr,
-                         &ieee->external_reference_max_index,'X');
+         symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
+                              &prev_reference_ptr,
+                              &ieee->external_reference_max_index, 'X');
 
 
-      symbol->symbol.the_bfd = abfd;
-      symbol->symbol.name = read_id(&(ieee->h));
-      symbol->symbol.udata = (PTR)NULL;
-      symbol->symbol.section = &bfd_und_section;
-      symbol->symbol.value = (bfd_vma)0;
-      symbol->symbol.flags =  0;
+         symbol->symbol.the_bfd = abfd;
+         symbol->symbol.name = read_id (&(ieee->h));
+         symbol->symbol.udata = (PTR) NULL;
+         symbol->symbol.section = &bfd_und_section;
+         symbol->symbol.value = (bfd_vma) 0;
+         symbol->symbol.flags = 0;
 
-      BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
-      break;
+         BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
+         break;
 
-    default:
-      loop = false;
+       default:
+         loop = false;
+       }
     }
-  }
-
-  if (ieee->external_symbol_max_index != 0) {
-    ieee->external_symbol_count = 
-      ieee->external_symbol_max_index -
-       ieee->external_symbol_min_index + 1  ;
-  }
-  else  {
-    ieee->external_symbol_count = 0;
-  }
 
+  if (ieee->external_symbol_max_index != 0)
+    {
+      ieee->external_symbol_count =
+       ieee->external_symbol_max_index -
+       ieee->external_symbol_min_index + 1;
+    }
+  else
+    {
+      ieee->external_symbol_count = 0;
+    }
 
-  if(ieee->external_reference_max_index != 0) {
-    ieee->external_reference_count = 
-      ieee->external_reference_max_index -
+  if (ieee->external_reference_max_index != 0)
+    {
+      ieee->external_reference_count =
+       ieee->external_reference_max_index -
        ieee->external_reference_min_index + 1;
-  }
-  else {
-    ieee->external_reference_count = 0;
-  }
+    }
+  else
+    {
+      ieee->external_reference_count = 0;
+    }
 
   abfd->symcount =
-    ieee->external_reference_count +  ieee->external_symbol_count;
-
-  if (symbol_count != abfd->symcount) {
-    /* There are gaps in the table -- */
-    ieee->symbol_table_full = false;
-  }
+    ieee->external_reference_count + ieee->external_symbol_count;
 
+  if (symbol_count != abfd->symcount)
+    {
+      /* There are gaps in the table -- */
+      ieee->symbol_table_full = false;
+    }
 
-  *prev_symbols_ptr = (ieee_symbol_type *)NULL;
-  *prev_reference_ptr = (ieee_symbol_type *)NULL;
+  *prev_symbols_ptr = (ieee_symbol_type *) NULL;
+  *prev_reference_ptr = (ieee_symbol_type *) NULL;
 }
 
 static void
-DEFUN(ieee_slurp_symbol_table,(abfd),
-      bfd *abfd)
+DEFUN (ieee_slurp_symbol_table, (abfd),
+       bfd * abfd)
 {
-  if (IEEE_DATA(abfd)->read_symbols == false) {
-    ieee_slurp_external_symbols(abfd);
-    IEEE_DATA(abfd)->read_symbols= true;
-  }
+  if (IEEE_DATA (abfd)->read_symbols == false)
+    {
+      ieee_slurp_external_symbols (abfd);
+      IEEE_DATA (abfd)->read_symbols = true;
+    }
 }
 
 unsigned int
-DEFUN(ieee_get_symtab_upper_bound,(abfd),
-      bfd *abfd)
+DEFUN (ieee_get_symtab_upper_bound, (abfd),
+       bfd * abfd)
 {
   ieee_slurp_symbol_table (abfd);
 
-  return (abfd->symcount != 0) ? 
-    (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;
+  return (abfd->symcount != 0) ?
+    (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
 }
 
-/* 
+/*
 Move from our internal lists to the canon table, and insert in
 symbol index order
 */
 
 extern bfd_target ieee_vec;
+
 unsigned int
-DEFUN(ieee_get_symtab,(abfd, location),
-      bfd *abfd AND
-      asymbol **location)
+DEFUN (ieee_get_symtab, (abfd, location),
+       bfd * abfd AND
+       asymbol ** location)
 {
   ieee_symbol_type *symp;
   static bfd dummy_bfd;
   static asymbol empty_symbol =
-    /* the_bfd, name, value, attr, section */
-    { &dummy_bfd, " ieee empty", (symvalue)0, BSF_DEBUGGING, &bfd_abs_section};
-
-  if (abfd->symcount) 
-{
-    ieee_data_type *ieee = IEEE_DATA(abfd);
-    dummy_bfd.xvec= &ieee_vec;
-    ieee_slurp_symbol_table(abfd);
-
-    if (ieee->symbol_table_full == false) {
-      /* Arrgh - there are gaps in the table, run through and fill them */
-      /* up with pointers to a null place */
-      unsigned int i;
-      for (i= 0; i < abfd->symcount; i++) {
-       location[i] = &empty_symbol;
-      }
-    }
+  /* the_bfd, name, value, attr, section */
+  {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, &bfd_abs_section};
 
+  if (abfd->symcount)
+    {
+      ieee_data_type *ieee = IEEE_DATA (abfd);
+      dummy_bfd.xvec = &ieee_vec;
+      ieee_slurp_symbol_table (abfd);
 
-    ieee->external_symbol_base_offset= -  ieee->external_symbol_min_index;
-    for (symp = IEEE_DATA(abfd)->external_symbols;
-        symp != (ieee_symbol_type *)NULL;
-        symp = symp->next) {
-      /* Place into table at correct index locations */
-      location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
+      if (ieee->symbol_table_full == false)
+       {
+         /* Arrgh - there are gaps in the table, run through and fill them */
+         /* up with pointers to a null place */
+         unsigned int i;
+         for (i = 0; i < abfd->symcount; i++)
+           {
+             location[i] = &empty_symbol;
+           }
+       }
 
-    }
+      ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
+      for (symp = IEEE_DATA (abfd)->external_symbols;
+          symp != (ieee_symbol_type *) NULL;
+          symp = symp->next)
+       {
+         /* Place into table at correct index locations */
+         location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
+       }
 
-    /* The external refs are indexed in a bit */
-    ieee->external_reference_base_offset   =
-     -  ieee->external_reference_min_index +ieee->external_symbol_count ;
+      /* The external refs are indexed in a bit */
+      ieee->external_reference_base_offset =
+       -ieee->external_reference_min_index + ieee->external_symbol_count;
 
-    for (symp = IEEE_DATA(abfd)->external_reference;
-        symp != (ieee_symbol_type *)NULL;
-        symp = symp->next) {
-      location[symp->index + ieee->external_reference_base_offset] =
-       &symp->symbol;
+      for (symp = IEEE_DATA (abfd)->external_reference;
+          symp != (ieee_symbol_type *) NULL;
+          symp = symp->next)
+       {
+         location[symp->index + ieee->external_reference_base_offset] =
+           &symp->symbol;
 
+       }
+    }
+  if (abfd->symcount)
+    {
+      location[abfd->symcount] = (asymbol *) NULL;
     }
-
-
-
-
-  }
-  if (abfd->symcount) {
-   location[abfd->symcount] = (asymbol *)NULL;
-  }
   return abfd->symcount;
 }
+
 static asection *
-DEFUN(get_section_entry,(abfd, ieee,index),
- bfd *abfd AND
-     ieee_data_type *ieee AND
-      unsigned int index)
-{
-  if (ieee->section_table[index] == (asection *)NULL) {
-    char *tmp = bfd_alloc(abfd,11);
-    asection *section;
-    sprintf(tmp," fsec%4d", index);
-    section = bfd_make_section(abfd, tmp);
-    ieee->section_table[index] = section;
-    section->flags = SEC_NO_FLAGS;
-    section->target_index = index;
-    ieee->section_table[index] = section;
-  }
+DEFUN (get_section_entry, (abfd, ieee, index),
+       bfd * abfd AND
+       ieee_data_type * ieee AND
+       unsigned int index)
+{
+  if (ieee->section_table[index] == (asection *) NULL)
+    {
+      char *tmp = bfd_alloc (abfd, 11);
+      asection *section;
+
+      if (!tmp)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
+      sprintf (tmp, " fsec%4d", index);
+      section = bfd_make_section (abfd, tmp);
+      ieee->section_table[index] = section;
+      section->flags = SEC_NO_FLAGS;
+      section->target_index = index;
+      ieee->section_table[index] = section;
+    }
   return ieee->section_table[index];
 }
 
 static void
-DEFUN(ieee_slurp_sections,(abfd),
-      bfd *abfd)
+DEFUN (ieee_slurp_sections, (abfd),
+       bfd * abfd)
 {
-  ieee_data_type *ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
   file_ptr offset = ieee->w.r.section_part;
-  asection *section = (asection *)NULL;
+  asection *section = (asection *) NULL;
   char *name;
 
-  if (offset != 0) {
-    bfd_byte section_type[3];
-    ieee_seek(abfd, offset);
-    while (true) {
-      switch (this_byte(&(ieee->h))) {
-      case ieee_section_type_enum:
-         {
-           unsigned int section_index ;
-           next_byte(&(ieee->h));
-           section_index = must_parse_int(&(ieee->h));
-           /* Fixme to be nice about a silly number of sections */
-           BFD_ASSERT(section_index < NSECTIONS);
-
-           section =get_section_entry(abfd, ieee, section_index);
-
-           section_type[0] =  this_byte_and_next(&(ieee->h));
-           switch (section_type[0]) {
-           case 0xC1:
-             /* Normal attributes for absolute sections        */
-             section_type[1] = this_byte(&(ieee->h));
-             section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
-             switch(section_type[1]) {
-             case 0xD3:                /* AS Absolute section attributes */
-               next_byte(&(ieee->h));
-               section_type[2] = this_byte(&(ieee->h));
-               switch (section_type[2]) 
-                   {
-                   case 0xD0:
-                     /* Normal code */
-                     next_byte(&(ieee->h));
-                     section->flags |= SEC_LOAD | SEC_CODE;
-                     break;
-                   case 0xC4:
-                     next_byte(&(ieee->h));
-                     section->flags |= SEC_LOAD  | SEC_DATA;
-                     /* Normal data */
-                     break;
-                   case 0xD2:
-                     next_byte(&(ieee->h));
-                     /* Normal rom data */
-                     section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
-                     break;
-                   default:
-                     break;
-                   }
-             }
-             break;
-           case 0xC3:          /* Named relocatable sections (type C) */
-             section_type[1] = this_byte(&(ieee->h));
-             section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
-             switch (section_type[1]) {
-             case 0xD0:        /* Normal code (CP) */
-               next_byte(&(ieee->h));
-               section->flags |= SEC_LOAD | SEC_CODE;
-               break;
-             case 0xC4:        /* Normal data (CD) */
-               next_byte(&(ieee->h));
-               section->flags |= SEC_LOAD  | SEC_DATA;
-               break;
-             case 0xD2:        /* Normal rom data (CR) */
-               next_byte(&(ieee->h));
-               section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
-               break;
-             default:
-               break;
-             }
-           }
-
-           /* Read section name, use it if non empty. */
-           name = read_id (&ieee->h);
-           if (name[0])
-             section->name = name;
-           
-           /* Skip these fields, which we don't care about */
+  if (offset != 0)
+    {
+      bfd_byte section_type[3];
+      ieee_seek (abfd, offset);
+      while (true)
+       {
+         switch (this_byte (&(ieee->h)))
            {
-             bfd_vma parent, brother, context;
-               parse_int(&(ieee->h), &parent);
-               parse_int(&(ieee->h), &brother);
-               parse_int(&(ieee->h), &context);
-           }
-         }
-       break;
-      case ieee_section_alignment_enum:
-         { 
-           unsigned int section_index;
-           bfd_vma value;
-           asection *section;
-           next_byte(&(ieee->h));
-           section_index = must_parse_int(&ieee->h);
-           section = get_section_entry(abfd, ieee, section_index);
-           if (section_index > ieee->section_count) {
-             ieee->section_count = section_index;
-           }
-           section->alignment_power =
-             bfd_log2(must_parse_int(&ieee->h));
-           (void)parse_int(&(ieee->h), & value);
-         }
-       break;
-      case ieee_e2_first_byte_enum: 
-         {
-           ieee_record_enum_type t = (ieee_record_enum_type)(read_2bytes(&(ieee->h)));
+           case ieee_section_type_enum:
+             {
+               unsigned int section_index;
+               next_byte (&(ieee->h));
+               section_index = must_parse_int (&(ieee->h));
+               /* Fixme to be nice about a silly number of sections */
+               BFD_ASSERT (section_index < NSECTIONS);
 
-           switch (t) {
-           case ieee_section_size_enum:
-             section = ieee->section_table[must_parse_int(&(ieee->h))];
-             section->_raw_size = must_parse_int(&(ieee->h));
-             break;
-           case ieee_physical_region_size_enum:
-             section = ieee->section_table[must_parse_int(&(ieee->h))];
-             section->_raw_size = must_parse_int(&(ieee->h));
-             break;
-           case ieee_region_base_address_enum:
-             section = ieee->section_table[must_parse_int(&(ieee->h))];
-             section->vma = must_parse_int(&(ieee->h));
-             break;
-           case ieee_mau_size_enum:
-             must_parse_int(&(ieee->h));
-             must_parse_int(&(ieee->h));
-             break;
-           case ieee_m_value_enum:
-             must_parse_int(&(ieee->h));
-             must_parse_int(&(ieee->h));
+               section = get_section_entry (abfd, ieee, section_index);
+
+               section_type[0] = this_byte_and_next (&(ieee->h));
+               switch (section_type[0])
+                 {
+                 case 0xC1:
+                   /* Normal attributes for absolute sections  */
+                   section_type[1] = this_byte (&(ieee->h));
+                   section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
+                   switch (section_type[1])
+                     {
+                     case 0xD3:        /* AS Absolute section attributes */
+                       next_byte (&(ieee->h));
+                       section_type[2] = this_byte (&(ieee->h));
+                       switch (section_type[2])
+                         {
+                         case 0xD0:
+                           /* Normal code */
+                           next_byte (&(ieee->h));
+                           section->flags |= SEC_LOAD | SEC_CODE;
+                           break;
+                         case 0xC4:
+                           next_byte (&(ieee->h));
+                           section->flags |= SEC_LOAD | SEC_DATA;
+                           /* Normal data */
+                           break;
+                         case 0xD2:
+                           next_byte (&(ieee->h));
+                           /* Normal rom data */
+                           section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
+                           break;
+                         default:
+                           break;
+                         }
+                     }
+                   break;
+                 case 0xC3:    /* Named relocatable sections (type C) */
+                   section_type[1] = this_byte (&(ieee->h));
+                   section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
+                   switch (section_type[1])
+                     {
+                     case 0xD0:        /* Normal code (CP) */
+                       next_byte (&(ieee->h));
+                       section->flags |= SEC_LOAD | SEC_CODE;
+                       break;
+                     case 0xC4:        /* Normal data (CD) */
+                       next_byte (&(ieee->h));
+                       section->flags |= SEC_LOAD | SEC_DATA;
+                       break;
+                     case 0xD2:        /* Normal rom data (CR) */
+                       next_byte (&(ieee->h));
+                       section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
+                       break;
+                     default:
+                       break;
+                     }
+                 }
+
+               /* Read section name, use it if non empty. */
+               name = read_id (&ieee->h);
+               if (name[0])
+                 section->name = name;
+
+               /* Skip these fields, which we don't care about */
+               {
+                 bfd_vma parent, brother, context;
+                 parse_int (&(ieee->h), &parent);
+                 parse_int (&(ieee->h), &brother);
+                 parse_int (&(ieee->h), &context);
+               }
+             }
              break;
-           case ieee_section_base_address_enum:
-             section = ieee->section_table[must_parse_int(&(ieee->h))];
-             section->vma = must_parse_int(&(ieee->h));
+           case ieee_section_alignment_enum:
+             {
+               unsigned int section_index;
+               bfd_vma value;
+               asection *section;
+               next_byte (&(ieee->h));
+               section_index = must_parse_int (&ieee->h);
+               section = get_section_entry (abfd, ieee, section_index);
+               if (section_index > ieee->section_count)
+                 {
+                   ieee->section_count = section_index;
+                 }
+               section->alignment_power =
+                 bfd_log2 (must_parse_int (&ieee->h));
+               (void) parse_int (&(ieee->h), &value);
+             }
              break;
-           case ieee_section_offset_enum:
-             (void) must_parse_int(&(ieee->h));
-             (void) must_parse_int(&(ieee->h));
+           case ieee_e2_first_byte_enum:
+             {
+               ieee_record_enum_type t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
+
+               switch (t)
+                 {
+                 case ieee_section_size_enum:
+                   section = ieee->section_table[must_parse_int (&(ieee->h))];
+                   section->_raw_size = must_parse_int (&(ieee->h));
+                   break;
+                 case ieee_physical_region_size_enum:
+                   section = ieee->section_table[must_parse_int (&(ieee->h))];
+                   section->_raw_size = must_parse_int (&(ieee->h));
+                   break;
+                 case ieee_region_base_address_enum:
+                   section = ieee->section_table[must_parse_int (&(ieee->h))];
+                   section->vma = must_parse_int (&(ieee->h));
+                   break;
+                 case ieee_mau_size_enum:
+                   must_parse_int (&(ieee->h));
+                   must_parse_int (&(ieee->h));
+                   break;
+                 case ieee_m_value_enum:
+                   must_parse_int (&(ieee->h));
+                   must_parse_int (&(ieee->h));
+                   break;
+                 case ieee_section_base_address_enum:
+                   section = ieee->section_table[must_parse_int (&(ieee->h))];
+                   section->vma = must_parse_int (&(ieee->h));
+                   break;
+                 case ieee_section_offset_enum:
+                   (void) must_parse_int (&(ieee->h));
+                   (void) must_parse_int (&(ieee->h));
+                   break;
+                 default:
+                   return;
+                 }
+             }
              break;
            default:
              return;
            }
-         }
-       break;
-      default:
-       return;
-      }
+       }
     }
-  }
 }
+\f
 
 /***********************************************************************
-*  archive stuff 
+*  archive stuff
 */
+
 bfd_target *
-DEFUN(ieee_archive_p,(abfd),
-      bfd *abfd)
+DEFUN (ieee_archive_p, (abfd),
+       bfd * abfd)
 {
   char *library;
   boolean loop;
@@ -1008,215 +1050,245 @@ DEFUN(ieee_archive_p,(abfd),
   struct obstack ob;
   file_ptr buffer_offset = 0;
   ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
-  ieee_ar_data_type *ieee ;
-  abfd->tdata.ieee_ar_data = (ieee_ar_data_type *)bfd_alloc(abfd, sizeof(ieee_ar_data_type));
-  ieee=  IEEE_AR_DATA(abfd);
-
-
+  ieee_ar_data_type *ieee;
+  abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));
+  if (!abfd->tdata.ieee_ar_data)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
+  ieee = IEEE_AR_DATA (abfd);
 
-  bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
+  bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
 
   ieee->h.first_byte = buffer;
   ieee->h.input_p = buffer;
 
   ieee->h.abfd = abfd;
 
-  if (this_byte(&(ieee->h)) != Module_Beginning) {
-    abfd->tdata.ieee_ar_data = save;
-      return (bfd_target*)NULL;
+  if (this_byte (&(ieee->h)) != Module_Beginning)
+    {
+      abfd->tdata.ieee_ar_data = save;
+      return (bfd_target *) NULL;
     }
-  
 
-  next_byte(&(ieee->h));
-  library= read_id(&(ieee->h));
-  if (strcmp(library , "LIBRARY") != 0) {
-    bfd_release(abfd, ieee);
-    abfd->tdata.ieee_ar_data = save;
-    return (bfd_target *)NULL;
-  }
+  next_byte (&(ieee->h));
+  library = read_id (&(ieee->h));
+  if (strcmp (library, "LIBRARY") != 0)
+    {
+      bfd_release (abfd, ieee);
+      abfd->tdata.ieee_ar_data = save;
+      return (bfd_target *) NULL;
+    }
   /* Throw away the filename */
-  read_id(&(ieee->h));
+  read_id (&(ieee->h));
   /* This must be an IEEE archive, so we'll buy some space to do
      things */
 
-  obstack_begin(&ob, 128);
-
+  if (!obstack_begin (&ob, 128))
+    {
+      bfd_error = no_memory;
+      return (bfd_target *) NULL;
+    }
 
   ieee->element_count = 0;
   ieee->element_index = 0;
 
-  next_byte(&(ieee->h));       /* Drop the ad part */
-  must_parse_int(&(ieee->h));  /* And the two dummy numbers */
-  must_parse_int(&(ieee->h));
+  next_byte (&(ieee->h));      /* Drop the ad part */
+  must_parse_int (&(ieee->h)); /* And the two dummy numbers */
+  must_parse_int (&(ieee->h));
 
   loop = true;
   /* Read the index of the BB table */
-  while (loop) {
-    ieee_ar_obstack_type t; 
-    int rec =read_2bytes(&(ieee->h));
-    if (rec ==(int)ieee_assign_value_to_variable_enum) {
-      must_parse_int(&(ieee->h));
-      t.file_offset = must_parse_int(&(ieee->h));
-      t.abfd = (bfd *)NULL;
-      ieee->element_count++;
-
-      obstack_grow(&ob, (PTR)&t, sizeof(t));
-
-      /* Make sure that we don't go over the end of the buffer */
-
-      if (ieee_pos(abfd) > sizeof(buffer)/2) {
-       /* Past half way, reseek and reprime */
-       buffer_offset += ieee_pos(abfd);
-       bfd_seek(abfd, buffer_offset, SEEK_SET);
-       bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
-       ieee->h.first_byte = buffer;
-       ieee->h.input_p = buffer;
-      }
+  while (loop)
+    {
+      ieee_ar_obstack_type t;
+      int rec = read_2bytes (&(ieee->h));
+      if (rec == (int) ieee_assign_value_to_variable_enum)
+       {
+         must_parse_int (&(ieee->h));
+         t.file_offset = must_parse_int (&(ieee->h));
+         t.abfd = (bfd *) NULL;
+         ieee->element_count++;
+
+         obstack_grow (&ob, (PTR) & t, sizeof (t));
+
+         /* Make sure that we don't go over the end of the buffer */
+
+         if (ieee_pos (abfd) > sizeof (buffer) / 2)
+           {
+             /* Past half way, reseek and reprime */
+             buffer_offset += ieee_pos (abfd);
+             bfd_seek (abfd, buffer_offset, SEEK_SET);
+             bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
+             ieee->h.first_byte = buffer;
+             ieee->h.input_p = buffer;
+           }
+       }
+      else
+       loop = false;
     }
-    else loop = false;
-  }
 
-  ieee->elements = (ieee_ar_obstack_type *)obstack_finish(&ob);
+  ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
+  if (!ieee->elements)
+    {
+      bfd_error = no_memory;
+      return (bfd_target *) NULL;
+    }
 
   /* Now scan the area again, and replace BB offsets with file */
   /* offsets */
 
-
-  for (i = 2; i < ieee->element_count; i++) {
-    bfd_seek(abfd, ieee->elements[i].file_offset, SEEK_SET);
-    bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
-    ieee->h.first_byte = buffer;
-    ieee->h.input_p = buffer;
-    
-    next_byte(&(ieee->h));     /* Drop F8 */
-    next_byte(&(ieee->h));     /* Drop 14 */
-    must_parse_int(&(ieee->h));        /* Drop size of block */
-    if (must_parse_int(&(ieee->h)) != 0) {
-      /* This object has been deleted */
-      ieee->elements[i].file_offset = 0;
-    }
-    else {
-      ieee->elements[i].file_offset = must_parse_int(&(ieee->h));
+  for (i = 2; i < ieee->element_count; i++)
+    {
+      bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET);
+      bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
+      ieee->h.first_byte = buffer;
+      ieee->h.input_p = buffer;
+
+      next_byte (&(ieee->h));  /* Drop F8 */
+      next_byte (&(ieee->h));  /* Drop 14 */
+      must_parse_int (&(ieee->h));     /* Drop size of block */
+      if (must_parse_int (&(ieee->h)) != 0)
+       {
+         /* This object has been deleted */
+         ieee->elements[i].file_offset = 0;
+       }
+      else
+       {
+         ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
+       }
     }
-  }
 
 /*  abfd->has_armap = ;*/
   return abfd->xvec;
-
 }
 
 static boolean
-DEFUN(ieee_mkobject,(abfd),
-      bfd *abfd)
-{ 
-abfd->tdata.ieee_data = (ieee_data_type *)bfd_zalloc(abfd,sizeof(ieee_data_type));
-  
-
-  return true;
+DEFUN (ieee_mkobject, (abfd),
+       bfd * abfd)
+{
+  abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
+  return abfd->tdata.ieee_data ? true : false;
 }
 
 bfd_target *
-DEFUN(ieee_object_p,(abfd),
-      bfd *abfd)
+DEFUN (ieee_object_p, (abfd),
+       bfd * abfd)
 {
   char *processor;
   unsigned int part;
   ieee_data_type *ieee;
   unsigned char buffer[300];
-  ieee_data_type *save = IEEE_DATA(abfd);
+  ieee_data_type *save = IEEE_DATA (abfd);
 
   abfd->tdata.ieee_data = 0;
-  ieee_mkobject(abfd);
-  
-  ieee = IEEE_DATA(abfd);
-  bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
+  ieee_mkobject (abfd);
+
+  ieee = IEEE_DATA (abfd);
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
   /* Read the first few bytes in to see if it makes sense */
-  bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
+  bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
 
   ieee->h.input_p = buffer;
-  if (this_byte_and_next(&(ieee->h)) != Module_Beginning) goto fail;
+  if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
+    goto fail;
 
-  ieee->read_symbols= false;
-  ieee->read_data= false;
+  ieee->read_symbols = false;
+  ieee->read_data = false;
   ieee->section_count = 0;
   ieee->external_symbol_max_index = 0;
   ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
-  ieee->external_reference_min_index =IEEE_REFERENCE_BASE;
+  ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
   ieee->external_reference_max_index = 0;
   ieee->h.abfd = abfd;
-  memset((PTR)ieee->section_table, 0,   sizeof(ieee->section_table));
+  memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
 
-  processor = ieee->mb.processor = read_id(&(ieee->h));
-  if (strcmp(processor,"LIBRARY") == 0) goto fail;
-  ieee->mb.module_name = read_id(&(ieee->h));
-  if (abfd->filename == (CONST char *)NULL) {
-    abfd->filename =  ieee->mb.module_name;
-  }
-  /* Determine the architecture and machine type of the object file.
-     */
+  processor = ieee->mb.processor = read_id (&(ieee->h));
+  if (strcmp (processor, "LIBRARY") == 0)
+    goto fail;
+  ieee->mb.module_name = read_id (&(ieee->h));
+  if (abfd->filename == (CONST char *) NULL)
     {
-      bfd_arch_info_type *arch = bfd_scan_arch(processor);
-      if (arch == 0) goto fail;
-      abfd->arch_info = arch;
+      abfd->filename = ieee->mb.module_name;
     }
-
-  if (this_byte(&(ieee->h)) != (int)ieee_address_descriptor_enum) {
-    goto fail;
-  }
-  next_byte(&(ieee->h));       
-
-  if (parse_int(&(ieee->h), &ieee->ad.number_of_bits_mau) == false) {
-    goto fail;
-  }
-  if(parse_int(&(ieee->h), &ieee->ad.number_of_maus_in_address) == false) {
-    goto fail;
+  /* Determine the architecture and machine type of the object file.
+     */
+  {
+    bfd_arch_info_type *arch = bfd_scan_arch (processor);
+    if (arch == 0)
+      goto fail;
+    abfd->arch_info = arch;
   }
 
-  /* If there is a byte order info, take it */
-  if (this_byte(&(ieee->h)) == (int)ieee_variable_L_enum ||
-      this_byte(&(ieee->h)) == (int)ieee_variable_M_enum)
-    next_byte(&(ieee->h));
-
-
-  for (part = 0; part < N_W_VARIABLES; part++) {
-    boolean ok;
-    if (read_2bytes(&(ieee->h)) != (int) ieee_assign_value_to_variable_enum) {
+  if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
+    {
       goto fail;
     }
-    if (this_byte_and_next(&(ieee->h)) != part)  {
+  next_byte (&(ieee->h));
+
+  if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
+    {
       goto fail;
     }
-
-    ieee->w.offset[part] = parse_i(&(ieee->h), &ok);
-    if (ok==false) {
+  if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
+    {
       goto fail;
     }
 
-  }
+  /* If there is a byte order info, take it */
+  if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
+      this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
+    next_byte (&(ieee->h));
+
+  for (part = 0; part < N_W_VARIABLES; part++)
+    {
+      boolean ok;
+      if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
+       {
+         goto fail;
+       }
+      if (this_byte_and_next (&(ieee->h)) != part)
+       {
+         goto fail;
+       }
+
+      ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
+      if (ok == false)
+       {
+         goto fail;
+       }
+
+    }
   abfd->flags = HAS_SYMS;
 /* By now we know that this is a real IEEE file, we're going to read
    the whole thing into memory so that we can run up and down it
    quickly. We can work out how big the file is from the trailer
    record */
 
-  IEEE_DATA(abfd)->h.first_byte = (unsigned char *) bfd_alloc(ieee->h.abfd, ieee->w.r.me_record
-                                           + 50);
-  bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
-  bfd_read((PTR)(IEEE_DATA(abfd)->h.first_byte), 1,   ieee->w.r.me_record+50,  abfd);
+  IEEE_DATA (abfd)->h.first_byte = (unsigned char *) bfd_alloc (ieee->h.abfd, ieee->w.r.me_record
+                                                               + 50);
+  if (!IEEE_DATA (abfd)->h.first_byte)
+    {
+      bfd_error = no_memory;
+      goto fail;
+    }
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
+  bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
 
-  ieee_slurp_sections(abfd);
+  ieee_slurp_sections (abfd);
   return abfd->xvec;
- fail:
-  (void)  bfd_release(abfd, ieee);
-abfd->tdata.ieee_data = save;
-  return (bfd_target *)NULL;
+fail:
+  (void) bfd_release (abfd, ieee);
+  abfd->tdata.ieee_data = save;
+  return (bfd_target *) NULL;
 }
 
-void 
-DEFUN(ieee_get_symbol_info,(ignore_abfd, symbol, ret),
-      bfd *ignore_abfd AND
-      asymbol *symbol AND
-      symbol_info *ret)
+void
+DEFUN (ieee_get_symbol_info, (ignore_abfd, symbol, ret),
+       bfd * ignore_abfd AND
+       asymbol * symbol AND
+       symbol_info * ret)
 {
   bfd_symbol_info (symbol, ret);
   if (symbol->name[0] == ' ')
@@ -1225,430 +1297,458 @@ DEFUN(ieee_get_symbol_info,(ignore_abfd, symbol, ret),
     ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
 }
 
-void 
-DEFUN(ieee_print_symbol,(ignore_abfd, afile,  symbol, how),
-      bfd *ignore_abfd AND
-      PTR afile AND
-      asymbol *symbol AND
-      bfd_print_symbol_type how)
+void
+DEFUN (ieee_print_symbol, (ignore_abfd, afile, symbol, how),
+       bfd * ignore_abfd AND
+       PTR afile AND
+       asymbol * symbol AND
+       bfd_print_symbol_type how)
 {
-  FILE *file = (FILE *)afile;
+  FILE *file = (FILE *) afile;
 
-  switch (how) {
-  case bfd_print_symbol_name:
-    fprintf(file,"%s", symbol->name);
-    break;
-  case bfd_print_symbol_more:
+  switch (how)
+    {
+    case bfd_print_symbol_name:
+      fprintf (file, "%s", symbol->name);
+      break;
+    case bfd_print_symbol_more:
 #if 0
-    fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff,
-           aout_symbol(symbol)->other  & 0xff);
+      fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
+              aout_symbol (symbol)->other & 0xff);
 #endif
-    BFD_FAIL();
-    break;
-  case bfd_print_symbol_all:
+      BFD_FAIL ();
+      break;
+    case bfd_print_symbol_all:
       {
-       CONST char *section_name = symbol->section == (asection *)NULL ?
-         (CONST char *)"*abs" : symbol->section->name;
-       if (symbol->name[0] == ' ') {
-         fprintf(file,"* empty table entry ");
-       }
-       else {
-         bfd_print_symbol_vandf((PTR)file,symbol);
+       CONST char *section_name = symbol->section == (asection *) NULL ?
+       (CONST char *) "*abs" : symbol->section->name;
+       if (symbol->name[0] == ' ')
+         {
+           fprintf (file, "* empty table entry ");
+         }
+       else
+         {
+           bfd_print_symbol_vandf ((PTR) file, symbol);
 
-         fprintf(file," %-5s %04x %02x %s",
-                 section_name,
-                 (unsigned)          ieee_symbol(symbol)->index,
-                 (unsigned)          0, /*
+           fprintf (file, " %-5s %04x %02x %s",
+                    section_name,
+                    (unsigned) ieee_symbol (symbol)->index,
+                    (unsigned) 0,      /*
                                           aout_symbol(symbol)->desc & 0xffff,
                                           aout_symbol(symbol)->other  & 0xff,*/
-                 symbol->name);
-       }
+                    symbol->name);
+         }
       }
-    break;
-  }
+      break;
+    }
 }
 
-
-static void
-DEFUN(do_one,(ieee, current_map, location_ptr,s),
-      ieee_data_type *ieee AND
-      ieee_per_section_type *current_map AND
-      unsigned char *location_ptr AND
-      asection *s)
+static boolean
+DEFUN (do_one, (ieee, current_map, location_ptr, s),
+       ieee_data_type * ieee AND
+       ieee_per_section_type * current_map AND
+       unsigned char *location_ptr AND
+       asection * s)
 {
-  switch (this_byte(&(ieee->h)))  
+  switch (this_byte (&(ieee->h)))
+    {
+    case ieee_load_constant_bytes_enum:
       {
-      case ieee_load_constant_bytes_enum:
+       unsigned int number_of_maus;
+       unsigned int i;
+       next_byte (&(ieee->h));
+       number_of_maus = must_parse_int (&(ieee->h));
+
+       for (i = 0; i < number_of_maus; i++)
          {
-           unsigned int number_of_maus;
-           unsigned int i;
-           next_byte(&(ieee->h));
-           number_of_maus = must_parse_int(&(ieee->h));
-
-           for (i = 0; i < number_of_maus; i++) {
-             location_ptr[current_map->pc++]= this_byte(&(ieee->h));
-             next_byte(&(ieee->h));
-           }
+           location_ptr[current_map->pc++] = this_byte (&(ieee->h));
+           next_byte (&(ieee->h));
          }
-       break;
+      }
+      break;
 
-      case ieee_load_with_relocation_enum:
+    case ieee_load_with_relocation_enum:
+      {
+       boolean loop = true;
+       next_byte (&(ieee->h));
+       while (loop)
          {
-           boolean loop = true;
-           next_byte(&(ieee->h));
-           while (loop) 
+           switch (this_byte (&(ieee->h)))
+             {
+             case ieee_variable_R_enum:
+
+             case ieee_function_signed_open_b_enum:
+             case ieee_function_unsigned_open_b_enum:
+             case ieee_function_either_open_b_enum:
                {
-                 switch (this_byte(&(ieee->h))) 
-                     {
-                     case ieee_variable_R_enum:
+                 unsigned int extra = 4;
+                 boolean pcrel = false;
+                 asection *section;
+                 ieee_reloc_type *r =
+                 (ieee_reloc_type *) bfd_alloc (ieee->h.abfd,
+                                                sizeof (ieee_reloc_type));
+                 if (!r)
+                   {
+                     bfd_error = no_memory;
+                     return false;
+                   }
 
-                     case ieee_function_signed_open_b_enum:
-                     case ieee_function_unsigned_open_b_enum:
-                     case ieee_function_either_open_b_enum:
-                         {
-                           unsigned int extra = 4;
-                           boolean pcrel = false;
-asection *section;
-                           ieee_reloc_type *r = 
-                             (ieee_reloc_type *) bfd_alloc(ieee->h.abfd,
-                                                           sizeof(ieee_reloc_type));
-
-                           *(current_map->reloc_tail_ptr) = r;
-                           current_map->reloc_tail_ptr= &r->next;
-                           r->next = (ieee_reloc_type *)NULL;
-                           next_byte(&(ieee->h));
+                 *(current_map->reloc_tail_ptr) = r;
+                 current_map->reloc_tail_ptr = &r->next;
+                 r->next = (ieee_reloc_type *) NULL;
+                 next_byte (&(ieee->h));
 /*                         abort();*/
-                           r->relent.sym_ptr_ptr = 0;
-                           parse_expression(ieee,
-                                            &r->relent.addend,
-                                            &r->symbol,
-                                            &pcrel, &extra, &section);
-                           r->relent.address = current_map->pc;
-                           s->reloc_count++;
-if (r->relent.sym_ptr_ptr == 0) {
-                            r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
-}                          
-
-                           if (this_byte(&(ieee->h)) == (int)ieee_comma) {
-                             next_byte(&(ieee->h));
-                             /* Fetch number of bytes to pad */
-                             extra = must_parse_int(&(ieee->h));
-                           };
-                  
-                           switch (this_byte(&(ieee->h))) {
-                           case ieee_function_signed_close_b_enum:
-                             next_byte(&(ieee->h));
-                             break;
-                           case ieee_function_unsigned_close_b_enum:
-                             next_byte(&(ieee->h));
-                             break;
-                           case ieee_function_either_close_b_enum:
-                             next_byte(&(ieee->h));
-                             break;
-                           default:
-                             break;
-                           }
-                           /* Build a relocation entry for this type */
-                           /* If pc rel then stick -ve pc into instruction
+                 r->relent.sym_ptr_ptr = 0;
+                 parse_expression (ieee,
+                                   &r->relent.addend,
+                                   &r->symbol,
+                                   &pcrel, &extra, &section);
+                 r->relent.address = current_map->pc;
+                 s->reloc_count++;
+                 if (r->relent.sym_ptr_ptr == 0)
+                   {
+                     r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
+                   }
+
+                 if (this_byte (&(ieee->h)) == (int) ieee_comma)
+                   {
+                     next_byte (&(ieee->h));
+                     /* Fetch number of bytes to pad */
+                     extra = must_parse_int (&(ieee->h));
+                   };
+
+                 switch (this_byte (&(ieee->h)))
+                   {
+                   case ieee_function_signed_close_b_enum:
+                     next_byte (&(ieee->h));
+                     break;
+                   case ieee_function_unsigned_close_b_enum:
+                     next_byte (&(ieee->h));
+                     break;
+                   case ieee_function_either_close_b_enum:
+                     next_byte (&(ieee->h));
+                     break;
+                   default:
+                     break;
+                   }
+                 /* Build a relocation entry for this type */
+                 /* If pc rel then stick -ve pc into instruction
                               and take out of reloc ..
 
                               I've changed this. It's all too
                               complicated. I keep 0 in the
                               instruction  now.
                               */
-                   
-                           switch (extra) 
-                               {
-                               case 0:
-                               case 4:
-                                 
-                                 if (pcrel == true) 
-                                     {
+
+                 switch (extra)
+                   {
+                   case 0:
+                   case 4:
+
+                     if (pcrel == true)
+                       {
 #if KEEPMINUSPCININST
-                                       bfd_put_32(ieee->h.abfd, -current_map->pc, location_ptr +
-                                                   current_map->pc);
-                                       r->relent.howto = &rel32_howto;
-                                       r->relent.addend -=
-                                         current_map->pc;
+                         bfd_put_32 (ieee->h.abfd, -current_map->pc, location_ptr +
+                                     current_map->pc);
+                         r->relent.howto = &rel32_howto;
+                         r->relent.addend -=
+                           current_map->pc;
 #else
-                                       bfd_put_32(ieee->h.abfd,0, location_ptr +
-                                                   current_map->pc);
-                                       r->relent.howto = &rel32_howto;
+                         bfd_put_32 (ieee->h.abfd, 0, location_ptr +
+                                     current_map->pc);
+                         r->relent.howto = &rel32_howto;
 #endif
-                                     }
-                                 else 
-                                     {
-                                       bfd_put_32(ieee->h.abfd, 0, location_ptr +
-                                                   current_map->pc);
-                                       r->relent.howto = &abs32_howto;
-                                     }
-                                 current_map->pc +=4;
-                                 break;
-                               case 2:
-                                 if (pcrel == true) {
+                       }
+                     else
+                       {
+                         bfd_put_32 (ieee->h.abfd, 0, location_ptr +
+                                     current_map->pc);
+                         r->relent.howto = &abs32_howto;
+                       }
+                     current_map->pc += 4;
+                     break;
+                   case 2:
+                     if (pcrel == true)
+                       {
 #if KEEPMINUSPCININST
-                                   bfd_put_16(ieee->h.abfd, (int)(-current_map->pc),  location_ptr +current_map->pc);
-                                   r->relent.addend -= current_map->pc;
-                                   r->relent.howto = &rel16_howto;
+                         bfd_put_16 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
+                         r->relent.addend -= current_map->pc;
+                         r->relent.howto = &rel16_howto;
 #else
 
-                                   bfd_put_16(ieee->h.abfd, 0,  location_ptr +current_map->pc);
-                                   r->relent.howto = &rel16_howto;
+                         bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
+                         r->relent.howto = &rel16_howto;
 #endif
-                                 }
-
-                                 else {
-                                   bfd_put_16(ieee->h.abfd, 0,  location_ptr +current_map->pc);
-                                   r->relent.howto = &abs16_howto;
-                                 }
-                                 current_map->pc +=2;
-                                 break;
-                               case 1:
-                                 if (pcrel == true) {
+                       }
+
+                     else
+                       {
+                         bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
+                         r->relent.howto = &abs16_howto;
+                       }
+                     current_map->pc += 2;
+                     break;
+                   case 1:
+                     if (pcrel == true)
+                       {
 #if KEEPMINUSPCININST
-                                   bfd_put_8(ieee->h.abfd, (int)(-current_map->pc),  location_ptr +current_map->pc);
-                                   r->relent.addend -= current_map->pc;
-                                   r->relent.howto = &rel8_howto;
+                         bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
+                         r->relent.addend -= current_map->pc;
+                         r->relent.howto = &rel8_howto;
 #else
-                                   bfd_put_8(ieee->h.abfd,0,  location_ptr +current_map->pc);
-                                   r->relent.howto = &rel8_howto;
+                         bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
+                         r->relent.howto = &rel8_howto;
 #endif
-                                 }
-                                 else {
-                                   bfd_put_8(ieee->h.abfd, 0,  location_ptr +current_map->pc);
-                                   r->relent.howto = &abs8_howto;
-                                 }
-                                 current_map->pc +=1;
-                                 break;
-
-                               default:
-                                 BFD_FAIL();
-                                 break;
-                               }
-                         }
-                       break;
-                     default: 
-                         {
-                           bfd_vma this_size ;
-                           if (parse_int(&(ieee->h), &this_size) == true) {
-                             unsigned int i;
-                             for (i = 0; i < this_size; i++) {
-                               location_ptr[current_map->pc ++] = this_byte(&(ieee->h));
-                               next_byte(&(ieee->h));
-                             }
-                           }
-                           else {
-                             loop = false;
-                           }
-                         }
-                     }
+                       }
+                     else
+                       {
+                         bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
+                         r->relent.howto = &abs8_howto;
+                       }
+                     current_map->pc += 1;
+                     break;
+
+                   default:
+                     BFD_FAIL ();
+                     break;
+                   }
+               }
+               break;
+             default:
+               {
+                 bfd_vma this_size;
+                 if (parse_int (&(ieee->h), &this_size) == true)
+                   {
+                     unsigned int i;
+                     for (i = 0; i < this_size; i++)
+                       {
+                         location_ptr[current_map->pc++] = this_byte (&(ieee->h));
+                         next_byte (&(ieee->h));
+                       }
+                   }
+                 else
+                   {
+                     loop = false;
+                   }
                }
+             }
          }
       }
+    }
+  return true;
 }
 
 /* Read in all the section data and relocation stuff too */
-static boolean 
-DEFUN(ieee_slurp_section_data,(abfd),
-      bfd *abfd)
+static boolean
+DEFUN (ieee_slurp_section_data, (abfd),
+       bfd * abfd)
 {
-  bfd_byte *location_ptr = (bfd_byte *)NULL;
-  ieee_data_type *ieee = IEEE_DATA(abfd);
-  unsigned int section_number ;
+  bfd_byte *location_ptr = (bfd_byte *) NULL;
+  ieee_data_type *ieee = IEEE_DATA (abfd);
+  unsigned int section_number;
 
-  ieee_per_section_type *current_map = (ieee_per_section_type *)NULL;
+  ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
   asection *s;
   /* Seek to the start of the data area */
-  if (ieee->read_data== true)  return true;
+  if (ieee->read_data == true)
+    return true;
   ieee->read_data = true;
-  ieee_seek(abfd, ieee->w.r.data_part);
+  ieee_seek (abfd, ieee->w.r.data_part);
 
   /* Allocate enough space for all the section contents */
 
+  for (s = abfd->sections; s != (asection *) NULL; s = s->next)
+    {
+      ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
+      per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
+      if (!per->data)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
+      /*SUPPRESS 68*/
+      per->reloc_tail_ptr =
+       (ieee_reloc_type **) & (s->relocation);
+    }
 
-  for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
-    ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
-    per->data = (bfd_byte *) bfd_alloc(ieee->h.abfd, s->_raw_size);
-    /*SUPPRESS 68*/
-    per->reloc_tail_ptr =
-      (ieee_reloc_type **)&(s->relocation);
-  }
-
-
-
-  while (true) {
-    switch (this_byte(&(ieee->h))) 
+  while (true)
+    {
+      switch (this_byte (&(ieee->h)))
        {
          /* IF we see anything strange then quit */
        default:
          return true;
 
        case ieee_set_current_section_enum:
-         next_byte(&(ieee->h));
-         section_number = must_parse_int(&(ieee->h));
+         next_byte (&(ieee->h));
+         section_number = must_parse_int (&(ieee->h));
          s = ieee->section_table[section_number];
          current_map = (ieee_per_section_type *) s->used_by_bfd;
          location_ptr = current_map->data - s->vma;
          /* The document I have says that Microtec's compilers reset */
          /* this after a sec section, even though the standard says not */
          /* to. SO .. */
-         current_map->pc =s->vma;
+         current_map->pc = s->vma;
          break;
 
-
        case ieee_e2_first_byte_enum:
-         next_byte(&(ieee->h));
-         switch (this_byte(&(ieee->h)))
+         next_byte (&(ieee->h));
+         switch (this_byte (&(ieee->h)))
+           {
+           case ieee_set_current_pc_enum & 0xff:
              {
-             case ieee_set_current_pc_enum & 0xff:
-                 {
-                   bfd_vma value;
-                   ieee_symbol_index_type symbol;
-                   unsigned int extra;
-                   boolean pcrel;
-                   next_byte(&(ieee->h));
-                   must_parse_int(&(ieee->h)); /* Thow away section #*/
-                   parse_expression(ieee, &value,
-                                    &symbol,
-                                    &pcrel, &extra,
-                                    0);
-                   current_map->pc = value;
-                   BFD_ASSERT((unsigned)(value - s->vma) <= s->_raw_size);
-                 }
-               break;
-
-             case ieee_value_starting_address_enum & 0xff:
-               /* We've got to the end of the data now - */
-               return true;
-             default:
-               BFD_FAIL();
-               return true;
+               bfd_vma value;
+               ieee_symbol_index_type symbol;
+               unsigned int extra;
+               boolean pcrel;
+               next_byte (&(ieee->h));
+               must_parse_int (&(ieee->h));    /* Thow away section #*/
+               parse_expression (ieee, &value,
+                                 &symbol,
+                                 &pcrel, &extra,
+                                 0);
+               current_map->pc = value;
+               BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
              }
+             break;
+
+           case ieee_value_starting_address_enum & 0xff:
+             /* We've got to the end of the data now - */
+             return true;
+           default:
+             BFD_FAIL ();
+             return true;
+           }
          break;
        case ieee_repeat_data_enum:
-           {
-             /* Repeat the following LD or LR n times - we do this by
+         {
+           /* Repeat the following LD or LR n times - we do this by
                 remembering the stream pointer before running it and
                 resetting it and running it n times. We special case
                 the repetition of a repeat_data/load_constant
                 */
 
-             unsigned int iterations ;
-             unsigned char *start ;
-             next_byte(&(ieee->h));
-             iterations = must_parse_int(&(ieee->h));
-             start =  ieee->h.input_p;
-             if (start[0] == (int)ieee_load_constant_bytes_enum &&
-                 start[1] == 1) {
-               while (iterations != 0) {
-                 location_ptr[current_map->pc++] = start[2];
-                 iterations--;
-               }
-               next_byte(&(ieee->h));
-               next_byte(&(ieee->h));
-               next_byte(&(ieee->h));
+           unsigned int iterations;
+           unsigned char *start;
+           next_byte (&(ieee->h));
+           iterations = must_parse_int (&(ieee->h));
+           start = ieee->h.input_p;
+           if (start[0] == (int) ieee_load_constant_bytes_enum &&
+               start[1] == 1)
+             {
+               while (iterations != 0)
+                 {
+                   location_ptr[current_map->pc++] = start[2];
+                   iterations--;
+                 }
+               next_byte (&(ieee->h));
+               next_byte (&(ieee->h));
+               next_byte (&(ieee->h));
              }
-             else {
-               while (iterations != 0) {
-                 ieee->h.input_p = start;
-                 do_one(ieee, current_map, location_ptr,s);
-                 iterations --;
-               }
+           else
+             {
+               while (iterations != 0)
+                 {
+                   ieee->h.input_p = start;
+                   if (!do_one (ieee, current_map, location_ptr, s))
+                     return false;
+                   iterations--;
+                 }
              }
-           }
+         }
          break;
        case ieee_load_constant_bytes_enum:
        case ieee_load_with_relocation_enum:
-           {
-             do_one(ieee, current_map, location_ptr,s);
-           }
+         {
+           if (!do_one (ieee, current_map, location_ptr, s))
+             return false;
+         }
        }
-  }
+    }
 }
 
-
-
-
-
 boolean
-DEFUN(ieee_new_section_hook,(abfd, newsect),
-      bfd *abfd AND
-      asection *newsect)
+DEFUN (ieee_new_section_hook, (abfd, newsect),
+       bfd * abfd AND
+       asection * newsect)
 {
   newsect->used_by_bfd = (PTR)
-    bfd_alloc(abfd, sizeof(ieee_per_section_type));
-  ieee_per_section( newsect)->data = (bfd_byte *)NULL;
-  ieee_per_section(newsect)->section = newsect;
+    bfd_alloc (abfd, sizeof (ieee_per_section_type));
+  if (!newsect->used_by_bfd)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
+  ieee_per_section (newsect)->data = (bfd_byte *) NULL;
+  ieee_per_section (newsect)->section = newsect;
   return true;
 }
 
-
 unsigned int
-DEFUN(ieee_get_reloc_upper_bound,(abfd, asect),
-      bfd *abfd AND
-      sec_ptr asect)
+DEFUN (ieee_get_reloc_upper_bound, (abfd, asect),
+       bfd * abfd AND
+       sec_ptr asect)
 {
-  ieee_slurp_section_data(abfd);
-  return (asect->reloc_count+1) * sizeof(arelent *);
+  ieee_slurp_section_data (abfd);
+  return (asect->reloc_count + 1) * sizeof (arelent *);
 }
 
 static boolean
-DEFUN(ieee_get_section_contents,(abfd, section, location, offset, count),
-      bfd *abfd AND
-      sec_ptr section AND
-      PTR location AND
-      file_ptr offset AND
-      bfd_size_type count)
+DEFUN (ieee_get_section_contents, (abfd, section, location, offset, count),
+       bfd * abfd AND
+       sec_ptr section AND
+       PTR location AND
+       file_ptr offset AND
+       bfd_size_type count)
 {
   ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
-  ieee_slurp_section_data(abfd);
-  (void)  memcpy((PTR)location, (PTR)(p->data + offset), (unsigned)count);
+  ieee_slurp_section_data (abfd);
+  (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
   return true;
 }
 
-
 unsigned int
-DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols),
-      bfd *abfd AND
-      sec_ptr section AND
-      arelent **relptr AND
-      asymbol **symbols)
+DEFUN (ieee_canonicalize_reloc, (abfd, section, relptr, symbols),
+       bfd * abfd AND
+       sec_ptr section AND
+       arelent ** relptr AND
+       asymbol ** symbols)
 {
 /*  ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
-  ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation);
-  ieee_data_type *ieee = IEEE_DATA(abfd);
-
-  while (src != (ieee_reloc_type *)NULL) {
-    /* Work out which symbol to attach it this reloc to */
-    switch (src->symbol.letter) {
-    case 'X':
-      src->relent.sym_ptr_ptr =
-       symbols + src->symbol.index +  ieee->external_reference_base_offset;
-      break;
-    case 0:
-      src->relent.sym_ptr_ptr = 
-       src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
-      break;
-    default:
+  ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
+
+  while (src != (ieee_reloc_type *) NULL)
+    {
+      /* Work out which symbol to attach it this reloc to */
+      switch (src->symbol.letter)
+       {
+       case 'X':
+         src->relent.sym_ptr_ptr =
+           symbols + src->symbol.index + ieee->external_reference_base_offset;
+         break;
+       case 0:
+         src->relent.sym_ptr_ptr =
+           src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
+         break;
+       default:
 
-      BFD_FAIL();
+         BFD_FAIL ();
+       }
+      *relptr++ = &src->relent;
+      src = src->next;
     }
-    *relptr++ = &src->relent;
-    src = src->next;
-  }
-  *relptr = (arelent *)NULL;
+  *relptr = (arelent *) NULL;
   return section->reloc_count;
 }
 
-
-
-static int 
-DEFUN(comp,(ap, bp),
-     CONST PTR ap AND
-     CONST PTR bp)
+static int
+DEFUN (comp, (ap, bp),
+       CONST PTR ap AND
+       CONST PTR bp)
 {
-  arelent *a = *((arelent **)ap);
-  arelent *b = *((arelent **)bp);
+  arelent *a = *((arelent **) ap);
+  arelent *b = *((arelent **) bp);
   return a->address - b->address;
 }
 
@@ -1657,278 +1757,302 @@ Write the section headers
 */
 
 static void
-DEFUN(ieee_write_section_part,(abfd),
-      bfd *abfd)
+DEFUN (ieee_write_section_part, (abfd),
+       bfd * abfd)
 {
-  ieee_data_type *ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
   asection *s;
-  ieee->w.r.section_part = bfd_tell(abfd);
-  for (s = abfd->sections; s != (asection *)NULL; s=s->next) {
-      if (s != &bfd_abs_section) 
-      {
-       
-       ieee_write_byte(abfd, ieee_section_type_enum);
-       ieee_write_byte(abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
-
-       if (abfd->flags & EXEC_P) 
-       {
-         /* This image is executable, so output absolute sections */
-         ieee_write_byte(abfd, ieee_variable_A_enum);
-         ieee_write_byte(abfd, ieee_variable_S_enum);
-       }
-       else  
+  ieee->w.r.section_part = bfd_tell (abfd);
+  for (s = abfd->sections; s != (asection *) NULL; s = s->next)
+    {
+      if (s != &bfd_abs_section)
        {
-         ieee_write_byte(abfd, ieee_variable_C_enum);
-       }
+         ieee_write_byte (abfd, ieee_section_type_enum);
+         ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
 
-       switch (s->flags &(SEC_CODE | SEC_DATA | SEC_ROM)) 
-       {
-       case SEC_CODE | SEC_LOAD:
-       case SEC_CODE:
-         ieee_write_byte(abfd, ieee_variable_P_enum);
-         break;
-       case SEC_DATA:
-       default:
-         ieee_write_byte(abfd, ieee_variable_D_enum);
-         break;
-       case SEC_ROM:
-       case SEC_ROM | SEC_DATA:
-       case SEC_ROM | SEC_LOAD:
-       case SEC_ROM | SEC_DATA | SEC_LOAD:
+         if (abfd->flags & EXEC_P)
+           {
+             /* This image is executable, so output absolute sections */
+             ieee_write_byte (abfd, ieee_variable_A_enum);
+             ieee_write_byte (abfd, ieee_variable_S_enum);
+           }
+         else
+           {
+             ieee_write_byte (abfd, ieee_variable_C_enum);
+           }
 
-         ieee_write_byte(abfd, ieee_variable_R_enum);
-       }
+         switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
+           {
+           case SEC_CODE | SEC_LOAD:
+           case SEC_CODE:
+             ieee_write_byte (abfd, ieee_variable_P_enum);
+             break;
+           case SEC_DATA:
+           default:
+             ieee_write_byte (abfd, ieee_variable_D_enum);
+             break;
+           case SEC_ROM:
+           case SEC_ROM | SEC_DATA:
+           case SEC_ROM | SEC_LOAD:
+           case SEC_ROM | SEC_DATA | SEC_LOAD:
 
+             ieee_write_byte (abfd, ieee_variable_R_enum);
+           }
 
-       ieee_write_id(abfd, s->name);
+
+         ieee_write_id (abfd, s->name);
 #if 0
-       ieee_write_int(abfd, 0); /* Parent */
-       ieee_write_int(abfd, 0); /* Brother */
-       ieee_write_int(abfd, 0); /* Context */
+         ieee_write_int (abfd, 0);     /* Parent */
+         ieee_write_int (abfd, 0);     /* Brother */
+         ieee_write_int (abfd, 0);     /* Context */
 #endif
-       /* Alignment */
-       ieee_write_byte(abfd, ieee_section_alignment_enum);
-       ieee_write_byte(abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
-       ieee_write_int(abfd, 1 << s->alignment_power);
-
-       /* Size */
-       ieee_write_2bytes(abfd, ieee_section_size_enum);
-       ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
-       ieee_write_int(abfd, s->_raw_size);
-       if (abfd->flags & EXEC_P) {
-           /* Relocateable sections don't have asl records */
-           /* Vma */
-           ieee_write_2bytes(abfd, ieee_section_base_address_enum);
-           ieee_write_byte(abfd,
-               (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
-           ieee_write_int(abfd, s->vma);
-         }
-      }
-      
+         /* Alignment */
+         ieee_write_byte (abfd, ieee_section_alignment_enum);
+         ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
+         ieee_write_int (abfd, 1 << s->alignment_power);
+
+         /* Size */
+         ieee_write_2bytes (abfd, ieee_section_size_enum);
+         ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
+         ieee_write_int (abfd, s->_raw_size);
+         if (abfd->flags & EXEC_P)
+           {
+             /* Relocateable sections don't have asl records */
+             /* Vma */
+             ieee_write_2bytes (abfd, ieee_section_base_address_enum);
+             ieee_write_byte (abfd,
+                         (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
+             ieee_write_int (abfd, s->vma);
+           }
+       }
+
     }
 }
 
 
-
-static void 
-DEFUN(do_with_relocs,(abfd, s),
-      bfd *abfd AND
-      asection *s)
+static boolean
+DEFUN (do_with_relocs, (abfd, s),
+       bfd * abfd AND
+       asection * s)
 {
   unsigned int relocs_to_go = s->reloc_count;
 
-
-  bfd_byte *stream = ieee_per_section(s)->data;
+  bfd_byte *stream = ieee_per_section (s)->data;
   arelent **p = s->orelocation;
 
   bfd_size_type current_byte_index = 0;
 
-  qsort(s->orelocation,
-       relocs_to_go,
-       sizeof(arelent **),
-       comp);
+  qsort (s->orelocation,
+        relocs_to_go,
+        sizeof (arelent **),
+        comp);
 
   /* Output the section preheader */
-  ieee_write_byte(abfd, ieee_set_current_section_enum);
-  ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
+  ieee_write_byte (abfd, ieee_set_current_section_enum);
+  ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
 
-  ieee_write_twobyte(abfd, ieee_set_current_pc_enum);
-  ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
-  ieee_write_expression(abfd, 0, s->symbol, 0, 0);
+  ieee_write_twobyte (abfd, ieee_set_current_pc_enum);
+  ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
+  ieee_write_expression (abfd, 0, s->symbol, 0, 0);
 
-  if (relocs_to_go == 0) 
-      {
-       /* If there arn't any relocations then output the load constant byte
+  if (relocs_to_go == 0)
+    {
+      /* If there arn't any relocations then output the load constant byte
           opcode rather than the load with relocation opcode */
 
-       while (current_byte_index < s->_raw_size) {
+      while (current_byte_index < s->_raw_size)
+       {
          bfd_size_type run;
-         unsigned int MAXRUN  = 32;
+         unsigned int MAXRUN = 32;
          run = MAXRUN;
-         if (run > s->_raw_size - current_byte_index) {
-           run = s->_raw_size - current_byte_index;
-         }
+         if (run > s->_raw_size - current_byte_index)
+           {
+             run = s->_raw_size - current_byte_index;
+           }
 
-         if (run != 0) {
-           ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
-           /* Output a stream of bytes */
-           ieee_write_int(abfd, run);
-           bfd_write((PTR)(stream + current_byte_index), 
-                     1,
-                     run,
-                     abfd);
-           current_byte_index += run;
-         }
+         if (run != 0)
+           {
+             ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
+             /* Output a stream of bytes */
+             ieee_write_int (abfd, run);
+             bfd_write ((PTR) (stream + current_byte_index),
+                        1,
+                        run,
+                        abfd);
+             current_byte_index += run;
+           }
        }
-      }
-  else 
-      {
-       ieee_write_byte(abfd, ieee_load_with_relocation_enum);
+    }
+  else
+    {
+      ieee_write_byte (abfd, ieee_load_with_relocation_enum);
 
 
-       /* Output the data stream as the longest sequence of bytes
+      /* Output the data stream as the longest sequence of bytes
           possible, allowing for the a reasonable packet size and
           relocation stuffs */
 
-       if ((PTR)stream == (PTR)NULL) {
+      if ((PTR) stream == (PTR) NULL)
+       {
          /* Outputting a section without data, fill it up */
-         stream = (unsigned char *)(bfd_alloc(abfd, s->_raw_size));
-         memset((PTR)stream, 0, s->_raw_size);
+         stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
+         if (!stream)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
+         memset ((PTR) stream, 0, s->_raw_size);
        }
-       while (current_byte_index < s->_raw_size) {
+      while (current_byte_index < s->_raw_size)
+       {
          bfd_size_type run;
          unsigned int MAXRUN = 32;
-         if (relocs_to_go) {
-           run = (*p)->address - current_byte_index;
-         }
-         else {
-           run = MAXRUN;
-         }
-         if (run > s->_raw_size - current_byte_index) {
-           run = s->_raw_size - current_byte_index;
-         }
+         if (relocs_to_go)
+           {
+             run = (*p)->address - current_byte_index;
+           }
+         else
+           {
+             run = MAXRUN;
+           }
+         if (run > s->_raw_size - current_byte_index)
+           {
+             run = s->_raw_size - current_byte_index;
+           }
 
-         if (run != 0) {
-           /* Output a stream of bytes */
-           ieee_write_int(abfd, run);
-           bfd_write((PTR)(stream + current_byte_index), 
-                     1,
-                     run,
-                     abfd);
-           current_byte_index += run;
-         }
+         if (run != 0)
+           {
+             /* Output a stream of bytes */
+             ieee_write_int (abfd, run);
+             bfd_write ((PTR) (stream + current_byte_index),
+                        1,
+                        run,
+                        abfd);
+             current_byte_index += run;
+           }
          /* Output any relocations here */
-         if (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
-           while (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
+         if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
+           {
+             while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
+               {
 
-             arelent *r = *p;
-             bfd_vma ov;
+                 arelent *r = *p;
+                 bfd_vma ov;
 
 #if 0
-             if (r->howto->pc_relative) {
-               r->addend += current_byte_index ;
-             }
+                 if (r->howto->pc_relative)
+                   {
+                     r->addend += current_byte_index;
+                   }
 #endif
 
-             switch (r->howto->size) {
-             case 2:
+                 switch (r->howto->size)
+                   {
+                   case 2:
 
-               ov = bfd_get_32(abfd,
-                               stream+current_byte_index);
-               current_byte_index +=4;
-               break;
-             case 1:
-               ov = bfd_get_16(abfd,
-                               stream+current_byte_index);
-               current_byte_index +=2;
-               break;
-             case 0:
-               ov = bfd_get_8(abfd,
-                              stream+current_byte_index);
-               current_byte_index ++;
-               break;
-             default:
-               ov = 0;
-               BFD_FAIL();
-             }
-             ieee_write_byte(abfd, ieee_function_either_open_b_enum);
+                     ov = bfd_get_32 (abfd,
+                                      stream + current_byte_index);
+                     current_byte_index += 4;
+                     break;
+                   case 1:
+                     ov = bfd_get_16 (abfd,
+                                      stream + current_byte_index);
+                     current_byte_index += 2;
+                     break;
+                   case 0:
+                     ov = bfd_get_8 (abfd,
+                                     stream + current_byte_index);
+                     current_byte_index++;
+                     break;
+                   default:
+                     ov = 0;
+                     BFD_FAIL ();
+                   }
+                 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
 /*           abort();*/
-           
-             if (r->sym_ptr_ptr != (asymbol **)NULL) {
-               ieee_write_expression(abfd, r->addend + ov,
-                                     *(r->sym_ptr_ptr),
-                                     r->howto->pc_relative, s->index);
-             }
-             else {
-               ieee_write_expression(abfd, r->addend + ov,
-                                     (asymbol *)NULL,
-                                     r->howto->pc_relative, s->index);
-             }
 
-             if (1 || r->howto->size != 2) {
-               ieee_write_byte(abfd, ieee_comma);
-               ieee_write_int(abfd, 1<< r->howto->size);
-             }
-             ieee_write_byte(abfd,
-                             ieee_function_either_close_b_enum);
+                 if (r->sym_ptr_ptr != (asymbol **) NULL)
+                   {
+                     ieee_write_expression (abfd, r->addend + ov,
+                                            *(r->sym_ptr_ptr),
+                                          r->howto->pc_relative, s->index);
+                   }
+                 else
+                   {
+                     ieee_write_expression (abfd, r->addend + ov,
+                                            (asymbol *) NULL,
+                                          r->howto->pc_relative, s->index);
+                   }
 
-             relocs_to_go --;
-             p++;
-           }
+                 if (1 || r->howto->size != 2)
+                   {
+                     ieee_write_byte (abfd, ieee_comma);
+                     ieee_write_int (abfd, 1 << r->howto->size);
+                   }
+                 ieee_write_byte (abfd,
+                                  ieee_function_either_close_b_enum);
 
-         }
+                 relocs_to_go--;
+                 p++;
+               }
+
+           }
        }
-      }
+    }
+  return true;
 }
 
 /* If there are no relocations in the output section then we can
 be clever about how we write. We block items up into a max of 127
 bytes */
 
-static void 
-DEFUN(do_as_repeat, (abfd, s),
-      bfd *abfd AND
-      asection *s)
-{
-  if (s->_raw_size) {
-    ieee_write_byte(abfd, ieee_set_current_section_enum);
-    ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
-    ieee_write_byte(abfd, ieee_set_current_pc_enum >> 8);
-    ieee_write_byte(abfd, ieee_set_current_pc_enum  & 0xff);
-    ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
-    ieee_write_int(abfd,  s->vma );
-
-    ieee_write_byte(abfd,ieee_repeat_data_enum);
-    ieee_write_int(abfd, s->_raw_size);
-    ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
-    ieee_write_byte(abfd, 1);
-    ieee_write_byte(abfd, 0);
-  }
+static void
+DEFUN (do_as_repeat, (abfd, s),
+       bfd * abfd AND
+       asection * s)
+{
+  if (s->_raw_size)
+    {
+      ieee_write_byte (abfd, ieee_set_current_section_enum);
+      ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
+      ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8);
+      ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff);
+      ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
+      ieee_write_int (abfd, s->vma);
+
+      ieee_write_byte (abfd, ieee_repeat_data_enum);
+      ieee_write_int (abfd, s->_raw_size);
+      ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
+      ieee_write_byte (abfd, 1);
+      ieee_write_byte (abfd, 0);
+    }
 }
 
-static void 
-DEFUN(do_without_relocs, (abfd, s),
-      bfd *abfd AND
-      asection *s)
+static void
+DEFUN (do_without_relocs, (abfd, s),
+       bfd * abfd AND
+       asection * s)
 {
-  bfd_byte *stream = ieee_per_section(s)->data;
+  bfd_byte *stream = ieee_per_section (s)->data;
 
-  if (stream == 0 || ((s->flags & SEC_LOAD) == 0)) 
-      {
-       do_as_repeat(abfd, s);
-      }
-  else 
-      {
-       unsigned int i;
-       for (i = 0; i < s->_raw_size; i++) {
-         if (stream[i] != 0) {
-           do_with_relocs(abfd, s);
-           return;
-         }
+  if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
+    {
+      do_as_repeat (abfd, s);
+    }
+  else
+    {
+      unsigned int i;
+      for (i = 0; i < s->_raw_size; i++)
+       {
+         if (stream[i] != 0)
+           {
+             do_with_relocs (abfd, s);
+             return;
+           }
        }
-       do_as_repeat(abfd, s);
-      }
-  
+      do_as_repeat (abfd, s);
+    }
+
 }
 
 
@@ -1942,14 +2066,16 @@ static bfd *input_bfd;
 static bfd *output_bfd;
 static int output_buffer;
 
-static void fill()
+static void 
+fill ()
 {
-  bfd_read((PTR)input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
+  bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
   input_ptr = input_ptr_start;
 }
-static void flush()
+static void 
+flush ()
 {
-  bfd_write((PTR)(output_ptr_start),1,output_ptr - output_ptr_start, output_bfd);
+  bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start, output_bfd);
   output_ptr = output_ptr_start;
   output_buffer++;
 }
@@ -1958,481 +2084,636 @@ static void flush()
 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end)  flush(); }
 
-static void write_int(value)
-int value;
+static void 
+write_int (value)
+     int value;
 {
-  if (value >= 0 && value <= 127) {
-    OUT(value);
-  }
-  else {
-    unsigned int length;
-    /* How many significant bytes ? */
-    /* FIXME FOR LONGER INTS */
-    if (value & 0xff000000) {
-      length = 4;
-    }
-    else if (value & 0x00ff0000) {
-      length  = 3;
-    }
-    else if (value & 0x0000ff00) {
-      length = 2;
+  if (value >= 0 && value <= 127)
+    {
+      OUT (value);
     }
-    else length = 1;
+  else
+    {
+      unsigned int length;
+      /* How many significant bytes ? */
+      /* FIXME FOR LONGER INTS */
+      if (value & 0xff000000)
+       {
+         length = 4;
+       }
+      else if (value & 0x00ff0000)
+       {
+         length = 3;
+       }
+      else if (value & 0x0000ff00)
+       {
+         length = 2;
+       }
+      else
+       length = 1;
 
-    OUT((int)ieee_number_repeat_start_enum + length);
-    switch (length) {
-    case 4:
-      OUT( value >> 24);
-    case 3:
-      OUT( value >> 16);
-    case 2:
-      OUT( value >> 8);
-    case 1:
-      OUT( value);
-    }
+      OUT ((int) ieee_number_repeat_start_enum + length);
+      switch (length)
+       {
+       case 4:
+         OUT (value >> 24);
+       case 3:
+         OUT (value >> 16);
+       case 2:
+         OUT (value >> 8);
+       case 1:
+         OUT (value);
+       }
 
-  }
+    }
 }
-static void copy_id() 
+
+static void 
+copy_id ()
 {
-  int length  = THIS();
+  int length = THIS ();
   char ch;
-  OUT(length);
-  NEXT();
-  while (length--) {
-    ch = THIS();
-    OUT(ch);
-    NEXT();
-  }
+  OUT (length);
+  NEXT ();
+  while (length--)
+    {
+      ch = THIS ();
+      OUT (ch);
+      NEXT ();
+    }
 }
+
 #define VAR(x) ((x | 0x80))
-static void copy_expression()
+static void 
+copy_expression ()
 {
   int stack[10];
   int *tos = stack;
   int value = 0;
-  while (1) {
-    switch (THIS()) {
-    case 0x84:
-      NEXT();
-      value =  THIS(); NEXT();
-      value = (value << 8) | THIS(); NEXT();
-      value = (value << 8) | THIS(); NEXT();
-      value = (value << 8) | THIS(); NEXT();
-      *tos ++ = value;
-      break;
-    case 0x83:
-      NEXT();
-      value =  THIS(); NEXT();
-      value = (value << 8) | THIS(); NEXT();
-      value = (value << 8) | THIS(); NEXT();
-      *tos ++ = value;
-      break;
-    case 0x82: 
-      NEXT();
-      value =  THIS(); NEXT();
-      value = (value << 8) | THIS(); NEXT();
-      *tos ++ = value;
-      break;
-    case 0x81:
-      NEXT();
-      value =  THIS(); NEXT();
-      *tos ++ = value;
-      break;
-      case 0x80:
-      NEXT();
-      *tos ++ = 0;
-      break;
-    default:
-      if (THIS() >0x84) {
-       /* Not a number, just bug out with the answer */
-       write_int(*(--tos));
-       return;
-      }
-      *tos++ = THIS();
-NEXT();
-      value = 0;
-      break;
-    case 0xa5:
-      /* PLUS anything */
+  while (1)
+    {
+      switch (THIS ())
        {
-         int value = *(--tos);
-         value += *(--tos);
+       case 0x84:
+         NEXT ();
+         value = THIS ();
+         NEXT ();
+         value = (value << 8) | THIS ();
+         NEXT ();
+         value = (value << 8) | THIS ();
+         NEXT ();
+         value = (value << 8) | THIS ();
+         NEXT ();
          *tos++ = value;
-         NEXT();
-       }
-      break;
-    case VAR('R') :
-       {
-         int section_number ;
-         ieee_data_type *ieee;
-         asection *s;
-         NEXT();
-         section_number = THIS();
-       
-         NEXT();
-         ieee= IEEE_DATA(input_bfd);
-         s =   ieee->section_table[section_number];
-         if (s->output_section) {
-           value = s->output_section->vma ;
-         } else { value = 0; }
-         value += s->output_offset;
+         break;
+       case 0x83:
+         NEXT ();
+         value = THIS ();
+         NEXT ();
+         value = (value << 8) | THIS ();
+         NEXT ();
+         value = (value << 8) | THIS ();
+         NEXT ();
+         *tos++ = value;
+         break;
+       case 0x82:
+         NEXT ();
+         value = THIS ();
+         NEXT ();
+         value = (value << 8) | THIS ();
+         NEXT ();
+         *tos++ = value;
+         break;
+       case 0x81:
+         NEXT ();
+         value = THIS ();
+         NEXT ();
          *tos++ = value;
+         break;
+       case 0x80:
+         NEXT ();
+         *tos++ = 0;
+         break;
+       default:
+         if (THIS () > 0x84)
+           {
+             /* Not a number, just bug out with the answer */
+             write_int (*(--tos));
+             return;
+           }
+         *tos++ = THIS ();
+         NEXT ();
          value = 0;
-       }
-      break;
-    case 0x90:
-       {       
-         NEXT();
-         write_int(*(--tos));
-         OUT(0x90);
-         return;
+         break;
+       case 0xa5:
+         /* PLUS anything */
+         {
+           int value = *(--tos);
+           value += *(--tos);
+           *tos++ = value;
+           NEXT ();
+         }
+         break;
+       case VAR ('R'):
+         {
+           int section_number;
+           ieee_data_type *ieee;
+           asection *s;
+           NEXT ();
+           section_number = THIS ();
+
+           NEXT ();
+           ieee = IEEE_DATA (input_bfd);
+           s = ieee->section_table[section_number];
+           if (s->output_section)
+             {
+               value = s->output_section->vma;
+             }
+           else
+             {
+               value = 0;
+             }
+           value += s->output_offset;
+           *tos++ = value;
+           value = 0;
+         }
+         break;
+       case 0x90:
+         {
+           NEXT ();
+           write_int (*(--tos));
+           OUT (0x90);
+           return;
 
+         }
        }
     }
-  }
 
 }
 
 /* Drop the int in the buffer, and copy a null into the gap, which we
    will overwrite later */
 
-struct output_buffer_struct {
-unsigned  char *ptrp;
+struct output_buffer_struct
+{
+  unsigned char *ptrp;
   int buffer;
-} ;
+};
 
 static void
-DEFUN(fill_int,(buf),
-      struct output_buffer_struct *buf)
-{
-  if (buf->buffer == output_buffer) {
-    /* Still a chance to output the size */
-    int value = output_ptr - buf->ptrp + 3;
-    buf->ptrp[0] =  value >> 24;
-    buf->ptrp[1] =  value >> 16;
-    buf->ptrp[2] =  value >> 8;
-    buf->ptrp[3] =  value >> 0;
-  }
-
+DEFUN (fill_int, (buf),
+       struct output_buffer_struct *buf)
+{
+  if (buf->buffer == output_buffer)
+    {
+      /* Still a chance to output the size */
+      int value = output_ptr - buf->ptrp + 3;
+      buf->ptrp[0] = value >> 24;
+      buf->ptrp[1] = value >> 16;
+      buf->ptrp[2] = value >> 8;
+      buf->ptrp[3] = value >> 0;
+    }
 }
+
 static void
-DEFUN(drop_int,(buf),
-      struct output_buffer_struct *buf)
+DEFUN (drop_int, (buf),
+       struct output_buffer_struct *buf)
 {
-  int type = THIS();
+  int type = THIS ();
   int ch;
-  if (type <= 0x84) {
-    NEXT();
-    switch(type) {
-    case 0x84: ch = THIS(); NEXT();
-    case 0x83: ch = THIS(); NEXT();
-    case 0x82: ch = THIS(); NEXT();
-    case 0x81: ch = THIS(); NEXT();
-    case 0x80: break;
+  if (type <= 0x84)
+    {
+      NEXT ();
+      switch (type)
+       {
+       case 0x84:
+         ch = THIS ();
+         NEXT ();
+       case 0x83:
+         ch = THIS ();
+         NEXT ();
+       case 0x82:
+         ch = THIS ();
+         NEXT ();
+       case 0x81:
+         ch = THIS ();
+         NEXT ();
+       case 0x80:
+         break;
+       }
     }
-  }
-  OUT(0x84);
+  OUT (0x84);
   buf->ptrp = output_ptr;
-  buf->buffer  = output_buffer;
-  OUT(0);OUT(0);OUT(0);OUT(0);
+  buf->buffer = output_buffer;
+  OUT (0);
+  OUT (0);
+  OUT (0);
+  OUT (0);
 }
 
-static void copy_int()
+static void 
+copy_int ()
 {
-  int type = THIS();
+  int type = THIS ();
   int ch;
-  if (type <= 0x84) {
-    OUT(type);
-    NEXT();
-    switch(type) {
-    case 0x84: ch = THIS(); NEXT(); OUT(ch);
-    case 0x83: ch = THIS(); NEXT(); OUT(ch);
-    case 0x82: ch = THIS(); NEXT(); OUT(ch);
-    case 0x81: ch = THIS(); NEXT(); OUT(ch);
-    case 0x80: break;
+  if (type <= 0x84)
+    {
+      OUT (type);
+      NEXT ();
+      switch (type)
+       {
+       case 0x84:
+         ch = THIS ();
+         NEXT ();
+         OUT (ch);
+       case 0x83:
+         ch = THIS ();
+         NEXT ();
+         OUT (ch);
+       case 0x82:
+         ch = THIS ();
+         NEXT ();
+         OUT (ch);
+       case 0x81:
+         ch = THIS ();
+         NEXT ();
+         OUT (ch);
+       case 0x80:
+         break;
+       }
     }
-  }
 }
 
 #define ID copy_id()
 #define INT copy_int()
 #define EXP copy_expression()
-static void copy_till_end();
+static void copy_till_end ();
 #define INTn(q) copy_int()
 #define EXPn(q) copy_expression()
-static void f1_record()
+
+static void 
+f1_record ()
 {
   int ch;
   /* ATN record */
-  NEXT();
-  ch = THIS();
-  switch (ch)
-      {
-      default:
-       OUT(0xf1); OUT(ch);
-       break;
-      case 0xc9:
-       NEXT();
-       OUT(0xf1); OUT(0xc9);
-       INT; INT; ch = THIS(); 
-       switch (ch) 
-           {
-           case 0x16: NEXT();break;
-           case 0x01: NEXT();break;
-           case 0x00: NEXT(); INT; break;
-           case 0x03: NEXT(); INT; break;
-           case 0x13: EXPn(instruction address); break;
-           default:
-             break;
-           }
-       break;
-      case 0xd8:
-       /* EXternal ref */
-       NEXT(); 
-       OUT(0xf1); OUT(0xd8);
-       EXP ; EXP; EXP; EXP;
-       break;
-      case 0xce:
-       NEXT();
-       OUT(0xf1);OUT(0xce); INT; INT; ch = THIS(); INT;
-       switch (ch) {
+  NEXT ();
+  ch = THIS ();
+  switch (ch)
+    {
+    default:
+      OUT (0xf1);
+      OUT (ch);
+      break;
+    case 0xc9:
+      NEXT ();
+      OUT (0xf1);
+      OUT (0xc9);
+      INT;
+      INT;
+      ch = THIS ();
+      switch (ch)
+       {
+       case 0x16:
+         NEXT ();
+         break;
+       case 0x01:
+         NEXT ();
+         break;
+       case 0x00:
+         NEXT ();
+         INT;
+         break;
+       case 0x03:
+         NEXT ();
+         INT;
+         break;
+       case 0x13:
+         EXPn (instruction address);
+         break;
+       default:
+         break;
+       }
+      break;
+    case 0xd8:
+      /* EXternal ref */
+      NEXT ();
+      OUT (0xf1);
+      OUT (0xd8);
+      EXP;
+      EXP;
+      EXP;
+      EXP;
+      break;
+    case 0xce:
+      NEXT ();
+      OUT (0xf1);
+      OUT (0xce);
+      INT;
+      INT;
+      ch = THIS ();
+      INT;
+      switch (ch)
+       {
        case 0x01:
-         INT; INT; break;
+         INT;
+         INT;
+         break;
        case 0x02:
-         INT; break;
+         INT;
+         break;
        case 0x04:
-         EXPn(external function); break;
+         EXPn (external function);
+         break;
        case 0x05:
          break;
-       case 0x07: INTn(line number); INT;
-       case 0x08: break;
-       case 0x0a: INTn(locked register); INT; break;
-       case 0x3f: copy_till_end(); break;
-       case 0x3e: copy_till_end(); break;
-       case 0x40: copy_till_end(); break;
-       case 0x41: ID; break;
+       case 0x07:
+         INTn (line number);
+         INT;
+       case 0x08:
+         break;
+       case 0x0a:
+         INTn (locked register);
+         INT;
+         break;
+       case 0x3f:
+         copy_till_end ();
+         break;
+       case 0x3e:
+         copy_till_end ();
+         break;
+       case 0x40:
+         copy_till_end ();
+         break;
+       case 0x41:
+         ID;
+         break;
        }
-      }
+    }
 
 }
-static void f0_record()
+
+static void 
+f0_record ()
 {
   /* Attribute record */
-  NEXT();
-  OUT(0xf0);
-  INTn(Symbol name );
+  NEXT ();
+  OUT (0xf0);
+  INTn (Symbol name);
   ID;
 }
-static void copy_till_end()
+
+static void 
+copy_till_end ()
 {
-  int  ch = THIS();
-  while (1) {
-    while (ch <= 0x80) 
+  int ch = THIS ();
+  while (1)
+    {
+      while (ch <= 0x80)
        {
-         OUT(ch);
-         NEXT();
-         ch = THIS();
+         OUT (ch);
+         NEXT ();
+         ch = THIS ();
+       }
+      switch (ch)
+       {
+       case 0x84:
+         OUT (THIS ());
+         NEXT ();
+       case 0x83:
+         OUT (THIS ());
+         NEXT ();
+       case 0x82:
+         OUT (THIS ());
+         NEXT ();
+       case 0x81:
+         OUT (THIS ());
+         NEXT ();
+         OUT (THIS ());
+         NEXT ();
+
+         ch = THIS ();
+         break;
+       default:
+         return;
        }
-    switch (ch) {
-    case 0x84:
-      OUT(THIS());
-      NEXT();
-    case 0x83:
-      OUT(THIS());
-      NEXT();
-    case 0x82:
-      OUT(THIS());
-      NEXT();
-    case 0x81:
-      OUT(THIS());
-      NEXT();
-      OUT(THIS());
-      NEXT();
-
-      ch = THIS();
-      break;
-    default:
-      return;
     }
-  }    
 
 }
 
-static void f2_record()
+static void 
+f2_record ()
 {
-  NEXT();
-  OUT(0xf2);
-  INT ;
-  NEXT();
-  OUT(0xce);
-  INT ;
-  copy_till_end();
+  NEXT ();
+  OUT (0xf2);
+  INT;
+  NEXT ();
+  OUT (0xce);
+  INT;
+  copy_till_end ();
 }
 
 
-static void block();
-static void f8_record()
+static void block ();
+static void 
+f8_record ()
 {
   int ch;
-  NEXT();
-  ch = THIS();
-  switch (ch) 
+  NEXT ();
+  ch = THIS ();
+  switch (ch)
+    {
+    case 0x01:
+    case 0x02:
+    case 0x03:
+      /* Unique typedefs for module */
+      /* GLobal typedefs  */
+      /* High level module scope beginning */
       {
-      case 0x01:
-      case 0x02:
-      case 0x03:
-       /* Unique typedefs for module */
-       /* GLobal typedefs  */
-       /* High level module scope beginning */
-         {
-           struct output_buffer_struct ob;
-           NEXT();
-           OUT(0xf8); OUT(ch);
-           drop_int(&ob); ID ;
-
-           block();
-
-           NEXT();
-           fill_int(&ob);
-           OUT(0xf9);
-         }
-       break;
-      case 0x04:       
-       /* Global function */
-         {
-           struct output_buffer_struct ob;
-           NEXT();
-           OUT(0xf8); OUT(0x04);
-           drop_int(&ob); ID ; INTn(stack size); INTn(ret val);
-           EXPn(offset); 
-
-           block();
-
-           NEXT();
-           OUT(0xf9);  
-           EXPn(size of block);
-           fill_int(&ob);
-         }
-       break;
+       struct output_buffer_struct ob;
+       NEXT ();
+       OUT (0xf8);
+       OUT (ch);
+       drop_int (&ob);
+       ID;
+
+       block ();
+
+       NEXT ();
+       fill_int (&ob);
+       OUT (0xf9);
+      }
+      break;
+    case 0x04:
+      /* Global function */
+      {
+       struct output_buffer_struct ob;
+       NEXT ();
+       OUT (0xf8);
+       OUT (0x04);
+       drop_int (&ob);
+       ID;
+       INTn (stack size);
+       INTn (ret val);
+       EXPn (offset);
+
+       block ();
+
+       NEXT ();
+       OUT (0xf9);
+       EXPn (size of block);
+       fill_int (&ob);
+      }
+      break;
 
-      case 0x05:
-       /* File name for source line numbers */
-         {
-           struct output_buffer_struct ob;
-           NEXT();
-           OUT(0xf8); OUT(0x05);
-           drop_int(&ob);
-           ID; INTn(year); INTn(month); INTn(day);
-           INTn(hour); INTn(monute); INTn(second);
-           block();
-           NEXT();
-           OUT(0xf9);
-           fill_int(&ob);
-         }
-       break;
-       
-      case 0x06:
-       /* Local function */
-         { struct output_buffer_struct ob;
-           NEXT(); OUT(0xf8); OUT(0x06);
-           drop_int(&ob);
-           ID; INTn(stack size); INTn(type return);
-           EXPn(offset);
-           block();
-           NEXT();
-           OUT(0xf9);
-           EXPn(size);
-           fill_int(&ob);
-         }
-       break;
-       
-      case 0x0a:
-       /* Assembler module scope beginning -*/
-         { struct output_buffer_struct ob;
-
-           NEXT();
-           OUT(0xf8); OUT(0x0a); 
-           drop_int(&ob);
-             ID; ID; INT; ID; INT; INT; INT; INT; INT; INT;
-
-           block();    
-
-           NEXT();
-           OUT(0xf9);
-           fill_int(&ob);
-         }
-       break;
-      case 0x0b:
-         {
-           struct output_buffer_struct ob;
-           NEXT();
-           OUT(0xf8); OUT(0x0b); 
-           drop_int(&ob); ID ; INT; INTn(section index); EXPn(offset); INTn(stuff);
+    case 0x05:
+      /* File name for source line numbers */
+      {
+       struct output_buffer_struct ob;
+       NEXT ();
+       OUT (0xf8);
+       OUT (0x05);
+       drop_int (&ob);
+       ID;
+       INTn (year);
+       INTn (month);
+       INTn (day);
+       INTn (hour);
+       INTn (monute);
+       INTn (second);
+       block ();
+       NEXT ();
+       OUT (0xf9);
+       fill_int (&ob);
+      }
+      break;
 
-           block();
+    case 0x06:
+      /* Local function */
+      {
+       struct output_buffer_struct ob;
+       NEXT ();
+       OUT (0xf8);
+       OUT (0x06);
+       drop_int (&ob);
+       ID;
+       INTn (stack size);
+       INTn (type return);
+       EXPn (offset);
+       block ();
+       NEXT ();
+       OUT (0xf9);
+       EXPn (size);
+       fill_int (&ob);
+      }
+      break;
 
-           OUT(0xf9);
-           NEXT();      
-           EXPn(Size in Maus);
-           fill_int(&ob);
-         }
-       break;
+    case 0x0a:
+      /* Assembler module scope beginning -*/
+      {
+       struct output_buffer_struct ob;
+
+       NEXT ();
+       OUT (0xf8);
+       OUT (0x0a);
+       drop_int (&ob);
+       ID;
+       ID;
+       INT;
+       ID;
+       INT;
+       INT;
+       INT;
+       INT;
+       INT;
+       INT;
+
+       block ();
+
+       NEXT ();
+       OUT (0xf9);
+       fill_int (&ob);
+      }
+      break;
+    case 0x0b:
+      {
+       struct output_buffer_struct ob;
+       NEXT ();
+       OUT (0xf8);
+       OUT (0x0b);
+       drop_int (&ob);
+       ID;
+       INT;
+       INTn (section index);
+       EXPn (offset);
+       INTn (stuff);
+
+       block ();
+
+       OUT (0xf9);
+       NEXT ();
+       EXPn (Size in Maus);
+       fill_int (&ob);
       }
+      break;
+    }
 }
 
-static void e2_record()
+static void 
+e2_record ()
 {
-  OUT(0xe2);
-  NEXT();
-  OUT(0xce);
-  NEXT();
+  OUT (0xe2);
+  NEXT ();
+  OUT (0xce);
+  NEXT ();
   INT;
   EXP;
 }
 
-static void DEFUN_VOID(block)
+static void 
+DEFUN_VOID (block)
 {
-  int ch ;
-  while (1) {
-    ch = THIS();
-    switch (ch) {
-    case 0xe1:
-    case 0xe5:
-      return;
-    case 0xf9:
-      return;
-    case 0xf0:
-      f0_record();
-      break;
-    case 0xf1:
-      f1_record();    
-      break;
-    case 0xf2:
-      f2_record();
-      break;
-    case 0xf8:
-      f8_record();
-      break;
-    case 0xe2:
-      e2_record();
-      break;
+  int ch;
+  while (1)
+    {
+      ch = THIS ();
+      switch (ch)
+       {
+       case 0xe1:
+       case 0xe5:
+         return;
+       case 0xf9:
+         return;
+       case 0xf0:
+         f0_record ();
+         break;
+       case 0xf1:
+         f1_record ();
+         break;
+       case 0xf2:
+         f2_record ();
+         break;
+       case 0xf8:
+         f8_record ();
+         break;
+       case 0xe2:
+         e2_record ();
+         break;
 
-    }  
-  }
+       }
+    }
 }
-  
 
 
-/* relocate_debug, 
+
+/* relocate_debug,
    moves all the debug information from the source bfd to the output
    bfd, and relocates any expressions it finds
 */
 
 static void
-DEFUN(relocate_debug,(output, input),
-      bfd *output AND
-      bfd *input)
+DEFUN (relocate_debug, (output, input),
+       bfd * output AND
+       bfd * input)
 {
 #define IBS 400
 #define OBS 400
@@ -2441,36 +2722,39 @@ DEFUN(relocate_debug,(output, input),
   input_ptr_start = input_ptr = input_buffer;
   input_ptr_end = input_buffer + IBS;
   input_bfd = input;
-  bfd_read((PTR)input_ptr_start, 1, IBS, input);
-  block();
+  bfd_read ((PTR) input_ptr_start, 1, IBS, input);
+  block ();
 }
-/* 
+
+/*
   During linking, we we told about the bfds which made up our
   contents, we have a list of them. They will still be open, so go to
   the debug info in each, and copy it out, relocating it as we go.
 */
 
-static void 
-DEFUN(ieee_write_debug_part, (abfd),
-      bfd *abfd)
+static void
+DEFUN (ieee_write_debug_part, (abfd),
+       bfd * abfd)
 {
-  ieee_data_type *ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
   bfd_chain_type *chain = ieee->chain_root;
   unsigned char output_buffer[OBS];
   boolean some_debug = false;
-  file_ptr here = bfd_tell(abfd);
+  file_ptr here = bfd_tell (abfd);
 
-  output_ptr_start = output_ptr = output_buffer ;
+  output_ptr_start = output_ptr = output_buffer;
   output_ptr_end = output_buffer + OBS;
   output_ptr = output_buffer;
   output_bfd = abfd;
 
-  if (chain == (bfd_chain_type *)NULL) {
+  if (chain == (bfd_chain_type *) NULL)
+    {
 #if 0
       /* There is no debug info, so we'll fake some up */
-      CONST static char fake[] = {
-         0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
-         '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 };
+      CONST static char fake[] =
+      {
+       0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
+       '1', '.', '1', 0x82, 1991 >> 8, 1991 & 0xff, 9, 20, 11, 07, 50};
       ieee->w.r.debug_information_part = 0;
 
 
@@ -2479,112 +2763,128 @@ DEFUN(ieee_write_debug_part, (abfd),
 
       /*    bfd_write(fake, 1, sizeof(fake), abfd);*/
       /* Now write a header for each section */
-    {
-      int i = 0;
-      asection *s = abfd->sections;
-      while (s) {
-         if (s != abfd->abs_section) 
+      {
+       int i = 0;
+       asection *s = abfd->sections;
+       while (s)
          {
-             
-           ieee_write_byte(abfd, 0xf8);        
-           ieee_write_byte(abfd, 0x0b);
-           ieee_write_byte(abfd, 0);
-           ieee_write_byte(abfd, 0);
-           ieee_write_byte(abfd, 1);
-           ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE);
-           ieee_write_expression(abfd, 0, s->symbol, 0, 0, 0);
-           ieee_write_byte(abfd,0);
-           ieee_write_byte(abfd, 0xf9);
-           ieee_write_expression(abfd, s->size,
-                                 bfd_abs_section.symbol, 0, 0, 0);     
-           i++;
-         }
-           
-         s = s->next;
+           if (s != abfd->abs_section)
+             {
 
-       }       
-      /* Close the scope */
-      ieee_write_byte(abfd, 0xf9);
-    }
+               ieee_write_byte (abfd, 0xf8);
+               ieee_write_byte (abfd, 0x0b);
+               ieee_write_byte (abfd, 0);
+               ieee_write_byte (abfd, 0);
+               ieee_write_byte (abfd, 1);
+               ieee_write_byte (abfd, i + IEEE_SECTION_NUMBER_BASE);
+               ieee_write_expression (abfd, 0, s->symbol, 0, 0, 0);
+               ieee_write_byte (abfd, 0);
+               ieee_write_byte (abfd, 0xf9);
+               ieee_write_expression (abfd, s->size,
+                                      bfd_abs_section.symbol, 0, 0, 0);
+               i++;
+             }
+
+           s = s->next;
+
+         }
+       /* Close the scope */
+       ieee_write_byte (abfd, 0xf9);
+      }
 #endif
     }
-  else{
-      while (chain != (bfd_chain_type *)NULL) {
+  else
+    {
+      while (chain != (bfd_chain_type *) NULL)
+       {
          bfd *entry = chain->this;
-         ieee_data_type *entry_ieee = IEEE_DATA(entry);
-         if (entry_ieee->w.r.debug_information_part) {
-             bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET);
-             relocate_debug(abfd, entry);
+         ieee_data_type *entry_ieee = IEEE_DATA (entry);
+         if (entry_ieee->w.r.debug_information_part)
+           {
+             bfd_seek (entry, entry_ieee->w.r.debug_information_part, SEEK_SET);
+             relocate_debug (abfd, entry);
            }
 
          chain = chain->next;
        }
-      if (some_debug) {
+      if (some_debug)
+       {
          ieee->w.r.debug_information_part = here;
        }
-      else {
+      else
+       {
          ieee->w.r.debug_information_part = 0;
        }
     }
-  flush();
+  flush ();
+
+}
 
-}  
 /* write the data in an ieee way */
 static void
-DEFUN(ieee_write_data_part,(abfd),
-      bfd *abfd)
+DEFUN (ieee_write_data_part, (abfd),
+       bfd * abfd)
 {
   asection *s;
-  ieee_data_type *ieee = IEEE_DATA(abfd);
-  ieee->w.r.data_part = bfd_tell(abfd);
-  for (s = abfd->sections; s != (asection *)NULL; s = s->next) 
-      {
-       /* Sort the reloc records so we can insert them in the correct
+  ieee_data_type *ieee = IEEE_DATA (abfd);
+  ieee->w.r.data_part = bfd_tell (abfd);
+  for (s = abfd->sections; s != (asection *) NULL; s = s->next)
+    {
+      /* Sort the reloc records so we can insert them in the correct
           places */
-       if (s->reloc_count != 0) 
-           {
-            do_with_relocs(abfd, s);
-           }
-       else
-           {
-             do_without_relocs(abfd, s);
-           }
-      }
+      if (s->reloc_count != 0)
+       {
+         do_with_relocs (abfd, s);
+       }
+      else
+       {
+         do_without_relocs (abfd, s);
+       }
+    }
 }
 
 
-
-static void
-DEFUN(init_for_output,(abfd),
-      bfd *abfd)
+static boolean
+DEFUN (init_for_output, (abfd),
+       bfd * abfd)
 {
-  asection *s; 
-  for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
-    if (s->_raw_size != 0) {
-      ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->_raw_size));
+  asection *s;
+  for (s = abfd->sections; s != (asection *) NULL; s = s->next)
+    {
+      if (s->_raw_size != 0)
+       {
+         ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, s->_raw_size));
+         if (!ieee_per_section (s)->data)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
+       }
     }
-  }
+  return true;
 }
-
+\f
 /** exec and core file sections */
 
-/* set section contents is complicated with IEEE since the format is 
+/* set section contents is complicated with IEEE since the format is
 * not a byte image, but a record stream.
 */
 boolean
-DEFUN(ieee_set_section_contents,(abfd, section, location, offset, count),
-      bfd *abfd AND
-      sec_ptr section AND
-      PTR location AND
-      file_ptr offset AND
-      bfd_size_type count)
-{
-  if (ieee_per_section(section)->data == (bfd_byte *)NULL) {
-    init_for_output(abfd);
-  }
-  (void) memcpy((PTR)(ieee_per_section(section)->data + offset),
-               (PTR)location,
-               (unsigned int)count);
+DEFUN (ieee_set_section_contents, (abfd, section, location, offset, count),
+       bfd * abfd AND
+       sec_ptr section AND
+       PTR location AND
+       file_ptr offset AND
+       bfd_size_type count)
+{
+  if (ieee_per_section (section)->data == (bfd_byte *) NULL)
+    {
+      if (!init_for_output (abfd))
+       return false;
+    }
+  memcpy ((PTR) (ieee_per_section (section)->data + offset),
+         (PTR) location,
+         (unsigned int) count);
   return true;
 }
 
@@ -2595,183 +2895,193 @@ to index them as well. When we write them out we turn their symbol
 values into indexes from the right base.
 */
 static void
-DEFUN(ieee_write_external_part,(abfd),
-      bfd *abfd)
+DEFUN (ieee_write_external_part, (abfd),
+       bfd * abfd)
 {
   asymbol **q;
-  ieee_data_type *ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
 
   unsigned int reference_index = IEEE_REFERENCE_BASE;
-  unsigned int public_index = IEEE_PUBLIC_BASE+2;
-  file_ptr here = bfd_tell(abfd);
+  unsigned int public_index = IEEE_PUBLIC_BASE + 2;
+  file_ptr here = bfd_tell (abfd);
   boolean hadone = false;
-  if (abfd->outsymbols != (asymbol **)NULL) {
-
-    for (q = abfd->outsymbols; *q  != (asymbol *)NULL; q++) {
-      asymbol *p = *q;
-      hadone = true;
-      if (p->section == &bfd_und_section) {
-       /* This must be a symbol reference .. */
-       ieee_write_byte(abfd, ieee_external_reference_enum);
-       ieee_write_int(abfd, reference_index);
-       ieee_write_id(abfd, p->name);
-       p->value = reference_index;
-       reference_index++;
-      }
-      else if (bfd_is_com_section (p->section)) {
-       /* This is a weak reference */
-       ieee_write_byte(abfd, ieee_external_reference_enum);
-       ieee_write_int(abfd, reference_index);
-       ieee_write_id(abfd, p->name);
-       ieee_write_byte(abfd, ieee_weak_external_reference_enum);
-       ieee_write_int(abfd, reference_index);
-       ieee_write_int(abfd, p->value);
-       ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);
-       p->value = reference_index;
-       reference_index++;
-      }
-      else if(p->flags & BSF_GLOBAL) {
-       /* This must be a symbol definition */
+  if (abfd->outsymbols != (asymbol **) NULL)
+    {
+
+      for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
+       {
+         asymbol *p = *q;
+         hadone = true;
+         if (p->section == &bfd_und_section)
+           {
+             /* This must be a symbol reference .. */
+             ieee_write_byte (abfd, ieee_external_reference_enum);
+             ieee_write_int (abfd, reference_index);
+             ieee_write_id (abfd, p->name);
+             p->value = reference_index;
+             reference_index++;
+           }
+         else if (bfd_is_com_section (p->section))
+           {
+             /* This is a weak reference */
+             ieee_write_byte (abfd, ieee_external_reference_enum);
+             ieee_write_int (abfd, reference_index);
+             ieee_write_id (abfd, p->name);
+             ieee_write_byte (abfd, ieee_weak_external_reference_enum);
+             ieee_write_int (abfd, reference_index);
+             ieee_write_int (abfd, p->value);
+             ieee_write_int (abfd, BFD_FORT_COMM_DEFAULT_VALUE);
+             p->value = reference_index;
+             reference_index++;
+           }
+         else if (p->flags & BSF_GLOBAL)
+           {
+             /* This must be a symbol definition */
 
 
-       ieee_write_byte(abfd, ieee_external_symbol_enum);
-       ieee_write_int(abfd, public_index );
-       ieee_write_id(abfd, p->name);
+             ieee_write_byte (abfd, ieee_external_symbol_enum);
+             ieee_write_int (abfd, public_index);
+             ieee_write_id (abfd, p->name);
 
-       ieee_write_twobyte(abfd, ieee_attribute_record_enum);
-       ieee_write_int(abfd, public_index );
-       ieee_write_byte(abfd, 15);       /* instruction address */
-       ieee_write_byte(abfd, 19);      /* static symbol */
-       ieee_write_byte(abfd, 1);       /* one of them */
+             ieee_write_twobyte (abfd, ieee_attribute_record_enum);
+             ieee_write_int (abfd, public_index);
+             ieee_write_byte (abfd, 15);       /* instruction address */
+             ieee_write_byte (abfd, 19);       /* static symbol */
+             ieee_write_byte (abfd, 1);        /* one of them */
 
 
-       /* Write out the value */
-       ieee_write_2bytes(abfd, ieee_value_record_enum);
-       ieee_write_int(abfd, public_index);
-       if (p->section != &bfd_abs_section)
-           {
-             if (abfd->flags & EXEC_P) 
-             {
-               /* If fully linked, then output all symbols
+             /* Write out the value */
+             ieee_write_2bytes (abfd, ieee_value_record_enum);
+             ieee_write_int (abfd, public_index);
+             if (p->section != &bfd_abs_section)
+               {
+                 if (abfd->flags & EXEC_P)
+                   {
+                     /* If fully linked, then output all symbols
                   relocated */
-               ieee_write_int(abfd,
-                              p->value + p->section->output_offset+ p->section->output_section->vma);
+                     ieee_write_int (abfd,
+                                     p->value + p->section->output_offset + p->section->output_section->vma);
 
-             }
-             else { 
-                 ieee_write_expression(abfd,
-                                       p->value + p->section->output_offset,
-                                       p->section->output_section->symbol
-                                       , false, 0);
+                   }
+                 else
+                   {
+                     ieee_write_expression (abfd,
+                                      p->value + p->section->output_offset,
+                                         p->section->output_section->symbol
+                                            ,false, 0);
+                   }
+               }
+             else
+               {
+                 ieee_write_expression (abfd,
+                                        p->value,
+                                        bfd_abs_section.symbol,
+                                        false, 0);
                }
+             p->value = public_index;
+             public_index++;
            }
-       else
+         else
            {
-             ieee_write_expression(abfd,
-                                   p->value,
-                                   bfd_abs_section.symbol,
-                                   false, 0);
+             /* This can happen - when there are gaps in the symbols read */
+             /* from an input ieee file */
            }
-       p->value = public_index;
-       public_index++;
-      }
-      else {
-       /* This can happen - when there are gaps in the symbols read */
-       /* from an input ieee file */
-      }
+       }
     }
-  }
   if (hadone)
     ieee->w.r.external_part = here;
 
 }
 
 
-static CONST unsigned char exten[] = 
-  {
-    0xf0, 0x20, 0x00,                                  
-    0xf1, 0xce, 0x20, 0x00, 37, 3, 3,  /* Set version 3 rev 3          */
-    0xf1, 0xce, 0x20, 0x00, 39, 2,     /* keep symbol in  original case */
-    0xf1, 0xce, 0x20, 0x00, 38         /* set object type relocateable to x */
-  };
+static CONST unsigned char exten[] =
+{
+  0xf0, 0x20, 0x00,
+  0xf1, 0xce, 0x20, 0x00, 37, 3, 3,    /* Set version 3 rev 3          */
+  0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in  original case */
+  0xf1, 0xce, 0x20, 0x00, 38   /* set object type relocateable to x */
+};
 
 static CONST unsigned char envi[] =
-  {
-    0xf0, 0x21, 0x00,
+{
+  0xf0, 0x21, 0x00,
 
 /*    0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
-    0x19, 0x2c, 
+    0x19, 0x2c,
 */
-    0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
+  0xf1, 0xce, 0x21, 00, 52, 0x00,      /* exec ok */
 
-    0xf1, 0xce, 0x21, 0, 53, 0x03,     /* host unix */
+  0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
 /*    0xf1, 0xce, 0x21, 0, 54, 2,1,1   tool & version # */
-  };
+};
 
 static
-void 
-DEFUN(ieee_write_me_part,(abfd),
-      bfd *abfd)
-{
-  ieee_data_type *ieee= IEEE_DATA(abfd);
-  ieee->w.r.trailer_part = bfd_tell(abfd);
-  if (abfd->start_address) {
-    ieee->w.r.me_record = bfd_tell(abfd);
-    ieee_write_2bytes(abfd, ieee_value_starting_address_enum);
-    ieee_write_byte(abfd, ieee_function_either_open_b_enum);
-    ieee_write_int(abfd, abfd->start_address);
-    ieee_write_byte(abfd, ieee_function_either_close_b_enum);
-  }
-  else {
-    ieee->w.r.me_record = bfd_tell(abfd);
-  }
-  ieee_write_byte(abfd, ieee_module_end_enum);
+void
+DEFUN (ieee_write_me_part, (abfd),
+       bfd * abfd)
+{
+  ieee_data_type *ieee = IEEE_DATA (abfd);
+  ieee->w.r.trailer_part = bfd_tell (abfd);
+  if (abfd->start_address)
+    {
+      ieee->w.r.me_record = bfd_tell (abfd);
+      ieee_write_2bytes (abfd, ieee_value_starting_address_enum);
+      ieee_write_byte (abfd, ieee_function_either_open_b_enum);
+      ieee_write_int (abfd, abfd->start_address);
+      ieee_write_byte (abfd, ieee_function_either_close_b_enum);
+    }
+  else
+    {
+      ieee->w.r.me_record = bfd_tell (abfd);
+    }
+  ieee_write_byte (abfd, ieee_module_end_enum);
 
 }
+
 boolean
-DEFUN(ieee_write_object_contents,(abfd),
-      bfd *abfd)
+DEFUN (ieee_write_object_contents, (abfd),
+       bfd * abfd)
 {
-  ieee_data_type *ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (abfd);
   unsigned int i;
-  file_ptr   old;
+  file_ptr old;
   /* Fast forward over the header area */
-  bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
-  ieee_write_byte(abfd, ieee_module_beginning_enum);
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
+  ieee_write_byte (abfd, ieee_module_beginning_enum);
 
-  ieee_write_id(abfd, bfd_printable_name(abfd));
-  ieee_write_id(abfd, abfd->filename);
+  ieee_write_id (abfd, bfd_printable_name (abfd));
+  ieee_write_id (abfd, abfd->filename);
 
-  /* Fast forward over the variable bits */    
-  ieee_write_byte(abfd, ieee_address_descriptor_enum);
+  /* Fast forward over the variable bits */
+  ieee_write_byte (abfd, ieee_address_descriptor_enum);
 
   /* Bits per MAU */
-  ieee_write_byte(abfd, (bfd_byte) (bfd_arch_bits_per_byte(abfd)));
+  ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
   /* MAU's per address */
-  ieee_write_byte(abfd,
-   (bfd_byte) (bfd_arch_bits_per_address(abfd) / bfd_arch_bits_per_byte(abfd)));
-
-  old = bfd_tell(abfd);
-  bfd_seek(abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR);
-
-  ieee->w.r.extension_record = bfd_tell(abfd);
-  bfd_write((char *)exten, 1, sizeof(exten), abfd);
-  if (abfd->flags & EXEC_P) 
-    ieee_write_byte(abfd, 0x1); /* Absolute */
-  else 
-    ieee_write_byte(abfd, 0x2); /* Relocateable */    
-  
-  ieee->w.r.environmental_record = bfd_tell(abfd);
-  bfd_write((char *)envi, 1, sizeof(envi), abfd);
+  ieee_write_byte (abfd,
+                  (bfd_byte) (bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd)));
+
+  old = bfd_tell (abfd);
+  bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR);
+
+  ieee->w.r.extension_record = bfd_tell (abfd);
+  bfd_write ((char *) exten, 1, sizeof (exten), abfd);
+  if (abfd->flags & EXEC_P)
+    ieee_write_byte (abfd, 0x1);/* Absolute */
+  else
+    ieee_write_byte (abfd, 0x2);/* Relocateable */
+
+  ieee->w.r.environmental_record = bfd_tell (abfd);
+  bfd_write ((char *) envi, 1, sizeof (envi), abfd);
   output_bfd = abfd;
-  flush();
+  flush ();
 
-  ieee_write_section_part(abfd);
+  ieee_write_section_part (abfd);
   /*
-    First write the symbols, this changes their values into table 
+    First write the symbols, this changes their values into table
     indeces so we cant use it after this point
     */
-  ieee_write_external_part(abfd);     
+  ieee_write_external_part (abfd);
   /*  ieee_write_byte(abfd, ieee_record_seperator_enum);*/
 
 
@@ -2779,38 +3089,38 @@ DEFUN(ieee_write_object_contents,(abfd),
 
 
   /*
-    Write any debugs we have been told about 
+    Write any debugs we have been told about
     */
-  ieee_write_debug_part(abfd);
+  ieee_write_debug_part (abfd);
 
-  /* 
+  /*
     Can only write the data once the symbols have been written since
     the data contains relocation information which points to the
-    symbols 
+    symbols
     */
-  ieee_write_data_part(abfd);     
+  ieee_write_data_part (abfd);
 
 
   /*
     At the end we put the end !
     */
-  ieee_write_me_part(abfd);
+  ieee_write_me_part (abfd);
 
 
   /* Generate the header */
-  bfd_seek(abfd, old, SEEK_SET);
+  bfd_seek (abfd, old, SEEK_SET);
 
-  for (i= 0; i < N_W_VARIABLES; i++) {
-    ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum);
-    ieee_write_byte(abfd, (bfd_byte) i);
-    ieee_write_int5_out(abfd, ieee->w.offset[i]);
-  }
+  for (i = 0; i < N_W_VARIABLES; i++)
+    {
+      ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum);
+      ieee_write_byte (abfd, (bfd_byte) i);
+      ieee_write_int5_out (abfd, ieee->w.offset[i]);
+    }
   return true;
 }
+\f
 
 
-
-\f
 /* Native-level interface to symbols. */
 
 /* We read the symbols into a buffer, which is discarded when this
@@ -2818,124 +3128,135 @@ function exits.  We read the strings into a buffer large enough to
 hold them all plus all the cached symbol entries. */
 
 asymbol *
-DEFUN(ieee_make_empty_symbol,(abfd),
-      bfd *abfd)
+DEFUN (ieee_make_empty_symbol, (abfd),
+       bfd * abfd)
 {
 
-  ieee_symbol_type  *new =
-    (ieee_symbol_type *)bfd_zmalloc (sizeof (ieee_symbol_type));
+  ieee_symbol_type *new =
+  (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
+  if (!new)
+    {
+      bfd_error = no_error;
+      return NULL;
+    }
   new->symbol.the_bfd = abfd;
   return &new->symbol;
-
 }
 
 static bfd *
-DEFUN(ieee_openr_next_archived_file,(arch, prev),
-      bfd *arch AND
-      bfd *prev)
+DEFUN (ieee_openr_next_archived_file, (arch, prev),
+       bfd * arch AND
+       bfd * prev)
 {
-  ieee_ar_data_type *ar = IEEE_AR_DATA(arch);
+  ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
   /* take the next one from the arch state, or reset */
-  if (prev == (bfd *)NULL) {
-    /* Reset the index - the first two entries are bogus*/
-    ar->element_index = 2;
-  }
-  while (true) {  
-    ieee_ar_obstack_type *p = ar->elements + ar->element_index;
-    ar->element_index++;
-    if (ar->element_index <= ar->element_count) {
-      if (p->file_offset != (file_ptr)0) {
-       if (p->abfd == (bfd *)NULL) {
-         p->abfd = _bfd_create_empty_archive_element_shell(arch);
-         p->abfd->origin = p->file_offset;
-       }
-       return p->abfd;
-      }
-    }
-    else {
-      bfd_error = no_more_archived_files;
-      return (bfd *)NULL;
+  if (prev == (bfd *) NULL)
+    {
+      /* Reset the index - the first two entries are bogus*/
+      ar->element_index = 2;
     }
+  while (true)
+    {
+      ieee_ar_obstack_type *p = ar->elements + ar->element_index;
+      ar->element_index++;
+      if (ar->element_index <= ar->element_count)
+       {
+         if (p->file_offset != (file_ptr) 0)
+           {
+             if (p->abfd == (bfd *) NULL)
+               {
+                 p->abfd = _bfd_create_empty_archive_element_shell (arch);
+                 p->abfd->origin = p->file_offset;
+               }
+             return p->abfd;
+           }
+       }
+      else
+       {
+         bfd_error = no_more_archived_files;
+         return (bfd *) NULL;
+       }
 
-  }
+    }
 }
 
 static boolean
-ieee_find_nearest_line(abfd,
-                        section,
-                        symbols,
-                        offset,
-                        filename_ptr,
-                        functionname_ptr,
-                        line_ptr)
-bfd *abfd;
-asection *section;
-asymbol **symbols;
-bfd_vma offset;
-char **filename_ptr;
-char **functionname_ptr;
-int *line_ptr;
+ieee_find_nearest_line (abfd,
+                       section,
+                       symbols,
+                       offset,
+                       filename_ptr,
+                       functionname_ptr,
+                       line_ptr)
+     bfd *abfd;
+     asection *section;
+     asymbol **symbols;
+     bfd_vma offset;
+     char **filename_ptr;
+     char **functionname_ptr;
+     int *line_ptr;
 {
   return false;
 }
 
-
 static int
-ieee_generic_stat_arch_elt(abfd, buf)
-bfd *abfd;
-struct stat *buf;
+ieee_generic_stat_arch_elt (abfd, buf)
+     bfd *abfd;
+     struct stat *buf;
 {
   ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
-  if (ar == (ieee_ar_data_type *)NULL) {
-    bfd_error = invalid_operation;
-    return -1;
-  }
-  else {
-    buf->st_size = 0x1;
-    buf->st_mode = 0666;
-    return !    ieee_object_p(abfd);
-  }
+  if (ar == (ieee_ar_data_type *) NULL)
+    {
+      bfd_error = invalid_operation;
+      return -1;
+    }
+  else
+    {
+      buf->st_size = 0x1;
+      buf->st_mode = 0666;
+      return !ieee_object_p (abfd);
+    }
 }
-static int 
-DEFUN(ieee_sizeof_headers,(abfd, x),
-      bfd *abfd AND
-      boolean x)
+
+static int
+DEFUN (ieee_sizeof_headers, (abfd, x),
+       bfd * abfd AND
+       boolean x)
 {
   return 0;
 }
 
 
+static void
+DEFUN (ieee_bfd_debug_info_start, (abfd),
+       bfd * abfd)
+{
 
-static void 
-DEFUN(ieee_bfd_debug_info_start,(abfd), 
-      bfd *abfd)
-  {
-
-  }
+}
 
-static void 
-DEFUN(ieee_bfd_debug_info_end,(abfd), 
-      bfd *abfd)
-  {
+static void
+DEFUN (ieee_bfd_debug_info_end, (abfd),
+       bfd * abfd)
+{
 
-  }
+}
 
 
 /* Add this section to the list of sections we have debug info for, to
-   be ready to output it at close time 
+   be ready to output it at close time
    */
-static void 
-DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section), 
-      bfd *abfd AND
-      asection *section)
+static void
+DEFUN (ieee_bfd_debug_info_accumulate, (abfd, section),
+       bfd * abfd AND
+       asection * section)
 {
-  ieee_data_type *ieee = IEEE_DATA(section->owner);
-  ieee_data_type *output_ieee = IEEE_DATA(abfd);
+  ieee_data_type *ieee = IEEE_DATA (section->owner);
+  ieee_data_type *output_ieee = IEEE_DATA (abfd);
   /* can only accumulate data from other ieee bfds */
   if (section->owner->xvec != abfd->xvec)
     return;
   /* Only bother once per bfd */
-  if (ieee->done_debug == true) 
+  if (ieee->done_debug == true)
     return;
   ieee->done_debug = true;
 
@@ -2945,27 +3266,30 @@ DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section),
 
 
   /* Add to chain */
-    {
-      bfd_chain_type *n = (bfd_chain_type *) bfd_alloc(abfd, sizeof(bfd_chain_type));
-      n->this = section->owner;
-      n->next = (bfd_chain_type *)NULL;
-       
-      if (output_ieee->chain_head) {
+  {
+    bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
+    if (!n)
+      {
+       bfd_error = no_memory;
+       abort();                /* FIXME */
+      }
+    n->this = section->owner;
+    n->next = (bfd_chain_type *) NULL;
+
+    if (output_ieee->chain_head)
+      {
        output_ieee->chain_head->next = n;
       }
-      else {
+    else
+      {
        output_ieee->chain_root = n;
 
       }
-       output_ieee->chain_head = n; 
-    }
+    output_ieee->chain_head = n;
+  }
 }
 
 
-
-
-
-
 #define FOO PROTO
 #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
 #define ieee_core_file_failing_signal (int (*)())bfd_0
@@ -2997,37 +3321,36 @@ bfd_target ieee_vec =
   (HAS_RELOC | EXEC_P |                /* object flags */
    HAS_LINENO | HAS_DEBUG |
    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
-  ( SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
-   |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
-   0,                          /* leading underscore */
+  (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
+   | SEC_ALLOC | SEC_LOAD | SEC_RELOC),        /* section flags */
+  0,                           /* leading underscore */
   ' ',                         /* ar_pad_char */
   16,                          /* ar_max_namelen */
-    1,                         /* minimum alignment */
-bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-    bfd_getb32, bfd_getb_signed_32, bfd_putb32,
-    bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
-bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-    bfd_getb32, bfd_getb_signed_32, bfd_putb32,
-    bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
-
-  { _bfd_dummy_target,
-     ieee_object_p,            /* bfd_check_format */
-     ieee_archive_p,
-    _bfd_dummy_target,
-     },
+  1,                           /* minimum alignment */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* data */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* hdrs */
+
+  {_bfd_dummy_target,
+   ieee_object_p,              /* bfd_check_format */
+   ieee_archive_p,
+   _bfd_dummy_target,
+  },
   {
     bfd_false,
-    ieee_mkobject, 
+    ieee_mkobject,
     _bfd_generic_mkarchive,
     bfd_false
-    },
+  },
   {
     bfd_false,
     ieee_write_object_contents,
     _bfd_write_archive_contents,
     bfd_false,
   },
-  JUMP_TABLE(ieee),
+  JUMP_TABLE (ieee),
   (PTR) 0
 };
-
index 0803c7db807a5cef1824a832958f764deefdfb00..3d8597e166525b2c256132c3304c662f392d0f9f 100644 (file)
@@ -1,22 +1,22 @@
 /* linker.c -- BFD linker routines
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright (C) 1993, 94 Free Software Foundation, Inc.
    Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support
 
-This file is part of BFD
+This file is part of BFD, the Binary File Descriptor library.
 
-GLD is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GLD is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GLD; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -443,15 +443,23 @@ _bfd_link_hash_newfunc (entry, table, string)
   if (ret == (struct bfd_link_hash_entry *) NULL)
     ret = ((struct bfd_link_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry)));
+  if (ret == (struct bfd_link_hash_entry *) NULL)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct bfd_link_hash_entry *)
         bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
 
-  /* Initialize the local fields.  */
-  ret->type = bfd_link_hash_new;
-  ret->written = false;
-  ret->next = NULL;
+  if (ret)
+    {
+      /* Initialize the local fields.  */
+      ret->type = bfd_link_hash_new;
+      ret->written = false;
+      ret->next = NULL;
+    }
 
   return (struct bfd_hash_entry *) ret;
 }
@@ -549,14 +557,22 @@ generic_link_hash_newfunc (entry, table, string)
   if (ret == (struct generic_link_hash_entry *) NULL)
     ret = ((struct generic_link_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry)));
+  if (ret == (struct generic_link_hash_entry *) NULL)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct generic_link_hash_entry *)
         _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
                                 table, string));
 
-  /* Set local fields.  */
-  ret->sym = NULL;
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->sym = NULL;
+    }
 
   return (struct bfd_hash_entry *) ret;
 }
@@ -570,7 +586,12 @@ _bfd_generic_link_hash_table_create (abfd)
   struct generic_link_hash_table *ret;
 
   ret = ((struct generic_link_hash_table *)
-        bfd_xmalloc (sizeof (struct generic_link_hash_table)));
+        malloc (sizeof (struct generic_link_hash_table)));
+  if (!ret)
+      {
+       bfd_error = no_memory;
+       return (struct bfd_link_hash_table *) NULL;
+      }
   if (! _bfd_link_hash_table_init (&ret->root, abfd,
                                   generic_link_hash_newfunc))
     {
@@ -683,13 +704,21 @@ archive_hash_newfunc (entry, table, string)
   if (ret == (struct archive_hash_entry *) NULL)
     ret = ((struct archive_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct archive_hash_entry)));
+  if (ret == (struct archive_hash_entry *) NULL)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct archive_hash_entry *)
         bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
 
-  /* Initialize the local fields.  */
-  ret->defs = (struct archive_list *) NULL;
+  if (ret)
+    {
+      /* Initialize the local fields.  */
+      ret->defs = (struct archive_list *) NULL;
+    }
 
   return (struct bfd_hash_entry *) ret;
 }
@@ -1405,6 +1434,11 @@ _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value,
            sub = ((struct bfd_link_hash_entry *)
                   bfd_hash_allocate (&info->hash->table,
                                      sizeof (struct bfd_link_hash_entry)));
+           if (!sub)
+             {
+               bfd_error = no_memory;
+               return false;
+             }
            *sub = *h;
            h->type = bfd_link_hash_warning;
            h->u.i.link = sub;
@@ -1452,6 +1486,7 @@ _bfd_generic_final_link (abfd, info)
       return false;
 
   /* Accumulate the global symbols.  */
+  wginfo.info = info;
   wginfo.output_bfd = abfd;
   wginfo.psymalloc = &outsymalloc;
   _bfd_generic_link_hash_traverse (_bfd_generic_hash_table (info),
@@ -1482,7 +1517,12 @@ _bfd_generic_final_link (abfd, info)
                  input_bfd = input_section->owner;
                  relsize = bfd_get_reloc_upper_bound (input_bfd,
                                                       input_section);
-                 relocs = (arelent **) bfd_xmalloc (relsize);
+                 relocs = (arelent **) malloc ((size_t) relsize);
+                 if (!relocs)
+                   {
+                     bfd_error = no_memory;
+                     return false;
+                   }
                  reloc_count =
                    bfd_canonicalize_reloc (input_bfd, input_section,
                                            relocs,
@@ -1498,6 +1538,11 @@ _bfd_generic_final_link (abfd, info)
                                bfd_alloc (abfd,
                                           (o->reloc_count
                                            * sizeof (arelent *))));
+             if (!o->orelocation)
+               {
+                 bfd_error = no_memory;
+                 return false;
+               }
              /* Reset the count so that it can be used as an index
                 when putting in the output relocs.  */
              o->reloc_count = 0;
@@ -1572,6 +1617,11 @@ _bfd_generic_link_output_symbols (output_bfd, input_bfd, info, psymalloc)
 
   symsize = get_symtab_upper_bound (input_bfd);
   input_bfd->outsymbols = (asymbol **) bfd_alloc (input_bfd, symsize);
+  if (!input_bfd->outsymbols)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   input_bfd->symcount = bfd_canonicalize_symtab (input_bfd,
                                                 input_bfd->outsymbols);
 
@@ -1589,6 +1639,8 @@ _bfd_generic_link_output_symbols (output_bfd, input_bfd, info, psymalloc)
              asymbol *newsym;
 
              newsym = bfd_make_empty_symbol (input_bfd);
+             if (!newsym)
+               return false;
              newsym->name = input_bfd->filename;
              newsym->value = 0;
              newsym->flags = BSF_LOCAL | BSF_FILE;
@@ -1767,6 +1819,14 @@ _bfd_generic_link_write_global_symbol (h, data)
   if (h->root.written)
     return true;
 
+  h->root.written = true;
+
+  if (wginfo->info->strip == strip_all
+      || (wginfo->info->strip == strip_some
+         && bfd_hash_lookup (wginfo->info->keep_hash, h->root.root.string,
+                             false, false) == NULL))
+    return true;
+
   if (h->sym != (asymbol *) NULL)
     {
       sym = h->sym;
@@ -1775,6 +1835,8 @@ _bfd_generic_link_write_global_symbol (h, data)
   else
     {
       sym = bfd_make_empty_symbol (wginfo->output_bfd);
+      if (!sym)
+       return false;
       sym->name = h->root.root.string;
       sym->flags = 0;
     }
@@ -1820,8 +1882,6 @@ _bfd_generic_link_write_global_symbol (h, data)
       abort ();
     }
 
-  h->root.written = true;
-
   return true;
 }
 \f
@@ -1836,6 +1896,11 @@ bfd_new_link_order (abfd, section)
 
   new = ((struct bfd_link_order *)
         bfd_alloc_by_size_t (abfd, sizeof (struct bfd_link_order)));
+  if (!new)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   new->type = bfd_undefined_link_order;
   new->offset = 0;
@@ -1948,6 +2013,11 @@ default_indirect_link_order (output_bfd, info, output_section, link_order)
 
       symsize = get_symtab_upper_bound (input_bfd);
       input_bfd->outsymbols = (asymbol **) bfd_alloc (input_bfd, symsize);
+      if (!input_bfd->outsymbols)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
       input_bfd->symcount = bfd_canonicalize_symtab (input_bfd,
                                                     input_bfd->outsymbols);
     }
@@ -1957,6 +2027,8 @@ default_indirect_link_order (output_bfd, info, output_section, link_order)
   contents = (bfd_get_relocated_section_contents
              (output_bfd, info, link_order, contents, info->relocateable,
               bfd_get_outsymbols (input_bfd)));
+  if (!contents)
+    return false;
 
   /* Output the section contents.  */
   if (! bfd_set_section_contents (output_bfd, output_section, (PTR) contents,
index 358bc40ccaf52db8814dcb28566975263a805e2d..17d3a1a9ee9ba3b27768f9190455ee34603f878e 100644 (file)
@@ -96,6 +96,7 @@ nlm_alpha_write_prefix (abfd)
       bfd_error = system_call_error;
       return false;
     }
+  return true;
 }
 \f
 /* How to process the various reloc types.  */
@@ -469,13 +470,13 @@ nlm_alpha_read_reloc (abfd, sym, secp, rel)
          rel->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
          rel->addend = 0;
        }
-      else if (r_symndx == RELOC_SECTION_TEXT)
+      else if (r_symndx == ALPHA_RELOC_SECTION_TEXT)
        {
          rel->sym_ptr_ptr = code_sec->symbol_ptr_ptr;
          BFD_ASSERT (bfd_get_section_vma (abfd, code_sec) == 0);
          rel->addend = 0;
        }
-      else if (r_symndx == RELOC_SECTION_DATA)
+      else if (r_symndx == ALPHA_RELOC_SECTION_DATA)
        {
          rel->sym_ptr_ptr = data_sec->symbol_ptr_ptr;
          rel->addend = - bfd_get_section_vma (abfd, data_sec);
@@ -573,14 +574,23 @@ nlm_alpha_read_reloc (abfd, sym, secp, rel)
       break;
 
     case ALPHA_R_NW_RELOC:
+      /* If this is SETGP, we set the addend to 0.  Otherwise we set
+        the addend to the size of the .lita section (this is
+        r_symndx) plus 1.  We have already set the address of the
+        reloc to r_vaddr.  */
       if (r_size == ALPHA_R_NW_RELOC_SETGP)
-       gp_value = r_vaddr;
+       {
+         gp_value = r_vaddr;
+         rel->addend = 0;
+       }
       else if (r_size == ALPHA_R_NW_RELOC_LITA)
-       lita_address = r_vaddr;
+       {
+         lita_address = r_vaddr;
+         rel->addend = r_symndx + 1;
+       }
       else
        BFD_ASSERT (0);
       rel->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
-      rel->addend = r_size;
       break;
 
     default:
@@ -628,6 +638,11 @@ nlm_alpha_read_import (abfd, sym)
     }
   sym -> symbol.the_bfd = abfd;
   sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
+  if (!sym -> symbol.name)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   if (bfd_read ((PTR) sym -> symbol.name, symlength, 1, abfd)
       != symlength)
     {
@@ -645,6 +660,11 @@ nlm_alpha_read_import (abfd, sym)
   rcount = bfd_h_get_32 (abfd, temp);
   nlm_relocs = ((struct nlm_relent *)
                bfd_alloc (abfd, rcount * sizeof (struct nlm_relent)));
+  if (!nlm_relocs)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   sym -> relocs = nlm_relocs;
   sym -> rcnt = 0;
   while (sym -> rcnt < rcount)
@@ -680,52 +700,72 @@ nlm_alpha_write_import (abfd, sec, rel)
   sym = *rel->sym_ptr_ptr;
 
   /* Get values for the relocation fields.  */
-  r_vaddr = bfd_get_section_vma (abfd, sec) + rel->address;
-  if (bfd_get_section (sym) == &bfd_und_section)
-    {
-      r_extern = 1;
-      r_symndx = 0;
-    }
-  else
+  r_type = rel->howto->type;
+  if (r_type != ALPHA_R_NW_RELOC)
     {
-      r_extern = 0;
-      if (bfd_get_section_flags (abfd, bfd_get_section (sym)) & SEC_CODE)
-       r_symndx = RELOC_SECTION_TEXT;
+      r_vaddr = bfd_get_section_vma (abfd, sec) + rel->address;
+      if ((sec->flags & SEC_CODE) == 0)
+       r_vaddr += bfd_section_size (abfd,
+                                    bfd_get_section_by_name (abfd,
+                                                             NLM_CODE_NAME));
+      if (bfd_get_section (sym) == &bfd_und_section)
+       {
+         r_extern = 1;
+         r_symndx = 0;
+       }
       else
-       r_symndx = RELOC_SECTION_DATA;
-    }
-  r_type = rel->howto->type;
-  r_offset = 0;
-  r_size = 0;
+       {
+         r_extern = 0;
+         if (bfd_get_section_flags (abfd, bfd_get_section (sym)) & SEC_CODE)
+           r_symndx = ALPHA_RELOC_SECTION_TEXT;
+         else
+           r_symndx = ALPHA_RELOC_SECTION_DATA;
+       }
+      r_offset = 0;
+      r_size = 0;
 
-  switch (r_type)
+      switch (r_type)
+       {
+       case ALPHA_R_LITUSE:
+       case ALPHA_R_GPDISP:
+         r_symndx = rel->addend;
+         break;
+
+       case ALPHA_R_OP_STORE:
+         r_size = rel->addend & 0xff;
+         r_offset = (rel->addend >> 8) & 0xff;
+         break;
+
+       case ALPHA_R_OP_PUSH:
+       case ALPHA_R_OP_PSUB:
+       case ALPHA_R_OP_PRSHIFT:
+         r_vaddr = rel->addend;
+         break;
+
+       case ALPHA_R_IGNORE:
+         r_vaddr = rel->address;
+         break;
+
+       default:
+         break;
+       }
+    }
+  else
     {
-    case ALPHA_R_LITUSE:
-    case ALPHA_R_GPDISP:
-      r_symndx = rel->addend;
-      break;
-
-    case ALPHA_R_OP_STORE:
-      r_size = rel->addend & 0xff;
-      r_offset = (rel->addend >> 8) & 0xff;
-      break;
-
-    case ALPHA_R_OP_PUSH:
-    case ALPHA_R_OP_PSUB:
-    case ALPHA_R_OP_PRSHIFT:
-      r_vaddr = rel->addend;
-      break;
-
-    case ALPHA_R_IGNORE:
+      /* r_type == ALPHA_R_NW_RELOC */
       r_vaddr = rel->address;
-      break;
-
-    case ALPHA_R_NW_RELOC:
-      r_size = rel->addend;
-      break;
-
-    default:
-      break;
+      if (rel->addend == 0)
+       {
+         r_symndx = 0;
+         r_size = ALPHA_R_NW_RELOC_SETGP;
+       }
+      else
+       {
+         r_symndx = rel->addend - 1;
+         r_size = ALPHA_R_NW_RELOC_LITA;
+       }
+      r_extern = 0;
+      r_offset = 0;
     }
 
   /* Swap out the relocation fields.  */
@@ -800,13 +840,14 @@ nlm_alpha_get_public_offset (abfd, sym)
 static boolean
 nlm_alpha_write_external (abfd, count, sym, relocs)
      bfd *abfd;
-     bfd_vma count;
+     bfd_size_type count;
      asymbol *sym;
      struct reloc_and_sec *relocs;
 {
   int i;
   bfd_byte len;
   unsigned char temp[NLM_TARGET_LONG_SIZE];
+  arelent r;
 
   len = strlen (sym->name);
   if ((bfd_write (&len, sizeof (bfd_byte), 1, abfd) != sizeof(bfd_byte))
@@ -816,13 +857,28 @@ nlm_alpha_write_external (abfd, count, sym, relocs)
       return false;
     }
 
-  bfd_put_32 (abfd, count, temp);
+  bfd_put_32 (abfd, count + 2, temp);
   if (bfd_write (temp, sizeof (temp), 1, abfd) != sizeof (temp))
     {
       bfd_error = system_call_error;
       return false;
     }
 
+  /* The first two relocs for each external symbol are the .lita
+     address and the GP value.  */
+  r.sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+  r.howto = &nlm32_alpha_nw_howto;
+
+  r.address = nlm_alpha_backend_data (abfd)->lita_address;
+  r.addend = nlm_alpha_backend_data (abfd)->lita_size + 1;
+  if (nlm_alpha_write_import (abfd, (asection *) NULL, &r) == false)
+    return false;
+
+  r.address = nlm_alpha_backend_data (abfd)->gp;
+  r.addend = 0;
+  if (nlm_alpha_write_import (abfd, (asection *) NULL, &r) == false)
+    return false;
+
   for (i = 0; i < count; i++)
     {
       if (nlm_alpha_write_import (abfd, relocs[i].sec,
@@ -842,6 +898,7 @@ static const struct nlm_backend_data nlm32_alpha_backend =
   sizeof (struct nlm32_alpha_external_prefix_header),
   bfd_arch_alpha,
   0,
+  true, /* no uninitialized data permitted by Alpha NetWare.  */
   nlm_alpha_backend_object_p,
   nlm_alpha_write_prefix,
   nlm_alpha_read_reloc,
@@ -853,6 +910,7 @@ static const struct nlm_backend_data nlm32_alpha_backend =
   nlm_swap_fixed_header_in,
   nlm_swap_fixed_header_out,
   nlm_alpha_write_external,
+  0,   /* write_export */
 };
 
 #define TARGET_LITTLE_NAME             "nlm32-alpha"
index 45260c5cb751ba51c01db582cc03aa8f76f9456c..f3fd7cef8d8d4d6b4c7a4299c2bef5e142033d9d 100644 (file)
@@ -363,6 +363,11 @@ nlm_i386_read_import (abfd, sym)
     }
   sym -> symbol.the_bfd = abfd;
   sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
+  if (!sym -> symbol.name)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   if (bfd_read ((PTR) sym -> symbol.name, symlength, 1, abfd)
       != symlength)
     {
@@ -380,6 +385,11 @@ nlm_i386_read_import (abfd, sym)
   rcount = bfd_h_get_32 (abfd, temp);
   nlm_relocs = ((struct nlm_relent *)
                bfd_alloc (abfd, rcount * sizeof (struct nlm_relent)));
+  if (!nlm_relocs)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   sym -> relocs = nlm_relocs;
   sym -> rcnt = 0;
   while (sym -> rcnt < rcount)
@@ -444,6 +454,7 @@ static const struct nlm_backend_data nlm32_i386_backend =
   0,   /* optional_prefix_size */
   bfd_arch_i386,
   0,
+  false,
   0,   /* backend_object_p */
   0,   /* write_prefix_func */
   nlm_i386_read_reloc,
@@ -455,6 +466,7 @@ static const struct nlm_backend_data nlm32_i386_backend =
   nlm_swap_fixed_header_in,
   nlm_swap_fixed_header_out,
   nlm_i386_write_external,
+  0,   /* write_export */
 };
 
 #define TARGET_LITTLE_NAME             "nlm32-i386"
index ef2f3948078e617988063d7be7033a189d438d81..220ebd60ae79237c70131c3b330d51e7e8cc45a6 100644 (file)
@@ -173,7 +173,7 @@ nlm_sparc_write_reloc (abfd, sec, rel)
      arelent *rel;
 {
   bfd_vma val;
-  struct nlm32_sparc_reloc_ext tmp_reloc = {0};
+  struct nlm32_sparc_reloc_ext tmp_reloc;
   int index;
   int type = -1;
   reloc_howto_type *tmp;
@@ -283,6 +283,11 @@ nlm_sparc_read_import (abfd, sym)
     }
   sym -> symbol.the_bfd = abfd;
   sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
+  if (!sym -> symbol.name)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   
   /*
    * Then read in the symbol
@@ -304,6 +309,11 @@ nlm_sparc_read_import (abfd, sym)
   
   nlm_relocs = ((struct nlm_relent *)
                bfd_alloc (abfd, rcount * sizeof (struct nlm_relent)));
+  if (!nlm_relocs)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   sym -> relocs = nlm_relocs;
   sym -> rcnt = 0;
   while (sym -> rcnt < rcount)
index b7568a57cb6582474618e1dbb277076c8110bcbb..43b263efc165bde02e68f3fbecc84f652c941ba6 100644 (file)
@@ -111,14 +111,11 @@ DEFUN (nlm_object_p, (abfd), bfd * abfd)
 
   /* Read in the fixed length portion of the NLM header in external format.  */
 
-  x_fxdhdr = alloca (nlm_fixed_header_size (abfd));
+  x_fxdhdr = (PTR) alloca (nlm_fixed_header_size (abfd));
 
   if (bfd_read ((PTR) x_fxdhdr, nlm_fixed_header_size (abfd), 1, abfd) !=
       nlm_fixed_header_size (abfd))
-    {
-      bfd_error = system_call_error;
-      goto got_no_match;
-    }
+    goto got_wrong_format_error;
 
   /* Allocate an instance of the nlm_obj_tdata structure and hook it up to
      the tdata pointer in the bfd.  */
@@ -561,7 +558,7 @@ DEFUN (nlm_swap_auxiliary_headers_in, (abfd),
        }
       else if (strncmp (tempstr, "CoPyRiGhT=", 10) == 0)
        {
-         if (bfd_read ((PTR) &nlm_copyright_header (abfd)->stamp,
+         if (bfd_read ((PTR) nlm_copyright_header (abfd)->stamp,
                        sizeof (nlm_copyright_header (abfd)->stamp),
                        1, abfd)
              != sizeof (nlm_copyright_header (abfd)->stamp))
@@ -859,7 +856,8 @@ nlm_make_empty_symbol (abfd)
   nlm_symbol_type *new;
 
   new = (nlm_symbol_type *) bfd_zalloc (abfd, sizeof (nlm_symbol_type));
-  new->symbol.the_bfd = abfd;
+  if (new)
+    new->symbol.the_bfd = abfd;
   return &new->symbol;
 }
 
@@ -964,6 +962,11 @@ nlm_slurp_symbol_table (abfd)
 
   sym = ((nlm_symbol_type *)
         bfd_zalloc (abfd, totsymcount * sizeof (nlm_symbol_type)));
+  if (!sym)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   nlm_set_symbols (abfd, sym);
 
   /* We use the bfd's symcount directly as the control count, so that early
@@ -982,6 +985,11 @@ nlm_slurp_symbol_table (abfd)
        }
       sym -> symbol.the_bfd = abfd;
       sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
+      if (!sym -> symbol.name)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
       if (bfd_read ((PTR) sym -> symbol.name, symlength, 1, abfd)
          != symlength)
        {
@@ -1048,6 +1056,11 @@ nlm_slurp_symbol_table (abfd)
            }
          sym -> symbol.the_bfd = abfd;
          sym -> symbol.name = bfd_alloc (abfd, symlength + 1);
+         if (!sym -> symbol.name)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
          if (bfd_read ((PTR) sym -> symbol.name, symlength, 1, abfd)
              != symlength)
            {
@@ -1399,6 +1412,15 @@ nlm_compute_section_file_positions (abfd)
   nlm_set_text_low (abfd, text_low);
   nlm_set_data_low (abfd, data_low);
 
+  if (nlm_no_uninitialized_data (abfd))
+    {
+      /* This NetWare format does not use uninitialized data.  We must
+        increase the size of the data section.  We will never wind up
+        writing those file locations, so they will remain zero.  */
+      data += bss;
+      bss = 0;
+    }
+
   text_ptr = BFD_ALIGN (sofar, 1 << text_align);
   data_ptr = BFD_ALIGN (text_ptr + text, 1 << data_align);
   other_ptr = BFD_ALIGN (data_ptr + data, 1 << other_align);
@@ -1465,8 +1487,17 @@ nlm_compute_section_file_positions (abfd)
          add += size;
          add = BFD_ALIGN (add, 1 << bss_sec->alignment_power);
        }
-      nlm_fixed_header (abfd)->uninitializedDataSize += add;
-      bss_sec->_raw_size += add;
+      if (add != 0)
+       {
+         if (nlm_no_uninitialized_data (abfd))
+           {
+             /* We could handle this case, but so far it hasn't been
+                necessary.  */
+             abort ();
+           }
+         nlm_fixed_header (abfd)->uninitializedDataSize += add;
+         bss_sec->_raw_size += add;
+       }
     }
 
   return true;
@@ -1530,9 +1561,17 @@ nlm_external_reloc_compare (p1, p2)
 {
   const struct reloc_and_sec *r1 = (const struct reloc_and_sec *) p1;
   const struct reloc_and_sec *r2 = (const struct reloc_and_sec *) p2;
+  int cmp;
 
-  return strcmp ((*r1->rel->sym_ptr_ptr)->name,
-                (*r2->rel->sym_ptr_ptr)->name);
+  cmp = strcmp ((*r1->rel->sym_ptr_ptr)->name,
+               (*r2->rel->sym_ptr_ptr)->name);
+  if (cmp != 0)
+    return cmp;
+
+  /* We sort by address within symbol to make the sort more stable and
+     increase the chances that different hosts will generate bit for
+     bit equivalent results.  */
+  return (int) (r1->rel->address - r2->rel->address);
 }
 
 /* Write out an NLM file.  We write out the information in this order:
@@ -1574,7 +1613,7 @@ nlm_write_object_contents (abfd)
   asymbol **sym_ptr_ptr;
   file_ptr last;
   boolean (*write_prefix_func) PARAMS ((bfd *));
-  unsigned char *fixed_header = alloca (nlm_fixed_header_size (abfd));
+  unsigned char *fixed_header = (unsigned char *) alloca (nlm_fixed_header_size (abfd));
 
   if (abfd->output_has_begun == false
       && nlm_compute_section_file_positions (abfd) == false)
@@ -1705,7 +1744,7 @@ nlm_write_object_contents (abfd)
   BFD_ASSERT (i == external_reloc_count);
 
   /* Sort the external relocs by name.  */
-  qsort (external_relocs, external_reloc_count,
+  qsort ((PTR) external_relocs, (size_t) external_reloc_count,
         sizeof (struct reloc_and_sec), nlm_external_reloc_compare);
 
   /* Write out the external relocs.  */
@@ -1745,10 +1784,13 @@ nlm_write_object_contents (abfd)
   if (sym_ptr_ptr != (asymbol **) NULL)
     {
       bfd_vma (*get_public_offset_func) PARAMS ((bfd *, asymbol *));
+      boolean (*write_export_func) PARAMS ((bfd*, asymbol *, bfd_vma));
+
       asymbol **sym_end;
 
       nlm_fixed_header (abfd)->publicsOffset = bfd_tell (abfd);
       get_public_offset_func = nlm_get_public_offset_func (abfd);
+      write_export_func = nlm_write_export_func (abfd);
       c = 0;
       sym_end = sym_ptr_ptr + bfd_get_symcount (abfd);
       for (; sym_ptr_ptr < sym_end; sym_ptr_ptr++)
@@ -1766,15 +1808,6 @@ nlm_write_object_contents (abfd)
 
          ++c;
 
-         len = strlen (sym->name);
-         if ((bfd_write (&len, sizeof (bfd_byte), 1, abfd)
-              != sizeof (bfd_byte))
-             || bfd_write (sym->name, len, 1, abfd) != len)
-           {
-             bfd_error = system_call_error;
-             return false;
-           }
-
          if (get_public_offset_func)
            {
              /* Most backends can use the code below, but
@@ -1804,13 +1837,30 @@ nlm_write_object_contents (abfd)
                }
            }
 
-         put_word (abfd, offset, temp);
-         if (bfd_write (temp, sizeof (temp), 1, abfd) != sizeof (temp))
+         if (write_export_func)
            {
-             bfd_error = system_call_error;
-             return false;
+             if ((*write_export_func) (abfd, sym, offset) == false)
+               return false;
            }
-       }         
+         else
+           {
+             len = strlen (sym->name);
+             if ((bfd_write (&len, sizeof (bfd_byte), 1, abfd)
+                  != sizeof (bfd_byte))
+                 || bfd_write (sym->name, len, 1, abfd) != len)
+               {
+                 bfd_error = system_call_error;
+                 return false;
+               }
+             
+             put_word (abfd, offset, temp);
+             if (bfd_write (temp, sizeof (temp), 1, abfd) != sizeof (temp))
+               {
+                 bfd_error = system_call_error;
+                 return false;
+               }
+           }     
+       }
       nlm_fixed_header (abfd)->numberOfPublics = c;
 
       /* Write out the debugging records.  The NLM conversion program
@@ -1849,16 +1899,18 @@ nlm_write_object_contents (abfd)
 
              ++c;
 
-             offset = sym->value;
+             offset = bfd_asymbol_value (sym);
              sec = sym->section;
              if (sec->flags & SEC_CODE)
-               type = 1;
-             else if (sec->flags & SEC_DATA)
-               type = 0;
-             else if (sec->flags & SEC_ALLOC)
                {
+                 offset -= nlm_get_text_low (abfd);
+                 type = 1;
+               }
+             else if (sec->flags & (SEC_DATA | SEC_ALLOC))
+               {
+                 /* SEC_ALLOC is for the .bss section.  */
+                 offset -= nlm_get_data_low (abfd);
                  type = 0;
-                 offset += nlm_fixed_header (abfd)->dataImageSize;
                }
              else
                type = 2;
index f144192755bb011fb46b28bba9b85fb2afa60fdc..adad8bf33e0faf4977dc5a64e4c8e77f34cdb927 100644 (file)
@@ -33,6 +33,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define offsetof(type, identifier) (size_t) &(((type *) 0)->identifier) 
 #endif
 
+static boolean oasys_write_sections PARAMS ((bfd *));
+
 /* Read in all the section data and relocation stuff too */
 PROTO(static boolean,oasys_slurp_section_data,(bfd *CONST abfd));
 
@@ -99,7 +101,11 @@ DEFUN(oasys_slurp_symbol_table,(abfd),
 #else
   data->strings = bfd_alloc(abfd, data->symbol_string_length);
 #endif
-
+  if (!data->symbols || !data->strings)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   dest_defined = data->symbols + abfd->symcount -1;
 
@@ -267,9 +273,14 @@ DEFUN(oasys_archive_p,(abfd),
       oasys_module_info_type *module = 
        (oasys_module_info_type*)
          bfd_alloc(abfd, sizeof(oasys_module_info_type) * header.mod_count);
-
       oasys_module_table_type record;
 
+      if (!ar || !module)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
+
       abfd->tdata.oasys_ar_data = ar;
       ar->module = module;
       ar->module_count = header.mod_count;
@@ -292,6 +303,11 @@ DEFUN(oasys_archive_p,(abfd),
          record.sect_count = bfd_h_get_32(abfd, record_ext.sect_count);
 
          module[i].name = bfd_alloc(abfd,33);
+         if (!module[i].name)
+           {
+             bfd_error = no_error;
+             return NULL;
+           }
 
          memcpy(module[i].name, record_ext.mod_name, 33);
          filepos +=
@@ -313,6 +329,11 @@ DEFUN(oasys_archive_p,(abfd),
          record.module_name_size = bfd_h_get_32(abfd, record_ext.mod_name_length);
 
          module[i].name = bfd_alloc(abfd,record.module_name_size + 1);
+         if (!module[i].name)
+           {
+             bfd_error = no_error;
+             return NULL;
+           }
          bfd_read((PTR)module[i].name, 1, record.module_name_size, abfd);
          module[i].name[record.module_name_size] = 0;
          filepos +=
@@ -338,7 +359,7 @@ DEFUN(oasys_mkobject,(abfd),
 {
 
   abfd->tdata.oasys_obj_data =    (oasys_data_type*)bfd_alloc(abfd, sizeof(oasys_data_type));
-  return true;
+  return abfd->tdata.oasys_obj_data ? true : false;
 }
 
 #define MAX_SECS 16
@@ -391,6 +412,11 @@ DEFUN(oasys_object_p,(abfd),
                goto fail;
              }
          buffer = bfd_alloc(abfd, 3);
+         if (!buffer)
+           {
+             bfd_error = no_memory;
+             goto fail;
+           }
          section_number= record.section.relb & RELOCATION_SECT_BITS;
          sprintf(buffer,"%u", section_number);
          s = bfd_make_section(abfd,buffer);
@@ -548,6 +574,11 @@ DEFUN(oasys_slurp_section_data,(abfd),
              if (per->initialized == false) 
                  {
                    per->data = (bfd_byte *) bfd_zalloc(abfd, section->_raw_size);
+                   if (!per->data)
+                     {
+                       bfd_error = no_memory;
+                       return false;
+                     }
                    per->reloc_tail_ptr = (oasys_reloc_type **)&(section->relocation);
                    per->had_vma = false;
                    per->initialized = true;
@@ -607,6 +638,11 @@ DEFUN(oasys_slurp_section_data,(abfd),
                                      (oasys_reloc_type *)
                                        bfd_alloc(abfd,
                                                  sizeof(oasys_reloc_type));
+                                   if (!r)
+                                     {
+                                       bfd_error = no_memory;
+                                       return false;
+                                     }
                                    *(per->reloc_tail_ptr) = r;
                                    per->reloc_tail_ptr = &r->next;
                                    r->next= (oasys_reloc_type *)NULL;
@@ -648,6 +684,11 @@ DEFUN(oasys_slurp_section_data,(abfd),
                                      (oasys_reloc_type *)
                                        bfd_alloc(abfd,
                                                  sizeof(oasys_reloc_type));
+                                   if (!r)
+                                     {
+                                       bfd_error = no_memory;
+                                       return false;
+                                     }
                                    *(per->reloc_tail_ptr) = r;
                                    per->reloc_tail_ptr = &r->next;
                                    r->next= (oasys_reloc_type *)NULL;
@@ -704,10 +745,6 @@ DEFUN(oasys_slurp_section_data,(abfd),
 
 }
 
-
-
-extern bfd_error_vector_type bfd_error_vector;
-
 static boolean
 DEFUN(oasys_new_section_hook,(abfd, newsect),
       bfd *abfd AND
@@ -715,6 +752,11 @@ DEFUN(oasys_new_section_hook,(abfd, newsect),
 {
   newsect->used_by_bfd = (PTR)
     bfd_alloc(abfd, sizeof(oasys_per_section_type));
+  if (!newsect->used_by_bfd)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   oasys_per_section( newsect)->data = (bfd_byte *)NULL;
   oasys_per_section(newsect)->section = newsect;
   oasys_per_section(newsect)->offset  = 0;
@@ -897,9 +939,9 @@ DEFUN(oasys_write_syms, (abfd),
 
 
   /* Write a section header for each section */
-static void 
-DEFUN(oasys_write_sections, (abfd),
-      bfd *CONST abfd)
+static boolean
+oasys_write_sections (abfd)
+     bfd *abfd;
 {
   asection *s;
   static oasys_section_record_type out;
@@ -907,8 +949,8 @@ DEFUN(oasys_write_sections, (abfd),
   for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
     if (!isdigit(s->name[0])) 
        {
-          bfd_error_vector.nonrepresentable_section(abfd,
-                                                   s->name);
+         bfd_error = nonrepresentable_section;
+         return false;
        }
     out.relb = RELOCATION_TYPE_REL | s->target_index;
     bfd_h_put_32(abfd, s->_cooked_size, out.value);
@@ -919,6 +961,7 @@ DEFUN(oasys_write_sections, (abfd),
                       (oasys_record_union_type *) &out,
                       sizeof(out));
   }
+  return true;
 }
 
 static void
@@ -1032,7 +1075,7 @@ DEFUN(oasys_write_data, (abfd),
 
                if (relocs_to_go != 0) {        
                  arelent *r = *p;
-                 reloc_howto_type *CONST how=r->howto;
+                 const reloc_howto_type * const how=r->howto;
                  /* There is a relocation, is it for this byte ? */
                  if (r->address == current_byte_index) {
                    unsigned char rel_byte;
@@ -1152,7 +1195,8 @@ DEFUN(oasys_write_object_contents, (abfd),
 {
   oasys_write_header(abfd);
   oasys_write_syms(abfd);
-  oasys_write_sections(abfd);
+  if (! oasys_write_sections(abfd))
+    return false;
   oasys_write_data(abfd);
   oasys_write_end(abfd);
   return true;
@@ -1179,6 +1223,11 @@ DEFUN(oasys_set_section_contents,(abfd, section, location, offset, count),
        {
          oasys_per_section(section)->data =
            (bfd_byte *)(bfd_alloc(abfd,section->_cooked_size));    
+         if (!   oasys_per_section(section)->data)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
        }
     (void) memcpy((PTR)(oasys_per_section(section)->data + offset),
                  location,
@@ -1202,9 +1251,13 @@ DEFUN(oasys_make_empty_symbol,(abfd),
 
   oasys_symbol_type  *new =
     (oasys_symbol_type *)bfd_zalloc (abfd, sizeof (oasys_symbol_type));
+  if (!new)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   new->symbol.the_bfd = abfd;
   return &new->symbol;
-
 }
 
 
@@ -1306,11 +1359,13 @@ return 0;
 #define oasys_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *, asection *)))bfd_void
 #define oasys_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
 #define oasys_bfd_relax_section bfd_generic_relax_section
-#define oasys_bfd_seclet_link bfd_generic_seclet_link
 #define oasys_bfd_reloc_type_lookup \
   ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
 #define oasys_bfd_make_debug_symbol \
   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
+#define oasys_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
+#define oasys_bfd_link_add_symbols _bfd_generic_link_add_symbols
+#define oasys_bfd_final_link _bfd_generic_final_link
 
 /*SUPPRESS 460 */
 bfd_target oasys_vec =
@@ -1321,7 +1376,7 @@ bfd_target oasys_vec =
   true,                                /* target headers byte order */
   (HAS_RELOC | EXEC_P |                /* object flags */
    HAS_LINENO | HAS_DEBUG |
-   HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
+   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
   (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
    |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
    0,                          /* leading underscore */
index ddddf930ea35edb3a67d249186ea744443b50d2c..242e65bc69e3c44518fa3a3e52c149fa6d40719e 100644 (file)
@@ -1,5 +1,5 @@
 /* opncls.c -- open and close a BFD.
-   Copyright (C) 1990-1991 Free Software Foundation, Inc.
+   Copyright (C) 1990 91, 92, 93, 94 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -29,7 +29,7 @@ FILE *bfd_open_file PARAMS ((bfd *));
    if we do that we can't use fcntl.  */
 
 
-#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
 
 /* Return a new BFD.  All BFD's are allocated through this routine.  */
@@ -41,10 +41,17 @@ _bfd_new_bfd ()
 
   nbfd = (bfd *)bfd_zmalloc (sizeof (bfd));
   if (!nbfd)
-    return 0;
+    {
+      bfd_error = no_memory;
+      return 0;
+    }
 
   bfd_check_init();
-  obstack_begin(&nbfd->memory, 128);
+  if (!obstack_begin(&nbfd->memory, 128))
+    {
+      bfd_error = no_memory;
+      return 0;
+    }
 
   nbfd->arch_info = &bfd_default_arch_struct;
 
@@ -490,8 +497,7 @@ bfd_alloc_by_size_t (abfd, size)
      bfd *abfd;
      size_t size;
 {
-  PTR res = obstack_alloc(&(abfd->memory), size);
-  return res;
+  return obstack_alloc(&(abfd->memory), size);
 }
 
 void
@@ -525,7 +531,8 @@ bfd_zalloc (abfd, size)
 {
   PTR res;
   res = bfd_alloc(abfd, size);
-  memset(res, 0, (size_t)size);
+  if (res)
+    memset(res, 0, (size_t)size);
   return res;
 }
 
@@ -536,6 +543,7 @@ bfd_realloc (abfd, old, size)
      size_t size;
 {
   PTR res = bfd_alloc(abfd, size);
-  memcpy(res, old, (size_t)size);
+  if (res)
+    memcpy(res, old, (size_t)size);
   return res;
 }
index c8c988c6de25d4c2b42a7130400fd3b194419921..94a53bc53fdd76f2639c9575af886b5569b0076b 100644 (file)
@@ -91,7 +91,8 @@ osf_core_make_empty_symbol (abfd)
      bfd *abfd;
 {
   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
-  new->the_bfd = abfd;
+  if (new)
+    new->the_bfd = abfd;
   return new;
 }
 
@@ -139,6 +140,11 @@ osf_core_core_file_p (abfd)
             for shared libraries), but bfd doesn't permit data sections with
             the same name. Construct a unique section name.  */
          secname = bfd_alloc (abfd, 40);
+         if (!secname)
+           {
+             bfd_error = no_memory;
+             return NULL;
+           }
          sprintf (secname, ".data%d", dseccnt++);
          break;
        case SCNSTACK:
@@ -202,7 +208,7 @@ osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
 #define        osf_core_close_and_cleanup              bfd_generic_close_and_cleanup
 #define        osf_core_set_section_contents           (boolean (*) PARAMS     \
         ((bfd *abfd, asection *section, PTR data, file_ptr offset,     \
-        bfd_size_type count))) bfd_false
+        bfd_size_type count))) bfd_generic_set_section_contents
 #define        osf_core_get_section_contents           bfd_generic_get_section_contents
 #define        osf_core_new_section_hook               (boolean (*) PARAMS     \
        ((bfd *, sec_ptr))) bfd_true
@@ -253,9 +259,10 @@ swap_abort()
 {
   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
 }
-#define        NO_GET  ((bfd_vma (*) PARAMS ((         bfd_byte *))) swap_abort )
+#define        NO_GET  ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
 #define        NO_PUT  ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
-#define        NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort )
+#define        NO_SIGNED_GET \
+  ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
 
 bfd_target osf_core_vec =
   {
diff --git a/bfd/rs6000-core.c b/bfd/rs6000-core.c
new file mode 100644 (file)
index 0000000..880cd91
--- /dev/null
@@ -0,0 +1,374 @@
+/* IBM RS/6000 "XCOFF" back-end for BFD.
+   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   FIXME: Can someone provide a transliteration of this name into ASCII?
+   Using the following chars caused a compiler warning on HIUX (so I replaced
+   them with octal escapes), and isn't useful without an understanding of what
+   character set it is.
+   Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365, 
+     and John Gilmore.
+   Archive support from Damon A. Permezel.
+   Contributed by IBM Corporation and Cygnus Support.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+/* This port currently only handles reading object files, except when
+   compiled on an RS/6000 host.  -- no archive support, no core files.
+   In all cases, it does not support writing.
+
+   FIXMEmgo comments are left from Metin Ozisik's original port.
+
+   This is in a separate file from coff-rs6000.c, because it includes
+   system include files that conflict with coff/rs6000.h.
+  */
+
+/* Internalcoff.h and coffcode.h modify themselves based on this flag.  */
+#define RS6000COFF_C 1
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+
+#ifdef COREFILES_PLEASE
+
+/* AOUTHDR is defined by the above.  We need another defn of it, from the
+   system include files.  Punt the old one and get us a new name for the
+   typedef in the system include files.  */
+#ifdef AOUTHDR
+#undef AOUTHDR
+#endif
+#define        AOUTHDR second_AOUTHDR
+
+#undef SCNHDR
+
+
+/* ------------------------------------------------------------------------ */
+/*     Support for core file stuff..                                       */
+/* ------------------------------------------------------------------------ */
+
+#include <sys/user.h>
+#include <sys/ldr.h>
+#include <sys/core.h>
+
+
+/* Number of special purpose registers supported by gdb.  This value
+   should match `tm.h' in gdb directory.  Clean this mess up and use
+   the macros in sys/reg.h.  FIXMEmgo. */
+
+#define        NUM_OF_SPEC_REGS  7
+#define        STACK_END_ADDR 0x2ff80000
+
+#define        core_hdr(bfd)           (((Rs6kCorData*)(bfd->tdata.any))->hdr)
+#define        core_datasec(bfd)       (((Rs6kCorData*)(bfd->tdata.any))->data_section)
+#define        core_stacksec(bfd)      (((Rs6kCorData*)(bfd->tdata.any))->stack_section)
+#define        core_regsec(bfd)        (((Rs6kCorData*)(bfd->tdata.any))->reg_section)
+#define        core_reg2sec(bfd)       (((Rs6kCorData*)(bfd->tdata.any))->reg2_section)
+
+/* These are stored in the bfd's tdata */
+typedef struct {
+  struct core *hdr;            /* core file header */
+  asection *data_section,
+          *stack_section,
+          *reg_section,        /* section for GPRs and special registers. */
+          *reg2_section;       /* section for FPRs. */
+
+  /* This tells us where everything is mapped (shared libraries and so on).
+     GDB needs it.  */
+  asection *ldinfo_section;
+#define core_ldinfosec(bfd) (((Rs6kCorData *)(bfd->tdata.any))->ldinfo_section)
+} Rs6kCorData;
+
+
+/* Decide if a given bfd represents a `core' file or not. There really is no
+   magic number or anything like, in rs6000coff. */
+
+bfd_target *
+rs6000coff_core_p (abfd)
+     bfd *abfd;
+{
+  int fd;
+  struct core_dump coredata;
+  struct stat statbuf;
+  char *tmpptr;
+
+  /* Use bfd_xxx routines, rather than O/S primitives to read coredata. FIXMEmgo */
+  fd = open (abfd->filename, O_RDONLY);
+  if (fd < 0)
+    {
+      bfd_error = system_call_error;
+      return NULL;
+    }
+
+  if (fstat (fd, &statbuf) < 0)
+    {
+      bfd_error = system_call_error;
+      close (fd);
+      return NULL;
+    }
+  if (read (fd, &coredata, sizeof (struct core_dump))
+      != sizeof (struct core_dump))
+    {
+      bfd_error = wrong_format;
+      close (fd);
+      return NULL;
+    }
+
+  if (close (fd) < 0)
+    {
+      bfd_error = system_call_error;
+      return NULL;
+    }
+
+  /* If the core file ulimit is too small, the system will first
+     omit the data segment, then omit the stack, then decline to
+     dump core altogether (as far as I know UBLOCK_VALID and LE_VALID
+     are always set) (this is based on experimentation on AIX 3.2).
+     Now, the thing is that GDB users will be surprised
+     if segments just silently don't appear (well, maybe they would
+     think to check "info files", I don't know), but we have no way of
+     returning warnings (as opposed to errors).
+
+     For the data segment, we have no choice but to keep going if it's
+     not there, since the default behavior is not to dump it (regardless
+     of the ulimit, it's based on SA_FULLDUMP).  But for the stack segment,
+     if it's not there, we refuse to have anything to do with this core
+     file.  The usefulness of a core dump without a stack segment is pretty
+     limited anyway.  */
+     
+  if (!(coredata.c_flag & UBLOCK_VALID)
+      || !(coredata.c_flag & LE_VALID))
+    {
+      bfd_error = wrong_format;
+      return NULL;
+    }
+
+  if ((coredata.c_flag & CORE_TRUNC)
+      || !(coredata.c_flag & USTACK_VALID))
+    {
+      bfd_error = file_truncated;
+      return NULL;
+    }
+
+  if (((bfd_vma)coredata.c_stack + coredata.c_size
+       + ((coredata.c_flag & FULL_CORE) ? coredata.c_u.u_dsize : 0))
+      != statbuf.st_size)
+    {
+      /* If the size is wrong, it means we're misinterpreting something.  */
+      bfd_error = wrong_format;
+      return NULL;
+    }
+
+  /* Sanity check on the c_tab field.  */
+  if ((u_long) coredata.c_tab < sizeof coredata ||
+      (u_long) coredata.c_tab >= statbuf.st_size ||
+      (long) coredata.c_tab >= (long)coredata.c_stack)
+    {
+      bfd_error = wrong_format;
+      return NULL;
+    }
+
+  /* maybe you should alloc space for the whole core chunk over here!! FIXMEmgo */
+  tmpptr = (char*)bfd_zalloc (abfd, sizeof (Rs6kCorData));
+  if (!tmpptr)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
+      
+  set_tdata (abfd, tmpptr);
+
+  /* .stack section. */
+  if ((core_stacksec (abfd) = (asection*) bfd_zalloc (abfd, sizeof (asection)))
+       == NULL)  {
+    bfd_error = no_memory;
+    /* bfd_release (abfd, ???? ) */
+    return NULL;
+  }
+  core_stacksec (abfd)->name = ".stack";
+  core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
+  core_stacksec (abfd)->_raw_size = coredata.c_size;
+  core_stacksec (abfd)->vma = STACK_END_ADDR - coredata.c_size;
+  core_stacksec (abfd)->filepos = (int)coredata.c_stack;       /*???? */
+
+  /* .reg section for GPRs and special registers. */
+  if ((core_regsec (abfd) = (asection*) bfd_zalloc (abfd, sizeof (asection)))
+       == NULL)  {
+    bfd_error = no_memory;
+    /* bfd_release (abfd, ???? ) */
+    return NULL;
+  }
+  core_regsec (abfd)->name = ".reg";
+  core_regsec (abfd)->flags = SEC_ALLOC;
+  core_regsec (abfd)->_raw_size = (32 + NUM_OF_SPEC_REGS) * 4;
+  core_regsec (abfd)->vma = 0;                 /* not used?? */
+  core_regsec (abfd)->filepos = 
+       (char*)&coredata.c_u.u_save - (char*)&coredata;
+
+  /* .reg2 section for FPRs (floating point registers). */
+  if ((core_reg2sec (abfd) = (asection*) bfd_zalloc (abfd, sizeof (asection)))
+       == NULL)  {
+    bfd_error = no_memory;
+    /* bfd_release (abfd, ???? ) */
+    return NULL;
+  }
+  core_reg2sec (abfd)->name = ".reg2";
+  core_reg2sec (abfd)->flags = SEC_ALLOC;
+  core_reg2sec (abfd)->_raw_size = 8 * 32;                     /* 32 FPRs. */
+  core_reg2sec (abfd)->vma = 0;                        /* not used?? */
+  core_reg2sec (abfd)->filepos = 
+       (char*)&coredata.c_u.u_save.fpr[0] - (char*)&coredata;
+
+  if ((core_ldinfosec (abfd) = (asection*) bfd_zalloc (abfd, sizeof (asection)))
+       == NULL)  {
+    bfd_error = no_memory;
+    /* bfd_release (abfd, ???? ) */
+    return NULL;
+  }
+  core_ldinfosec (abfd)->name = ".ldinfo";
+  core_ldinfosec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
+  /* To actually find out how long this section is in this particular
+     core dump would require going down the whole list of struct ld_info's.
+     See if we can just fake it.  */
+  core_ldinfosec (abfd)->_raw_size = 0x7fffffff;
+  /* Not relevant for ldinfo section.  */
+  core_ldinfosec (abfd)->vma = 0;
+  core_ldinfosec (abfd)->filepos = coredata.c_tab;
+
+  /* set up section chain here. */
+  abfd->section_count = 4;
+  abfd->sections = core_stacksec (abfd);
+  core_stacksec (abfd)->next = core_regsec(abfd);
+  core_regsec (abfd)->next = core_reg2sec (abfd);
+  core_reg2sec (abfd)->next = core_ldinfosec (abfd);
+  core_ldinfosec (abfd)->next = NULL;
+
+  if (coredata.c_flag & FULL_CORE)
+    {
+      asection *sec = (asection *) bfd_zalloc (abfd, sizeof (asection));
+      if (sec == NULL)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
+      sec->name = ".data";
+      sec->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
+      sec->_raw_size = coredata.c_u.u_dsize;
+      sec->vma = CDATA_ADDR (coredata.c_u.u_dsize);
+      sec->filepos = (int)coredata.c_stack + coredata.c_size;
+
+      sec->next = abfd->sections;
+      abfd->sections = sec;
+      ++abfd->section_count;
+    }
+
+  return abfd->xvec;                           /* this is garbage for now. */
+}
+
+
+
+/* return `true' if given core is from the given executable.. */
+boolean
+rs6000coff_core_file_matches_executable_p (core_bfd, exec_bfd)
+     bfd *core_bfd;
+     bfd *exec_bfd;
+{
+  FILE *fd;
+  struct core_dump coredata;
+  struct ld_info ldinfo;
+  char pathname [1024];
+  char *str1, *str2;
+
+  /* Use bfd_xxx routines, rather than O/S primitives, do error checking!!
+                                                               FIXMEmgo */
+  /* Actually should be able to use bfd_get_section_contents now that
+     we have a .ldinfo section.  */
+  fd = fopen (core_bfd->filename, FOPEN_RB);
+
+  fread (&coredata, sizeof (struct core_dump), 1, fd);
+  fseek (fd, (long)coredata.c_tab, 0);
+  fread (&ldinfo, (char*)&ldinfo.ldinfo_filename[0] - (char*)&ldinfo.ldinfo_next,
+        1, fd);
+  fscanf (fd, "%s", pathname);
+  
+  str1 = strrchr (pathname, '/');
+  str2 = strrchr (exec_bfd->filename, '/');
+
+  /* step over character '/' */
+  str1 = str1 ? str1+1 : &pathname[0];
+  str2 = str2 ? str2+1 : exec_bfd->filename;
+
+  fclose (fd);
+  return strcmp (str1, str2) == 0;
+}
+
+
+boolean
+rs6000coff_get_section_contents (abfd, section, location, offset, count)
+     bfd *abfd;
+     sec_ptr section;
+     PTR location;
+     file_ptr offset;
+     int count;
+{
+    if (count == 0)
+       return true;
+
+    /* Reading a core file's sections will be slightly different. For the
+       rest of them we can use bfd_generic_get_section_contents () I suppose. */
+    /* Make sure this routine works for any bfd and any section. FIXMEmgo. */
+
+    if (abfd->format == bfd_core && strcmp (section->name, ".reg") == 0) {
+
+      struct mstsave mstatus;
+      int    regoffset = (char*)&mstatus.gpr[0] - (char*)&mstatus;
+
+      /* Assert that the only way this code will be executed is reading the
+         whole section. */
+      if (offset || count != (sizeof(mstatus.gpr) + (4 * NUM_OF_SPEC_REGS)))
+        fprintf (stderr, "ERROR! in rs6000coff_get_section_contents()\n");
+
+      /* for `.reg' section, `filepos' is a pointer to the `mstsave' structure
+         in the core file. */
+
+      /* read GPR's into the location. */
+      if ( bfd_seek(abfd, section->filepos + regoffset, SEEK_SET) == -1
+       || bfd_read(location, sizeof (mstatus.gpr), 1, abfd) != sizeof (mstatus.gpr))
+       return (false); /* on error */
+
+      /* increment location to the beginning of special registers in the section,
+         reset register offset value to the beginning of first special register
+        in mstsave structure, and read special registers. */
+
+      location = (PTR) ((char*)location + sizeof (mstatus.gpr));
+      regoffset = (char*)&mstatus.iar - (char*)&mstatus;
+
+      if ( bfd_seek(abfd, section->filepos + regoffset, SEEK_SET) == -1
+       || bfd_read(location, 4 * NUM_OF_SPEC_REGS, 1, abfd) != 
+                                                       4 * NUM_OF_SPEC_REGS)
+       return (false); /* on error */
+      
+      /* increment location address, and read the special registers.. */
+      /* FIXMEmgo */
+      return (true);
+    }
+
+    /* else, use default bfd section content transfer. */
+    else
+      return bfd_generic_get_section_contents 
+                       (abfd, section, location, offset, count);
+}
+
+#endif /* COREFILES_PLEASE */
index 374e2faf05fdf247bd792caed62f10fdb7c795a7..02ae2188458bb89e708ea9a7f87b7cea4d641967 100644 (file)
@@ -553,6 +553,8 @@ bfd_make_section_anyway (abfd, name)
      useful for things like relocs which are relative to the base of a
      section.  */
   newsect->symbol = bfd_make_empty_symbol(abfd);
+  if (!newsect)
+    return NULL;
   newsect->symbol->name = name;
   newsect->symbol->value = 0;
   newsect->symbol->section = newsect;
@@ -637,6 +639,7 @@ DESCRIPTION
 
 */
 
+/*ARGSUSED*/
 boolean
 DEFUN(bfd_set_section_flags,(abfd, section, flags),
      bfd *abfd AND
index 92a010bd7e799a656357b599194a05e1b162a432..1ce4713ba2ad6287afa91a023e180203bccdb377 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -1021,16 +1021,16 @@ som_reloc_queue_find (p, size, queue)
      unsigned int size;
      struct reloc_queue *queue;
 {
-  if (!bcmp (p, queue[0].reloc, size)
+  if (queue[0].reloc && !bcmp (p, queue[0].reloc, size)
       && size == queue[0].size)
     return 0;
-  if (!bcmp (p, queue[1].reloc, size)
+  if (queue[1].reloc && !bcmp (p, queue[1].reloc, size)
       && size == queue[1].size)
     return 1;
-  if (!bcmp (p, queue[2].reloc, size)
+  if (queue[2].reloc && !bcmp (p, queue[2].reloc, size)
       && size == queue[2].size)
     return 2;
-  if (!bcmp (p, queue[3].reloc, size)
+  if (queue[3].reloc && !bcmp (p, queue[3].reloc, size)
       && size == queue[3].size)
     return 3;
   return -1;
@@ -1347,6 +1347,11 @@ hppa_som_gen_reloc_type (abfd, base_type, format, field)
 
   final_types = (int **) bfd_alloc_by_size_t (abfd, sizeof (int *) * 3);
   final_type = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
+  if (!final_types || !final_type)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
 
   /* The field selector may require additional relocations to be 
      generated.  It's impossible to know at this moment if additional
@@ -1369,6 +1374,11 @@ hppa_som_gen_reloc_type (abfd, base_type, format, field)
       case e_ltsel:
       case e_rtsel:
        final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
+       if (!final_types[0])
+         {
+           bfd_error = no_memory;
+           return NULL;
+         }
        if (field == e_tsel)
          *final_types[0] = R_FSEL;
        else if (field == e_ltsel)
@@ -1383,6 +1393,11 @@ hppa_som_gen_reloc_type (abfd, base_type, format, field)
       case e_lssel:
       case e_rssel:
        final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
+       if (!final_types[0])
+         {
+           bfd_error = no_memory;
+           return NULL;
+         }
        *final_types[0] = R_S_MODE;
        final_types[1] = final_type;
        final_types[2] = NULL;
@@ -1392,6 +1407,11 @@ hppa_som_gen_reloc_type (abfd, base_type, format, field)
       case e_lsel:
       case e_rsel:
        final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
+       if (!final_types[0])
+         {
+           bfd_error = no_memory;
+           return NULL;
+         }
        *final_types[0] = R_N_MODE;
        final_types[1] = final_type;
        final_types[2] = NULL;
@@ -1401,6 +1421,11 @@ hppa_som_gen_reloc_type (abfd, base_type, format, field)
       case e_ldsel:
       case e_rdsel:
        final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
+       if (!final_types[0])
+         {
+           bfd_error = no_memory;
+           return NULL;
+         }
        *final_types[0] = R_D_MODE;
        final_types[1] = final_type;
        final_types[2] = NULL;
@@ -1410,6 +1435,11 @@ hppa_som_gen_reloc_type (abfd, base_type, format, field)
       case e_lrsel:
       case e_rrsel:
        final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
+       if (!final_types[0])
+         {
+           bfd_error = no_memory;
+           return NULL;
+         }
        *final_types[0] = R_R_MODE;
        final_types[1] = final_type;
        final_types[2] = NULL;
@@ -1541,6 +1571,11 @@ make_unique_section (abfd, name, num)
     }
 
   newname = bfd_alloc (abfd, strlen (sect->name) + 1);
+  if (!newname)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   strcpy (newname, sect->name);
 
   sect->name = newname;
@@ -3879,8 +3914,13 @@ som_new_section_hook (abfd, newsect)
      bfd *abfd;
      asection *newsect;
 {
-  newsect->used_by_bfd
-    = (PTR) bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
+  newsect->used_by_bfd =
+    (PTR) bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
+  if (!newsect->used_by_bfd)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   newsect->alignment_power = 3;
 
   /* Initialize the subspace_index field to -1 so that it does
@@ -3976,7 +4016,12 @@ bfd_som_attach_aux_hdr (abfd, type, string)
        pad = (4 - (len % 4));
       obj_som_version_hdr (abfd) = (struct user_string_aux_hdr *)
        bfd_zalloc (abfd, sizeof (struct aux_id)
-                           + sizeof (unsigned int) + len + pad);
+                             + sizeof (unsigned int) + len + pad);
+      if (!obj_som_version_hdr (abfd))
+       {
+         bfd_error = no_memory;
+         abort();              /* FIXME */
+       }
       obj_som_version_hdr (abfd)->header_id.type = VERSION_AUX_ID;
       obj_som_version_hdr (abfd)->header_id.length = len + pad;
       obj_som_version_hdr (abfd)->header_id.length += sizeof (int);
@@ -3993,6 +4038,11 @@ bfd_som_attach_aux_hdr (abfd, type, string)
       obj_som_copyright_hdr (abfd) = (struct copyright_aux_hdr *)
        bfd_zalloc (abfd, sizeof (struct aux_id)
                            + sizeof (unsigned int) + len + pad);
+      if (!obj_som_copyright_hdr (abfd))
+       {
+         bfd_error = no_error;
+         abort();              /* FIXME */
+       }
       obj_som_copyright_hdr (abfd)->header_id.type = COPYRIGHT_AUX_ID;
       obj_som_copyright_hdr (abfd)->header_id.length = len + pad;
       obj_som_copyright_hdr (abfd)->header_id.length += sizeof (int);
index 02a49fbd2395331768634753c9841c108f4501d7..06432b95d6ca0927c9036a8d27ee85650bb2ed4b 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for s-record objects.
-   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -26,12 +26,12 @@ DESCRIPTION
        
        Ordinary S-Records cannot hold anything but addresses and
        data, so that's all that we implement.
-   
+
        The only interesting thing is that S-Records may come out of
        order and there is no header, so an initial scan is required
        to discover the minimum and maximum addresses used to create
        the vma and size of the only section we create.  We
-       arbitrarily call this section ".text". 
+       arbitrarily call this section ".text".
 
        When bfd_get_section_contents is called the file is read
        again, and this time the data is placed into a bfd_alloc'd
@@ -95,7 +95,7 @@ EXAMPLE
          _etext $8036
          _edata $8036
          _end $8036
-       $$ 
+       $$
 
 DESCRIPTION
        We allow symbols to be anywhere in the data stream - the module names
@@ -111,7 +111,7 @@ DESCRIPTION
 
 static CONST char digs[] = "0123456789ABCDEF";
 
-static char hex_value[1 + (unsigned char)~0];
+static char hex_value[1 + (unsigned char) ~0];
 
 #define NOT_HEX 20
 #define NIBBLE(x) hex_value[(unsigned char)(x)]
@@ -125,37 +125,37 @@ static char hex_value[1 + (unsigned char)~0];
 
 
 static void
-DEFUN_VOID(srec_init) 
+DEFUN_VOID (srec_init)
 {
-    unsigned int i;
-    static boolean inited = false;
-    
-    if (inited == false) 
+  unsigned int i;
+  static boolean inited = false;
+
+  if (inited == false)
     {
-       
-       inited = true;
-       
-       for (i = 0; i < sizeof (hex_value); i++) 
+
+      inited = true;
+
+      for (i = 0; i < sizeof (hex_value); i++)
        {
-           hex_value[i] = NOT_HEX;
+         hex_value[i] = NOT_HEX;
        }
-    
-       for (i = 0; i < 10; i++) 
+
+      for (i = 0; i < 10; i++)
        {
-           hex_value[i + '0'] = i;
-       
+         hex_value[i + '0'] = i;
+
        }
-       for (i = 0; i < 6; i++) 
+      for (i = 0; i < 6; i++)
        {
-           hex_value[i + 'a'] = i+10;
-           hex_value[i + 'A'] = i+10;
+         hex_value[i + 'a'] = i + 10;
+         hex_value[i + 'A'] = i + 10;
        }
-    }    
+    }
 }
 
 
 /* The maximum number of bytes on a line is FF */
-#define MAXCHUNK 0xff 
+#define MAXCHUNK 0xff
 /* The number of bytes we fit onto a line on output */
 #define CHUNK 21
 
@@ -164,21 +164,21 @@ DEFUN_VOID(srec_init)
 
 struct srec_data_list_struct
 {
-    unsigned    char *data;
-    bfd_vma where;
-    bfd_size_type size;
-    struct srec_data_list_struct *next;
+  unsigned char *data;
+  bfd_vma where;
+  bfd_size_type size;
+  struct srec_data_list_struct *next;
+
 
-    
-} ;
+};
 typedef struct srec_data_list_struct srec_data_list_type;
 
 
-typedef struct  srec_data_struct
-{
-    srec_data_list_type *head;    
+typedef struct srec_data_struct
+  {
+    srec_data_list_type *head;
     unsigned int type;
-    
+
     int done_symbol_read;
     int count;
     asymbol *symbols;
@@ -186,67 +186,75 @@ typedef struct  srec_data_struct
     int symbol_idx;
     int string_size;
     int string_idx;
-} tdata_type;
+  }
+tdata_type;
 
 
-/* 
+/*
    called once per input S-Record, used to work out vma and size of data.
  */
 
-static bfd_vma low,high;
+static bfd_vma low, high;
 
+/*ARGSUSED*/
 static void
-size_symbols(abfd, buf, len, val)
-bfd *abfd;
-char *buf;
-int len;
-int val;
-{
-  abfd->symcount ++;
-  abfd->tdata.srec_data->string_size  += len + 1;
+size_symbols (abfd, buf, len, val)
+     bfd *abfd;
+     char *buf;
+     int len;
+     int val;
+{
+  abfd->symcount++;
+  abfd->tdata.srec_data->string_size += len + 1;
 }
 
 static void
-fillup_symbols(abfd, buf, len, val)
-bfd *abfd;
-char *buf;
-int len;
-int val;
+fillup_symbols (abfd, buf, len, val)
+     bfd *abfd;
+     char *buf;
+     int len;
+     int val;
 {
   if (!abfd->tdata.srec_data->done_symbol_read)
-  {
-    asymbol *p;
-    if (abfd->tdata.srec_data->symbols == 0)
     {
-      abfd->tdata.srec_data->symbols = (asymbol *)bfd_alloc(abfd, abfd->symcount * sizeof(asymbol));
-      abfd->tdata.srec_data->strings = (char*)bfd_alloc(abfd, abfd->tdata.srec_data->string_size);
-      abfd->tdata.srec_data->symbol_idx = 0;
-      abfd->tdata.srec_data->string_idx = 0;
-    }
+      asymbol *p;
+      if (abfd->tdata.srec_data->symbols == 0)
+       {
+         abfd->tdata.srec_data->symbols = (asymbol *) bfd_alloc (abfd, abfd->symcount * sizeof (asymbol));
+         abfd->tdata.srec_data->strings = (char *) bfd_alloc (abfd, abfd->tdata.srec_data->string_size);
+         if (!abfd->tdata.srec_data->symbols || !abfd->tdata.srec_data->strings)
+           {
+             bfd_error = no_memory;
+             abort ();         /* FIXME */
+           }
+         abfd->tdata.srec_data->symbol_idx = 0;
+         abfd->tdata.srec_data->string_idx = 0;
+       }
 
-    p = abfd->tdata.srec_data->symbols + abfd->tdata.srec_data->symbol_idx++;
-    p->the_bfd = abfd;
-    p->name = abfd->tdata.srec_data->strings + abfd->tdata.srec_data->string_idx;
-    memcpy((char *)(p->name), buf, len+1);
-    abfd->tdata.srec_data->string_idx += len + 1;
-    p->value = val;
-    p->flags = BSF_EXPORT | BSF_GLOBAL;
-    p->section = &bfd_abs_section;
-    p->udata = 0;
-  }
+      p = abfd->tdata.srec_data->symbols + abfd->tdata.srec_data->symbol_idx++;
+      p->the_bfd = abfd;
+      p->name = abfd->tdata.srec_data->strings + abfd->tdata.srec_data->string_idx;
+      memcpy ((char *) (p->name), buf, len + 1);
+      abfd->tdata.srec_data->string_idx += len + 1;
+      p->value = val;
+      p->flags = BSF_EXPORT | BSF_GLOBAL;
+      p->section = &bfd_abs_section;
+      p->udata = 0;
+    }
 }
+/*ARGSUSED*/
 static void
-DEFUN(size_srec,(abfd, section, address, raw, length),
-      bfd *abfd AND
-      asection *section AND
-      bfd_vma address AND
-      bfd_byte *raw AND
-      unsigned int length)
+DEFUN (size_srec, (abfd, section, address, raw, length),
+       bfd * abfd AND
+       asection * section AND
+       bfd_vma address AND
+       bfd_byte * raw AND
+       unsigned int length)
 {
   if (address < low)
     low = address;
-  if (address + length > high) 
-    high = address + length -1;
+  if (address + length > high)
+    high = address + length - 1;
 }
 
 
@@ -254,280 +262,298 @@ DEFUN(size_srec,(abfd, section, address, raw, length),
  called once per input S-Record, copies data from input into bfd_alloc'd area
  */
 
+/*ARGSUSED*/
 static void
-DEFUN(fillup,(abfd, section, address, raw, length),
-bfd *abfd AND
-asection *section AND
-bfd_vma address AND
-bfd_byte *raw AND
-unsigned int length)
-{
-    unsigned int i;
-    bfd_byte *dst =
-     (bfd_byte *)(section->used_by_bfd) + address - section->vma;
-    /* length -1 because we don't read in the checksum */
-    for (i = 0; i < length -1 ; i++) {
-           *dst = HEX(raw);
-           dst++;
-           raw+=2;
-       }
+DEFUN (fillup, (abfd, section, address, raw, length),
+       bfd * abfd AND
+       asection * section AND
+       bfd_vma address AND
+       bfd_byte * raw AND
+       unsigned int length)
+{
+  unsigned int i;
+  bfd_byte *dst =
+  (bfd_byte *) (section->used_by_bfd) + address - section->vma;
+  /* length -1 because we don't read in the checksum */
+  for (i = 0; i < length - 1; i++)
+    {
+      *dst = HEX (raw);
+      dst++;
+      raw += 2;
+    }
 }
 
 /* Pass over an S-Record file, calling one of the above functions on each
    record.  */
 
-static int white(x)
-char x;
+static int 
+white (x)
+     char x;
 {
-  return (x== ' ' || x == '\t' || x == '\n' || x == '\r');
+  return (x == ' ' || x == '\t' || x == '\n' || x == '\r');
 }
 static int
-skipwhite(src,abfd)
-char *src;
-bfd *abfd;
+skipwhite (src, abfd)
+     char *src;
+     bfd *abfd;
 {
   int eof = 0;
-  while (white(*src) && !eof)
-  {
-    eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);    
-  }
+  while (white (*src) && !eof)
+    {
+      eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+    }
   return eof;
 }
 
 static boolean
-DEFUN(srec_mkobject, (abfd), 
-      bfd *abfd)
+DEFUN (srec_mkobject, (abfd),
+       bfd * abfd)
 {
-  if (abfd->tdata.srec_data == 0) 
-  {
-    tdata_type *tdata = (tdata_type *)bfd_alloc(abfd,  sizeof(tdata_type));
-    abfd->tdata.srec_data = tdata;
-    tdata->type = 1;
-    tdata->head = (srec_data_list_type *)NULL;
-  }
+  if (abfd->tdata.srec_data == 0)
+    {
+      tdata_type *tdata = (tdata_type *) bfd_alloc (abfd, sizeof (tdata_type));
+      if (!tdata)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
+      abfd->tdata.srec_data = tdata;
+      tdata->type = 1;
+      tdata->head = (srec_data_list_type *) NULL;
+    }
   return true;
-    
+
 }
 
-static void pass_over(abfd, func, symbolfunc, section)
+static void 
+pass_over (abfd, func, symbolfunc, section)
      bfd *abfd;
-     void (*func)();
-     void (*symbolfunc)();
+     void (*func) ();
+     void (*symbolfunc) ();
      asection *section;
 {
   unsigned int bytes_on_line;
   boolean eof = false;
 
-  srec_mkobject(abfd);
+  srec_mkobject (abfd);
   /* To the front of the file */
-  bfd_seek(abfd, (file_ptr)0, SEEK_SET);
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
   while (eof == false)
-  {
-    char buffer[MAXCHUNK];
-    char *src = buffer;
-    char type;
-    bfd_vma address = 0;
-
-    /* Find first 'S' or $ */
-    eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
-    switch (*src) 
     {
-     default:
-      eof = (boolean)(bfd_read(src, 1, 1, abfd) != 1);
-      if (eof)  return;
-      break;
-
-     case '$':
-      /* Inside a symbol definition - just ignore the module name */
-      while (*src != '\n' && !eof) 
-      {
-       eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);         
-      }
-      break;
-
-     case ' ':
-      /* spaces - maybe just before a symbol */
-      while (*src != '\n' && *src != '\r' && white(*src)) 
+      char buffer[MAXCHUNK];
+      char *src = buffer;
+      char type;
+      bfd_vma address = 0;
+
+      /* Find first 'S' or $ */
+      eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+      switch (*src)
        {
-         eof = skipwhite(src, abfd);
-
-         {
-           int val = 0;
-           int slen = 0;
-           char symbol[MAXCHUNK];
-
-           /* get the symbol part */
-           while (!eof && !white(*src) && slen < MAXCHUNK)
-             {
-               symbol[slen++] = *src;
-               eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);         
-             }
-           symbol[slen] = 0;
-           eof = skipwhite(src, abfd);
-           /* skip the $ for the hex value */
-           if (*src == '$') 
-             {
-               eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
-             }
+       default:
+         eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+         if (eof)
+           return;
+         break;
+
+       case '$':
+         /* Inside a symbol definition - just ignore the module name */
+         while (*src != '\n' && !eof)
+           {
+             eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+           }
+         break;
+
+       case ' ':
+         /* spaces - maybe just before a symbol */
+         while (*src != '\n' && *src != '\r' && white (*src))
+           {
+             eof = skipwhite (src, abfd);
 
-           /* Scan off the hex number */
-           while (isxdigit(*src ))
              {
-               val *= 16;
-               if (isdigit(*src))
-                 val += *src - '0';
-               else if (isupper(*src)) {
-                 val += *src - 'A' + 10;
-               }
-               else {
-                 val += *src - 'a' + 10;
-               }
-               eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
+               int val = 0;
+               int slen = 0;
+               char symbol[MAXCHUNK];
+
+               /* get the symbol part */
+               while (!eof && !white (*src) && slen < MAXCHUNK)
+                 {
+                   symbol[slen++] = *src;
+                   eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+                 }
+               symbol[slen] = 0;
+               eof = skipwhite (src, abfd);
+               /* skip the $ for the hex value */
+               if (*src == '$')
+                 {
+                   eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+                 }
+
+               /* Scan off the hex number */
+               while (isxdigit (*src))
+                 {
+                   val *= 16;
+                   if (isdigit (*src))
+                     val += *src - '0';
+                   else if (isupper (*src))
+                     {
+                       val += *src - 'A' + 10;
+                     }
+                   else
+                     {
+                       val += *src - 'a' + 10;
+                     }
+                   eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+                 }
+               symbolfunc (abfd, symbol, slen, val);
              }
-           symbolfunc(abfd, symbol, slen, val);
-         }
+           }
+         break;
+       case 'S':
+         src++;
+
+         /* Fetch the type and the length */
+         bfd_read (src, 1, 3, abfd);
+
+         type = *src++;
+
+         if (!ISHEX (src[0]) || !ISHEX (src[1]))
+           break;
+
+         bytes_on_line = HEX (src);
+
+         if (bytes_on_line > MAXCHUNK / 2)
+           break;
+         src += 2;
+
+         bfd_read (src, 1, bytes_on_line * 2, abfd);
+
+         switch (type)
+           {
+           case '0':
+           case '5':
+             /* Prologue - ignore */
+             break;
+           case '3':
+             address = HEX (src);
+             src += 2;
+             bytes_on_line--;
+
+           case '2':
+             address = HEX (src) | (address << 8);
+             src += 2;
+             bytes_on_line--;
+           case '1':
+             address = HEX (src) | (address << 8);
+             src += 2;
+             address = HEX (src) | (address << 8);
+             src += 2;
+             bytes_on_line -= 2;
+             func (abfd, section, address, src, bytes_on_line);
+             break;
+           default:
+             return;
+           }
        }
-      break;
-     case 'S':
-      src++;
-
-      /* Fetch the type and the length */
-      bfd_read(src, 1, 3, abfd);
-
-      type = *src++;
-
-      if (!ISHEX (src[0]) || !ISHEX (src[1]))
-       break;
-
-      bytes_on_line = HEX(src);
-
-      if (bytes_on_line > MAXCHUNK/2)
-       break;
-      src+=2 ;
-
-      bfd_read(src, 1 , bytes_on_line * 2, abfd);
-
-      switch (type) {
-       case '0':
-       case '5':
-       /* Prologue - ignore */
-       break;
-       case '3':
-       address = HEX(src);
-       src+=2;
-       bytes_on_line--;
-               
-       case '2':
-       address = HEX(src) | (address<<8) ;
-       src+=2;
-       bytes_on_line--;
-       case '1':
-       address = HEX(src) | (address<<8) ;
-       src+=2;
-       address = HEX(src) | (address<<8) ;
-       src+=2;
-       bytes_on_line-=2;
-       func(abfd,section, address, src, bytes_on_line);
-       break;
-       default:
-       return;
-      }
     }
-  }
 
 }
 
 static bfd_target *
-object_p(abfd)
-bfd *abfd;
+object_p (abfd)
+     bfd *abfd;
 {
   asection *section;
-  /* We create one section called .text for all the contents, 
+  /* We create one section called .text for all the contents,
      and allocate enough room for the entire file.  */
-  
-  section =  bfd_make_section(abfd, ".text");
+
+  section = bfd_make_section (abfd, ".text");
   section->_raw_size = 0;
   section->vma = 0xffffffff;
   low = 0xffffffff;
   high = 0;
-  pass_over(abfd, size_srec, size_symbols, section);
+  pass_over (abfd, size_srec, size_symbols, section);
   section->_raw_size = high - low;
   section->vma = low;
   section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
 
   if (abfd->symcount)
-   abfd->flags |= HAS_SYMS;  
+    abfd->flags |= HAS_SYMS;
   return abfd->xvec;
 }
 
 static bfd_target *
-DEFUN(srec_object_p, (abfd),
-      bfd *abfd)
+DEFUN (srec_object_p, (abfd),
+       bfd * abfd)
 {
   char b[4];
 
-  srec_init();
-  
-  bfd_seek(abfd, (file_ptr)0, SEEK_SET);
-  bfd_read(b, 1, 4, abfd);
+  srec_init ();
 
-  if (b[0] != 'S' || !ISHEX(b[1]) || !ISHEX(b[2]) || !ISHEX(b[3]))
-   return (bfd_target*) NULL;
-  
-  /* We create one section called .text for all the contents, 
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
+  bfd_read (b, 1, 4, abfd);
+
+  if (b[0] != 'S' || !ISHEX (b[1]) || !ISHEX (b[2]) || !ISHEX (b[3]))
+    return (bfd_target *) NULL;
+
+  /* We create one section called .text for all the contents,
      and allocate enough room for the entire file.  */
 
-  return object_p(abfd); 
+  return object_p (abfd);
 }
 
 
 static bfd_target *
-DEFUN(symbolsrec_object_p, (abfd),
-      bfd *abfd)
+DEFUN (symbolsrec_object_p, (abfd),
+       bfd * abfd)
 {
   char b[4];
 
-  srec_init();
-  
-  bfd_seek(abfd, (file_ptr)0, SEEK_SET);
-  bfd_read(b, 1, 4, abfd);
+  srec_init ();
+
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
+  bfd_read (b, 1, 4, abfd);
 
   if (b[0] != '$' || b[1] != '$')
-    return (bfd_target*) NULL;
+    return (bfd_target *) NULL;
 
-  return object_p(abfd);   
+  return object_p (abfd);
 }
 
 
 static boolean
-DEFUN(srec_get_section_contents,(abfd, section, location, offset, count),
-      bfd *abfd AND
-      asection *section AND
-      PTR location AND
-      file_ptr offset AND
-      bfd_size_type count)
-{
-    if (section->used_by_bfd == (PTR)NULL) 
+DEFUN (srec_get_section_contents, (abfd, section, location, offset, count),
+       bfd * abfd AND
+       asection * section AND
+       PTR location AND
+       file_ptr offset AND
+       bfd_size_type count)
+{
+  if (section->used_by_bfd == (PTR) NULL)
     {
-       section->used_by_bfd = (PTR)bfd_alloc (abfd, section->_raw_size);
-       
-       pass_over(abfd, fillup, fillup_symbols, section);
+      section->used_by_bfd = (PTR) bfd_alloc (abfd, section->_raw_size);
+      if (!section->used_by_bfd)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
+
+      pass_over (abfd, fillup, fillup_symbols, section);
     }
-    (void) memcpy((PTR)location,
-                 (PTR)((char *)(section->used_by_bfd) + offset),
-                 count);
-    return true;
+  memcpy ((PTR) location,
+                (PTR) ((char *) (section->used_by_bfd) + offset),
+                count);
+  return true;
 }
-      
+
 
 
 boolean
-DEFUN(srec_set_arch_mach,(abfd, arch, machine),
-      bfd *abfd AND
-      enum bfd_architecture arch AND
-      unsigned long machine)
+DEFUN (srec_set_arch_mach, (abfd, arch, machine),
+       bfd * abfd AND
+       enum bfd_architecture arch AND
+       unsigned long machine)
 {
-  return bfd_default_set_arch_mach(abfd, arch, machine);
+  return bfd_default_set_arch_mach (abfd, arch, machine);
 }
 
 
@@ -535,33 +561,44 @@ DEFUN(srec_set_arch_mach,(abfd, arch, machine),
    also remember   */
 
 static boolean
-DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do),
-      bfd *abfd AND
-      sec_ptr section AND
-      PTR location AND
-      file_ptr offset AND
-      bfd_size_type bytes_to_do)
-{
-  tdata_type  *tdata = abfd->tdata.srec_data;
+DEFUN (srec_set_section_contents, (abfd, section, location, offset, bytes_to_do),
+       bfd * abfd AND
+       sec_ptr section AND
+       PTR location AND
+       file_ptr offset AND
+       bfd_size_type bytes_to_do)
+{
+  tdata_type *tdata = abfd->tdata.srec_data;
   srec_data_list_type *entry = (srec_data_list_type *)
-    bfd_alloc(abfd, sizeof(srec_data_list_type));
+    bfd_alloc (abfd, sizeof (srec_data_list_type));
+
+  if (!entry)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   if ((section->flags & SEC_ALLOC)
-      && (section->flags & SEC_LOAD)) 
+      && (section->flags & SEC_LOAD))
     {
-      unsigned  char *data = (unsigned char *) bfd_alloc(abfd, bytes_to_do);
-      memcpy(data, location, bytes_to_do);
+      unsigned char *data = (unsigned char *) bfd_alloc (abfd, bytes_to_do);
+      if (!data)
+       {
+         bfd_error = no_memory;
+         return false;
+       }
+      memcpy (data, location, bytes_to_do);
 
-      if ((section->lma + offset + bytes_to_do) <= 0xffff)  
+      if ((section->lma + offset + bytes_to_do) <= 0xffff)
        {
 
        }
-      else if ((section->lma + offset + bytes_to_do) <= 0xffffff 
-              && tdata->type < 2) 
+      else if ((section->lma + offset + bytes_to_do) <= 0xffffff
+              && tdata->type < 2)
        {
          tdata->type = 2;
        }
-      else 
+      else
        {
          tdata->type = 3;
        }
@@ -572,7 +609,7 @@ DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do),
       entry->next = tdata->head;
       tdata->head = entry;
     }
-  return true;    
+  return true;
 }
 
 /* Write a record of type, of the supplied number of bytes. The
@@ -580,303 +617,305 @@ DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do),
    here
 */
 static
-void DEFUN(srec_write_record,(abfd, type, address, data, end),
-          bfd *abfd AND
-          char type AND
-          bfd_vma address AND
-          CONST unsigned char *data AND
-          CONST unsigned char *end)
-
-{
-    char buffer[MAXCHUNK];
-    
-    unsigned int check_sum = 0;
-    unsigned CONST char *src = data;
-    char *dst =buffer;
-    char *length;
-    
-
-    *dst++ = 'S';
-    *dst++ = '0' + type;
-
-    length = dst;
-    dst+=2;                    /* leave room for dst*/
-    
-    switch (type) 
+void 
+DEFUN (srec_write_record, (abfd, type, address, data, end),
+       bfd * abfd AND
+       char type AND
+       bfd_vma address AND
+       CONST unsigned char *data AND
+       CONST unsigned char *end)
+
+{
+  char buffer[MAXCHUNK];
+
+  unsigned int check_sum = 0;
+  CONST unsigned char *src = data;
+  char *dst = buffer;
+  char *length;
+
+
+  *dst++ = 'S';
+  *dst++ = '0' + type;
+
+  length = dst;
+  dst += 2;                    /* leave room for dst*/
+
+  switch (type)
     {
-      case 3:
-      case 7:
-       TOHEX(dst, (address >> 24), check_sum);
-       dst+=2;
-      case 8:
-      case 2:
-       TOHEX(dst, (address >> 16), check_sum);
-       dst+=2;
-      case 9:
-      case 1:
-      case 0:
-       TOHEX(dst, (address >> 8), check_sum);
-       dst+=2;
-       TOHEX(dst, (address), check_sum);
-       dst+=2;
-       break;
+    case 3:
+    case 7:
+      TOHEX (dst, (address >> 24), check_sum);
+      dst += 2;
+    case 8:
+    case 2:
+      TOHEX (dst, (address >> 16), check_sum);
+      dst += 2;
+    case 9:
+    case 1:
+    case 0:
+      TOHEX (dst, (address >> 8), check_sum);
+      dst += 2;
+      TOHEX (dst, (address), check_sum);
+      dst += 2;
+      break;
 
     }
-    for (src = data; src < end; src++) 
+  for (src = data; src < end; src++)
     {
-       TOHEX(dst, *src, check_sum);
-       dst+=2;
+      TOHEX (dst, *src, check_sum);
+      dst += 2;
     }
 
-    /* Fill in the length */
-    TOHEX(length, (dst - length)/2, check_sum);
-    check_sum &= 0xff;
-    check_sum = 255 - check_sum;
-    TOHEX(dst, check_sum, check_sum);
-    dst+=2;
-    
-    *dst ++ = '\r';
-    *dst ++ = '\n';
-    bfd_write((PTR)buffer, 1, dst - buffer , abfd);
+  /* Fill in the length */
+  TOHEX (length, (dst - length) / 2, check_sum);
+  check_sum &= 0xff;
+  check_sum = 255 - check_sum;
+  TOHEX (dst, check_sum, check_sum);
+  dst += 2;
+
+  *dst++ = '\r';
+  *dst++ = '\n';
+  bfd_write ((PTR) buffer, 1, dst - buffer, abfd);
 }
 
 
 
 static void
-DEFUN(srec_write_header,(abfd),
-      bfd *abfd)
+DEFUN (srec_write_header, (abfd),
+       bfd * abfd)
 {
-    unsigned char buffer[MAXCHUNK];
-    unsigned char *dst = buffer;
-    unsigned int i;
+  unsigned char buffer[MAXCHUNK];
+  unsigned char *dst = buffer;
+  unsigned int i;
 
-    /* I'll put an arbitary 40 char limit on header size */
-    for (i = 0; i < 40 && abfd->filename[i];  i++) 
+  /* I'll put an arbitary 40 char limit on header size */
+  for (i = 0; i < 40 && abfd->filename[i]; i++)
     {
-       *dst++ = abfd->filename[i];
+      *dst++ = abfd->filename[i];
     }
-    srec_write_record(abfd,0, 0, buffer, dst);
+  srec_write_record (abfd, 0, 0, buffer, dst);
 }
 
 static void
-DEFUN(srec_write_section,(abfd, tdata, list),
-       bfd *abfd AND
-       tdata_type *tdata AND
-       srec_data_list_type *list)
+DEFUN (srec_write_section, (abfd, tdata, list),
+       bfd * abfd AND
+       tdata_type * tdata AND
+       srec_data_list_type * list)
 {
-    unsigned int bytes_written = 0;
-    unsigned char *location = list->data;
+  unsigned int bytes_written = 0;
+  unsigned char *location = list->data;
 
-    while (bytes_written < list->size)
+  while (bytes_written < list->size)
     {
-       bfd_vma address;
-       
-       unsigned int bytes_this_chunk = list->size - bytes_written;
+      bfd_vma address;
+
+      unsigned int bytes_this_chunk = list->size - bytes_written;
 
-       if (bytes_this_chunk > CHUNK) 
+      if (bytes_this_chunk > CHUNK)
        {
-           bytes_this_chunk = CHUNK;
+         bytes_this_chunk = CHUNK;
        }
 
-       address = list->where +  bytes_written;
+      address = list->where + bytes_written;
 
-       srec_write_record(abfd,
-                         tdata->type,
-                         address,
-                         location,
-                         location + bytes_this_chunk);
+      srec_write_record (abfd,
+                        tdata->type,
+                        address,
+                        location,
+                        location + bytes_this_chunk);
 
-       bytes_written += bytes_this_chunk;
-       location += bytes_this_chunk;
+      bytes_written += bytes_this_chunk;
+      location += bytes_this_chunk;
     }
 
 }
 
 static void
-DEFUN(srec_write_terminator,(abfd, tdata),
-      bfd *abfd AND
-      tdata_type *tdata)
-{
-    unsigned    char buffer[2];
-    
-    srec_write_record(abfd, 10 - tdata->type,
-                     abfd->start_address, buffer, buffer);
+DEFUN (srec_write_terminator, (abfd, tdata),
+       bfd * abfd AND
+       tdata_type * tdata)
+{
+  unsigned char buffer[2];
+
+  srec_write_record (abfd, 10 - tdata->type,
+                    abfd->start_address, buffer, buffer);
 }
 
 
-      
+
 static void
-srec_write_symbols(abfd)
+srec_write_symbols (abfd)
      bfd *abfd;
 {
   char buffer[MAXCHUNK];
   /* Dump out the symbols of a bfd */
   int i;
-  int len = bfd_get_symcount(abfd);
+  int len = bfd_get_symcount (abfd);
 
-  if (len) 
-  {
-    asymbol **table = bfd_get_outsymbols(abfd);
-    sprintf(buffer, "$$ %s\r\n", abfd->filename);
+  if (len)
+    {
+      asymbol **table = bfd_get_outsymbols (abfd);
+      sprintf (buffer, "$$ %s\r\n", abfd->filename);
 
-    bfd_write(buffer, strlen(buffer), 1, abfd);
+      bfd_write (buffer, strlen (buffer), 1, abfd);
 
-    for (i = 0; i < len; i++) 
-    {
-      asymbol *s = table[i];
+      for (i = 0; i < len; i++)
+       {
+         asymbol *s = table[i];
 #if 0
-      int len = strlen(s->name);
+         int len = strlen (s->name);
 
-      /* If this symbol has a .[ocs] in it, it's probably a file name
+         /* If this symbol has a .[ocs] in it, it's probably a file name
         and we'll output that as the module name */
 
-      if (len > 3 && s->name[len-2] == '.') 
-      {
-       int l;
-       sprintf(buffer, "$$ %s\r\n", s->name);
-       l = strlen(buffer);
-       bfd_write(buffer, l, 1, abfd);
-      }
-      else
+         if (len > 3 && s->name[len - 2] == '.')
+           {
+             int l;
+             sprintf (buffer, "$$ %s\r\n", s->name);
+             l = strlen (buffer);
+             bfd_write (buffer, l, 1, abfd);
+           }
+         else
 #endif
-       if (s->flags & (BSF_GLOBAL | BSF_LOCAL) 
-              && (s->flags & BSF_DEBUGGING) == 0
-              && s->name[0] != '.'
-              && s->name[0] != 't')
-      {
-       /* Just dump out non debug symbols */
-
-       int l;
-       char buf2[40], *p;
-
-       sprintf_vma (buf2,
-                    s->value + s->section->output_section->lma 
-                    + s->section->output_offset);
-       p = buf2;
-       while (p[0] == '0' && p[1] != 0)
-         p++;
-       sprintf (buffer, "  %s $%s\r\n", s->name, p);
-       l = strlen(buffer);
-       bfd_write(buffer, l, 1,abfd);
-      }
+           if (s->flags & (BSF_GLOBAL | BSF_LOCAL)
+               && (s->flags & BSF_DEBUGGING) == 0
+               && s->name[0] != '.'
+               && s->name[0] != 't')
+           {
+             /* Just dump out non debug symbols */
+
+             int l;
+             char buf2[40], *p;
+
+             sprintf_vma (buf2,
+                          s->value + s->section->output_section->lma
+                          + s->section->output_offset);
+             p = buf2;
+             while (p[0] == '0' && p[1] != 0)
+               p++;
+             sprintf (buffer, "  %s $%s\r\n", s->name, p);
+             l = strlen (buffer);
+             bfd_write (buffer, l, 1, abfd);
+           }
+       }
+      sprintf (buffer, "$$ \r\n");
+      bfd_write (buffer, strlen (buffer), 1, abfd);
     }
-    sprintf(buffer, "$$ \r\n");
-    bfd_write(buffer, strlen(buffer), 1, abfd);
-  }
 }
 
 static boolean
-internal_srec_write_object_contents(abfd, symbols)
+internal_srec_write_object_contents (abfd, symbols)
      bfd *abfd;
      int symbols;
 {
-    int bytes_written;
-    tdata_type *tdata = abfd->tdata.srec_data;
-    srec_data_list_type *list;
+  tdata_type *tdata = abfd->tdata.srec_data;
+  srec_data_list_type *list;
 
-    bytes_written = 0;
-    
-    
-    if (symbols)
-     srec_write_symbols(abfd);
+  if (symbols)
+    srec_write_symbols (abfd);
 
-    srec_write_header(abfd);
+  srec_write_header (abfd);
 
-    /* Now wander though all the sections provided and output them */
-    list = tdata->head;
+  /* Now wander though all the sections provided and output them */
+  list = tdata->head;
 
-    while (list != (srec_data_list_type*)NULL) 
+  while (list != (srec_data_list_type *) NULL)
     {
-       srec_write_section(abfd, tdata, list); 
-       list = list->next;
+      srec_write_section (abfd, tdata, list);
+      list = list->next;
     }
-    srec_write_terminator(abfd, tdata);
-    return true;
+  srec_write_terminator (abfd, tdata);
+  return true;
 }
 
 static boolean
-srec_write_object_contents(abfd)
+srec_write_object_contents (abfd)
      bfd *abfd;
 {
-  return internal_srec_write_object_contents(abfd, 0);
+  return internal_srec_write_object_contents (abfd, 0);
 }
 
 static boolean
-symbolsrec_write_object_contents(abfd)
+symbolsrec_write_object_contents (abfd)
      bfd *abfd;
 {
-  return internal_srec_write_object_contents(abfd, 1);
+  return internal_srec_write_object_contents (abfd, 1);
 }
 
-static int 
-DEFUN(srec_sizeof_headers,(abfd, exec),
-      bfd *abfd AND
-      boolean exec)
+/*ARGSUSED*/
+static int
+DEFUN (srec_sizeof_headers, (abfd, exec),
+       bfd * abfd AND
+       boolean exec)
 {
-return 0;
+  return 0;
 }
 
 static asymbol *
-DEFUN(srec_make_empty_symbol, (abfd),
-      bfd*abfd)
+DEFUN (srec_make_empty_symbol, (abfd),
+       bfd * abfd)
 {
-  asymbol *new=  (asymbol *)bfd_zalloc (abfd, sizeof (asymbol));
-  new->the_bfd = abfd;
+  asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
+  if (new)
+    new->the_bfd = abfd;
   return new;
 }
 
 static unsigned int
-srec_get_symtab_upper_bound(abfd)
-bfd *abfd;
+srec_get_symtab_upper_bound (abfd)
+     bfd *abfd;
 {
   /* Read in all the info */
-  srec_get_section_contents(abfd,abfd->sections,0,0,0);
-  return (bfd_get_symcount(abfd) + 1) * (sizeof(asymbol *));
+  srec_get_section_contents (abfd, abfd->sections, 0, 0, 0);
+  return (bfd_get_symcount (abfd) + 1) * (sizeof (asymbol *));
 }
 
 static unsigned int
-DEFUN(srec_get_symtab, (abfd, alocation),
-      bfd            *abfd AND
-      asymbol       **alocation)
+DEFUN (srec_get_symtab, (abfd, alocation),
+       bfd * abfd AND
+       asymbol ** alocation)
 {
   int lim = abfd->symcount;
   int i;
-  for (i = 0; i < lim; i++) {
-    alocation[i] = abfd->tdata.srec_data->symbols + i;
-  }
+  for (i = 0; i < lim; i++)
+    {
+      alocation[i] = abfd->tdata.srec_data->symbols + i;
+    }
   alocation[i] = 0;
   return lim;
 }
 
-void 
-DEFUN(srec_get_symbol_info,(ignore_abfd, symbol, ret),
-      bfd *ignore_abfd AND
-      asymbol *symbol AND
-      symbol_info *ret)
+/*ARGSUSED*/
+void
+DEFUN (srec_get_symbol_info, (ignore_abfd, symbol, ret),
+       bfd * ignore_abfd AND
+       asymbol * symbol AND
+       symbol_info * ret)
 {
   bfd_symbol_info (symbol, ret);
 }
 
-void 
-DEFUN(srec_print_symbol,(ignore_abfd, afile, symbol, how),
-      bfd *ignore_abfd AND
-      PTR afile AND
-      asymbol *symbol AND
-      bfd_print_symbol_type how)
-{
-  FILE *file = (FILE *)afile;
-  switch (how) 
-  {
-   case bfd_print_symbol_name:
-    fprintf (file, "%s", symbol->name);
-    break;
-   default:
-    bfd_print_symbol_vandf ((PTR) file, symbol);
-    fprintf (file, " %-5s %s",
-            symbol->section->name,
-            symbol->name);
+/*ARGSUSED*/
+void
+DEFUN (srec_print_symbol, (ignore_abfd, afile, symbol, how),
+       bfd * ignore_abfd AND
+       PTR afile AND
+       asymbol * symbol AND
+       bfd_print_symbol_type how)
+{
+  FILE *file = (FILE *) afile;
+  switch (how)
+    {
+    case bfd_print_symbol_name:
+      fprintf (file, "%s", symbol->name);
+      break;
+    default:
+      bfd_print_symbol_vandf ((PTR) file, symbol);
+      fprintf (file, " %-5s %s",
+              symbol->section->name,
+              symbol->name);
 
-  }
+    }
 }
 
 #define FOO PROTO
@@ -916,90 +955,89 @@ DEFUN(srec_print_symbol,(ignore_abfd, afile, symbol, how),
 
 bfd_target srec_vec =
 {
-    "srec",                    /* name */
-    bfd_target_srec_flavour,
-    true,                      /* target byte order */
-    true,                      /* target headers byte order */
-    (HAS_RELOC | EXEC_P |      /* object flags */
-     HAS_LINENO | HAS_DEBUG |
-     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
-    (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
-     |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
-     0,                                /* leading underscore */
-    ' ',                       /* ar_pad_char */
-    16,                                /* ar_max_namelen */
-    1,                         /* minimum alignment */
-    bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-      bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
-      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
-    bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-      bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
-      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
+  "srec",                      /* name */
+  bfd_target_srec_flavour,
+  true,                                /* target byte order */
+  true,                                /* target headers byte order */
+  (HAS_RELOC | EXEC_P |                /* object flags */
+   HAS_LINENO | HAS_DEBUG |
+   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
+  (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
+   | SEC_ALLOC | SEC_LOAD | SEC_RELOC),        /* section flags */
+  0,                           /* leading underscore */
+  ' ',                         /* ar_pad_char */
+  16,                          /* ar_max_namelen */
+  1,                           /* minimum alignment */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* data */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* hdrs */
 
   {
-      _bfd_dummy_target,
-      srec_object_p,           /* bfd_check_format */
-      (struct bfd_target *(*)()) bfd_nullvoidptr,
-      (struct bfd_target *(*)())     bfd_nullvoidptr,
+    _bfd_dummy_target,
+    srec_object_p,             /* bfd_check_format */
+    (struct bfd_target * (*)()) bfd_nullvoidptr,
+    (struct bfd_target * (*)()) bfd_nullvoidptr,
   },
   {
-      bfd_false,
-      srec_mkobject,
-      _bfd_generic_mkarchive,
-      bfd_false,
+    bfd_false,
+    srec_mkobject,
+    _bfd_generic_mkarchive,
+    bfd_false,
   },
   {                            /* bfd_write_contents */
-      bfd_false,
-      srec_write_object_contents,
-      _bfd_write_archive_contents,
-      bfd_false,
+    bfd_false,
+    srec_write_object_contents,
+    _bfd_write_archive_contents,
+    bfd_false,
   },
-    JUMP_TABLE(srec)
- };
+  JUMP_TABLE (srec)
+};
 
 
 
 bfd_target symbolsrec_vec =
 {
-    "symbolsrec",              /* name */
-    bfd_target_srec_flavour,
-    true,                      /* target byte order */
-    true,                      /* target headers byte order */
-    (HAS_RELOC | EXEC_P |      /* object flags */
-     HAS_LINENO | HAS_DEBUG |
-     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
-    (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
-     |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
-     0,                                /* leading underscore */
-    ' ',                       /* ar_pad_char */
-    16,                                /* ar_max_namelen */
-    1,                         /* minimum alignment */
-    bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-      bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
-      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
-    bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-      bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
-      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
+  "symbolsrec",                        /* name */
+  bfd_target_srec_flavour,
+  true,                                /* target byte order */
+  true,                                /* target headers byte order */
+  (HAS_RELOC | EXEC_P |                /* object flags */
+   HAS_LINENO | HAS_DEBUG |
+   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
+  (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
+   | SEC_ALLOC | SEC_LOAD | SEC_RELOC),        /* section flags */
+  0,                           /* leading underscore */
+  ' ',                         /* ar_pad_char */
+  16,                          /* ar_max_namelen */
+  1,                           /* minimum alignment */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* data */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* hdrs */
 
   {
-      _bfd_dummy_target,
-      symbolsrec_object_p,             /* bfd_check_format */
-      (struct bfd_target *(*)()) bfd_nullvoidptr,
-      (struct bfd_target *(*)())     bfd_nullvoidptr,
+    _bfd_dummy_target,
+    symbolsrec_object_p,       /* bfd_check_format */
+    (struct bfd_target * (*)()) bfd_nullvoidptr,
+    (struct bfd_target * (*)()) bfd_nullvoidptr,
   },
   {
-      bfd_false,
-      srec_mkobject,
-      _bfd_generic_mkarchive,
-      bfd_false,
+    bfd_false,
+    srec_mkobject,
+    _bfd_generic_mkarchive,
+    bfd_false,
   },
   {                            /* bfd_write_contents */
-      bfd_false,
-      symbolsrec_write_object_contents,
-      _bfd_write_archive_contents,
-      bfd_false,
+    bfd_false,
+    symbolsrec_write_object_contents,
+    _bfd_write_archive_contents,
+    bfd_false,
   },
-    JUMP_TABLE(srec),
-    (PTR) 0
- };
-
+  JUMP_TABLE (srec),
+  (PTR) 0
+};
index 7f62a33ad860ae91f72901e4d89c3af79c3a3bc5..59ea75741b4c26d89e0a8a8ae7d795b50ad2d139 100644 (file)
@@ -85,6 +85,11 @@ sunos_read_dynamic_info (abfd)
 
   info = ((struct sunos_dynamic_info *)
          bfd_zalloc (abfd, sizeof (struct sunos_dynamic_info)));
+  if (!info)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   info->valid = false;
   info->dynsym = NULL;
   info->dynstr = NULL;
@@ -203,6 +208,11 @@ MY(read_dynamic_symbols) (abfd, syms, strs, strsize)
                                 (info->dynsym_count
                                  * EXTERNAL_NLIST_SIZE)));
       info->dynstr = (char *) bfd_alloc (abfd, info->dyninfo.ld_symb_size);
+      if (!info->dynsym || !info->dynstr)
+       {
+         bfd_error = no_memory;
+         return 0;
+       }
       if (bfd_seek (abfd, info->dyninfo.ld_stab, SEEK_SET) != 0
          || (bfd_read ((PTR) info->dynsym, info->dynsym_count,
                        EXTERNAL_NLIST_SIZE, abfd)
@@ -277,11 +287,16 @@ MY(read_dynamic_relocs) (abfd, relocs)
   if (! info->valid || info->dynrel_count == 0)
     return 0;
 
-  if (info->dynrel == (struct external_nlist *) NULL)
+  if (info->dynrel == NULL)
     {
       info->dynrel = (PTR) bfd_alloc (abfd,
                                      (info->dynrel_count
                                       * obj_reloc_entry_size (abfd)));
+      if (!info->dynrel)
+       {
+         bfd_error = no_memory;
+         return (bfd_size_type) -1;
+       }
       if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0
          || (bfd_read ((PTR) info->dynrel, info->dynrel_count,
                        obj_reloc_entry_size (abfd), abfd)
index 5c3d4707b2161b6cff674d8e428e130cabd419a1..9f2a50f6647ef2a87876ff30c6c745d3f2e8a59f 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD backend for Extended Tektronix Hex Format  objects.
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993 Free Software Foundation, Inc.
 
    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
 
@@ -32,7 +32,7 @@ DESCRIPTION
        It seems that the sections are descibed as being really big,
         the example I have says that the text section is 0..ffffffff.
        BFD would barf with this, many apps would try to alloc 4GB to
-       read in the file. 
+       read in the file.
 
        Tex Hex may contain many sections, but the data which comes in
        has no tag saying which section it belongs to, so we create
@@ -42,7 +42,7 @@ DESCRIPTION
        TekHex may come out of  order and there is no header, so an
        initial scan is required  to discover the minimum and maximum
        addresses used to create the vma and size of the sections we
-       create.  
+       create.
        We read in the data into pages of CHUNK_MASK+1 size and read
        them out from that whenever we need to.
 
@@ -73,26 +73,30 @@ serial protocol, so big files are unlikely, so we keep a list of 8k chunks
 #include "sysdep.h"
 #include "libbfd.h"
 
-typedef struct {
-bfd_vma low;
-bfd_vma high;
-} addr_range_type;
+typedef struct
+  {
+    bfd_vma low;
+    bfd_vma high;
+  } addr_range_type;
 
-typedef struct tekhex_symbol_struct {
+typedef struct tekhex_symbol_struct
+  {
 
-  asymbol symbol;
-struct  tekhex_symbol_struct *prev;
+    asymbol symbol;
+    struct tekhex_symbol_struct *prev;
 
-} tekhex_symbol_type;
+  } tekhex_symbol_type;
 
 static char digs[] = "0123456789ABCDEF";
 
 static char sum_block[256];
+
 /* Horrible ascii dependent macros for converting between hex and
    binary */
 
 #define CHARS_IN_SET 256
 static char hex_value[CHARS_IN_SET];
+
 #define NOT_HEX 20
 #define NIBBLE(x) hex_value[x]
 #define HEX(buffer) ((NIBBLE((buffer)[0])<<4) + NIBBLE((buffer)[1]))
@@ -146,7 +150,7 @@ explanation:
 %2832F9T_SEGMENT83i$18FFFFFFFC81$1481$214
 %0781010
 
-Turns into 
+Turns into
 sac@thepub$ ./objdump -dx -m m68k f
 
 f:     file format tekhex
@@ -157,9 +161,9 @@ start address 0x00000000
 SECTION 0 [D00000000]  : size 00020000 vma 00000000 align 2**0
  ALLOC, LOAD
 SECTION 1 [D00008000]  : size 00002001 vma 00008000 align 2**0
+
 SECTION 2 [T_SEGMENT]  : size ffffffff vma 00000000 align 2**0
+
 SYMBOL TABLE:
 00000000  g       T_SEGMENT gcc_compiled$
 00000000  g       T_SEGMENT hello$c
@@ -211,51 +215,54 @@ Disassembly of section D00000000:
 */
 
 static void
-DEFUN_VOID(tekhex_init) 
+tekhex_init ()
 {
   unsigned int i;
   static boolean inited = false;
-  int val;    
-  if (inited == false) 
+  int val;
+
+  if (inited == false)
     {
-       
+
       inited = true;
-       
-      for (i = 0; i < CHARS_IN_SET; i++) 
+
+      for (i = 0; i < CHARS_IN_SET; i++)
        {
          hex_value[i] = NOT_HEX;
        }
-    
-      for (i = 0; i < 10; i++) 
+
+      for (i = 0; i < 10; i++)
        {
          hex_value[i + '0'] = i;
-       
+
        }
-      for (i = 0; i < 6; i++) 
+      for (i = 0; i < 6; i++)
        {
-         hex_value[i + 'a'] = i+10;
-         hex_value[i + 'A'] = i+10;
+         hex_value[i + 'a'] = i + 10;
+         hex_value[i + 'A'] = i + 10;
        }
       val = 0;
-      for (i = 0; i < 10; i++) {
-       sum_block[i + '0'] = val++;
-      }
-      for (i = 'A'; i <= 'Z'; i++) {
-       sum_block[i] = val++;
-      }
+      for (i = 0; i < 10; i++)
+       {
+         sum_block[i + '0'] = val++;
+       }
+      for (i = 'A'; i <= 'Z'; i++)
+       {
+         sum_block[i] = val++;
+       }
       sum_block['$'] = val++;
       sum_block['%'] = val++;
       sum_block['.'] = val++;
       sum_block['_'] = val++;
-      for (i = 'a'; i <= 'z'; i++) {
-       sum_block[i] = val++;
-      }
-    }    
+      for (i = 'a'; i <= 'z'; i++)
+       {
+         sum_block[i] = val++;
+       }
+    }
 }
 
-
 /* The maximum number of bytes on a line is FF */
-#define MAXCHUNK 0xff 
+#define MAXCHUNK 0xff
 /* The number of bytes we fit onto a line on output */
 #define CHUNK 21
 
@@ -264,62 +271,63 @@ DEFUN_VOID(tekhex_init)
 
 struct tekhex_data_list_struct
 {
-    unsigned    char *data;
-    bfd_vma where;
-    bfd_size_type size;
-    struct tekhex_data_list_struct *next;
-    
-} ;
-typedef struct tekhex_data_list_struct tekhex_data_list_type;
-
+  unsigned char *data;
+  bfd_vma where;
+  bfd_size_type size;
+  struct tekhex_data_list_struct *next;
 
+};
+typedef struct tekhex_data_list_struct tekhex_data_list_type;
 
 #define CHUNK_MASK 0x1fff
 
-struct data_struct {
-  char chunk_data[CHUNK_MASK+1];
-  char chunk_init[CHUNK_MASK+1];
-  bfd_vma vma;
-  struct data_struct *next;
-} ;
+struct data_struct
+  {
+    char chunk_data[CHUNK_MASK + 1];
+    char chunk_init[CHUNK_MASK + 1];
+    bfd_vma vma;
+    struct data_struct *next;
+  };
 
 typedef struct tekhex_data_struct
 {
-    tekhex_data_list_type *head;    
-    unsigned int type;
-    struct tekhex_symbol_struct *symbols;
-    struct data_struct *data;
+  tekhex_data_list_type *head;
+  unsigned int type;
+  struct tekhex_symbol_struct *symbols;
+  struct data_struct *data;
 } tdata_type;
 
-
-
 #define enda(x) (x->vma + x->size)
 
-
-static bfd_vma 
-DEFUN(getvalue,(srcp),
-      char **srcp)
+static bfd_vma
+getvalue (srcp)
+     char **srcp;
 {
   char *src = *srcp;
   bfd_vma value = 0;
   unsigned int len = hex_value[*src++];
-  if (len == 0) len=16;
-  while (len --) {
-    value = value << 4 | hex_value[*src++];
-  }
+
+  if (len == 0)
+    len = 16;
+  while (len--)
+    {
+      value = value << 4 | hex_value[*src++];
+    }
   *srcp = src;
   return value;
 }
 
-static unsigned int 
-DEFUN(getsym,(dstp,srcp),
-      char *dstp AND
-      char **srcp)
+static unsigned int
+getsym (dstp, srcp)
+     char *dstp;
+     char **srcp;
 {
   char *src = *srcp;
   unsigned int i;
   unsigned int len = hex_value[*src++];
-  if (len == 0) len=16;
+
+  if (len == 0)
+    len = 16;
   for (i = 0; i < len; i++)
     dstp[i] = src[i];
   dstp[i] = 0;
@@ -328,136 +336,168 @@ DEFUN(getsym,(dstp,srcp),
 }
 
 struct data_struct *
-DEFUN(find_chunk,(abfd, vma),
-      bfd *abfd  AND
-      bfd_vma vma)
+find_chunk (abfd, vma)
+     bfd *abfd;
+     bfd_vma vma;
 {
   struct data_struct *d = abfd->tdata.tekhex_data->data;
+
   vma &= ~CHUNK_MASK;
   while (d && (d->vma) != vma)
     {
       d = d->next;
     }
-  if (!d) {
-    char *sname = bfd_alloc(abfd, 12);
-    asection *s;
-
-    /* No chunk for this address, so make one up */
-    d =(struct data_struct *)
-      bfd_alloc(abfd, sizeof(struct data_struct));
-    memset(d->chunk_init, 0, CHUNK_MASK+1);
-    memset(d->chunk_data, 0, CHUNK_MASK+1);
-    d->next = abfd->tdata.tekhex_data->data ;
-    d->vma = vma;
-    abfd->tdata.tekhex_data->data = d;
-  }
+  if (!d)
+    {
+      char *sname = bfd_alloc (abfd, 12);
+      asection *s;
+
+      /* No chunk for this address, so make one up */
+      d = (struct data_struct *)
+       bfd_alloc (abfd, sizeof (struct data_struct));
+
+      if (!sname || !d)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
+
+      memset (d->chunk_init, 0, CHUNK_MASK + 1);
+      memset (d->chunk_data, 0, CHUNK_MASK + 1);
+      d->next = abfd->tdata.tekhex_data->data;
+      d->vma = vma;
+      abfd->tdata.tekhex_data->data = d;
+    }
   return d;
 }
 
-DEFUN(insert_byte,(abfd, value, addr),
-      bfd *abfd AND
-      int value AND
-      bfd_vma addr)
+static void
+insert_byte (abfd, value, addr)
+     bfd *abfd;
+     int value;
+     bfd_vma addr;
 {
   /* Find the chunk that this byte needs and put it in */
-  struct data_struct *d = find_chunk(abfd, addr);
-  d->chunk_data[addr &CHUNK_MASK] = value;
-  d->chunk_init[addr &CHUNK_MASK] = 1;
+  struct data_struct *d = find_chunk (abfd, addr);
 
+  d->chunk_data[addr & CHUNK_MASK] = value;
+  d->chunk_init[addr & CHUNK_MASK] = 1;
 }
-/* The first pass is to find the names of all the sections, and see 
+
+/* The first pass is to find the names of all the sections, and see
   how big the data is */
 static void
-DEFUN(first_phase,(abfd, type, src),
-      bfd *abfd AND
-      char type AND
-      char *src)
+first_phase (abfd, type, src)
+     bfd *abfd;
+     char type;
+     char *src;
 {
   asection *section = &bfd_abs_section;
   int len;
   char sym[17];                        /* A symbol can only be 16chars long */
+
   switch (type)
     {
     case '6':
       /* Data record - read it and store it */
       {
-       bfd_vma addr = getvalue(&src);
-       while (*src) {
-         insert_byte(abfd, HEX(src), addr);
-         src+=2;
-         addr++;
-       }
+       bfd_vma addr = getvalue (&src);
+
+       while (*src)
+         {
+           insert_byte (abfd, HEX (src), addr);
+           src += 2;
+           addr++;
+         }
       }
-      
+
       return;
     case '3':
       /* Symbol record, read the segment */
-      len = getsym(sym, &src);
-      section = bfd_get_section_by_name(abfd, sym);
-      if (section == (asection *)NULL) 
+      len = getsym (sym, &src);
+      section = bfd_get_section_by_name (abfd, sym);
+      if (section == (asection *) NULL)
        {
-         char *n = bfd_alloc(abfd, len+1);
-         memcpy(n, sym, len+1);
-         section = bfd_make_section(abfd, n);
+         char *n = bfd_alloc (abfd, len + 1);
+
+         if (!n)
+           {
+             bfd_error = no_memory;
+             abort();          /* FIXME */
+           }
+         memcpy (n, sym, len + 1);
+         section = bfd_make_section (abfd, n);
        }
-      while (*src) 
+      while (*src)
        {
-         switch (*src) {
-           asection *s;
-         case '1':             /* section range */
-           src++;
-           section->vma = getvalue(&src);
-           section->_raw_size = getvalue(&src) - section->vma;
-           section->flags = SEC_HAS_CONTENTS | SEC_LOAD |  SEC_ALLOC; 
-           break;
-
-         case '2':
-         case '3':
-         case '4':
-         case '6':
-         case '7':
-         case '8':
-           /* Symbols, add to section */
+         switch (*src)
            {
-             tekhex_symbol_type *new =
-               (tekhex_symbol_type *)bfd_alloc(abfd,
-                                               sizeof(tekhex_symbol_type));
-             char type=(*src);
-             new->symbol.the_bfd = abfd;
+             asection *s;
+
+           case '1':           /* section range */
              src++;
-             abfd->symcount++;
-             abfd->flags |= HAS_SYMS;
-             new->prev = abfd->tdata.tekhex_data->symbols;
-             abfd->tdata.tekhex_data->symbols = new;
-             len = getsym(sym, &src);
-             new->symbol.name = bfd_alloc(abfd,len+1);
-             memcpy((char *)(new->symbol.name), sym, len+1);
-             new->symbol.section = section ;
-             if (type <= '4')
-                 new->symbol.flags = (BSF_GLOBAL|BSF_EXPORT);
-             else
+             section->vma = getvalue (&src);
+             section->_raw_size = getvalue (&src) - section->vma;
+             section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
+             break;
+
+           case '2':
+           case '3':
+           case '4':
+           case '6':
+           case '7':
+           case '8':
+             /* Symbols, add to section */
+             {
+               tekhex_symbol_type *new =
+               (tekhex_symbol_type *) bfd_alloc (abfd,
+                                              sizeof (tekhex_symbol_type));
+               char type = (*src);
+
+               if (!new)
+                 {
+                   bfd_error = no_memory;
+                   abort();    /* FIXME */
+                 }
+               new->symbol.the_bfd = abfd;
+               src++;
+               abfd->symcount++;
+               abfd->flags |= HAS_SYMS;
+               new->prev = abfd->tdata.tekhex_data->symbols;
+               abfd->tdata.tekhex_data->symbols = new;
+               len = getsym (sym, &src);
+               new->symbol.name = bfd_alloc (abfd, len + 1);
+               if (!new->symbol.name)
+                 {
+                   bfd_error = no_memory;
+                   abort();    /* FIXME */
+                 }
+               memcpy ((char *) (new->symbol.name), sym, len + 1);
+               new->symbol.section = section;
+               if (type <= '4')
+                 new->symbol.flags = (BSF_GLOBAL | BSF_EXPORT);
+               else
                  new->symbol.flags = BSF_LOCAL;
-             new->symbol.value = getvalue(&src) - section->vma;
+               new->symbol.value = getvalue (&src) - section->vma;
+             }
            }
-         }
-       }  
+       }
     }
 }
 
-
 /* Pass over an tekhex, calling one of the above functions on each
    record.  */
 
 static void
-    DEFUN(pass_over,(abfd, func),
-      bfd *abfd AND
-      void (*func) PARAMS ((bfd *, char, char *)))
+ pass_over (abfd, func)
+     bfd *abfd;
+     void (*func) ();
 {
   unsigned int chars_on_line;
   boolean eof = false;
 
   /* To the front of the file */
-  bfd_seek(abfd, (file_ptr)0, SEEK_SET);
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
   while (eof == false)
     {
       char buffer[MAXCHUNK];
@@ -466,233 +506,242 @@ static void
       bfd_vma address = 0;
 
       /* Find first '%' */
-      eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
-      while (*src!= '%' && !eof) {
-       eof = (boolean)(bfd_read(src, 1, 1, abfd) != 1);
-      }
-      if (eof) break;
+      eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+      while (*src != '%' && !eof)
+       {
+         eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
+       }
+      if (eof)
+       break;
       src++;
 
-
       /* Fetch the type and the length and the checksum */
-      bfd_read(src, 1, 5, abfd);
+      bfd_read (src, 1, 5, abfd);
 
       type = src[2];
 
       if (!ISHEX (src[0]) || !ISHEX (src[1]))
        break;
 
-      chars_on_line = HEX(src) - 5; /* Already read five char */
+      chars_on_line = HEX (src) - 5;   /* Already read five char */
 
-      bfd_read(src, 1 , chars_on_line , abfd);
+      bfd_read (src, 1, chars_on_line, abfd);
       src[chars_on_line] = 0;  /* put a null at the end */
 
-
-
-      func(abfd, type, src);
+      func (abfd, type, src);
     }
 
 }
 
-
-
-
 unsigned int
-DEFUN(tekhex_get_symtab,(abfd, table),
-      bfd *abfd AND
-      asymbol **table)
+tekhex_get_symtab (abfd, table)
+     bfd *abfd;
+     asymbol **table;
+
 {
   tekhex_symbol_type *p = abfd->tdata.tekhex_data->symbols;
-  unsigned int c = bfd_get_symcount(abfd)  ;
-  table[c]= 0;
-  while (p) {
-    table[--c] = &(p->symbol);
-    p = p->prev;
-  }
-
-  return bfd_get_symcount(abfd);
+  unsigned int c = bfd_get_symcount (abfd);
+
+  table[c] = 0;
+  while (p)
+    {
+      table[--c] = &(p->symbol);
+      p = p->prev;
+    }
+
+  return bfd_get_symcount (abfd);
 }
-      
+
 unsigned int
-DEFUN(tekhex_get_symtab_upper_bound,(abfd),
-      bfd *abfd)
+tekhex_get_symtab_upper_bound (abfd)
+     bfd *abfd;
 {
-  return (abfd->symcount+1) * (sizeof(struct tekhex_asymbol_struct *));
+  return (abfd->symcount + 1) * (sizeof (struct tekhex_asymbol_struct *));
 
 }
 
 static boolean
-DEFUN(tekhex_mkobject, (abfd), 
-      bfd *abfd)
+tekhex_mkobject (abfd)
+     bfd *abfd;
 {
-    tdata_type *tdata = (tdata_type *)bfd_alloc(abfd, sizeof(tdata_type));
-    abfd->tdata.tekhex_data = tdata;
-    tdata->type = 1;
-    tdata->head = (tekhex_data_list_type *)NULL;
-    tdata->symbols = (struct tekhex_symbol_struct *)NULL;
-tdata->data = (struct data_struct *)NULL;
-    return true;
-    
+  tdata_type *tdata = (tdata_type *) bfd_alloc (abfd, sizeof (tdata_type));
+
+  if (!tdata)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
+  abfd->tdata.tekhex_data = tdata;
+  tdata->type = 1;
+  tdata->head = (tekhex_data_list_type *) NULL;
+  tdata->symbols = (struct tekhex_symbol_struct *) NULL;
+  tdata->data = (struct data_struct *) NULL;
+  return true;
 }
 
-/* 
+/*
   Return true if the file looks like it's in TekHex format. Just look
   for a percent sign and some hex digits */
-       
 
 static bfd_target *
-DEFUN(tekhex_object_p, (abfd),
-      bfd *abfd)
+tekhex_object_p (abfd)
+     bfd *abfd;
 {
   char b[4];
   asection *section;
-  tekhex_init();
-  
-  bfd_seek(abfd, (file_ptr)0, SEEK_SET);
-  bfd_read(b, 1, 4, abfd);
 
-  if (b[0] != '%' || !ISHEX(b[1]) || !ISHEX(b[2]) || !ISHEX(b[3]))
-    return (bfd_target*) NULL;
+  tekhex_init ();
+
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
+  bfd_read (b, 1, 4, abfd);
+
+  if (b[0] != '%' || !ISHEX (b[1]) || !ISHEX (b[2]) || !ISHEX (b[3]))
+    return (bfd_target *) NULL;
 
-  tekhex_mkobject(abfd);
+  tekhex_mkobject (abfd);
 
-  pass_over(abfd, first_phase);
+  pass_over (abfd, first_phase);
   return abfd->xvec;
 }
 
-
 static boolean
-DEFUN(move_section_contents,(abfd, section, locationp, offset,count,
-                            get),
-      
-      bfd *abfd AND
-      asection *section AND
-      PTR locationp AND
-      file_ptr offset AND
-      bfd_size_type count AND
-      boolean get)
+move_section_contents (abfd, section, locationp, offset, count, get)
+     bfd *abfd;
+     asection *section;
+     PTR locationp;
+     file_ptr offset;
+     bfd_size_type count;
+     boolean get;
 {
   bfd_vma addr;
-  char *location = (char *)locationp;
+  char *location = (char *) locationp;
   bfd_vma prev_number = 1;     /* Nothing can have this as a high bit*/
-  struct data_struct *d = (struct data_struct *)NULL;  
-  for (addr = section->vma; count != 0; count --, addr++)
+  struct data_struct *d = (struct data_struct *) NULL;
+
+  for (addr = section->vma; count != 0; count--, addr++)
     {
 
-      bfd_vma chunk_number = addr & ~ CHUNK_MASK; /* Get high bits of address */
+      bfd_vma chunk_number = addr & ~CHUNK_MASK;       /* Get high bits of address */
       bfd_vma low_bits = addr & CHUNK_MASK;
-      if (chunk_number != prev_number) 
+
+      if (chunk_number != prev_number)
        {
          /* Different chunk, so move pointer */
-         d = find_chunk(abfd, chunk_number);
+         d = find_chunk (abfd, chunk_number);
        }
 
-      if (get)    {
-       if (d->chunk_init[low_bits]) 
-         {
-           *location = d->chunk_data[low_bits];
-         }
-       else
-         {
-           *location = 0;
-         }
-      }
-      else {
-       d->chunk_data[low_bits] =  *location ;
-       d->chunk_init[low_bits] = (*location != 0);
-      }
-
+      if (get)
+       {
+         if (d->chunk_init[low_bits])
+           {
+             *location = d->chunk_data[low_bits];
+           }
+         else
+           {
+             *location = 0;
+           }
+       }
+      else
+       {
+         d->chunk_data[low_bits] = *location;
+         d->chunk_init[low_bits] = (*location != 0);
+       }
 
-      location ++;
+      location++;
 
     }
 
-}      
+}
 static boolean
-DEFUN(tekhex_get_section_contents,(abfd, section, locationp, offset, count),
-      bfd *abfd AND
-      asection *section AND
-      PTR locationp AND
-      file_ptr offset AND
-      bfd_size_type count)
+tekhex_get_section_contents (abfd, section, locationp, offset, count)
+     bfd *abfd;
+     asection *section;
+     PTR locationp;
+     file_ptr offset;
+     bfd_size_type count;
 {
   if (section->flags & (SEC_LOAD | SEC_ALLOC))
     {
-      move_section_contents(abfd, section, locationp, offset, count, true);
+      move_section_contents (abfd, section, locationp, offset, count, true);
       return true;
     }
-  else return false;
+  else
+    return false;
 }
-      
-
 
 boolean
-DEFUN(tekhex_set_arch_mach,(abfd, arch, machine),
-      bfd *abfd AND
-      enum bfd_architecture arch AND
-      unsigned long machine)
+tekhex_set_arch_mach (abfd, arch, machine)
+     bfd *abfd;
+     enum bfd_architecture arch;
+     unsigned long machine;
 {
-  return bfd_default_set_arch_mach(abfd, arch, machine);
+  return bfd_default_set_arch_mach (abfd, arch, machine);
 }
 
-
 /* we have to save up all the Tekhexords for a splurge before output,
     */
 
 static boolean
-DEFUN(tekhex_set_section_contents,(abfd, section, locationp, offset, bytes_to_do),
-      bfd *abfd AND
-      sec_ptr section AND
-      PTR locationp AND
-      file_ptr offset AND
-      bfd_size_type bytes_to_do)
+tekhex_set_section_contents (abfd, section, locationp, offset, bytes_to_do)
+     bfd *abfd;
+     sec_ptr section;
+     PTR locationp;
+     file_ptr offset;
+     bfd_size_type bytes_to_do;
 {
 
-  if (abfd->output_has_begun == false) {
-    /* The first time around, allocate enough sections to hold all the chunks */
-    asection *s = abfd->sections;
-    bfd_vma vma;
-    for (s = abfd->sections; s ; s = s->next) {
-      if (s->flags & SEC_LOAD) {
-       for (vma = s->vma & ~CHUNK_MASK;
-            vma < s->vma + s->_raw_size;
-            vma += CHUNK_MASK)
-         find_chunk(abfd, vma);
-      }
-    }
+  if (abfd->output_has_begun == false)
+    {
+      /* The first time around, allocate enough sections to hold all the chunks */
+      asection *s = abfd->sections;
+      bfd_vma vma;
+
+      for (s = abfd->sections; s; s = s->next)
+       {
+         if (s->flags & SEC_LOAD)
+           {
+             for (vma = s->vma & ~CHUNK_MASK;
+                  vma < s->vma + s->_raw_size;
+                  vma += CHUNK_MASK)
+               find_chunk (abfd, vma);
+           }
+       }
 
-  }
+    }
   if (section->flags & (SEC_LOAD | SEC_ALLOC))
     {
-      move_section_contents(abfd, section, locationp, offset, bytes_to_do, false);
+      move_section_contents (abfd, section, locationp, offset, bytes_to_do, false);
       return true;
     }
-  else return false;
+  else
+    return false;
 
 }
 
-
 static void
-DEFUN(writevalue,(dst, value),
-      char **dst AND
-      bfd_vma value)
+writevalue (dst, value)
+     char **dst;
+     bfd_vma value;
 {
   char *p = *dst;
-  int len ;
+  int len;
   int shift;
-  for (len = 8, shift = 28; shift  ; shift-=4, len--)
+
+  for (len = 8, shift = 28; shift; shift -= 4, len--)
     {
-      if ((value>>shift) & 0xf) {
-       *p ++ = len + '0';
-       while (len) {
-         *p ++ = digs[(value>>shift) &0xf];
-         shift-=4;
-         len --;
-       }
-       *dst = p;
-       return;
+      if ((value >> shift) & 0xf)
+       {
+         *p++ = len + '0';
+         while (len)
+           {
+             *p++ = digs[(value >> shift) & 0xf];
+             shift -= 4;
+             len--;
+           }
+         *dst = p;
+         return;
 
-      }
+       }
     }
   *p++ = '1';
   *p++ = '0';
@@ -700,66 +749,73 @@ DEFUN(writevalue,(dst, value),
 }
 
 static void
-DEFUN(writesym,(dst, sym),
-      char **dst AND
-     CONST char *sym)
+writesym (dst, sym)
+     char **dst;
+     CONST char *sym;
 {
   char *p = *dst;
-  int len = (sym?strlen(sym):0);
-  if (len >= 16) {
-    *p++ = '0';
-    len = 16;
-  }
+  int len = (sym ? strlen (sym) : 0);
 
-  else {
-    if (len == 0) {
-      *p++ =  '1';
-      sym = "$";
-      len=1;
+  if (len >= 16)
+    {
+      *p++ = '0';
+      len = 16;
     }
-    else
-      {
-       *p++ = digs[len];
-      }
-  }
 
-  while (len--) {
-    *p++ = *sym++;
-  }
+  else
+    {
+      if (len == 0)
+       {
+         *p++ = '1';
+         sym = "$";
+         len = 1;
+       }
+      else
+       {
+         *p++ = digs[len];
+       }
+    }
+
+  while (len--)
+    {
+      *p++ = *sym++;
+    }
   *dst = p;
 }
 
-static void 
-DEFUN(out,(abfd, type, start, end),
-      bfd *abfd AND
-      char type AND
-      char *start AND
-      char *end)
+static void
+out (abfd, type, start, end)
+     bfd *abfd;
+     char type;
+     char *start;
+     char *end;
 {
   int sum = 0;
   char *s;
   char front[6];
+
   front[0] = '%';
-  TOHEX(front+1, end - start  + 5);
+  TOHEX (front + 1, end - start + 5);
   front[3] = type;
 
-  for (s = start; s < end; s++) {
-    sum += sum_block[*s];
-  }
-
+  for (s = start; s < end; s++)
+    {
+      sum += sum_block[*s];
+    }
 
-  sum += sum_block[front[1]];/*  length */
+  sum += sum_block[front[1]];  /*  length */
   sum += sum_block[front[2]];
-  sum += sum_block[front[3]];/* type */
-  TOHEX(front+4, sum);
-  bfd_write(front, 1, 6,abfd);
+  sum += sum_block[front[3]];  /* type */
+  TOHEX (front + 4, sum);
+  bfd_write (front, 1, 6, abfd);
   end[0] = '\n';
-  bfd_write(start, 1,end-start+1,abfd);
+  bfd_write (start, 1, end - start + 1, abfd);
 
 }
+
 static boolean
-DEFUN(tekhex_write_object_contents,(abfd),
-     bfd *abfd)
+tekhex_write_object_contents (abfd)
+     bfd *abfd;
 {
   int bytes_written;
   char buffer[100];
@@ -768,159 +824,173 @@ DEFUN(tekhex_write_object_contents,(abfd),
   tekhex_data_list_type *list;
   asection *s;
   struct data_struct *d;
+
   bytes_written = 0;
 
   /* And the raw data */
   for (d = abfd->tdata.tekhex_data->data;
-       d != (struct data_struct *)NULL;
+       d != (struct data_struct *) NULL;
        d = d->next)
     {
       int low;
 
-      CONST int span=32;
+      CONST int span = 32;
       int addr;
+
       /* Write it in blocks of 32 bytes */
 
-      for (addr = 0; addr < CHUNK_MASK + 1; addr+=span) 
+      for (addr = 0; addr < CHUNK_MASK + 1; addr += span)
        {
          int need = 0;
+
          /* Check to see if necessary */
-         for (low = 0; !need && low < span; low++) {
-           if (d->chunk_init[addr + low]) need = 1;
-         }
-         if (need){
-           char * dst = buffer;
-           writevalue(&dst, addr + d->vma);
-           for (low = 0; low <span; low++) {
-             TOHEX(dst, d->chunk_data[addr + low]);
-             dst+=2;
+         for (low = 0; !need && low < span; low++)
+           {
+             if (d->chunk_init[addr + low])
+               need = 1;
+           }
+         if (need)
+           {
+             char *dst = buffer;
+
+             writevalue (&dst, addr + d->vma);
+             for (low = 0; low < span; low++)
+               {
+                 TOHEX (dst, d->chunk_data[addr + low]);
+                 dst += 2;
+               }
+             out (abfd, '6', buffer, dst);
            }
-           out(abfd, '6', buffer, dst);
-         }
        }
     }
   /* write all the section headers for the sections */
-  for (s = abfd->sections ; s != (asection *)NULL ; s = s->next) 
+  for (s = abfd->sections; s != (asection *) NULL; s = s->next)
     {
       char *dst = buffer;
-      writesym(&dst, s->name);
+
+      writesym (&dst, s->name);
       *dst++ = '1';
-      writevalue(&dst, s->vma);
-      writevalue(&dst,  s->vma + s->_raw_size);
-      out(abfd, '3',buffer, dst);
+      writevalue (&dst, s->vma);
+      writevalue (&dst, s->vma + s->_raw_size);
+      out (abfd, '3', buffer, dst);
     }
 
   /* And the symbols */
-  for (p = abfd->outsymbols; *p; p++) {
-    int section_code = bfd_decode_symclass  (*p);
-    if (section_code != '?') { /* do not include debug symbols */
-       asymbol *s = *p;
-       char *dst = buffer;
-       writesym(&dst, s->section->name);
-  
-       switch(section_code) {
-         case 'A':
-           *dst++ = '2';
-           break;
-         case 'a':
-           *dst++ = '6';
-           break;
-         case 'D':
-         case 'B':
-         case 'O':
-           *dst++ = '4';
-           break;
-         case 'd':
-         case 'b':
-         case 'o':
-           *dst++ = '8';
-           break;
-         case 'T':
-           *dst++ = '3';
-           break;
-         case 't':
-           *dst++ = '7';
-           break;
-         case 'C':
-         case 'U':
-           bfd_error=wrong_format;
-           return false;
-       }
+  for (p = abfd->outsymbols; *p; p++)
+    {
+      int section_code = bfd_decode_symclass (*p);
+
+      if (section_code != '?')
+       {                       /* do not include debug symbols */
+         asymbol *s = *p;
+         char *dst = buffer;
+
+         writesym (&dst, s->section->name);
+
+         switch (section_code)
+           {
+           case 'A':
+             *dst++ = '2';
+             break;
+           case 'a':
+             *dst++ = '6';
+             break;
+           case 'D':
+           case 'B':
+           case 'O':
+             *dst++ = '4';
+             break;
+           case 'd':
+           case 'b':
+           case 'o':
+             *dst++ = '8';
+             break;
+           case 'T':
+             *dst++ = '3';
+             break;
+           case 't':
+             *dst++ = '7';
+             break;
+           case 'C':
+           case 'U':
+             bfd_error = wrong_format;
+             return false;
+           }
 
-       writesym(&dst, s->name);
-       writevalue(&dst, s->value + s->section->vma);
-       out(abfd, '3', buffer, dst);
+         writesym (&dst, s->name);
+         writevalue (&dst, s->value + s->section->vma);
+         out (abfd, '3', buffer, dst);
+       }
     }
-  }
 
-    
   /* And the terminator */
-  bfd_write("%7081010\n", 1,9 , abfd);
-return true;
+  bfd_write ("%7081010\n", 1, 9, abfd);
+  return true;
 }
-    
 
-static int 
-DEFUN(tekhex_sizeof_headers,(abfd, exec),
-      bfd *abfd AND
-      boolean exec)
+static int
+  tekhex_sizeof_headers (abfd, exec)
+     bfd *abfd;
+     boolean exec;
+
 {
-return 0;
+  return 0;
 }
 
 static asymbol *
-DEFUN(tekhex_make_empty_symbol, (abfd),
-      bfd*abfd)
+tekhex_make_empty_symbol (abfd)
+     bfd *abfd;
 {
-  tekhex_symbol_type *new=
-    (tekhex_symbol_type *)bfd_zalloc (abfd, sizeof (struct tekhex_symbol_struct));
+  tekhex_symbol_type *new =
+  (tekhex_symbol_type *) bfd_zalloc (abfd, sizeof (struct tekhex_symbol_struct));
+
+  if (!new)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   new->symbol.the_bfd = abfd;
-  new->prev = (struct tekhex_symbol_struct *)NULL;
+  new->prev = (struct tekhex_symbol_struct *) NULL;
   return &(new->symbol);
 }
 
 static void
-DEFUN(tekhex_print_symbol,(ignore_abfd, filep, symbol, how),
-      bfd            *ignore_abfd AND
-      PTR           filep AND
-      asymbol        *symbol AND
-      bfd_print_symbol_type how)
+tekhex_get_symbol_info (ignore_abfd, symbol, ret)
+     bfd *ignore_abfd;
+     asymbol *symbol;
+     symbol_info *ret;
 {
-  FILE *file = (FILE *)filep;
-  switch (how) {
-  case bfd_print_symbol_name:
-    fprintf(file, "%s", symbol->name);
-    break;
-  case bfd_print_symbol_more:
-    break;
-  case bfd_print_symbol_nm:
-    {
-      int section_code = bfd_decode_symclass  (symbol);
+  bfd_symbol_info (symbol, ret);
+}
 
-      if (section_code == 'U')
-       fprintf(file, "        ");
-      fprintf_vma(file, symbol->value+symbol->section->vma);
-      if (section_code == '?')
-       {
-       fprintf(file," ?");
-        }
-      else
-       fprintf(file," %c", section_code);
-      if (symbol->name)
-        fprintf(file," %s", symbol->name);
-    }
-    break;
-  case bfd_print_symbol_all:
+static void
+tekhex_print_symbol (ignore_abfd, filep, symbol, how)
+     bfd *ignore_abfd;
+     PTR filep;
+     asymbol *symbol;
+     bfd_print_symbol_type how;
+{
+  FILE *file = (FILE *) filep;
+
+  switch (how)
     {
-      CONST char *section_name = symbol->section->name;
-      bfd_print_symbol_vandf((PTR) file, symbol);
+    case bfd_print_symbol_name:
+      fprintf (file, "%s", symbol->name);
+      break;
+    case bfd_print_symbol_more:
+      break;
 
-       
-      fprintf(file, " %-5s %s",
-             section_name,
-             symbol->name);
-    }  
-  }
+    case bfd_print_symbol_all:
+      {
+       CONST char *section_name = symbol->section->name;
+
+       bfd_print_symbol_vandf ((PTR) file, symbol);
+
+       fprintf (file, " %-5s %s",
+                section_name,
+                symbol->name);
+      }
+    }
 }
 
 #define FOO PROTO
@@ -928,12 +998,10 @@ DEFUN(tekhex_print_symbol,(ignore_abfd, filep, symbol, how),
 #define tekhex_get_reloc_upper_bound (FOO(unsigned int, (*),(bfd*, asection *)))bfd_false
 #define tekhex_canonicalize_reloc (FOO(unsigned int, (*),(bfd*,asection *, arelent **, asymbol **))) bfd_0
 
-
 #define tekhex_openr_next_archived_file (FOO(bfd *, (*), (bfd*,bfd*))) bfd_nullvoidptr
 #define tekhex_find_nearest_line (FOO(boolean, (*),(bfd*,asection*,asymbol**,bfd_vma, CONST char**, CONST char**, unsigned int *))) bfd_false
 #define tekhex_generic_stat_arch_elt  (FOO(int, (*), (bfd *,struct stat *))) bfd_0
 
-
 #define tekhex_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
 #define tekhex_core_file_failing_signal (int (*)())bfd_0
 #define tekhex_core_file_matches_executable_p (FOO(boolean, (*),(bfd*, bfd*)))bfd_false
@@ -948,43 +1016,54 @@ DEFUN(tekhex_print_symbol,(ignore_abfd, filep, symbol, how),
 #define tekhex_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *,       asection *))) bfd_void
 #define tekhex_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
 #define tekhex_bfd_relax_section bfd_generic_relax_section
+#define tekhex_bfd_reloc_type_lookup \
+  ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
+#define tekhex_bfd_make_debug_symbol \
+  ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
+#define tekhex_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
+#define tekhex_bfd_link_add_symbols _bfd_generic_link_add_symbols
+#define tekhex_bfd_final_link _bfd_generic_final_link
+
 bfd_target tekhex_vec =
 {
-    "tekhex",                  /* name */
-    bfd_target_tekhex_flavour,
-    true,                      /* target byte order */
-    true,                      /* target headers byte order */
-    ( EXEC_P | /* object flags */
-     HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
-    (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
-     |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
-    0,                         /* leading underscore */
-    ' ',                       /* ar_pad_char */
-    16,                                /* ar_max_namelen */
-    1,                         /* minimum alignment */
-    _do_getb64, _do_putb64,  _do_getb32,
-    _do_putb32, _do_getb16, _do_putb16, /* data */
-    _do_getb64, _do_putb64,  _do_getb32,
-    _do_putb32, _do_getb16, _do_putb16, /* hdrs */
+  "tekhex",                    /* name */
+  bfd_target_tekhex_flavour,
+  true,                                /* target byte order */
+  true,                                /* target headers byte order */
+  (EXEC_P |                    /* object flags */
+   HAS_SYMS | HAS_LINENO | HAS_DEBUG | HAS_RELOC | HAS_LOCALS |
+   WP_TEXT | D_PAGED),
+  (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
+   | SEC_ALLOC | SEC_LOAD | SEC_RELOC),        /* section flags */
+  0,                           /* leading underscore */
+  ' ',                         /* ar_pad_char */
+  16,                          /* ar_max_namelen */
+  1,                           /* minimum alignment */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* data */
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* hdrs */
 
   {
-      _bfd_dummy_target,
-      tekhex_object_p,         /* bfd_check_format */
-      (struct bfd_target *(*)()) bfd_nullvoidptr,
-      (struct bfd_target *(*)())     bfd_nullvoidptr,
+    _bfd_dummy_target,
+    tekhex_object_p,           /* bfd_check_format */
+    (struct bfd_target * (*)()) bfd_nullvoidptr,
+    (struct bfd_target * (*)()) bfd_nullvoidptr,
   },
   {
-      bfd_false,
-      tekhex_mkobject,
-      _bfd_generic_mkarchive,
-      bfd_false,
+    bfd_false,
+    tekhex_mkobject,
+    _bfd_generic_mkarchive,
+    bfd_false,
   },
   {                            /* bfd_write_contents */
-      bfd_false,
-      tekhex_write_object_contents,
-      _bfd_write_archive_contents,
-      bfd_false,
+    bfd_false,
+    tekhex_write_object_contents,
+    _bfd_write_archive_contents,
+    bfd_false,
   },
-    JUMP_TABLE(tekhex)
- };
-
+  JUMP_TABLE (tekhex),
+  (PTR) 0
+};
This page took 0.253899 seconds and 4 git commands to generate.