Restore GET_SAVED_REGISTERS
[deliverable/binutils-gdb.git] / bfd / coff-mcore.c
index 199a5ab70f0633482202a6154c43268197a0f1cd..f20c2ca815f49e664de281c90a67a4d9ef80395f 100644 (file)
@@ -1,5 +1,5 @@
-/* BFD back-end for Motorolla MCore COFF/PE
-   Copyright 1999 Free Software Foundation, Inc.
+/* BFD back-end for Motorola MCore COFF/PE
+   Copyright (C) 1999 Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -52,10 +52,6 @@ static reloc_howto_type *           mcore_coff_reloc_type_lookup
 static reloc_howto_type *           coff_mcore_rtype_to_howto
   PARAMS ((bfd *, asection *, struct internal_reloc *,
           struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *));
-static const bfd_target *           pe_object_p
-  PARAMS ((bfd *));
-
-
 \f
 /* The NT loader points the toc register to &toc + 32768, in order to
    use the complete range of a 16-bit displacement. We have to adjust
@@ -64,7 +60,7 @@ static const bfd_target *           pe_object_p
 #define TOC_SECTION_NAME ".private.toc"
 
 /* The main body of code is in coffcode.h.  */
-#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2
 
 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
    from smaller values.  Start with zero, widen, *then* decrement.  */
@@ -248,6 +244,25 @@ coff_mcore_link_hash_table_create (abfd)
   return & ret->root.root;
 }
 \f
+/* Add an entry to the base file.  */
+static void
+mcore_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)
+      struct bfd_link_info * info;
+      bfd *                  output_bfd;
+      asection *             input_section;
+      bfd_vma                reloc_offset;
+{
+  bfd_vma addr = reloc_offset
+                 - input_section->vma
+                 + input_section->output_offset
+                 + input_section->output_section->vma;
+
+  if (coff_data (output_bfd)->pe)
+     addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
+  
+  fwrite (&addr, 1, sizeof (addr), (FILE *) info->base_file);
+}
+\f
 /*ARGSUSED*/
 static bfd_reloc_status_type
 mcore_coff_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
@@ -320,7 +335,7 @@ coff_mcore_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
   if (rel->r_type == IMAGE_REL_MCORE_RVA)
     * addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
   
-  if (howto->pc_relative)
+  else if (howto->pc_relative)
     {
       * addendp = sec->vma - 2; /* XXX guess - is this right ? */
       
@@ -421,6 +436,8 @@ coff_mcore_relocate_section (output_bfd, info, input_bfd, input_section,
          sym = syms + symndx;
        }
 
+      addend = 0;
+      
       /* Get the howto and initialise the addend.  */
       howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
                                       sym, & addend);
@@ -471,7 +488,7 @@ coff_mcore_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              if (! ((*info->callbacks->undefined_symbol)
                     (info, h->root.root.string, input_bfd, input_section,
-                     rel->r_vaddr - input_section->vma)))
+                     rel->r_vaddr - input_section->vma, true)))
                return false;
            }
          
@@ -507,11 +524,25 @@ coff_mcore_relocate_section (output_bfd, info, input_bfd, input_section,
        case IMAGE_REL_MCORE_PCREL_32:
        case IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2:
        case IMAGE_REL_MCORE_ADDR32:
-       case IMAGE_REL_MCORE_RVA:
+         /* XXX fixme - shouldn't this be like the code for the RVA reloc ? */
          rstat = _bfd_relocate_contents (howto, input_bfd, val, loc);
          break;
+         
+       case IMAGE_REL_MCORE_RVA:
+         rstat = _bfd_final_link_relocate
+           (howto, input_bfd,
+            input_section, contents, rel->r_vaddr - input_section->vma,
+            val, addend);
+         break;
        }
       
+      if (info->base_file)
+       {
+         /* Emit a reloc if the backend thinks it needs it.  */
+         if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto))
+            mcore_emit_base_file_entry (info, output_bfd, input_section, rel->r_vaddr);
+       }
+  
       switch (rstat)
        {
        default:
@@ -547,72 +578,13 @@ coff_mcore_relocate_section (output_bfd, info, input_bfd, input_section,
 
 #include "coffcode.h"
 \f
-static const bfd_target *
-pe_object_p (abfd)
-     bfd * abfd;
-{
-#ifdef COFF_IMAGE_WITH_PE
-  /* We need to hack badly to handle a PE image correctly.  In PE
-     images created by the GNU linker, the offset to the COFF header
-     is always the size.  However, this is not the case in images
-     generated by other PE linkers.  The PE format stores a four byte
-     offset to the PE signature just before the COFF header at
-     location 0x3c of the file.  We pick up that offset, verify that
-     the PE signature is there, and then set ourselves up to read in
-     the COFF header.  */
-  {
-    bfd_byte ext_offset[4];
-    file_ptr offset;
-    bfd_byte ext_signature[4];
-    unsigned long signature;
-
-    if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0
-       || bfd_read (ext_offset, 1, 4, abfd) != 4)
-      {
-       if (bfd_get_error () != bfd_error_system_call)
-         bfd_set_error (bfd_error_wrong_format);
-       return NULL;
-      }
-    
-    offset = bfd_h_get_32 (abfd, ext_offset);
-    
-    if (bfd_seek (abfd, offset, SEEK_SET) != 0
-       || bfd_read (ext_signature, 1, 4, abfd) != 4)
-      {
-       if (bfd_get_error () != bfd_error_system_call)
-         bfd_set_error (bfd_error_wrong_format);
-       
-       return NULL;
-      }
-    
-    signature = bfd_h_get_32 (abfd, ext_signature);
-
-    if (signature != 0x4550)
-      {
-       bfd_set_error (bfd_error_wrong_format);
-       return NULL;
-      }
-
-    /* Here is the hack.  coff_object_p wants to read filhsz bytes to
-       pick up the COFF header.  We adjust so that that will work.  20
-       is the size of the mips COFF filehdr.  */
-    if (bfd_seek (abfd, (bfd_tell (abfd) - bfd_coff_filhsz (abfd) + 20),
-                 SEEK_SET) != 0)
-      {
-       if (bfd_get_error () != bfd_error_system_call)
-         bfd_set_error (bfd_error_wrong_format);
-       
-       return NULL;
-      }
-  }
-#endif
-
-  return coff_object_p (abfd);
-}
-\f
 /* Forward declaration to initialise alterbative_target field.  */
 extern const bfd_target TARGET_LITTLE_SYM;
 
 /* The transfer vectors that lead the outside world to all of the above. */
-CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, (SEC_LINK_ONCE | SEC_LINK_DUPLICATES), 0, & TARGET_LITTLE_SYM)
-CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, (SEC_LINK_ONCE | SEC_LINK_DUPLICATES), 0, & TARGET_BIG_SYM)
+CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED,
+                           (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
+                           0, & TARGET_LITTLE_SYM)
+CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED,
+                              (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
+                              0, & TARGET_BIG_SYM)
This page took 0.025963 seconds and 4 git commands to generate.