Special handling of AIX xcoff text alignment fix.
[deliverable/binutils-gdb.git] / bfd / coffcode.h
index 2cdc137699e7ff542bf8d53b8b38124311e31787..b5bd4429c779b8726c93bf99a138aac41f9a2f9e 100644 (file)
@@ -248,39 +248,37 @@ CODE_FRAGMENT
 .
 .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;
 .
-.       {* 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 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. *}
+.  unsigned int fix_tag : 1;
 .
-.       {* Should the tag field of this symbol be renumbered.
-.          Created by coff_pointerize_aux. *}
-.unsigned int fix_tag : 1;
+.  {* Should the endidx field of this symbol be renumbered.
+.     Created by coff_pointerize_aux. *}
+.  unsigned int fix_end : 1;
 .
-.       {* Should the endidx field of this symbol be renumbered.
-.          Created by coff_pointerize_aux. *}
-.unsigned int fix_end : 1;
+.  {* Should the x_csect.x_scnlen field be renumbered.
+.     Created by coff_pointerize_aux. *}
+.  unsigned int fix_scnlen : 1;
 .
-.       {* Should the x_csect.x_scnlen field be renumbered.
-.          Created by coff_pointerize_aux. *}
-.unsigned int fix_scnlen : 1;
+.  {* Fix up an XCOFF C_BINCL/C_EINCL symbol.  The value is the
+.     index into the line number entries.  Set by coff_slurp_symbol_table.  *}
+.  unsigned int fix_line : 1;
 .
-.       {* Fix up an XCOFF C_BINCL/C_EINCL symbol.  The value is the
-.          index into the line number entries.  Set by
-.          coff_slurp_symbol_table.  *}
-.unsigned int fix_line : 1;
-.
-.       {* The container for the symbol structure as read and translated
-.           from the file. *}
-.
-.union {
-.   union internal_auxent auxent;
-.   struct internal_syment syment;
-. } u;
+.  {* The container for the symbol structure as read and translated
+.     from the file. *}
+.  union
+.  {
+.    union internal_auxent auxent;
+.    struct internal_syment syment;
+.  } u;
 .} combined_entry_type;
 .
 .
@@ -288,17 +286,17 @@ CODE_FRAGMENT
 .
 .typedef struct coff_symbol_struct
 .{
-.   {* The actual symbol which the rest of BFD works with *}
-.asymbol symbol;
+.  {* The actual symbol which the rest of BFD works with *}
+.  asymbol symbol;
 .
-.   {* A pointer to the hidden information for this symbol *}
-.combined_entry_type *native;
+.  {* A pointer to the hidden information for this symbol *}
+.  combined_entry_type *native;
 .
-.   {* A pointer to the linenumber information for this symbol *}
-.struct lineno_cache_entry *lineno;
+.  {* A pointer to the linenumber information for this symbol *}
+.  struct lineno_cache_entry *lineno;
 .
-.   {* Have the line numbers been relocated yet ? *}
-.boolean done_lineno;
+.  {* Have the line numbers been relocated yet ? *}
+.  boolean done_lineno;
 .} coff_symbol_type;
 
 */
@@ -312,8 +310,8 @@ CODE_FRAGMENT
 #define STRING_SIZE_SIZE (4)
 
 static long sec_to_styp_flags PARAMS ((const char *, flagword));
-static flagword styp_to_sec_flags
-  PARAMS ((bfd *, PTR, const char *, asection *));
+static boolean styp_to_sec_flags
+  PARAMS ((bfd *, PTR, const char *, asection *, flagword *));
 static boolean coff_bad_format_hook PARAMS ((bfd *, PTR));
 static void coff_set_custom_section_alignment
   PARAMS ((bfd *, asection *, const struct coff_section_alignment_entry *,
@@ -324,12 +322,12 @@ static boolean coff_write_relocs PARAMS ((bfd *, int));
 static boolean coff_set_flags
   PARAMS ((bfd *, unsigned int *, unsigned short *));
 static boolean coff_set_arch_mach
-  PARAMS ((bfd *, enum bfd_architecture, unsigned long));
+  PARAMS ((bfd *, enum bfd_architecture, unsigned long)) ATTRIBUTE_UNUSED;
 static boolean coff_compute_section_file_positions PARAMS ((bfd *));
-static boolean coff_write_object_contents PARAMS ((bfd *));
+static boolean coff_write_object_contents PARAMS ((bfd *)) ATTRIBUTE_UNUSED;
 static boolean coff_set_section_contents
   PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
-static PTR buy_and_read PARAMS ((bfd *, file_ptr, int, size_t));
+static PTR buy_and_read PARAMS ((bfd *, file_ptr, bfd_size_type));
 static boolean coff_slurp_line_table PARAMS ((bfd *, asection *));
 static boolean coff_slurp_symbol_table PARAMS ((bfd *));
 static enum coff_symbol_classification coff_classify_symbol
@@ -368,7 +366,7 @@ static flagword handle_COMDAT PARAMS ((bfd *, flagword, PTR, const char *, asect
 
 static long
 sec_to_styp_flags (sec_name, sec_flags)
-     CONST char *sec_name;
+     const char *sec_name;
      flagword sec_flags;
 {
   long styp_flags = 0;
@@ -430,6 +428,14 @@ sec_to_styp_flags (sec_name, sec_flags)
     {
       styp_flags = STYP_LOADER;
     }
+  else if (!strcmp (sec_name, _EXCEPT))
+    {
+      styp_flags = STYP_EXCEPT;
+    }
+  else if (!strcmp (sec_name, _TYPCHK))
+    {
+      styp_flags = STYP_TYPCHK;
+    }
 #endif
   /* Try and figure out what it should be */
   else if (sec_flags & SEC_CODE)
@@ -508,7 +514,7 @@ sec_to_styp_flags (sec_name, sec_flags)
   if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
     styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
   /* skip ROM */
-  /* skip CONSTRUCTOR */
+  /* skip constRUCTOR */
   /* skip CONTENTS */
 #ifdef STYP_NOLOAD
   if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
@@ -553,12 +559,13 @@ sec_to_styp_flags (sec_name, sec_flags)
 
 #ifndef COFF_WITH_PE
 
-static flagword
-styp_to_sec_flags (abfd, hdr, name, section)
+static boolean
+styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
      bfd *abfd ATTRIBUTE_UNUSED;
      PTR hdr;
      const char *name;
      asection *section ATTRIBUTE_UNUSED;
+     flagword *flags_ptr;
 {
   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
   long styp_flags = internal_s->s_flags;
@@ -566,19 +573,17 @@ styp_to_sec_flags (abfd, hdr, name, section)
 
 #ifdef STYP_BLOCK
   if (styp_flags & STYP_BLOCK)
-      sec_flags |= SEC_BLOCK;
+    sec_flags |= SEC_BLOCK;
 #endif
 
 #ifdef STYP_CLINK
   if (styp_flags & STYP_CLINK)
-      sec_flags |= SEC_CLINK;
+    sec_flags |= SEC_CLINK;
 #endif
 
 #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
@@ -619,9 +624,7 @@ styp_to_sec_flags (abfd, hdr, name, section)
 #endif
     }
   else if (styp_flags & STYP_PAD)
-    {
-      sec_flags = 0;
-    }
+    sec_flags = 0;
   else if (strcmp (name, _TEXT) == 0)
     {
       if (sec_flags & SEC_NEVER_LOAD)
@@ -664,26 +667,19 @@ styp_to_sec_flags (abfd, hdr, name, section)
 #endif
 #ifdef _LIT
   else if (strcmp (name, _LIT) == 0)
-    {
-      sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
-    }
+    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
 #endif
   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);
-    }
+    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);
-    }
+    sec_flags = (SEC_LOAD | SEC_ALLOC);
 #endif /* STYP_SDATA */
 
 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
@@ -697,7 +693,11 @@ styp_to_sec_flags (abfd, hdr, name, section)
     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
-  return sec_flags;
+  if (flags_ptr == NULL)
+    return false;
+
+  * flags_ptr = sec_flags;
+  return true;
 }
 
 #else /* COFF_WITH_PE */
@@ -736,7 +736,7 @@ handle_COMDAT (abfd, sec_flags, hdr, name, section)
 
   if (! _bfd_coff_get_external_symbols (abfd))
     return sec_flags;
-  
+
   esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
   esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
 
@@ -923,21 +923,23 @@ handle_COMDAT (abfd, sec_flags, hdr, name, section)
                 drop through from the above).  */
              {
                char *newname;
+               bfd_size_type amt;
 
-               /* This must the the second symbol with the
+               /* This must the second symbol with the
                   section #.  It is the actual symbol name.
                   Intel puts the two adjacent, but Alpha (at
                   least) spreads them out.  */
 
-               section->comdat =
-                 bfd_alloc (abfd, sizeof (struct bfd_comdat_info));
+               amt = sizeof (struct bfd_comdat_info);
+               section->comdat = bfd_alloc (abfd, amt);
                if (section->comdat == NULL)
                  abort ();
 
                section->comdat->symbol =
                  (esym - esymstart) / bfd_coff_symesz (abfd);
 
-               newname = bfd_alloc (abfd, strlen (symname) + 1);
+               amt = strlen (symname) + 1;
+               newname = bfd_alloc (abfd, amt);
                if (newname == NULL)
                  abort ();
 
@@ -966,16 +968,18 @@ handle_COMDAT (abfd, sec_flags, hdr, name, section)
    required information.  FIXME: Is the COMDAT symbol index used for
    any purpose other than objdump?  */
 
-static flagword
-styp_to_sec_flags (abfd, hdr, name, section)
+static boolean
+styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
      bfd *abfd;
      PTR hdr;
      const char *name;
      asection *section;
+     flagword *flags_ptr;
 {
   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
   long styp_flags = internal_s->s_flags;
   flagword sec_flags;
+  boolean result = true;
 
   /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
   sec_flags = SEC_READONLY;
@@ -985,7 +989,7 @@ styp_to_sec_flags (abfd, hdr, name, section)
     {
       long flag = styp_flags & - styp_flags;
       char * unhandled = NULL;
-      
+
       styp_flags &= ~ flag;
 
       /* We infer from the distinct read/write/execute bits the settings
@@ -1010,7 +1014,7 @@ styp_to_sec_flags (abfd, hdr, name, section)
        case STYP_NOLOAD:
          sec_flags |= SEC_NEVER_LOAD;
          break;
-#endif 
+#endif
        case IMAGE_SCN_MEM_READ:
          /* Ignored, assume it always to be true.  */
          break;
@@ -1067,17 +1071,17 @@ styp_to_sec_flags (abfd, hdr, name, section)
          break;
        default:
          /* Silently ignore for now.  */
-         break;          
+         break;
        }
 
-      /* If the section flag was not handled, report it here.  This will allow
-        users of the BFD library to report a problem but continue executing.
-        Tools which need to be aware of these problems (such as the linker)
-        can override the default bfd_error_handler to intercept these reports.  */
+      /* If the section flag was not handled, report it here.  */
       if (unhandled != NULL)
-       (*_bfd_error_handler)
-         (_("%s (%s): Section flag %s (0x%x) ignored"),
-          bfd_get_filename (abfd), name, unhandled, flag);
+       {
+         (*_bfd_error_handler)
+           (_("%s (%s): Section flag %s (0x%x) ignored"),
+            bfd_archive_filename (abfd), name, unhandled, flag);
+         result = false;
+       }
     }
 
 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
@@ -1091,7 +1095,10 @@ styp_to_sec_flags (abfd, hdr, name, section)
     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
-  return sec_flags;
+  if (flags_ptr)
+    * flags_ptr = sec_flags;
+
+  return result;
 }
 
 #endif /* COFF_WITH_PE */
@@ -1123,234 +1130,166 @@ CODE_FRAGMENT
 Special entry points for gdb to swap in coff symbol table parts:
 .typedef struct
 .{
-.  void (*_bfd_coff_swap_aux_in) PARAMS ((
-.       bfd            *abfd,
-.       PTR             ext,
-.       int             type,
-.       int             class,
-.       int             indaux,
-.       int             numaux,
-.       PTR             in));
+.  void (*_bfd_coff_swap_aux_in)
+.    PARAMS ((bfd *, PTR, int, int, int, int, PTR));
 .
-.  void (*_bfd_coff_swap_sym_in) PARAMS ((
-.       bfd            *abfd ,
-.       PTR             ext,
-.       PTR             in));
+.  void (*_bfd_coff_swap_sym_in)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-.  void (*_bfd_coff_swap_lineno_in) PARAMS ((
-.       bfd            *abfd,
-.       PTR            ext,
-.       PTR             in));
+.  void (*_bfd_coff_swap_lineno_in)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-
-Special entry points for gas to swap out coff parts:
-
-. unsigned int (*_bfd_coff_swap_aux_out) PARAMS ((
-.       bfd    *abfd,
-.       PTR    in,
-.       int            type,
-.       int            class,
-.       int     indaux,
-.       int     numaux,
-.       PTR            ext));
+.  unsigned int (*_bfd_coff_swap_aux_out)
+.    PARAMS ((bfd *, PTR, int, int, int, int, PTR));
 .
-. unsigned int (*_bfd_coff_swap_sym_out) PARAMS ((
-.      bfd      *abfd,
-.      PTR     in,
-.      PTR     ext));
+.  unsigned int (*_bfd_coff_swap_sym_out)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-. unsigned int (*_bfd_coff_swap_lineno_out) PARAMS ((
-.              bfd     *abfd,
-.              PTR     in,
-.      PTR     ext));
+.  unsigned int (*_bfd_coff_swap_lineno_out)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-. unsigned int (*_bfd_coff_swap_reloc_out) PARAMS ((
-.              bfd     *abfd,
-.      PTR     src,
-.      PTR     dst));
+.  unsigned int (*_bfd_coff_swap_reloc_out)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-. unsigned int (*_bfd_coff_swap_filehdr_out) PARAMS ((
-.              bfd     *abfd,
-.      PTR     in,
-.      PTR     out));
+.  unsigned int (*_bfd_coff_swap_filehdr_out)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-. unsigned int (*_bfd_coff_swap_aouthdr_out) PARAMS ((
-.              bfd     *abfd,
-.      PTR     in,
-.      PTR     out));
+.  unsigned int (*_bfd_coff_swap_aouthdr_out)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-. unsigned int (*_bfd_coff_swap_scnhdr_out) PARAMS ((
-.              bfd     *abfd,
-.              PTR     in,
-.      PTR     out));
+.  unsigned int (*_bfd_coff_swap_scnhdr_out)
+.    PARAMS ((bfd *, PTR, PTR));
 .
-
-Special entry points for generic COFF routines to call target
-dependent COFF routines:
-
-. unsigned int _bfd_filhsz;
-. unsigned int _bfd_aoutsz;
-. unsigned int _bfd_scnhsz;
-. unsigned int _bfd_symesz;
-. unsigned int _bfd_auxesz;
-. unsigned int _bfd_relsz;
-. unsigned int _bfd_linesz;
-. unsigned int _bfd_filnmlen;
-. boolean _bfd_coff_long_filenames;
-. boolean _bfd_coff_long_section_names;
-. unsigned int _bfd_coff_default_section_alignment_power;
-. boolean _bfd_coff_force_symnames_in_strings;
-. unsigned int _bfd_coff_debug_string_prefix_length;
-. void (*_bfd_coff_swap_filehdr_in) PARAMS ((
-.       bfd     *abfd,
-.       PTR     ext,
-.       PTR     in));
-. void (*_bfd_coff_swap_aouthdr_in) PARAMS ((
-.       bfd     *abfd,
-.       PTR     ext,
-.       PTR     in));
-. void (*_bfd_coff_swap_scnhdr_in) PARAMS ((
-.       bfd     *abfd,
-.       PTR     ext,
-.       PTR     in));
-. void (*_bfd_coff_swap_reloc_in) PARAMS ((
-.       bfd     *abfd,
-.       PTR     ext,
-.       PTR     in));
-. boolean (*_bfd_coff_bad_format_hook) PARAMS ((
-.       bfd     *abfd,
-.       PTR     internal_filehdr));
-. boolean (*_bfd_coff_set_arch_mach_hook) PARAMS ((
-.       bfd     *abfd,
-.       PTR     internal_filehdr));
-. PTR (*_bfd_coff_mkobject_hook) PARAMS ((
-.       bfd     *abfd,
-.       PTR     internal_filehdr,
-.       PTR     internal_aouthdr));
-. flagword (*_bfd_styp_to_sec_flags_hook) PARAMS ((
-.       bfd     *abfd,
-.       PTR     internal_scnhdr,
-.       const char *name,
-.       asection *section));
-. void (*_bfd_set_alignment_hook) PARAMS ((
-.       bfd     *abfd,
-.       asection *sec,
-.       PTR     internal_scnhdr));
-. boolean (*_bfd_coff_slurp_symbol_table) PARAMS ((
-.       bfd     *abfd));
-. boolean (*_bfd_coff_symname_in_debug) PARAMS ((
-.       bfd     *abfd,
-.       struct internal_syment *sym));
-. boolean (*_bfd_coff_pointerize_aux_hook) PARAMS ((
-.       bfd *abfd,
-.       combined_entry_type *table_base,
-.       combined_entry_type *symbol,
-.       unsigned int indaux,
-.       combined_entry_type *aux));
-. boolean (*_bfd_coff_print_aux) PARAMS ((
-.       bfd *abfd,
-.       FILE *file,
-.       combined_entry_type *table_base,
-.       combined_entry_type *symbol,
-.       combined_entry_type *aux,
-.       unsigned int indaux));
-. void (*_bfd_coff_reloc16_extra_cases) PARAMS ((
-.       bfd     *abfd,
-.       struct bfd_link_info *link_info,
-.       struct bfd_link_order *link_order,
-.       arelent *reloc,
-.       bfd_byte *data,
-.       unsigned int *src_ptr,
-.       unsigned int *dst_ptr));
-. int (*_bfd_coff_reloc16_estimate) PARAMS ((
-.       bfd *abfd,
-.       asection *input_section,
-.       arelent *r,
-.       unsigned int shrink,
-.       struct bfd_link_info *link_info));
-. enum coff_symbol_classification (*_bfd_coff_classify_symbol) PARAMS ((
-.       bfd *abfd,
-.       struct internal_syment *));
-. boolean (*_bfd_coff_compute_section_file_positions) PARAMS ((
-.       bfd *abfd));
-. boolean (*_bfd_coff_start_final_link) PARAMS ((
-.       bfd *output_bfd,
-.       struct bfd_link_info *info));
-. boolean (*_bfd_coff_relocate_section) PARAMS ((
-.       bfd *output_bfd,
-.       struct bfd_link_info *info,
-.       bfd *input_bfd,
-.       asection *input_section,
-.       bfd_byte *contents,
-.       struct internal_reloc *relocs,
-.       struct internal_syment *syms,
-.       asection **sections));
-. reloc_howto_type *(*_bfd_coff_rtype_to_howto) PARAMS ((
-.       bfd *abfd,
-.       asection *sec,
-.       struct internal_reloc *rel,
-.       struct coff_link_hash_entry *h,
-.       struct internal_syment *sym,
-.       bfd_vma *addendp));
-. boolean (*_bfd_coff_adjust_symndx) PARAMS ((
-.       bfd *obfd,
-.       struct bfd_link_info *info,
-.       bfd *ibfd,
-.       asection *sec,
-.       struct internal_reloc *reloc,
-.       boolean *adjustedp));
-. boolean (*_bfd_coff_link_add_one_symbol) PARAMS ((
-.       struct bfd_link_info *info,
-.       bfd *abfd,
-.       const char *name,
-.       flagword flags,
-.       asection *section,
-.       bfd_vma value,
-.       const char *string,
-.       boolean copy,
-.       boolean collect,
-.       struct bfd_link_hash_entry **hashp));
+.  unsigned int _bfd_filhsz;
+.  unsigned int _bfd_aoutsz;
+.  unsigned int _bfd_scnhsz;
+.  unsigned int _bfd_symesz;
+.  unsigned int _bfd_auxesz;
+.  unsigned int _bfd_relsz;
+.  unsigned int _bfd_linesz;
+.  unsigned int _bfd_filnmlen;
+.  boolean _bfd_coff_long_filenames;
+.  boolean _bfd_coff_long_section_names;
+.  unsigned int _bfd_coff_default_section_alignment_power;
+.  boolean _bfd_coff_force_symnames_in_strings;
+.  unsigned int _bfd_coff_debug_string_prefix_length;
+.
+.  void (*_bfd_coff_swap_filehdr_in)
+.    PARAMS ((bfd *, PTR, PTR));
+.
+.  void (*_bfd_coff_swap_aouthdr_in)
+.    PARAMS ((bfd *, PTR, PTR));
+.
+.  void (*_bfd_coff_swap_scnhdr_in)
+.    PARAMS ((bfd *, PTR, PTR));
+.
+.  void (*_bfd_coff_swap_reloc_in)
+.    PARAMS ((bfd *abfd, PTR, PTR));
+.
+.  boolean (*_bfd_coff_bad_format_hook)
+.    PARAMS ((bfd *, PTR));
+.
+.  boolean (*_bfd_coff_set_arch_mach_hook)
+.    PARAMS ((bfd *, PTR));
+.
+.  PTR (*_bfd_coff_mkobject_hook)
+.    PARAMS ((bfd *, PTR, PTR));
+.
+.  boolean (*_bfd_styp_to_sec_flags_hook)
+.    PARAMS ((bfd *, PTR, const char *, asection *, flagword *));
+.
+.  void (*_bfd_set_alignment_hook)
+.    PARAMS ((bfd *, asection *, PTR));
+.
+.  boolean (*_bfd_coff_slurp_symbol_table)
+.    PARAMS ((bfd *));
+.
+.  boolean (*_bfd_coff_symname_in_debug)
+.    PARAMS ((bfd *, struct internal_syment *));
+.
+.  boolean (*_bfd_coff_pointerize_aux_hook)
+.    PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
+.           unsigned int, combined_entry_type *));
+.
+.  boolean (*_bfd_coff_print_aux)
+.    PARAMS ((bfd *, FILE *, combined_entry_type *, combined_entry_type *,
+.           combined_entry_type *, unsigned int));
+.
+.  void (*_bfd_coff_reloc16_extra_cases)
+.    PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
+.          bfd_byte *, unsigned int *, unsigned int *));
+.
+.  int (*_bfd_coff_reloc16_estimate)
+.    PARAMS ((bfd *, asection *, arelent *, unsigned int,
+.           struct bfd_link_info *));
+.
+.  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
+.    PARAMS ((bfd *, struct internal_syment *));
+.
+.  boolean (*_bfd_coff_compute_section_file_positions)
+.    PARAMS ((bfd *));
+.
+.  boolean (*_bfd_coff_start_final_link)
+.    PARAMS ((bfd *, struct bfd_link_info *));
 .
-. boolean (*_bfd_coff_link_output_has_begun) PARAMS ((
-.      bfd * abfd,
-.       struct coff_final_link_info * pfinfo));
-. boolean (*_bfd_coff_final_link_postscript) PARAMS ((
-.      bfd * abfd,
-.      struct coff_final_link_info * pfinfo));
+.  boolean (*_bfd_coff_relocate_section)
+.    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
+.           struct internal_reloc *, struct internal_syment *, asection **));
+.
+.  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
+.    PARAMS ((bfd *, asection *, struct internal_reloc *,
+.           struct coff_link_hash_entry *, struct internal_syment *,
+.           bfd_vma *));
+.
+.  boolean (*_bfd_coff_adjust_symndx)\
+.    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
+.           struct internal_reloc *, boolean *));
+.
+.  boolean (*_bfd_coff_link_add_one_symbol)
+.    PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
+.           asection *, bfd_vma, const char *, boolean, boolean,
+.           struct bfd_link_hash_entry **));
+.
+.  boolean (*_bfd_coff_link_output_has_begun)
+.    PARAMS ((bfd *, struct coff_final_link_info *));
+.
+.  boolean (*_bfd_coff_final_link_postscript)
+.    PARAMS ((bfd *, struct coff_final_link_info *));
 .
 .} bfd_coff_backend_data;
 .
-.#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
+.#define coff_backend_info(abfd) \
+.  ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
 .
 .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
-.        ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
+.  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
 .
 .#define bfd_coff_swap_sym_in(a,e,i) \
-.        ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
+.  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
 .
 .#define bfd_coff_swap_lineno_in(a,e,i) \
-.        ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
+.  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
 .
 .#define bfd_coff_swap_reloc_out(abfd, i, o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
 .
 .#define bfd_coff_swap_lineno_out(abfd, i, o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
 .
 .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
-.        ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
+.  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
 .
 .#define bfd_coff_swap_sym_out(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
 .
 .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
 .
 .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
 .
 .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
 .
 .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
 .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
@@ -1360,90 +1299,91 @@ dependent COFF routines:
 .#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
 .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
 .#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
-.#define bfd_coff_long_filenames(abfd) (coff_backend_info (abfd)->_bfd_coff_long_filenames)
+.#define bfd_coff_long_filenames(abfd) \
+.  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
 .#define bfd_coff_long_section_names(abfd) \
-.        (coff_backend_info (abfd)->_bfd_coff_long_section_names)
+.  (coff_backend_info (abfd)->_bfd_coff_long_section_names)
 .#define bfd_coff_default_section_alignment_power(abfd) \
-.       (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
+.  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
 .#define bfd_coff_swap_filehdr_in(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
 .
 .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
 .
 .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
 .
 .#define bfd_coff_swap_reloc_in(abfd, i, o) \
-.        ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
+.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
 .
 .#define bfd_coff_bad_format_hook(abfd, filehdr) \
-.        ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
+.  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
 .
 .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
-.        ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
+.  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
 .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
-.        ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
+.  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
 .
-.#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section)\
-.        ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
-.         (abfd, scnhdr, name, section))
+.#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
+.  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
+.   (abfd, scnhdr, name, section, flags_ptr))
 .
 .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
-.        ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
+.  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
 .
 .#define bfd_coff_slurp_symbol_table(abfd)\
-.        ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
+.  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
 .
 .#define bfd_coff_symname_in_debug(abfd, sym)\
-.        ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
+.  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
 .
 .#define bfd_coff_force_symnames_in_strings(abfd)\
-.      (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
+.  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
 .
 .#define bfd_coff_debug_string_prefix_length(abfd)\
-.      (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
+.  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
 .
 .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
-.        ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
-.         (abfd, file, base, symbol, aux, indaux))
+.  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
+.   (abfd, file, base, symbol, aux, indaux))
 .
 .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\
-.        ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
-.         (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
+.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
+.   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
 .
 .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
-.        ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
-.         (abfd, section, reloc, shrink, link_info))
+.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
+.   (abfd, section, reloc, shrink, link_info))
 .
 .#define bfd_coff_classify_symbol(abfd, sym)\
-.        ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
-.         (abfd, sym))
+.  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
+.   (abfd, sym))
 .
 .#define bfd_coff_compute_section_file_positions(abfd)\
-.        ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
-.         (abfd))
+.  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
+.   (abfd))
 .
 .#define bfd_coff_start_final_link(obfd, info)\
-.        ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
-.         (obfd, info))
+.  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
+.   (obfd, info))
 .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
-.        ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
-.         (obfd, info, ibfd, o, con, rel, isyms, secs))
+.  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
+.   (obfd, info, ibfd, o, con, rel, isyms, secs))
 .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
-.        ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
-.         (abfd, sec, rel, h, sym, addendp))
+.  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
+.   (abfd, sec, rel, h, sym, addendp))
 .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
-.        ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
-.         (obfd, info, ibfd, sec, rel, adjustedp))
+.  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
+.   (obfd, info, ibfd, sec, rel, adjustedp))
 .#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\
-.        ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
-.         (info, abfd, name, flags, section, value, string, cp, coll, hashp))
+.  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
+.   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
 .
 .#define bfd_coff_link_output_has_begun(a,p) \
-.        ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p))
+.  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p))
 .#define bfd_coff_final_link_postscript(a,p) \
-.        ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p))
+.  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p))
 .
 */
 
@@ -1506,7 +1446,10 @@ coff_set_custom_section_alignment (abfd, section, alignment_table, table_size)
     return;
 
   if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
-      && default_alignment > alignment_table[i].default_alignment_max)
+#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
+      && default_alignment > alignment_table[i].default_alignment_max
+#endif
+      )
     return;
 
   section->alignment_power = alignment_table[i].alignment_power;
@@ -1545,6 +1488,7 @@ coff_new_section_hook (abfd, section)
      asection * section;
 {
   combined_entry_type *native;
+  bfd_size_type amt;
 
   section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
 
@@ -1562,8 +1506,8 @@ coff_new_section_hook (abfd, section)
 
      @@ The 10 is a guess at a plausible maximum number of aux entries
      (but shouldn't be a constant).  */
-  native = ((combined_entry_type *)
-           bfd_zalloc (abfd, sizeof (combined_entry_type) * 10));
+  amt = sizeof (combined_entry_type) * 10;
+  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
   if (native == NULL)
     return false;
 
@@ -1645,6 +1589,7 @@ coff_set_alignment_hook (abfd, section, scnhdr)
      PTR scnhdr;
 {
   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
+  bfd_size_type amt;
 
   ALIGN_SET     (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
@@ -1660,8 +1605,8 @@ coff_set_alignment_hook (abfd, section, scnhdr)
      mapped onto a generic BFD section bit.  */
   if (coff_section_data (abfd, section) == NULL)
     {
-      section->used_by_bfd =
-       (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
+      amt = sizeof (struct coff_section_tdata);
+      section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
       if (section->used_by_bfd == NULL)
        {
          /* FIXME: Return error.  */
@@ -1670,8 +1615,8 @@ coff_set_alignment_hook (abfd, section, scnhdr)
     }
   if (pei_section_data (abfd, section) == NULL)
     {
-      coff_section_data (abfd, section)->tdata =
-       (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata));
+      amt = sizeof (struct pei_section_tdata);
+      coff_section_data (abfd, section)->tdata = (PTR) bfd_zalloc (abfd, amt);
       if (coff_section_data (abfd, section)->tdata == NULL)
        {
          /* FIXME: Return error.  */
@@ -1688,16 +1633,15 @@ coff_set_alignment_hook (abfd, section, scnhdr)
     {
       struct external_reloc dst;
       struct internal_reloc n;
-      int oldpos = bfd_tell (abfd);
-      bfd_seek (abfd, hdr->s_relptr, 0);
-      if (bfd_read ((PTR) & dst, 1, bfd_coff_relsz (abfd), abfd)
+      file_ptr oldpos = bfd_tell (abfd);
+      bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0);
+      if (bfd_bread ((PTR) &dst, (bfd_size_type) bfd_coff_relsz (abfd), abfd)
          != bfd_coff_relsz (abfd))
        return;
 
       coff_swap_reloc_in (abfd, &dst, &n);
       bfd_seek (abfd, oldpos, 0);
-      section->reloc_count =
-       hdr->s_nreloc = n.r_vaddr;
+      section->reloc_count = hdr->s_nreloc = n.r_vaddr;
     }
 }
 #undef ALIGN_SET
@@ -1725,7 +1669,7 @@ coff_set_alignment_hook (abfd, section, scnhdr)
   if ((hdr->s_flags & STYP_OVRFLO) == 0)
     return;
 
-  real_sec = coff_section_from_bfd_index (abfd, hdr->s_nreloc);
+  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
   if (real_sec == NULL)
     return;
 
@@ -1761,8 +1705,9 @@ coff_mkobject (abfd)
      bfd * abfd;
 {
   coff_data_type *coff;
+  bfd_size_type amt = sizeof (coff_data_type);
 
-  abfd->tdata.coff_obj_data = (struct coff_tdata *) bfd_zalloc (abfd, sizeof (coff_data_type));
+  abfd->tdata.coff_obj_data = (struct coff_tdata *) bfd_zalloc (abfd, amt);
   if (abfd->tdata.coff_obj_data == 0)
     return false;
   coff = coff_data (abfd);
@@ -1870,7 +1815,7 @@ coff_set_arch_mach_hook (abfd, filehdr)
      bfd *abfd;
      PTR filehdr;
 {
-  long machine;
+  unsigned long machine;
   enum bfd_architecture arch;
   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
 
@@ -2030,11 +1975,11 @@ coff_set_arch_mach_hook (abfd, filehdr)
              {
                bfd_byte *buf;
                struct internal_syment sym;
+               bfd_size_type amt = bfd_coff_symesz (abfd);
 
-               buf = (bfd_byte *) bfd_malloc (bfd_coff_symesz (abfd));
+               buf = (bfd_byte *) bfd_malloc (amt);
                if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
-                   || (bfd_read (buf, 1, bfd_coff_symesz (abfd), abfd)
-                       != bfd_coff_symesz (abfd)))
+                   || bfd_bread (buf, amt, abfd) != amt)
                  {
                    free (buf);
                    return false;
@@ -2053,21 +1998,8 @@ coff_set_arch_mach_hook (abfd, filehdr)
          {
          default:
          case 0:
-#ifdef POWERMAC
-           /* PowerPC Macs use the same magic numbers as RS/6000
-              (because that's how they were bootstrapped originally),
-              but they are always PowerPC architecture.  */
-           arch = bfd_arch_powerpc;
-           machine = bfd_mach_ppc;
-#else
-#ifdef XCOFF64
-           arch = bfd_arch_powerpc;
-           machine = bfd_mach_ppc_620;
-#else
-           arch = bfd_arch_rs6000;
-           machine = bfd_mach_rs6k;
-#endif
-#endif /* POWERMAC */
+           arch = bfd_xcoff_architecture (abfd);
+           machine = bfd_xcoff_machine (abfd);
            break;
 
          case 1:
@@ -2338,13 +2270,21 @@ coff_print_aux (abfd, file, table_base, symbol, aux, indaux)
       if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
        {
          BFD_ASSERT (! aux->fix_scnlen);
-         fprintf (file, "val %5ld", aux->u.auxent.x_csect.x_scnlen.l);
+#ifdef XCOFF64
+         fprintf (file, "val %5lld", aux->u.auxent.x_csect.x_scnlen.l);
+#else
+         fprintf (file, "val %5ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
+#endif
        }
       else
        {
          fprintf (file, "indx ");
          if (! aux->fix_scnlen)
-           fprintf (file, "%4ld", aux->u.auxent.x_csect.x_scnlen.l);
+#ifdef XCOFF64
+           fprintf (file, "%4lld", aux->u.auxent.x_csect.x_scnlen.l);
+#else
+           fprintf (file, "%4ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
+#endif
          else
            fprintf (file, "%4ld",
                     (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
@@ -2418,12 +2358,18 @@ coff_write_relocs (abfd, first_undef)
 #ifndef TARG_AUX
       p = s->orelocation;
 #else
-      /* sort relocations before we write them out */
-      p = (arelent **) bfd_malloc (s->reloc_count * sizeof (arelent *));
-      if (p == NULL && s->reloc_count > 0)
-       return false;
-      memcpy (p, s->orelocation, s->reloc_count * sizeof (arelent *));
-      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
+      {
+       /* sort relocations before we write them out */
+       bfd_size_type amt;
+
+       amt = s->reloc_count;
+       amt *= sizeof (arelent *);
+       p = (arelent **) bfd_malloc (amt);
+       if (p == NULL && s->reloc_count > 0)
+         return false;
+       memcpy (p, s->orelocation, (size_t) amt);
+       qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
+      }
 #endif
 
       if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
@@ -2438,8 +2384,8 @@ coff_write_relocs (abfd, first_undef)
          /* add one to count *this* reloc (grr) */
          n.r_vaddr = s->reloc_count + 1;
          coff_swap_reloc_out (abfd, &n, &dst);
-         if (bfd_write ((PTR) & dst, 1, bfd_coff_relsz (abfd), abfd)
-             != bfd_coff_relsz (abfd))
+         if (bfd_bwrite ((PTR) & dst, (bfd_size_type) bfd_coff_relsz (abfd),
+                        abfd) != bfd_coff_relsz (abfd))
            return false;
        }
 #endif
@@ -2462,15 +2408,15 @@ coff_write_relocs (abfd, first_undef)
 
          if (q->sym_ptr_ptr[0]->the_bfd != abfd)
            {
-             int i;
+             int j;
              const char *sname = q->sym_ptr_ptr[0]->name;
              asymbol **outsyms = abfd->outsymbols;
-             for (i = first_undef; outsyms[i]; i++)
+             for (j = first_undef; outsyms[j]; j++)
                {
-                 const char *intable = outsyms[i]->name;
+                 const char *intable = outsyms[j]->name;
                  if (strcmp (intable, sname) == 0) {
                    /* got a hit, so repoint the reloc */
-                   q->sym_ptr_ptr = outsyms + i;
+                   q->sym_ptr_ptr = outsyms + j;
                    break;
                  }
                }
@@ -2517,8 +2463,8 @@ coff_write_relocs (abfd, first_undef)
          n.r_type = q->howto->type;
 #endif
          coff_swap_reloc_out (abfd, &n, &dst);
-         if (bfd_write ((PTR) & dst, 1, bfd_coff_relsz (abfd), abfd)
-             != bfd_coff_relsz (abfd))
+         if (bfd_bwrite ((PTR) & dst, (bfd_size_type) bfd_coff_relsz (abfd),
+                        abfd) != bfd_coff_relsz (abfd))
            return false;
        }
 
@@ -2994,17 +2940,19 @@ coff_compute_section_file_positions (abfd)
        right order in the image file itself, but we do need to get the
        target_index values right.  */
 
-    int count;
+    unsigned int count;
     asection **section_list;
-    int i;
+    unsigned int i;
     int target_index;
+    bfd_size_type amt;
 
     count = 0;
     for (current = abfd->sections; current != NULL; current = current->next)
       ++count;
 
     /* We allocate an extra cell to simplify the final loop.  */
-    section_list = bfd_malloc (sizeof (struct asection *) * (count + 1));
+    amt = sizeof (struct asection *) * (count + 1);
+    section_list = bfd_malloc (amt);
     if (section_list == NULL)
       return false;
 
@@ -3068,15 +3016,16 @@ coff_compute_section_file_positions (abfd)
         page size too, and remember both sizes.  */
       if (coff_section_data (abfd, current) == NULL)
        {
-         current->used_by_bfd =
-           (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
+         bfd_size_type amt = sizeof (struct coff_section_tdata);
+         current->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
          if (current->used_by_bfd == NULL)
            return false;
        }
       if (pei_section_data (abfd, current) == NULL)
        {
-         coff_section_data (abfd, current)->tdata =
-           (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata));
+         bfd_size_type amt = sizeof (struct pei_section_tdata);
+         coff_section_data (abfd, current)->tdata
+           = (PTR) bfd_zalloc (abfd, amt);
          if (coff_section_data (abfd, current)->tdata == NULL)
            return false;
        }
@@ -3105,7 +3054,36 @@ coff_compute_section_file_positions (abfd)
             padding the previous section up if necessary */
 
          old_sofar = sofar;
-         sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
+#ifdef RS6000COFF_C
+         /* AIX loader checks the text section alignment of (vma - filepos)
+            So even though the filepos may be aligned wrt the o_algntext, for
+            AIX executables, this check fails. This shows up when an native 
+            AIX executable is stripped with gnu strip because the default vma
+            of native is 0x10000150 but default for gnu is 0x10000140.  Gnu
+            stripped gnu excutable passes this check because the filepos is 
+            0x0140. */
+         if (!strcmp (current->name, _TEXT)) 
+           {
+             bfd_vma pad;
+             bfd_vma align;
+
+             sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
+
+             align = 1 << current->alignment_power;
+             pad = abs (current->vma - sofar) % align;
+             
+             if (pad) 
+               {
+                 pad = align - pad;
+                 sofar += pad;
+               }
+           }
+         else
+#else
+           {
+             sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
+           }
+#endif
          if (previous != (asection *) NULL)
            {
              previous->_raw_size += sofar - old_sofar;
@@ -3181,7 +3159,7 @@ coff_compute_section_file_positions (abfd)
 
       b = 0;
       if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
-         || bfd_write (&b, 1, 1, abfd) != 1)
+         || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
        return false;
     }
 
@@ -3214,11 +3192,12 @@ coff_add_missing_symbols (abfd)
   asymbol **sympp2;
   unsigned int i;
   int need_text = 1, need_data = 1, need_bss = 1, need_file = 1;
+  bfd_size_type amt;
 
   for (i = 0; i < nsyms; i++)
     {
       coff_symbol_type *csym = coff_symbol_from (abfd, sympp[i]);
-      CONST char *name;
+      const char *name;
       if (csym)
        {
          /* only do this if there is a coff representation of the input
@@ -3250,7 +3229,9 @@ coff_add_missing_symbols (abfd)
   if (!need_text && !need_data && !need_bss && !need_file)
     return true;
   nsyms += need_text + need_data + need_bss + need_file;
-  sympp2 = (asymbol **) bfd_alloc (abfd, nsyms * sizeof (asymbol *));
+  amt = nsyms;
+  amt *= sizeof (asymbol *);
+  sympp2 = (asymbol **) bfd_alloc (abfd, amt);
   if (!sympp2)
     return false;
   memcpy (sympp2, sympp, i * sizeof (asymbol *));
@@ -3370,10 +3351,12 @@ coff_write_object_contents (abfd)
     {
       scn_base = bfd_coff_filhsz (abfd);
 #ifdef RS6000COFF_C
+#ifndef XCOFF64
       if (xcoff_data (abfd)->full_aouthdr)
        scn_base += bfd_coff_aoutsz (abfd);
       else
        scn_base += SMALL_AOUTSZ;
+#endif
 #endif
     }
 
@@ -3523,9 +3506,10 @@ coff_write_object_contents (abfd)
 #endif
        {
          SCNHDR buff;
+         bfd_size_type amt = bfd_coff_scnhsz (abfd);
+
          if (coff_swap_scnhdr_out (abfd, &section, &buff) == 0
-             || bfd_write ((PTR) (&buff), 1, bfd_coff_scnhsz (abfd), abfd)
-             != bfd_coff_scnhsz (abfd))
+             || bfd_bwrite ((PTR) &buff, amt, abfd) != amt)
            return false;
        }
 
@@ -3625,6 +3609,7 @@ coff_write_object_contents (abfd)
     }
 
 #ifdef RS6000COFF_C
+#ifndef XCOFF64
   /* XCOFF handles overflows in the reloc and line number count fields
      by creating a new section header to hold the correct values.  */
   for (current = abfd->sections; current != NULL; current = current->next)
@@ -3633,6 +3618,7 @@ coff_write_object_contents (abfd)
        {
          struct internal_scnhdr scnhdr;
          SCNHDR buff;
+         bfd_size_type amt;
 
          internal_f.f_nscns++;
          strncpy (&(scnhdr.s_name[0]), current->name, 8);
@@ -3645,12 +3631,13 @@ coff_write_object_contents (abfd)
          scnhdr.s_nreloc = current->target_index;
          scnhdr.s_nlnno = current->target_index;
          scnhdr.s_flags = STYP_OVRFLO;
+         amt = bfd_coff_scnhsz (abfd);
          if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
-             || bfd_write ((PTR) &buff, 1, bfd_coff_scnhsz (abfd), abfd)
-             != bfd_coff_scnhsz (abfd))
+             || bfd_bwrite ((PTR) &buff, amt, abfd) != amt)
            return false;
        }
     }
+#endif
 #endif
 
   /* OK, now set up the filehdr...  */
@@ -3673,10 +3660,12 @@ coff_write_object_contents (abfd)
     {
       internal_f.f_opthdr = 0;
 #ifdef RS6000COFF_C
+#ifndef XCOFF64
       if (xcoff_data (abfd)->full_aouthdr)
        internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
       else
        internal_f.f_opthdr = SMALL_AOUTSZ;
+#endif
 #endif
     }
 
@@ -3890,9 +3879,9 @@ coff_write_object_contents (abfd)
          rounded up to the page size.  */
       b = 0;
       if (bfd_seek (abfd,
-                   BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
+                   (file_ptr) BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
                    SEEK_SET) != 0
-         || bfd_write (&b, 1, 1, abfd) != 1)
+         || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
        return false;
     }
 #endif
@@ -4016,14 +4005,14 @@ coff_write_object_contents (abfd)
 
   {
     char * buff;
-    bfd_size_type amount;
+    bfd_size_type amount = bfd_coff_filhsz (abfd);
 
-    buff = bfd_malloc (bfd_coff_filhsz (abfd));
+    buff = bfd_malloc (amount);
     if (buff == NULL)
       return false;
 
-    bfd_coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) buff);
-    amount = bfd_write ((PTR) buff, 1, bfd_coff_filhsz (abfd), abfd);
+    bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) buff);
+    amount = bfd_bwrite ((PTR) buff, amount, abfd);
 
     free (buff);
 
@@ -4036,14 +4025,14 @@ coff_write_object_contents (abfd)
       /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
         include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)) */
       char * buff;
-      bfd_size_type amount;
+      bfd_size_type amount = bfd_coff_aoutsz (abfd);
 
-      buff = bfd_malloc (bfd_coff_aoutsz (abfd));
+      buff = bfd_malloc (amount);
       if (buff == NULL)
        return false;
 
-      coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff);
-      amount = bfd_write ((PTR) buff, 1, bfd_coff_aoutsz (abfd), abfd);
+      coff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) buff);
+      amount = bfd_bwrite ((PTR) buff, amount, abfd);
 
       free (buff);
 
@@ -4062,7 +4051,7 @@ coff_write_object_contents (abfd)
        size = bfd_coff_aoutsz (abfd);
       else
        size = SMALL_AOUTSZ;
-      if (bfd_write ((PTR) &buff, 1, size, abfd) != size)
+      if (bfd_bwrite ((PTR) &buff, (bfd_size_type) size, abfd) != size)
        return false;
     }
 #endif
@@ -4129,14 +4118,13 @@ coff_set_section_contents (abfd, section, location, offset, count)
   if (section->filepos == 0)
     return true;
 
-  if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) != 0)
+  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
     return false;
 
-  if (count != 0)
-    {
-      return (bfd_write (location, 1, count, abfd) == count) ? true : false;
-    }
-  return true;
+  if (count == 0)
+    return true;
+
+  return bfd_bwrite (location, count, abfd) == count;
 }
 #if 0
 static boolean
@@ -4166,17 +4154,16 @@ coff_close_and_cleanup (abfd)
 #endif
 
 static PTR
-buy_and_read (abfd, where, seek_direction, size)
+buy_and_read (abfd, where, size)
      bfd *abfd;
      file_ptr where;
-     int seek_direction;
-     size_t size;
+     bfd_size_type size;
 {
   PTR area = (PTR) bfd_alloc (abfd, size);
   if (!area)
     return (NULL);
-  if (bfd_seek (abfd, where, seek_direction) != 0
-      || bfd_read (area, 1, size, abfd) != size)
+  if (bfd_seek (abfd, where, SEEK_SET) != 0
+      || bfd_bread (area, size, abfd) != size)
     return (NULL);
   return (area);
 }                              /* buy_and_read() */
@@ -4212,16 +4199,14 @@ coff_slurp_line_table (abfd, asect)
 {
   LINENO *native_lineno;
   alent *lineno_cache;
+  bfd_size_type amt;
 
   BFD_ASSERT (asect->lineno == (alent *) NULL);
 
-  native_lineno = (LINENO *) buy_and_read (abfd,
-                                          asect->line_filepos,
-                                          SEEK_SET,
-                                          (size_t) (bfd_coff_linesz (abfd) *
-                                                    asect->lineno_count));
-  lineno_cache =
-    (alent *) bfd_alloc (abfd, (size_t) ((asect->lineno_count + 1) * sizeof (alent)));
+  amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
+  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
+  amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
+  lineno_cache = (alent *) bfd_alloc (abfd, amt);
   if (lineno_cache == NULL)
     return false;
   else
@@ -4239,17 +4224,17 @@ coff_slurp_line_table (abfd, asect)
          if (cache_ptr->line_number == 0)
            {
              boolean warned;
-             long symndx;
+             bfd_signed_vma symndx;
              coff_symbol_type *sym;
 
              warned = false;
              symndx = dst.l_addr.l_symndx;
              if (symndx < 0
-                 || (unsigned long) symndx >= obj_raw_syment_count (abfd))
+                 || (bfd_vma) symndx >= obj_raw_syment_count (abfd))
                {
                  (*_bfd_error_handler)
                    (_("%s: warning: illegal symbol index %ld in line numbers"),
-                    bfd_get_filename (abfd), dst.l_addr.l_symndx);
+                    bfd_archive_filename (abfd), dst.l_addr.l_symndx);
                  symndx = 0;
                  warned = true;
                }
@@ -4263,7 +4248,7 @@ coff_slurp_line_table (abfd, asect)
                {
                  (*_bfd_error_handler)
                    (_("%s: warning: duplicate line number information for `%s'"),
-                    bfd_get_filename (abfd),
+                    bfd_archive_filename (abfd),
                     bfd_asymbol_name (&sym->symbol));
                }
              sym->lineno = cache_ptr;
@@ -4297,6 +4282,7 @@ coff_slurp_symbol_table (abfd)
   combined_entry_type *native_symbols;
   coff_symbol_type *cached_area;
   unsigned int *table_ptr;
+  bfd_size_type amt;
 
   unsigned int number_of_symbols = 0;
 
@@ -4310,17 +4296,15 @@ coff_slurp_symbol_table (abfd)
     }                          /* on error */
 
   /* Allocate enough room for all the symbols in cached form */
-  cached_area = ((coff_symbol_type *)
-                bfd_alloc (abfd,
-                           (obj_raw_syment_count (abfd)
-                            * sizeof (coff_symbol_type))));
-
+  amt = obj_raw_syment_count (abfd);
+  amt *= sizeof (coff_symbol_type);
+  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
   if (cached_area == NULL)
     return false;
-  table_ptr = ((unsigned int *)
-              bfd_alloc (abfd,
-                         (obj_raw_syment_count (abfd)
-                          * sizeof (unsigned int))));
+
+  amt = obj_raw_syment_count (abfd);
+  amt *= sizeof (unsigned int);
+  table_ptr = (unsigned int *) bfd_alloc (abfd, amt);
 
   if (table_ptr == NULL)
     return false;
@@ -4623,7 +4607,7 @@ coff_slurp_symbol_table (abfd)
            default:
              (*_bfd_error_handler)
                (_("%s: Unrecognized storage class %d for %s symbol `%s'"),
-                bfd_get_filename (abfd), src->u.syment.n_sclass,
+                bfd_archive_filename (abfd), src->u.syment.n_sclass,
                 dst->symbol.section->name, dst->symbol.name);
              dst->symbol.flags = BSF_DEBUGGING;
              dst->symbol.value = (src->u.syment.n_value);
@@ -4754,7 +4738,7 @@ coff_classify_symbol (abfd, syment)
 
       (*_bfd_error_handler)
        (_("warning: %s: local symbol `%s' has no section"),
-        bfd_get_filename (abfd),
+        bfd_archive_filename (abfd),
         _bfd_coff_internal_syment_name (abfd, syment, buf));
     }
 
@@ -4818,8 +4802,8 @@ coff_slurp_reloc_table (abfd, asect, symbols)
   RELOC *native_relocs;
   arelent *reloc_cache;
   arelent *cache_ptr;
-
   unsigned int idx;
+  bfd_size_type amt;
 
   if (asect->relocation)
     return true;
@@ -4829,14 +4813,10 @@ coff_slurp_reloc_table (abfd, asect, symbols)
     return true;
   if (!coff_slurp_symbol_table (abfd))
     return false;
-  native_relocs =
-    (RELOC *) buy_and_read (abfd,
-                           asect->rel_filepos,
-                           SEEK_SET,
-                           (size_t) (bfd_coff_relsz (abfd) *
-                                     asect->reloc_count));
-  reloc_cache = (arelent *)
-    bfd_alloc (abfd, (size_t) (asect->reloc_count * sizeof (arelent)));
+  amt = (bfd_size_type) bfd_coff_relsz (abfd) * asect->reloc_count;
+  native_relocs = (RELOC *) buy_and_read (abfd, asect->rel_filepos, amt);
+  amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
+  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
 
   if (reloc_cache == NULL)
     return false;
@@ -4865,7 +4845,7 @@ coff_slurp_reloc_table (abfd, asect, symbols)
            {
              (*_bfd_error_handler)
                (_("%s: warning: illegal symbol index %ld in relocs"),
-                bfd_get_filename (abfd), dst.r_symndx);
+                bfd_archive_filename (abfd), dst.r_symndx);
              cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
              ptr = NULL;
            }
@@ -4903,7 +4883,7 @@ coff_slurp_reloc_table (abfd, asect, symbols)
        {
          (*_bfd_error_handler)
            (_("%s: illegal relocation type %d at address 0x%lx"),
-            bfd_get_filename (abfd), dst.r_type, (long) dst.r_vaddr);
+            bfd_archive_filename (abfd), dst.r_type, (long) dst.r_vaddr);
          bfd_set_error (bfd_error_bad_value);
          return false;
        }
@@ -5258,6 +5238,10 @@ static const bfd_coff_backend_data bfd_coff_std_swap_table =
 #define coff_bfd_gc_sections               bfd_generic_gc_sections
 #endif
 
+#ifndef coff_bfd_merge_sections
+#define coff_bfd_merge_sections                    bfd_generic_merge_sections
+#endif
+
 #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE)        \
 const bfd_target VAR =                                                 \
 {                                                                      \
This page took 0.082632 seconds and 4 git commands to generate.