2007-05-25 Andreas Tobler <a.tobler@schweiz.org>
[deliverable/binutils-gdb.git] / bfd / coffcode.h
index cec3992146d4e270a301f6437e70581ba1880083..a2aac5f63b4ccff42f4768a43d5ae82eb878d2ec 100644 (file)
@@ -1,6 +1,6 @@
 /* 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, 2003, 2004, 2005
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -18,7 +18,7 @@
 
    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.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 /* Most of this hacked by  Steve Chamberlain,
                        sac@cygnus.com.  */
@@ -427,7 +427,7 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
       styp_flags = STYP_LIT;
 #endif /* _LIT */
     }
-  else if (!strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1))
+  else if (CONST_STRNEQ (sec_name, DOT_DEBUG))
     {
       /* Handle the XCOFF debug section and DWARF2 debug sections.  */
       if (!sec_name[6])
@@ -435,12 +435,12 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
       else
         styp_flags = STYP_DEBUG_INFO;
     }
-  else if (!strncmp (sec_name, ".stab", 5))
+  else if (CONST_STRNEQ (sec_name, ".stab"))
     {
       styp_flags = STYP_DEBUG_INFO;
     }
 #ifdef COFF_LONG_SECTION_NAMES
-  else if (!strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1))
+  else if (CONST_STRNEQ (sec_name, GNU_LINKONCE_WI))
     {
       styp_flags = STYP_DEBUG_INFO;
     }
@@ -529,9 +529,9 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
      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;
+  if (CONST_STRNEQ (sec_name, DOT_DEBUG)
+      || CONST_STRNEQ (sec_name, GNU_LINKONCE_WI))
+    sec_flags = SEC_DEBUGGING;
 
   /* skip LOAD */
   /* READONLY later */
@@ -545,10 +545,6 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
   /* skip ROM */
   /* skip constRUCTOR */
   /* skip CONTENTS */
-#ifdef STYP_NOLOAD
-  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
-    styp_flags |= STYP_NOLOAD;
-#endif
   if ((sec_flags & SEC_IS_COMMON) != 0)
     styp_flags |= IMAGE_SCN_LNK_COMDAT;
   if ((sec_flags & SEC_DEBUGGING) != 0)
@@ -564,17 +560,19 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
   /* skip LINK_DUPLICATES */
   /* skip LINKER_CREATED */
 
-  /* 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.  */
-
-  styp_flags |= IMAGE_SCN_MEM_READ;       /* Always readable.  */
-  if ((sec_flags & SEC_READONLY) == 0)
-    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
-  if (sec_flags & SEC_CODE)
-    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
-  if (sec_flags & SEC_COFF_SHARED)
-    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
+  if (sec_flags & (SEC_ALLOC | SEC_LOAD))
+    {
+      /* 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.  */
+      styp_flags |= IMAGE_SCN_MEM_READ;       /* Always readable.  */
+      if ((sec_flags & SEC_READONLY) == 0)
+       styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
+      if (sec_flags & SEC_CODE)
+       styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
+      if (sec_flags & SEC_COFF_SHARED)
+       styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
+    }
 
   return styp_flags;
 }
@@ -676,14 +674,14 @@ styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
 #endif
        sec_flags |= SEC_ALLOC;
     }
-  else if (strncmp (name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
+  else if (CONST_STRNEQ (name, DOT_DEBUG)
 #ifdef _COMMENT
           || strcmp (name, _COMMENT) == 0
 #endif
 #ifdef COFF_LONG_SECTION_NAMES
-          || strncmp (name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0
+          || CONST_STRNEQ (name, GNU_LINKONCE_WI)
 #endif
-          || strncmp (name, ".stab", 5) == 0)
+          || CONST_STRNEQ (name, ".stab"))
     {
 #ifdef COFF_PAGE_SIZE
       sec_flags |= SEC_DEBUGGING;
@@ -717,7 +715,7 @@ styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
      The symbols will be defined as weak, so that multiple definitions
      are permitted.  The GNU linker extension is to actually discard
      all but one of the sections.  */
-  if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
+  if (CONST_STRNEQ (name, ".gnu.linkonce"))
     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
@@ -1073,7 +1071,7 @@ styp_to_sec_flags (bfd *abfd,
          /* 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)
+         if (! CONST_STRNEQ (name, ".reloc"))
            sec_flags |= SEC_DEBUGGING;
          break;
        case IMAGE_SCN_MEM_SHARED:
@@ -1128,7 +1126,7 @@ styp_to_sec_flags (bfd *abfd,
      The symbols will be defined as weak, so that multiple definitions
      are permitted.  The GNU linker extension is to actually discard
      all but one of the sections.  */
-  if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
+  if (CONST_STRNEQ (name, ".gnu.linkonce"))
     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
@@ -1562,6 +1560,10 @@ coff_new_section_hook (bfd * abfd, asection * section)
     section->alignment_power = bfd_xcoff_data_align_power (abfd);
 #endif
 
+  /* Set up the section symbol.  */
+  if (!_bfd_generic_new_section_hook (abfd, section))
+    return FALSE;
+
   /* Allocate aux records for section symbols, to store size and
      related info.
 
@@ -1880,9 +1882,15 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
 #ifdef I386MAGIC
     case I386MAGIC:
     case I386PTXMAGIC:
-    case I386AIXMAGIC:         /* Danbury PS/2 AIX C Compiler */
-    case LYNXCOFFMAGIC:        /* shadows the m68k Lynx number below, sigh */
+    case I386AIXMAGIC:         /* Danbury PS/2 AIX C Compiler.  */
+    case LYNXCOFFMAGIC:                /* Shadows the m68k Lynx number below, sigh.  */
+      arch = bfd_arch_i386;
+      break;
+#endif
+#ifdef AMD64MAGIC
+    case AMD64MAGIC:
       arch = bfd_arch_i386;
+      machine = bfd_mach_x86_64;
       break;
 #endif
 #ifdef IA64MAGIC
@@ -1890,12 +1898,6 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
       arch = bfd_arch_ia64;
       break;
 #endif
-#ifdef A29K_MAGIC_BIG
-    case A29K_MAGIC_BIG:
-    case A29K_MAGIC_LITTLE:
-      arch = bfd_arch_a29k;
-      break;
-#endif
 #ifdef ARMMAGIC
     case ARMMAGIC:
     case ARMPEMAGIC:
@@ -1963,6 +1965,23 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
       machine = 88100;
       break;
 #endif
+#ifdef Z80MAGIC
+    case Z80MAGIC:
+      arch = bfd_arch_z80;
+      switch (internal_f->f_flags & F_MACHMASK)
+       {
+       case 0:
+       case bfd_mach_z80strict << 12:
+       case bfd_mach_z80 << 12:
+       case bfd_mach_z80full << 12:
+       case bfd_mach_r800 << 12:
+         machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
+         break;
+       default:
+         return FALSE;
+       }
+      break;
+#endif
 #ifdef Z8KMAGIC
     case Z8KMAGIC:
       arch = bfd_arch_z8k;
@@ -2519,11 +2538,15 @@ coff_write_relocs (bfd * abfd, int first_undef)
                else
                  {
                    n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
-                   /* Take notice if the symbol reloc points to a symbol
-                      we don't have in our symbol table.  What should we
-                      do for this??  */
+                   /* Check to see if the symbol reloc points to a symbol
+                      we don't have in our symbol table.  */
                    if (n.r_symndx > obj_conv_table_size (abfd))
-                     abort ();
+                     {
+                       bfd_set_error (bfd_error_bad_value);
+                       _bfd_error_handler (_("%B: reloc against a non-existant symbol index: %ld"),
+                                           abfd, n.r_symndx);
+                       return FALSE;
+                     }
                  }
              }
 
@@ -2563,6 +2586,24 @@ coff_set_flags (bfd * abfd,
 {
   switch (bfd_get_arch (abfd))
     {
+#ifdef Z80MAGIC
+    case bfd_arch_z80:
+      *magicp = Z80MAGIC;
+      switch (bfd_get_mach (abfd))
+       {
+       case 0:
+       case bfd_mach_z80strict:
+       case bfd_mach_z80:
+       case bfd_mach_z80full:
+       case bfd_mach_r800:
+         *flagsp = bfd_get_mach (abfd) << 12;
+         break;
+       default:
+         return FALSE;
+       }
+      return TRUE;
+#endif
+
 #ifdef Z8KMAGIC
     case bfd_arch_z8k:
       *magicp = Z8KMAGIC;
@@ -2686,12 +2727,17 @@ coff_set_flags (bfd * abfd,
       return TRUE;
 #endif
 
-#ifdef I386MAGIC
+#if defined(I386MAGIC) || defined(AMD64MAGIC)
     case bfd_arch_i386:
+#if defined(I386MAGIC)
       *magicp = I386MAGIC;
-#ifdef LYNXOS
+#endif
+#if defined LYNXOS
       /* Just overwrite the usual value if we're doing Lynx.  */
       *magicp = LYNXCOFFMAGIC;
+#endif
+#if defined AMD64MAGIC
+      *magicp = AMD64MAGIC;
 #endif
       return TRUE;
 #endif
@@ -2783,15 +2829,6 @@ coff_set_flags (bfd * abfd,
       break;
 #endif
 
-#ifdef A29K_MAGIC_BIG
-    case bfd_arch_a29k:
-      if (bfd_big_endian (abfd))
-       *magicp = A29K_MAGIC_BIG;
-      else
-       *magicp = A29K_MAGIC_LITTLE;
-      return TRUE;
-#endif
-
 #ifdef WE32KMAGIC
     case bfd_arch_we32k:
       *magicp = WE32KMAGIC;
@@ -3733,6 +3770,7 @@ coff_write_object_contents (bfd * abfd)
     internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
 #endif
 
+#ifndef COFF_WITH_pex64
 #ifdef COFF_WITH_PE
   internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
 #else
@@ -3741,6 +3779,7 @@ coff_write_object_contents (bfd * abfd)
   else
     internal_f.f_flags |= F_AR32W;
 #endif
+#endif
 
 #ifdef TI_TARGET_ID
   /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
@@ -3773,18 +3812,6 @@ coff_write_object_contents (bfd * abfd)
     internal_f.f_flags |= flags;
     /* ...and the "opt"hdr...  */
 
-#ifdef A29K
-#ifdef ULTRA3                  /* NYU's machine */
-    /* FIXME: This is a bogus check.  I really want to see if there
-       is a .shbss or a .shdata section, if so then set the magic
-       number to indicate a shared data executable.  */
-    if (internal_f.f_nscns >= 7)
-      internal_a.magic = SHMAGIC; /* Shared magic.  */
-    else
-#endif /* ULTRA3 */
-      internal_a.magic = NMAGIC; /* Assume separate i/d.  */
-#define __A_MAGIC_SET__
-#endif /* A29K */
 #ifdef TICOFF_AOUT_MAGIC
     internal_a.magic = TICOFF_AOUT_MAGIC;
 #define __A_MAGIC_SET__
@@ -3846,16 +3873,18 @@ coff_write_object_contents (bfd * abfd)
 
 #if defined(I386)
 #define __A_MAGIC_SET__
-#if defined(LYNXOS)
+#if defined LYNXOS
     internal_a.magic = LYNXCOFFMAGIC;
-#else  /* LYNXOS */
+#elif defined AMD64
+    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
+#else
     internal_a.magic = ZMAGIC;
-#endif /* LYNXOS */
+#endif
 #endif /* I386 */
 
 #if defined(IA64)
 #define __A_MAGIC_SET__
-    internal_a.magic = ZMAGIC;
+    internal_a.magic = PE32PMAGIC;
 #endif /* IA64 */
 
 #if defined(SPARC)
@@ -4483,11 +4512,6 @@ coff_slurp_symbol_table (bfd * abfd)
 
            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.  */
-#endif
-#endif
            case C_REGPARM:     /* Register parameter.  */
            case C_REG:         /* register variable.  */
               /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
@@ -4832,7 +4856,7 @@ coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
   amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
   reloc_cache = bfd_alloc (abfd, amt);
 
-  if (reloc_cache == NULL)
+  if (reloc_cache == NULL || native_relocs == NULL)
     return FALSE;
 
   for (idx = 0; idx < asect->reloc_count; idx++)
@@ -4846,6 +4870,7 @@ coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
       cache_ptr = reloc_cache + idx;
       src = native_relocs + idx;
 
+      dst.r_offset = 0;
       coff_swap_reloc_in (abfd, src, &dst);
 
 #ifdef RELOC_PROCESSING
@@ -4926,6 +4951,7 @@ coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
 {
   arelent genrel;
 
+  genrel.howto = NULL;
   RTYPE2HOWTO (&genrel, rel);
   return genrel.howto;
 }
@@ -5309,6 +5335,9 @@ static const bfd_coff_backend_data ticoff1_swap_table =
 #ifndef coff_bfd_reloc_type_lookup
 #define coff_bfd_reloc_type_lookup         _bfd_norelocs_bfd_reloc_type_lookup
 #endif
+#ifndef coff_bfd_reloc_name_lookup
+#define coff_bfd_reloc_name_lookup    _bfd_norelocs_bfd_reloc_name_lookup
+#endif
 
 #ifndef coff_bfd_get_relocated_section_contents
 #define coff_bfd_get_relocated_section_contents \
This page took 0.033119 seconds and 4 git commands to generate.