binutils ChangeLog:
[deliverable/binutils-gdb.git] / bfd / coffcode.h
index 1b6ef0be201a735007ff3fd3eb1246093ce83340..d50744695fd4e5bf2153486de17a098f6d306866 100644 (file)
@@ -1,24 +1,24 @@
 /* Support for the generic parts of most COFF variants, for BFD.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002
+   2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
-This file is part of BFD, the Binary File Descriptor library.
+   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 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.
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /*
 Most of this hacked by  Steve Chamberlain,
@@ -225,7 +225,7 @@ SUBSUBSECTION
        This routine runs though the provided symbol table and uses
        the offsets generated by the previous pass and the pointers
        generated when the symbol table was read in to create the
-       structured hierachy required by coff. It changes each pointer
+       structured hierarchy required by coff. It changes each pointer
        to a symbol into the index into the symbol table of the asymbol.
 
        o <<coff_write_symbols>>
@@ -309,6 +309,9 @@ CODE_FRAGMENT
 
 #define STRING_SIZE_SIZE (4)
 
+#define DOT_DEBUG      ".debug"
+#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
+
 static long sec_to_styp_flags
   PARAMS ((const char *, flagword));
 static bfd_boolean styp_to_sec_flags
@@ -333,7 +336,7 @@ static bfd_boolean coff_compute_section_file_positions
 static bfd_boolean coff_write_object_contents
   PARAMS ((bfd *)) ATTRIBUTE_UNUSED;
 static bfd_boolean coff_set_section_contents
-  PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
+  PARAMS ((bfd *, asection *, const PTR, file_ptr, bfd_size_type));
 static PTR buy_and_read
   PARAMS ((bfd *, file_ptr, bfd_size_type));
 static bfd_boolean coff_slurp_line_table
@@ -362,6 +365,12 @@ static unsigned int coff_compute_checksum
 static bfd_boolean coff_apply_checksum
   PARAMS ((bfd *));
 #endif
+#ifdef TICOFF
+static bfd_boolean ticoff0_bad_format_hook
+    PARAMS ((bfd *, PTR ));
+static bfd_boolean ticoff1_bad_format_hook
+    PARAMS ((bfd *, PTR ));
+#endif
 \f
 /* void warning(); */
 
@@ -422,7 +431,7 @@ sec_to_styp_flags (sec_name, sec_flags)
       styp_flags = STYP_LIT;
 #endif /* _LIT */
     }
-  else if (!strncmp (sec_name, ".debug", 6))
+  else if (!strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1))
     {
       /* Handle the XCOFF debug section and DWARF2 debug sections.  */
       if (!sec_name[6])
@@ -435,7 +444,7 @@ sec_to_styp_flags (sec_name, sec_flags)
       styp_flags = STYP_DEBUG_INFO;
     }
 #ifdef COFF_LONG_SECTION_NAMES
-  else if (!strncmp (sec_name, ".gnu.linkonce.wi.", 17))
+  else if (!strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1))
     {
       styp_flags = STYP_DEBUG_INFO;
     }
@@ -512,7 +521,7 @@ sec_to_styp_flags (sec_name, sec_flags)
 
 static long
 sec_to_styp_flags (sec_name, sec_flags)
-     const char *sec_name ATTRIBUTE_UNUSED;
+     const char *sec_name;
      flagword sec_flags;
 {
   long styp_flags = 0;
@@ -525,6 +534,11 @@ sec_to_styp_flags (sec_name, sec_flags)
      PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
      but there are more IMAGE_SCN_* flags.  */
 
+  /* FIXME: There is no gas syntax to specify the debug section flag.  */
+  if (strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
+      || strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0)
+    sec_flags = SEC_READONLY | SEC_DEBUGGING;
+
   /* skip LOAD */
   /* READONLY later */
   /* skip RELOC */
@@ -558,15 +572,15 @@ sec_to_styp_flags (sec_name, sec_flags)
 
   /* For now, the read/write bits are mapped onto SEC_READONLY, even
      though the semantics don't quite match.  The bits from the input
-     are retained in pei_section_data(abfd, section)->pe_flags */
+     are retained in pei_section_data(abfd, section)->pe_flags */
 
-  styp_flags |= IMAGE_SCN_MEM_READ;       /* always readable.  */
+  styp_flags |= IMAGE_SCN_MEM_READ;       /* Always readable.  */
   if ((sec_flags & SEC_READONLY) == 0)
-    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write */
+    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write */
   if (sec_flags & SEC_CODE)
-    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE */
+    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE */
   if (sec_flags & SEC_SHARED)
-    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful */
+    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful */
 
   return styp_flags;
 }
@@ -669,12 +683,12 @@ styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
 #endif
        sec_flags |= SEC_ALLOC;
     }
-  else if (strncmp (name, ".debug", 6) == 0
+  else if (strncmp (name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
 #ifdef _COMMENT
           || strcmp (name, _COMMENT) == 0
 #endif
 #ifdef COFF_LONG_SECTION_NAMES
-          || strncmp (name, ".gnu.linkonce.wi.", 17) == 0
+          || strncmp (name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0
 #endif
           || strncmp (name, ".stab", 5) == 0)
     {
@@ -693,12 +707,12 @@ styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
   else
     sec_flags |= SEC_ALLOC | SEC_LOAD;
 
-#ifdef STYP_LIT                        /* A29k readonly text/data section type */
+#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 */
 
-#ifdef STYP_OTHER_LOAD         /* Other loaded sections */
+#ifdef STYP_OTHER_LOAD         /* Other loaded sections */
   if (styp_flags & STYP_OTHER_LOAD)
     sec_flags = (SEC_LOAD | SEC_ALLOC);
 #endif /* STYP_SDATA */
@@ -802,7 +816,7 @@ handle_COMDAT (abfd, sec_flags, hdr, name, section)
             gas-generated, and look for <something> (whatever
             follows the $) as the comdat symbol.  */
 
-         /* All 3 branches use this */
+         /* All 3 branches use this */
          symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
 
          if (symname == NULL)
@@ -930,7 +944,7 @@ handle_COMDAT (abfd, sec_flags, hdr, name, section)
 #ifndef TARGET_UNDERSCORE
 #define TARGET_UNDERSCORE 0
 #endif
-             /* Is this the name we're looking for? */
+             /* Is this the name we're looking for ?  */
              if (strcmp (target_name,
                          symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
                {
@@ -1058,7 +1072,11 @@ styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
          sec_flags &= ~ SEC_READONLY;
          break;
        case IMAGE_SCN_MEM_DISCARDABLE:
-         sec_flags |= SEC_DEBUGGING;
+         /* The MS PE spec sets the DISCARDABLE flag on .reloc sections
+            but we do not want them to be labelled as debug section, since
+            then strip would remove them.  */
+         if (strncmp (name, ".reloc", sizeof ".reloc" - 1) != 0)
+           sec_flags |= SEC_DEBUGGING;
          break;
        case IMAGE_SCN_MEM_SHARED:
          sec_flags |= SEC_SHARED;
@@ -1344,7 +1362,8 @@ Special entry points for gdb to swap in coff symbol table parts:
 .#define 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, flags_ptr)\
 .  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
@@ -1369,7 +1388,8 @@ Special entry points for gdb to swap in coff symbol table parts:
 .  ((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)\
+.#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))
 .
@@ -1397,7 +1417,8 @@ Special entry points for gdb to swap in coff symbol table parts:
 .#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))
-.#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\
+.#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))
 .
@@ -1420,14 +1441,13 @@ coff_bad_format_hook (abfd, filehdr)
   if (BADMAG (*internal_f))
     return FALSE;
 
-  /* if the optional header is NULL or not the correct size then
+  /* If the optional header is NULL or not the correct size then
      quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
      and Intel 960 readwrite headers (I960WRMAGIC) is that the
      optional header is of a different size.
 
      But the mips keeps extra stuff in it's opthdr, so dont check
-     when doing that
-     */
+     when doing that.  */
 
 #if defined(M88) || defined(I960)
   if (internal_f->f_opthdr != 0 && bfd_coff_aoutsz (abfd) != internal_f->f_opthdr)
@@ -1437,6 +1457,36 @@ coff_bad_format_hook (abfd, filehdr)
   return TRUE;
 }
 
+#ifdef TICOFF
+static bfd_boolean
+ticoff0_bad_format_hook (abfd, filehdr)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     PTR filehdr;
+{
+  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
+
+  if (COFF0_BADMAG (*internal_f))
+    return FALSE;
+
+  return TRUE;
+}
+#endif
+
+#ifdef TICOFF
+static bfd_boolean
+ticoff1_bad_format_hook (abfd, filehdr)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     PTR filehdr;
+{
+  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
+
+  if (COFF1_BADMAG (*internal_f))
+    return FALSE;
+
+  return TRUE;
+}
+#endif
+
 /* Check whether this section uses an alignment other than the
    default.  */
 
@@ -1453,6 +1503,7 @@ coff_set_custom_section_alignment (abfd, section, alignment_table, table_size)
   for (i = 0; i < table_size; ++i)
     {
       const char *secname = bfd_get_section_name (abfd, section);
+
       if (alignment_table[i].comparison_length == (unsigned int) -1
          ? strcmp (alignment_table[i].name, secname) == 0
          : strncmp (alignment_table[i].name, secname,
@@ -1533,7 +1584,7 @@ coff_new_section_hook (abfd, section)
     return FALSE;
 
   /* We don't need to set up n_name, n_value, or n_scnum in the native
-     symbol information, since they'll be overriden by the BFD symbol
+     symbol information, since they'll be overridden by the BFD symbol
      anyhow.  However, we do need to set the type and storage class,
      in case this symbol winds up getting written out.  The value 0
      for n_numaux is already correct.  */
@@ -1566,13 +1617,13 @@ coff_set_alignment_hook (abfd, section, scnhdr)
   unsigned int i;
 
 #ifdef I960
-  /* Extract ALIGN from 2**ALIGN stored in section header */
+  /* Extract ALIGN from 2**ALIGN stored in section header */
   for (i = 0; i < 32; i++)
     if ((1 << i) >= hdr->s_align)
       break;
 #endif
 #ifdef TIC80COFF
-  /* TI tools puts the alignment power in bits 8-11 */
+  /* TI tools puts the alignment power in bits 8-11 */
   i = (hdr->s_flags >> 8) & 0xF ;
 #endif
 #ifdef COFF_DECODE_ALIGNMENT
@@ -1588,7 +1639,7 @@ coff_set_alignment_hook (abfd, section, scnhdr)
 #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
 #ifdef COFF_WITH_PE
 
-/* a couple of macros to help setting the alignment power field */
+/* A couple of macros to help setting the alignment power field.  */
 #define ALIGN_SET(field,x,y) \
   if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x )\
   {\
@@ -1649,21 +1700,27 @@ coff_set_alignment_hook (abfd, section, scnhdr)
 
   section->lma = hdr->s_vaddr;
 
-  /* check for extended relocs */
+  /* Check for extended relocs.  */
   if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
     {
       struct external_reloc dst;
       struct internal_reloc n;
       file_ptr oldpos = bfd_tell (abfd);
+      bfd_size_type relsz = bfd_coff_relsz (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))
+      if (bfd_bread ((PTR) &dst, relsz, abfd) != relsz)
        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 - 1;
+      section->rel_filepos += relsz;
     }
+  else if (hdr->s_nreloc == 0xffff)
+    (*_bfd_error_handler)
+      ("%s: warning: claims to have 0xffff relocs, without overflow",
+       bfd_get_filename (abfd));
 }
 #undef ALIGN_SET
 #undef ELIFALIGN_SET
@@ -1745,6 +1802,7 @@ coff_mkobject (abfd)
 #endif
 
 /* Create the COFF backend specific information.  */
+
 #ifndef coff_mkobject_hook
 static PTR
 coff_mkobject_hook (abfd, filehdr, aouthdr)
@@ -1879,21 +1937,25 @@ coff_set_arch_mach_hook (abfd, filehdr)
     case ARMPEMAGIC:
     case THUMBPEMAGIC:
       arch = bfd_arch_arm;
-      switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
+      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
+      if (machine == bfd_mach_arm_unknown)
        {
-        case F_ARM_2:  machine = bfd_mach_arm_2;  break;
-        case F_ARM_2a: machine = bfd_mach_arm_2a; break;
-        case F_ARM_3:  machine = bfd_mach_arm_3;  break;
-        default:
-        case F_ARM_3M: machine = bfd_mach_arm_3M; break;
-        case F_ARM_4:  machine = bfd_mach_arm_4;  break;
-        case F_ARM_4T: machine = bfd_mach_arm_4T; break;
-         /* The COFF header does not have enough bits available
-            to cover all the different ARM architectures.  So
-            we interpret F_ARM_5, the highest flag value to mean
-            "the highest ARM architecture known to BFD" which is
-            currently the XScale.  */
-        case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
+         switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
+           {
+           case F_ARM_2:  machine = bfd_mach_arm_2;  break;
+           case F_ARM_2a: machine = bfd_mach_arm_2a; break;
+           case F_ARM_3:  machine = bfd_mach_arm_3;  break;
+           default:
+           case F_ARM_3M: machine = bfd_mach_arm_3M; break;
+           case F_ARM_4:  machine = bfd_mach_arm_4;  break;
+           case F_ARM_4T: machine = bfd_mach_arm_4T; break;
+             /* The COFF header does not have enough bits available
+                to cover all the different ARM architectures.  So
+                we interpret F_ARM_5, the highest flag value to mean
+                "the highest ARM architecture known to BFD" which is
+                currently the XScale.  */
+           case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
+           }
        }
       break;
 #endif
@@ -2063,7 +2125,7 @@ coff_set_arch_mach_hook (abfd, filehdr)
     case H8300MAGIC:
       arch = bfd_arch_h8300;
       machine = bfd_mach_h8300;
-      /* !! FIXME this probably isn't the right place for this */
+      /* !! FIXME this probably isn't the right place for this */
       abfd->flags |= BFD_IS_RELAXABLE;
       break;
 #endif
@@ -2072,7 +2134,7 @@ coff_set_arch_mach_hook (abfd, filehdr)
     case H8300HMAGIC:
       arch = bfd_arch_h8300;
       machine = bfd_mach_h8300h;
-      /* !! FIXME this probably isn't the right place for this */
+      /* !! FIXME this probably isn't the right place for this */
       abfd->flags |= BFD_IS_RELAXABLE;
       break;
 #endif
@@ -2081,7 +2143,25 @@ coff_set_arch_mach_hook (abfd, filehdr)
     case H8300SMAGIC:
       arch = bfd_arch_h8300;
       machine = bfd_mach_h8300s;
-      /* !! FIXME this probably isn't the right place for this */
+      /* !! FIXME this probably isn't the right place for this.  */
+      abfd->flags |= BFD_IS_RELAXABLE;
+      break;
+#endif
+
+#ifdef H8300HNMAGIC
+    case H8300HNMAGIC:
+      arch = bfd_arch_h8300;
+      machine = bfd_mach_h8300hn;
+      /* !! FIXME this probably isn't the right place for this.  */
+      abfd->flags |= BFD_IS_RELAXABLE;
+      break;
+#endif
+
+#ifdef H8300SNMAGIC
+    case H8300SNMAGIC:
+      arch = bfd_arch_h8300;
+      machine = bfd_mach_h8300sn;
+      /* !! FIXME this probably isn't the right place for this.  */
       abfd->flags |= BFD_IS_RELAXABLE;
       break;
 #endif
@@ -2125,16 +2205,17 @@ coff_set_arch_mach_hook (abfd, filehdr)
 
 #ifdef TICOFF0MAGIC
 #ifdef TICOFF_TARGET_ARCH
-      /* this TI COFF section should be used by all new TI COFF v0 targets */
+      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
     case TICOFF0MAGIC:
       arch = TICOFF_TARGET_ARCH;
+      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
       break;
 #endif
 #endif
 
 #ifdef TICOFF1MAGIC
-      /* this TI COFF section should be used by all new TI COFF v1/2 targets */
-      /* TI COFF1 and COFF2 use the target_id field to specify which arch */
+      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
+      /* TI COFF1 and COFF2 use the target_id field to specify which arch */
     case TICOFF1MAGIC:
     case TICOFF2MAGIC:
       switch (internal_f->f_target_id)
@@ -2142,6 +2223,7 @@ coff_set_arch_mach_hook (abfd, filehdr)
 #ifdef TI_TARGET_ID
         case TI_TARGET_ID:
           arch = TICOFF_TARGET_ARCH;
+         machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
           break;
 #endif
         default:
@@ -2172,7 +2254,7 @@ coff_set_arch_mach_hook (abfd, filehdr)
       break;
 #endif
 
-    default:                   /* Unreadable input file type */
+    default:                   /* Unreadable input file type */
       arch = bfd_arch_obscure;
       break;
     }
@@ -2213,7 +2295,6 @@ static bfd_boolean coff_pointerize_aux_hook
   PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
           unsigned int, combined_entry_type *));
 
-/*ARGSUSED*/
 static bfd_boolean
 coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux)
      bfd *abfd ATTRIBUTE_UNUSED;
@@ -2253,7 +2334,6 @@ static bfd_boolean coff_pointerize_aux_hook
   PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
           unsigned int, combined_entry_type *));
 
-/*ARGSUSED*/
 static bfd_boolean
 coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux)
      bfd *abfd ATTRIBUTE_UNUSED;
@@ -2358,7 +2438,7 @@ SUBSUBSECTION
 
 static int compare_arelent_ptr PARAMS ((const PTR, const PTR));
 
-/* AUX's ld wants relocations to be sorted */
+/* AUX's ld wants relocations to be sorted */
 static int
 compare_arelent_ptr (x, y)
      const PTR x;
@@ -2391,7 +2471,7 @@ coff_write_relocs (abfd, first_undef)
       p = s->orelocation;
 #else
       {
-       /* sort relocations before we write them out */
+       /* Sort relocations before we write them out.  */
        bfd_size_type amt;
 
        amt = s->reloc_count;
@@ -2410,10 +2490,11 @@ coff_write_relocs (abfd, first_undef)
 #ifdef COFF_WITH_PE
       if (obj_pe (abfd) && s->reloc_count >= 0xffff)
        {
-         /* encode real count here as first reloc */
+         /* Encode real count here as first reloc.  */
          struct internal_reloc n;
+
          memset ((PTR) & n, 0, sizeof (n));
-         /* add one to count *this* reloc (grr) */
+         /* Add one to count *this* reloc (grr).  */
          n.r_vaddr = s->reloc_count + 1;
          coff_swap_reloc_out (abfd, &n, &dst);
          if (bfd_bwrite ((PTR) & dst, (bfd_size_type) bfd_coff_relsz (abfd),
@@ -2426,6 +2507,7 @@ coff_write_relocs (abfd, first_undef)
        {
          struct internal_reloc n;
          arelent *q = p[i];
+
          memset ((PTR) & n, 0, sizeof (n));
 
          /* Now we've renumbered the symbols we know where the
@@ -2443,11 +2525,13 @@ coff_write_relocs (abfd, first_undef)
              int j;
              const char *sname = q->sym_ptr_ptr[0]->name;
              asymbol **outsyms = abfd->outsymbols;
+
              for (j = first_undef; outsyms[j]; j++)
                {
                  const char *intable = outsyms[j]->name;
+
                  if (strcmp (intable, sname) == 0) {
-                   /* got a hit, so repoint the reloc */
+                   /* Got a hit, so repoint the reloc.  */
                    q->sym_ptr_ptr = outsyms + j;
                    break;
                  }
@@ -2490,12 +2574,13 @@ coff_write_relocs (abfd, first_undef)
 #endif
 
 #ifdef SELECT_RELOC
-         /* Work out reloc type from what is required */
+         /* Work out reloc type from what is required */
          SELECT_RELOC (n, q->howto);
 #else
          n.r_type = q->howto->type;
 #endif
          coff_swap_reloc_out (abfd, &n, &dst);
+
          if (bfd_bwrite ((PTR) & dst, (bfd_size_type) bfd_coff_relsz (abfd),
                         abfd) != bfd_coff_relsz (abfd))
            return FALSE;
@@ -2591,12 +2676,12 @@ coff_set_flags (abfd, magicp, flagsp)
 
 #ifdef TICOFF_DEFAULT_MAGIC
     case TICOFF_TARGET_ARCH:
-      /* if there's no indication of which version we want, use the default */
+      /* If there's no indication of which version we want, use the default.  */
       if (!abfd->xvec )
         *magicp = TICOFF_DEFAULT_MAGIC;
       else
         {
-          /* we may want to output in a different COFF version */
+          /* We may want to output in a different COFF version.  */
           switch (abfd->xvec->name[4])
             {
             case '0':
@@ -2612,6 +2697,7 @@ coff_set_flags (abfd, magicp, flagsp)
               return FALSE;
             }
         }
+      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
       return TRUE;
 #endif
 
@@ -2725,6 +2811,12 @@ coff_set_flags (abfd, magicp, flagsp)
        case bfd_mach_h8300s:
          *magicp = H8300SMAGIC;
          return TRUE;
+       case bfd_mach_h8300hn:
+         *magicp = H8300HNMAGIC;
+         return TRUE;
+       case bfd_mach_h8300sn:
+         *magicp = H8300SNMAGIC;
+         return TRUE;
        }
       break;
 #endif
@@ -2920,7 +3012,7 @@ coff_compute_section_file_positions (abfd)
        {
          asection *dsec;
 
-         dsec = bfd_make_section_old_way (abfd, ".debug");
+         dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
          if (dsec == NULL)
            abort ();
          dsec->_raw_size = sz;
@@ -2934,6 +3026,11 @@ coff_compute_section_file_positions (abfd)
   if (coff_data (abfd)->link_info)
     {
       page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
+
+      /* If no file alignment has been set, default to one.
+        This repairs 'ld -r' for arm-wince-pe target.  */
+      if (page_size == 0)
+        page_size = 1;
     }
   else
     page_size = PE_DEF_FILE_ALIGNMENT;
@@ -3088,14 +3185,14 @@ coff_compute_section_file_positions (abfd)
 #ifdef ALIGN_SECTIONS_IN_FILE
       if ((abfd->flags & EXEC_P) != 0)
        {
-         /* make sure this section is aligned on the right boundary - by
-            padding the previous section up if necessary */
+         /* Make sure this section is aligned on the right boundary - by
+            padding the previous section up if necessary */
 
          old_sofar = sofar;
 #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 executables, this check fails. This shows up when a 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
@@ -3125,9 +3222,7 @@ coff_compute_section_file_positions (abfd)
            }
 #endif
          if (previous != (asection *) NULL)
-           {
-             previous->_raw_size += sofar - old_sofar;
-           }
+           previous->_raw_size += sofar - old_sofar;
        }
 
 #endif
@@ -3149,7 +3244,7 @@ coff_compute_section_file_positions (abfd)
       sofar += current->_raw_size;
 
 #ifdef ALIGN_SECTIONS_IN_FILE
-      /* make sure that this section is of the right size too */
+      /* Make sure that this section is of the right size too.  */
       if ((abfd->flags & EXEC_P) == 0)
        {
          bfd_size_type old_size;
@@ -3238,10 +3333,11 @@ 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 */
+         /* 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;
@@ -3275,11 +3371,11 @@ coff_add_missing_symbols (abfd)
   if (!sympp2)
     return FALSE;
   memcpy (sympp2, sympp, i * sizeof (asymbol *));
+
   if (need_file)
-    {
-      /* @@ Generate fake .file symbol, in sympp2[i], and increment i.  */
-      abort ();
-    }
+    /* @@ Generate fake .file symbol, in sympp2[i], and increment i.  */
+    abort ();
+
   if (need_text)
     sympp2[i++] = coff_section_symbol (abfd, _TEXT);
   if (need_data)
@@ -3416,7 +3512,7 @@ coff_write_object_contents (abfd)
   bfd_set_error (bfd_error_system_call);
 
   /* Make a pass through the symbol table to count line number entries and
-     put them into the correct asections */
+     put them into the correct asections */
 
   lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
 
@@ -3428,13 +3524,13 @@ coff_write_object_contents (abfd)
 
   reloc_base = obj_relocbase (abfd);
 
-  /* Work out the size of the reloc and linno areas */
+  /* Work out the size of the reloc and linno areas */
 
   for (current = abfd->sections; current != NULL; current =
        current->next)
     {
 #ifdef COFF_WITH_PE
-      /* we store the actual reloc count in the first reloc's addr */
+      /* We store the actual reloc count in the first reloc's addr.  */
       if (obj_pe (abfd) && current->reloc_count >= 0xffff)
        reloc_count ++;
 #endif
@@ -3446,7 +3542,7 @@ coff_write_object_contents (abfd)
   lineno_base = reloc_base + reloc_size;
   sym_base = lineno_base + lnno_size;
 
-  /* Indicate in each section->line_filepos its actual file address */
+  /* Indicate in each section->line_filepos its actual file address */
   for (current = abfd->sections; current != NULL; current =
        current->next)
     {
@@ -3465,7 +3561,7 @@ coff_write_object_contents (abfd)
          current->rel_filepos = reloc_base;
          reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
 #ifdef COFF_WITH_PE
-         /* extra reloc to hold real count */
+         /* Extra reloc to hold real count.  */
          if (obj_pe (abfd) && current->reloc_count >= 0xffff)
            reloc_base += bfd_coff_relsz (abfd);
 #endif
@@ -3561,19 +3657,14 @@ coff_write_object_contents (abfd)
        section.s_paddr = 0;
 #endif
 
-      /*
-        If this section has no size or is unloadable then the scnptr
-        will be 0 too
-        */
+      /* If this section has no size or is unloadable then the scnptr
+        will be 0 too.  */
       if (current->_raw_size == 0 ||
          (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
-       {
-         section.s_scnptr = 0;
-       }
+       section.s_scnptr = 0;
       else
-       {
-         section.s_scnptr = current->filepos;
-       }
+       section.s_scnptr = current->filepos;
+
       section.s_relptr = current->rel_filepos;
       section.s_lnnoptr = current->line_filepos;
       section.s_nreloc = current->reloc_count;
@@ -3603,17 +3694,11 @@ coff_write_object_contents (abfd)
       section.s_flags = sec_to_styp_flags (current->name, current->flags);
 
       if (!strcmp (current->name, _TEXT))
-       {
-         text_sec = current;
-       }
+       text_sec = current;
       else if (!strcmp (current->name, _DATA))
-       {
-         data_sec = current;
-       }
+       data_sec = current;
       else if (!strcmp (current->name, _BSS))
-       {
-         bss_sec = current;
-       }
+       bss_sec = current;
 
 #ifdef I960
       section.s_align = (current->alignment_power
@@ -3621,7 +3706,7 @@ coff_write_object_contents (abfd)
                         : 0);
 #endif
 #ifdef TIC80COFF
-      /* TI COFF puts the alignment power in bits 8-11 of the flags */
+      /* TI COFF puts the alignment power in bits 8-11 of the flags */
       section.s_flags |= (current->alignment_power & 0xF) << 8;
 #endif
 #ifdef COFF_ENCODE_ALIGNMENT
@@ -3778,14 +3863,11 @@ coff_write_object_contents (abfd)
 
   /* Don't include the internal abs section in the section count */
 
-  /*
-     We will NOT put a fucking timestamp in the header here. Every time you
+  /* We will NOT put a fucking timestamp in the header here. Every time you
      put it back, I will come in and take it out again.  I'm sorry.  This
      field does not belong here.  We fill it with a 0 so it compares the
-     same but is not a reasonable time. -- gnu@cygnus.com
-     */
+     same but is not a reasonable time. -- gnu@cygnus.com  */
   internal_f.f_timdat = 0;
-
   internal_f.f_flags = 0;
 
   if (abfd->flags & EXEC_P)
@@ -3812,9 +3894,13 @@ coff_write_object_contents (abfd)
 #ifdef COFF_IMAGE_WITH_PE
   if (! hasdebug)
     internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
+  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
+    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
 #endif
 
-#ifndef COFF_WITH_PE
+#ifdef COFF_WITH_PE
+  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
+#else
   if (bfd_little_endian (abfd))
     internal_f.f_flags |= F_AR32WR;
   else
@@ -3822,18 +3908,16 @@ coff_write_object_contents (abfd)
 #endif
 
 #ifdef TI_TARGET_ID
-  /* target id is used in TI COFF v1 and later; COFF0 won't use this field,
-     but it doesn't hurt to set it internally */
+  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
+     but it doesn't hurt to set it internally */
   internal_f.f_target_id = TI_TARGET_ID;
 #endif
 #ifdef TIC80_TARGET_ID
   internal_f.f_target_id = TIC80_TARGET_ID;
 #endif
 
-  /*
-     FIXME, should do something about the other byte orders and
-     architectures.
-     */
+  /* FIXME, should do something about the other byte orders and
+     architectures.  */
 
 #ifdef RS6000COFF_C
   if ((abfd->flags & DYNAMIC) != 0)
@@ -3844,11 +3928,11 @@ coff_write_object_contents (abfd)
 
   memset (&internal_a, 0, sizeof internal_a);
 
-  /* Set up architecture-dependent stuff */
-
+  /* 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;
@@ -3857,14 +3941,13 @@ coff_write_object_contents (abfd)
 #ifdef A29K
 #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.
-     */
+       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 */
+      internal_a.magic = SHMAGIC; /* Shared magic */
     else
 #endif /* ULTRA3 */
-      internal_a.magic = NMAGIC; /* Assume separate i/d */
+      internal_a.magic = NMAGIC; /* Assume separate i/d */
 #define __A_MAGIC_SET__
 #endif /* A29K */
 #ifdef TICOFF_AOUT_MAGIC
@@ -3979,7 +4062,7 @@ coff_write_object_contents (abfd)
   /* FIXME: Does anybody ever set this to another value?  */
   internal_a.vstamp = 0;
 
-  /* Now should write relocs, strings, syms */
+  /* Now should write relocs, strings, syms */
   obj_sym_filepos (abfd) = sym_base;
 
   if (bfd_get_symcount (abfd) != 0)
@@ -4162,7 +4245,7 @@ coff_write_object_contents (abfd)
   if (abfd->flags & EXEC_P)
     {
       /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
-        include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)) */
+        include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)) */
       char * buff;
       bfd_size_type amount = bfd_coff_aoutsz (abfd);
 
@@ -4207,11 +4290,11 @@ static bfd_boolean
 coff_set_section_contents (abfd, section, location, offset, count)
      bfd * abfd;
      sec_ptr section;
-     PTR location;
+     const PTR location;
      file_ptr offset;
      bfd_size_type count;
 {
-  if (! abfd->output_has_begun)        /* set by bfd.c handler */
+  if (! abfd->output_has_begun)        /* Set by bfd.c handler.  */
     {
       if (! coff_compute_section_file_positions (abfd))
        return FALSE;
@@ -4238,7 +4321,7 @@ coff_set_section_contents (abfd, section, location, offset, count)
       code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
       <robertl@arnet.com> (Thanks!).
 
-      Gvran Uddeborg <gvran@uddeborg.pp.se> */
+      Gvran Uddeborg <gvran@uddeborg.pp.se> */
 
     if (strcmp (section->name, _LIB) == 0)
       {
@@ -4349,6 +4432,13 @@ coff_slurp_line_table (abfd, asect)
 
   amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
   native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
+  if (native_lineno == NULL)
+    {
+      (*_bfd_error_handler)
+        (_("%s: warning: line number table read failed"),
+        bfd_archive_filename (abfd));
+      return FALSE;
+    }
   amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
   lineno_cache = (alent *) bfd_alloc (abfd, amt);
   if (lineno_cache == NULL)
@@ -4362,6 +4452,7 @@ coff_slurp_line_table (abfd, asect)
       while (counter < asect->lineno_count)
        {
          struct internal_lineno dst;
+
          bfd_coff_swap_lineno_in (abfd, src, &dst);
          cache_ptr->line_number = dst.l_lnno;
 
@@ -4427,19 +4518,16 @@ coff_slurp_symbol_table (abfd)
   coff_symbol_type *cached_area;
   unsigned int *table_ptr;
   bfd_size_type amt;
-
   unsigned int number_of_symbols = 0;
 
   if (obj_symbols (abfd))
     return TRUE;
 
-  /* Read in the symbol table */
+  /* Read in the symbol table */
   if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
-    {
-      return FALSE;
-    }                          /* on error */
+    return FALSE;
 
-  /* Allocate enough room for all the symbols in cached form */
+  /* Allocate enough room for all the symbols in cached form */
   amt = obj_raw_syment_count (abfd);
   amt *= sizeof (coff_symbol_type);
   cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
@@ -4457,6 +4545,7 @@ coff_slurp_symbol_table (abfd)
       coff_symbol_type *dst = cached_area;
       unsigned int last_native_index = obj_raw_syment_count (abfd);
       unsigned int this_index = 0;
+
       while (this_index < last_native_index)
        {
          combined_entry_type *src = native_symbols + this_index;
@@ -4480,8 +4569,7 @@ coff_slurp_symbol_table (abfd)
              dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
              dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
 #endif
-             /* Fall through to next case */
-
+             /* Fall through to next case.  */
 #endif
 
            case C_EXT:
@@ -4494,10 +4582,10 @@ coff_slurp_symbol_table (abfd)
            case C_HIDEXT:
 #endif
 #ifdef C_SYSTEM
-           case C_SYSTEM:      /* System Wide variable */
+           case C_SYSTEM:      /* System Wide variable */
 #endif
 #ifdef COFF_WITH_PE
-            /* In PE, 0x68 (104) denotes a section symbol */
+            /* In PE, 0x68 (104) denotes a section symbol */
             case C_SECTION:
            /* In PE, 0x69 (105) denotes a weak external symbol.  */
            case C_NT_WEAK:
@@ -4571,16 +4659,16 @@ coff_slurp_symbol_table (abfd)
 
              break;
 
-           case C_STAT:        /* static                        */
+           case C_STAT:         /* Static.  */
 #ifdef I960
-           case C_LEAFSTAT:    /* static leaf procedure        */
+           case C_LEAFSTAT:     /* Static leaf procedure.  */
 #endif
 #if defined ARM
-            case C_THUMBSTAT:   /* Thumb static                  */
-            case C_THUMBLABEL:  /* Thumb label                   */
-            case C_THUMBSTATFUNC:/* Thumb static function        */
+            case C_THUMBSTAT:    /* Thumb static.  */
+            case C_THUMBLABEL:   /* Thumb label.  */
+            case C_THUMBSTATFUNC:/* Thumb static function.  */
 #endif
-           case C_LABEL:       /* label                         */
+           case C_LABEL:        /* Label.  */
              if (src->u.syment.n_scnum == N_DEBUG)
                dst->symbol.flags = BSF_DEBUGGING;
              else
@@ -4603,35 +4691,35 @@ coff_slurp_symbol_table (abfd)
                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 */
+           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             */
-              /* C_AUTOARG conflictes with TI COFF C_UEXT */
+           case C_REGPARM:     /* Register parameter.  */
+           case C_REG:         /* register variable.  */
+              /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
 #if !defined (TIC80COFF) && !defined (TICOFF)
 #ifdef C_AUTOARG
-           case C_AUTOARG:     /* 960-specific storage class */
+           case C_AUTOARG:     /* 960-specific storage class */
 #endif
 #endif
-           case C_TPDEF:       /* type definition               */
+           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                     */
+           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_FILE:        /* File name.  */
+           case C_STRTAG:      /* Structure tag.  */
 #ifdef RS6000COFF_C
            case C_GSYM:
            case C_LSYM:
@@ -4639,7 +4727,9 @@ coff_slurp_symbol_table (abfd)
            case C_RSYM:
            case C_RPSYM:
            case C_STSYM:
+           case C_TCSYM:
            case C_BCOMM:
+           case C_ECOML:
            case C_ECOMM:
            case C_DECL:
            case C_ENTRY:
@@ -4651,8 +4741,8 @@ coff_slurp_symbol_table (abfd)
              break;
 
 #ifdef RS6000COFF_C
-           case C_BINCL:       /* beginning of include file     */
-           case C_EINCL:       /* ending of include file        */
+           case C_BINCL:       /* Beginning of include file.  */
+           case C_EINCL:       /* Ending of include file.  */
              /* The value is actually a pointer into the line numbers
                  of the file.  We locate the line number entry, and
                  set the section to the section which contains it, and
@@ -4693,9 +4783,9 @@ coff_slurp_symbol_table (abfd)
              break;
 #endif
 
-           case C_BLOCK:       /* ".bb" or ".eb"                */
-           case C_FCN:         /* ".bf" or ".ef" (or PE ".lf")  */
-           case C_EFCN:        /* physical end of function      */
+           case C_BLOCK:       /* ".bb" or ".eb".  */
+           case C_FCN:         /* ".bf" or ".ef" (or PE ".lf").  */
+           case C_EFCN:        /* Physical end of function.  */
 #if defined COFF_WITH_PE
              /* PE sets the symbol to a value relative to the start
                 of the section.  */
@@ -4717,7 +4807,7 @@ coff_slurp_symbol_table (abfd)
 #endif
              break;
 
-           case C_STATLAB:     /* Static load time label */
+           case C_STATLAB:     /* Static load time label */
               dst->symbol.value = src->u.syment.n_value;
               dst->symbol.flags = BSF_GLOBAL;
               break;
@@ -4730,22 +4820,22 @@ coff_slurp_symbol_table (abfd)
                  && src->u.syment.n_scnum == 0)
                break;
              /* Fall through.  */
-           case C_EXTDEF:      /* external definition           */
-           case C_ULABEL:      /* undefined label               */
-           case C_USTATIC:     /* undefined static              */
+           case C_EXTDEF:      /* External definition.  */
+           case C_ULABEL:      /* Undefined label.  */
+           case C_USTATIC:     /* Undefined static.  */
 #ifndef COFF_WITH_PE
             /* C_LINE in regular coff is 0x68.  NT has taken over this storage
-               class to represent a section symbol */
-           case C_LINE:        /* line # reformatted as symbol table entry */
+               class to represent a section symbol */
+           case C_LINE:        /* line # reformatted as symbol table entry */
              /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
-           case C_ALIAS:       /* duplicate tag                 */
+           case C_ALIAS:       /* Duplicate tag.  */
 #endif
-             /* New storage classes for TI COFF */
+             /* New storage classes for TI COFF */
 #if defined(TIC80COFF) || defined(TICOFF)
-           case C_UEXT:        /* Tentative external definition */
+           case C_UEXT:        /* Tentative external definition */
 #endif
-           case C_EXTLAB:      /* External load time label */
-           case C_HIDDEN:      /* ext symbol in dmert public lib */
+           case C_EXTLAB:      /* External load time label */
+           case C_HIDDEN:      /* Ext symbol in dmert public lib.  */
            default:
              (*_bfd_error_handler)
                (_("%s: Unrecognized storage class %d for %s symbol `%s'"),
@@ -4765,17 +4855,18 @@ coff_slurp_symbol_table (abfd)
          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;
 
   bfd_get_symcount (abfd) = number_of_symbols;
   obj_convert (abfd) = table_ptr;
-  /* Slurp the line tables for each section too */
+  /* Slurp the line tables for each section too */
   {
     asection *p;
+
     p = abfd->sections;
     while (p)
       {
@@ -4783,6 +4874,7 @@ coff_slurp_symbol_table (abfd)
        p = p->next;
       }
   }
+
   return TRUE;
 }                              /* coff_slurp_symbol_table() */
 
@@ -5009,15 +5101,15 @@ coff_slurp_reloc_table (abfd, asect, symbols)
         refering to the symbols in the raw data have not been
         modified, so we have to have a negative addend to compensate.
 
-        Note that symbols which used to be common must be left alone */
+        Note that symbols which used to be common must be left alone */
 
-      /* Calculate any reloc addend by looking at the symbol */
+      /* Calculate any reloc addend by looking at the symbol */
       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 */
+      /* Fill in the cache_ptr->howto field from dst.r_type */
       RTYPE2HOWTO (cache_ptr, &dst);
 #endif /* RELOC_PROCESSING */
 
@@ -5049,7 +5141,6 @@ static reloc_howto_type *coff_rtype_to_howto
           struct coff_link_hash_entry *, struct internal_syment *,
           bfd_vma *));
 
-/*ARGSUSED*/
 static reloc_howto_type *
 coff_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
      bfd *abfd ATTRIBUTE_UNUSED;
@@ -5085,16 +5176,16 @@ coff_canonicalize_reloc (abfd, section, relptr, symbols)
 
   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 */
+      /* 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;
        }
-
     }
   else
     {
@@ -5318,6 +5409,92 @@ static const bfd_coff_backend_data bfd_coff_std_swap_table =
   coff_link_output_has_begun, coff_final_link_postscript
 };
 
+#ifdef TICOFF
+/* COFF0 differs in file/section header size and relocation entry size.  */
+static const bfd_coff_backend_data ticoff0_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_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
+#ifdef COFF_LONG_FILENAMES
+  TRUE,
+#else
+  FALSE,
+#endif
+#ifdef COFF_LONG_SECTION_NAMES
+  TRUE,
+#else
+  FALSE,
+#endif
+  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
+#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
+  TRUE,
+#else
+  FALSE,
+#endif
+#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
+  4,
+#else
+  2,
+#endif
+  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
+  coff_SWAP_reloc_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
+  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
+  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
+  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
+  coff_classify_symbol, coff_compute_section_file_positions,
+  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
+  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_link_output_has_begun, coff_final_link_postscript
+};
+#endif
+
+#ifdef TICOFF
+/* COFF1 differs in section header size.  */
+static const bfd_coff_backend_data ticoff1_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_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
+#ifdef COFF_LONG_FILENAMES
+  TRUE,
+#else
+  FALSE,
+#endif
+#ifdef COFF_LONG_SECTION_NAMES
+  TRUE,
+#else
+  FALSE,
+#endif
+  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
+#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
+  TRUE,
+#else
+  FALSE,
+#endif
+#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
+  4,
+#else
+  2,
+#endif
+  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
+  coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
+  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
+  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
+  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
+  coff_classify_symbol, coff_compute_section_file_positions,
+  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
+  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_link_output_has_begun, coff_final_link_postscript
+};
+#endif
+
 #ifndef coff_close_and_cleanup
 #define        coff_close_and_cleanup              _bfd_generic_close_and_cleanup
 #endif
@@ -5334,6 +5511,10 @@ static const bfd_coff_backend_data bfd_coff_std_swap_table =
 #define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef coff_bfd_copy_private_header_data
+#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef coff_bfd_copy_private_section_data
 #define coff_bfd_copy_private_section_data  _bfd_generic_bfd_copy_private_section_data
 #endif
@@ -5389,11 +5570,15 @@ static const bfd_coff_backend_data bfd_coff_std_swap_table =
 #define coff_bfd_merge_sections                    bfd_generic_merge_sections
 #endif
 
+#ifndef coff_bfd_is_group_section
+#define coff_bfd_is_group_section          bfd_generic_is_group_section
+#endif
+
 #ifndef coff_bfd_discard_group
 #define coff_bfd_discard_group             bfd_generic_discard_group
 #endif
 
-#define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE)        \
+#define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)    \
 const bfd_target VAR =                                                 \
 {                                                                      \
   NAME ,                                                               \
@@ -5440,10 +5625,60 @@ const bfd_target VAR =                                                  \
                                                                        \
   ALTERNATIVE,                                                         \
                                                                        \
-  COFF_SWAP_TABLE                                                      \
+  SWAP_TABLE                                                           \
+};
+
+#define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
+const bfd_target VAR =                                                 \
+{                                                                      \
+  NAME ,                                                               \
+  bfd_target_coff_flavour,                                             \
+  BFD_ENDIAN_LITTLE,           /* data byte order is little */         \
+  BFD_ENDIAN_BIG,              /* header byte order is big */          \
+  /* object flags */                                                   \
+  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |                       \
+   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),                   \
+  /* section flags */                                                  \
+  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
+  UNDER,                       /* leading symbol underscore */         \
+  '/',                         /* ar_pad_char */                       \
+  15,                          /* ar_max_namelen */                    \
+                                                                       \
+  /* Data conversion functions.  */                                    \
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,                          \
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,                          \
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,                          \
+                                                                       \
+  /* Header conversion functions.  */                                  \
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,                          \
+  bfd_getb32, bfd_getb_signed_32, bfd_putb32,                          \
+  bfd_getb16, bfd_getb_signed_16, bfd_putb16,                          \
+                                                                       \
+       /* bfd_check_format */                                          \
+  { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p,           \
+    _bfd_dummy_target },                                               \
+       /* bfd_set_format */                                            \
+  { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false },     \
+       /* bfd_write_contents */                                        \
+  { bfd_false, coff_write_object_contents, _bfd_write_archive_contents,        \
+    bfd_false },                                                       \
+                                                                       \
+  BFD_JUMP_TABLE_GENERIC (coff),                                       \
+  BFD_JUMP_TABLE_COPY (coff),                                          \
+  BFD_JUMP_TABLE_CORE (_bfd_nocore),                                   \
+  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),                          \
+  BFD_JUMP_TABLE_SYMBOLS (coff),                                       \
+  BFD_JUMP_TABLE_RELOCS (coff),                                                \
+  BFD_JUMP_TABLE_WRITE (coff),                                         \
+  BFD_JUMP_TABLE_LINK (coff),                                          \
+  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),                             \
+                                                                       \
+  ALTERNATIVE,                                                         \
+                                                                       \
+  SWAP_TABLE                                                           \
 };
 
-#define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE)     \
+#define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
 const bfd_target VAR =                                                 \
 {                                                                      \
   NAME ,                                                               \
@@ -5488,5 +5723,5 @@ const bfd_target VAR =                                                    \
                                                                        \
   ALTERNATIVE,                                                         \
                                                                        \
-  COFF_SWAP_TABLE                                                      \
+  SWAP_TABLE                                                           \
 };
This page took 0.048782 seconds and 4 git commands to generate.