Files removed as of the 1999-08-23 snapshot.
[deliverable/binutils-gdb.git] / bfd / coff-i386.c
index 7898cc159ca853815dfd5bd5ea0a8b17183a2eec..e686b7b6cc5b359ceed443c9294328e5e6cbc732 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for Intel 386 COFF files.
-   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -42,8 +42,10 @@ static bfd_reloc_status_type coff_i386_reloc
 static reloc_howto_type *coff_i386_rtype_to_howto
   PARAMS ((bfd *, asection *, struct internal_reloc *,
           struct coff_link_hash_entry *, struct internal_syment *,
-
           bfd_vma *));
+static reloc_howto_type *coff_i386_reloc_type_lookup
+  PARAMS ((bfd *, bfd_reloc_code_real_type));
+static const bfd_target *i3coff_object_p PARAMS ((bfd *));
 
 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
 /* The page size is a guess based on ELF.  */
@@ -66,9 +68,9 @@ coff_i386_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
      arelent *reloc_entry;
      asymbol *symbol;
      PTR data;
-     asection *input_section;
+     asection *input_section ATTRIBUTE_UNUSED;
      bfd *output_bfd;
-     char **error_message;
+     char **error_message ATTRIBUTE_UNUSED;
 {
   symvalue diff;
 
@@ -106,8 +108,8 @@ coff_i386_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
 
 #ifdef COFF_WITH_PE
   /* FIXME: How should this case be handled?  */
-  if (reloc_entry->howto->type == R_IMAGEBASE && diff != 0)
-    abort ();
+  if (reloc_entry->howto->type == R_IMAGEBASE)
+    diff -= pe_data (output_bfd)->pe_opthdr.ImageBase;
 #endif
 
 #define DOIT(x) \
@@ -158,7 +160,7 @@ coff_i386_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
    appear in the output .reloc section. */
 
 static boolean in_reloc_p(abfd, howto)
-     bfd * abfd;
+     bfd * abfd ATTRIBUTE_UNUSED;
      reloc_howto_type *howto;
 {
   return ! howto->pc_relative && howto->type != R_IMAGEBASE;
@@ -171,12 +173,12 @@ static boolean in_reloc_p(abfd, howto)
 
 static reloc_howto_type howto_table[] = 
 {
-  {0},
-  {1},
-  {2},
-  {3},
-  {4},
-  {5},
+  EMPTY_HOWTO (0),
+  EMPTY_HOWTO (1),
+  EMPTY_HOWTO (2),
+  EMPTY_HOWTO (3),
+  EMPTY_HOWTO (4),
+  EMPTY_HOWTO (5),
   HOWTO (R_DIR32,               /* type */                                 
         0,                     /* rightshift */                           
         2,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -190,7 +192,7 @@ static reloc_howto_type howto_table[] =
         0xffffffff,            /* src_mask */                             
         0xffffffff,            /* dst_mask */                             
         true),                /* pcrel_offset */
-  /* {7}, */
+  /* PE IMAGE_REL_I386_DIR32NB relocation (7).  */
   HOWTO (R_IMAGEBASE,            /* type */                                 
         0,                     /* rightshift */                           
         2,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -204,14 +206,15 @@ static reloc_howto_type howto_table[] =
         0xffffffff,            /* src_mask */                             
         0xffffffff,            /* dst_mask */                             
         false),                /* pcrel_offset */
-  {010},
-  {011},
-  {012},
-  {013},
-  {014},
-  {015},
-  {016},
-  HOWTO (R_RELBYTE,            /* type */                                 
+  EMPTY_HOWTO (010),
+  EMPTY_HOWTO (011),
+  EMPTY_HOWTO (012),
+  EMPTY_HOWTO (013),
+  EMPTY_HOWTO (014),
+  EMPTY_HOWTO (015),
+  EMPTY_HOWTO (016),
+  /* Byte relocation (017).  */
+  HOWTO (R_RELBYTE,            /* type */
         0,                     /* rightshift */                           
         0,                     /* size (0 = byte, 1 = short, 2 = long) */ 
         8,                     /* bitsize */                   
@@ -224,6 +227,7 @@ static reloc_howto_type howto_table[] =
         0x000000ff,            /* src_mask */                             
         0x000000ff,            /* dst_mask */                             
         PCRELOFFSET),          /* pcrel_offset */
+  /* 16-bit word relocation (020).  */
   HOWTO (R_RELWORD,            /* type */                                 
         0,                     /* rightshift */                           
         1,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -237,6 +241,7 @@ static reloc_howto_type howto_table[] =
         0x0000ffff,            /* src_mask */                             
         0x0000ffff,            /* dst_mask */                             
         PCRELOFFSET),          /* pcrel_offset */
+  /* 32-bit longword relocation (021).  */
   HOWTO (R_RELLONG,            /* type */                                 
         0,                     /* rightshift */                           
         2,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -250,6 +255,7 @@ static reloc_howto_type howto_table[] =
         0xffffffff,            /* src_mask */                             
         0xffffffff,            /* dst_mask */                             
         PCRELOFFSET),          /* pcrel_offset */
+  /* Byte PC relative relocation (022).  */
   HOWTO (R_PCRBYTE,            /* type */                                 
         0,                     /* rightshift */                           
         0,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -263,6 +269,7 @@ static reloc_howto_type howto_table[] =
         0x000000ff,            /* src_mask */                             
         0x000000ff,            /* dst_mask */                             
         PCRELOFFSET),          /* pcrel_offset */
+  /* 16-bit word PC relative relocation (023).  */
   HOWTO (R_PCRWORD,            /* type */                                 
         0,                     /* rightshift */                           
         1,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -276,6 +283,7 @@ static reloc_howto_type howto_table[] =
         0x0000ffff,            /* src_mask */                             
         0x0000ffff,            /* dst_mask */                             
         PCRELOFFSET),          /* pcrel_offset */
+  /* 32-bit longword PC relative relocation (024).  */
   HOWTO (R_PCRLONG,            /* type */                                 
         0,                     /* rightshift */                           
         2,                     /* size (0 = byte, 1 = short, 2 = long) */ 
@@ -297,8 +305,11 @@ static reloc_howto_type howto_table[] =
 #define BADMAG(x) I386BADMAG(x)
 #define I386 1                 /* Customize coffcode.h */
 
-#define RTYPE2HOWTO(cache_ptr, dst) \
-           (cache_ptr)->howto = howto_table + (dst)->r_type;
+#define RTYPE2HOWTO(cache_ptr, dst)                                    \
+  ((cache_ptr)->howto =                                                        \
+   ((dst)->r_type < sizeof (howto_table) / sizeof (howto_table[0])     \
+    ? howto_table + (dst)->r_type                                      \
+    : NULL))
 
 /* For 386 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
    library.  On some other COFF targets STYP_BSS is normally
@@ -385,19 +396,25 @@ coff_pe_i386_relocate_section (output_bfd, info, input_bfd,
 
 static reloc_howto_type *
 coff_i386_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      asection *sec;
      struct internal_reloc *rel;
      struct coff_link_hash_entry *h;
      struct internal_syment *sym;
      bfd_vma *addendp;
 {
-
   reloc_howto_type *howto;
 
+  if (rel->r_type > sizeof (howto_table) / sizeof (howto_table[0]))
+    {
+      bfd_set_error (bfd_error_bad_value);
+      return NULL;
+    }
+
   howto = howto_table + rel->r_type;
 
 #ifdef COFF_WITH_PE
+  /* Cancel out code in _bfd_coff_generic_relocate_section.  */
   *addendp = 0;
 #endif
 
@@ -458,13 +475,11 @@ coff_i386_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
   return howto;
 }
 
-
 #define coff_bfd_reloc_type_lookup coff_i386_reloc_type_lookup
 
-
 static reloc_howto_type *
 coff_i386_reloc_type_lookup (abfd, code)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      bfd_reloc_code_real_type code;
 {
   switch (code)
@@ -633,5 +648,7 @@ const bfd_target
      BFD_JUMP_TABLE_LINK (coff),
      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
 
-  COFF_SWAP_TABLE,
+  NULL,
+  
+  COFF_SWAP_TABLE
 };
This page took 0.026852 seconds and 4 git commands to generate.