* elf32-mn10200.c (mn10200_elf_final_link_relocate): New function.
authorJeff Law <law@redhat.com>
Thu, 20 Feb 1997 20:54:28 +0000 (20:54 +0000)
committerJeff Law <law@redhat.com>
Thu, 20 Feb 1997 20:54:28 +0000 (20:54 +0000)
        (mn10200_elf_relocate_section): Likewise.
        (elf_backend_relocate_section): Define.
New style linker for the mn10200.

bfd/ChangeLog
bfd/elf32-mn10200.c

index cef59c0a2f0e4517587d01f761c02f1418ea2422..4266562d651cac61466fb16b8a5d07c32d239828 100644 (file)
@@ -1,3 +1,9 @@
+Thu Feb 20 13:52:16 1997  Jeffrey A Law  (law@cygnus.com)
+
+       * elf32-mn10200.c (mn10200_elf_final_link_relocate): New function.
+       (mn10200_elf_relocate_section): Likewise.
+       (elf_backend_relocate_section): Define.
+
 start-sanitize-d30v
 Tue Feb 18 17:22:59 1997  Martin M. Hunt  <hunt@pizza.cygnus.com>
 
index 747c84e5629e6ca1a4c6e224c5c9dadb4f205217..d86c18def0fe8db1b087566fccb794bd08dabd25 100644 (file)
@@ -213,6 +213,275 @@ mn10200_info_to_howto (abfd, cache_ptr, dst)
   cache_ptr->howto = &elf_mn10200_howto_table[r_type];
 }
 
+/* Perform a relocation as part of a final link.  */
+static bfd_reloc_status_type
+mn10200_elf_final_link_relocate (howto, input_bfd, output_bfd,
+                                input_section, contents, offset, value,
+                                addend, info, sym_sec, is_local)
+     reloc_howto_type *howto;
+     bfd *input_bfd;
+     bfd *output_bfd;
+     asection *input_section;
+     bfd_byte *contents;
+     bfd_vma offset;
+     bfd_vma value;
+     bfd_vma addend;
+     struct bfd_link_info *info;
+     asection *sym_sec;
+     int is_local;
+{
+  unsigned long insn;
+  unsigned long r_type = howto->type;
+  bfd_byte *hit_data = contents + offset;
+
+  switch (r_type)
+    {
+
+    case R_MN10200_NONE:
+      return bfd_reloc_ok;
+
+    case R_MN10200_32:
+      value += bfd_get_32 (input_bfd, hit_data);
+      value += addend;
+      bfd_put_32 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    case R_MN10200_16:
+      value += (short)bfd_get_16 (input_bfd, hit_data);
+      value += addend;
+
+      if ((long)value > 0x7fff || (long)value < -0x8000)
+       return bfd_reloc_overflow;
+
+      bfd_put_16 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    case R_MN10200_8:
+      value += (char)bfd_get_8 (input_bfd, hit_data);
+      value += addend;
+
+      if ((long)value > 0x7fff || (long)value < -0x8000)
+       return bfd_reloc_overflow;
+
+      bfd_put_8 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    case R_MN10200_24:
+      value += (bfd_get_32 (input_bfd, hit_data) & 0xffffff);
+      value += addend;
+
+      if ((long)value > 0x7fffff || (long)value < -0x800000)
+       return bfd_reloc_overflow;
+
+      value &= 0xffffff;
+      value |= (bfd_get_32 (input_bfd, hit_data) & 0xff000000);
+      bfd_put_32 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    case R_MN10200_PCREL8:
+      value -= (input_section->output_section->vma
+               + input_section->output_offset);
+      value -= offset;
+      value += addend;
+
+      if ((long)value > 0xff || (long)value < -0x100)
+        return bfd_reloc_overflow;
+
+      bfd_put_8 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    case R_MN10200_PCREL16:
+      value -= (input_section->output_section->vma
+               + input_section->output_offset);
+      value -= offset;
+      value += addend;
+
+      if ((long)value > 0xffff || (long)value < -0x10000)
+        return bfd_reloc_overflow;
+
+      bfd_put_16 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    case R_MN10200_PCREL24:
+      value -= (input_section->output_section->vma
+               + input_section->output_offset);
+      value -= offset;
+      value += addend;
+
+      if ((long)value > 0xffffff || (long)value < -0x1000000)
+        return bfd_reloc_overflow;
+
+      value &= 0xffffff;
+      value |= (bfd_get_32 (input_bfd, hit_data) & 0xff000000);
+      bfd_put_32 (input_bfd, value, hit_data);
+      return bfd_reloc_ok;
+
+    default:
+      return bfd_reloc_notsupported;
+    }
+}
+
+\f
+/* Relocate an MN10200 ELF section.  */
+static boolean
+mn10200_elf_relocate_section (output_bfd, info, input_bfd, input_section,
+                             contents, relocs, local_syms, local_sections)
+     bfd *output_bfd;
+     struct bfd_link_info *info;
+     bfd *input_bfd;
+     asection *input_section;
+     bfd_byte *contents;
+     Elf_Internal_Rela *relocs;
+     Elf_Internal_Sym *local_syms;
+     asection **local_sections;
+{
+  Elf_Internal_Shdr *symtab_hdr;
+  struct elf_link_hash_entry **sym_hashes;
+  Elf_Internal_Rela *rel, *relend;
+
+  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+  sym_hashes = elf_sym_hashes (input_bfd);
+
+  rel = relocs;
+  relend = relocs + input_section->reloc_count;
+  for (; rel < relend; rel++)
+    {
+      int r_type;
+      reloc_howto_type *howto;
+      unsigned long r_symndx;
+      Elf_Internal_Sym *sym;
+      asection *sec;
+      struct elf_link_hash_entry *h;
+      bfd_vma relocation;
+      bfd_reloc_status_type r;
+
+      r_symndx = ELF32_R_SYM (rel->r_info);
+      r_type = ELF32_R_TYPE (rel->r_info);
+      howto = elf_mn10200_howto_table + r_type;
+
+      if (info->relocateable)
+       {
+         /* This is a relocateable link.  We don't have to change
+             anything, unless the reloc is against a section symbol,
+             in which case we have to adjust according to where the
+             section symbol winds up in the output section.  */
+         if (r_symndx < symtab_hdr->sh_info)
+           {
+             sym = local_syms + r_symndx;
+             if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
+               {
+                 sec = local_sections[r_symndx];
+                 rel->r_addend += sec->output_offset + sym->st_value;
+               }
+           }
+
+         continue;
+       }
+
+      /* This is a final link.  */
+      h = NULL;
+      sym = NULL;
+      sec = NULL;
+      if (r_symndx < symtab_hdr->sh_info)
+       {
+         sym = local_syms + r_symndx;
+         sec = local_sections[r_symndx];
+         relocation = (sec->output_section->vma
+                       + sec->output_offset
+                       + sym->st_value);
+       }
+      else
+       {
+         h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+         while (h->root.type == bfd_link_hash_indirect
+                || h->root.type == bfd_link_hash_warning)
+           h = (struct elf_link_hash_entry *) h->root.u.i.link;
+         if (h->root.type == bfd_link_hash_defined
+             || h->root.type == bfd_link_hash_defweak)
+           {
+             sec = h->root.u.def.section;
+             relocation = (h->root.u.def.value
+                           + sec->output_section->vma
+                           + sec->output_offset);
+           }
+         else if (h->root.type == bfd_link_hash_undefweak)
+           relocation = 0;
+         else
+           {
+             if (! ((*info->callbacks->undefined_symbol)
+                    (info, h->root.root.string, input_bfd,
+                     input_section, rel->r_offset)))
+               return false;
+             relocation = 0;
+           }
+       }
+
+      r = mn10200_elf_final_link_relocate (howto, input_bfd, output_bfd,
+                                          input_section,
+                                          contents, rel->r_offset,
+                                          relocation, rel->r_addend,
+                                          info, sec, h == NULL);
+
+      if (r != bfd_reloc_ok)
+       {
+         const char *name;
+         const char *msg = (const char *)0;
+
+         if (h != NULL)
+           name = h->root.root.string;
+         else
+           {
+             name = (bfd_elf_string_from_elf_section
+                     (input_bfd, symtab_hdr->sh_link, sym->st_name));
+             if (name == NULL || *name == '\0')
+               name = bfd_section_name (input_bfd, sec);
+           }
+
+         switch (r)
+           {
+           case bfd_reloc_overflow:
+             if (! ((*info->callbacks->reloc_overflow)
+                    (info, name, howto->name, (bfd_vma) 0,
+                     input_bfd, input_section, rel->r_offset)))
+               return false;
+             break;
+
+           case bfd_reloc_undefined:
+             if (! ((*info->callbacks->undefined_symbol)
+                    (info, name, input_bfd, input_section,
+                     rel->r_offset)))
+               return false;
+             break;
+
+           case bfd_reloc_outofrange:
+             msg = "internal error: out of range error";
+             goto common_error;
+
+           case bfd_reloc_notsupported:
+             msg = "internal error: unsupported relocation error";
+             goto common_error;
+
+           case bfd_reloc_dangerous:
+             msg = "internal error: dangerous error";
+             goto common_error;
+
+           default:
+             msg = "internal error: unknown error";
+             /* fall through */
+
+           common_error:
+             if (!((*info->callbacks->warning)
+                   (info, msg, name, input_bfd, input_section,
+                    rel->r_offset)))
+               return false;
+             break;
+           }
+       }
+    }
+
+  return true;
+}
+
 #define TARGET_LITTLE_SYM      bfd_elf32_mn10200_vec
 #define TARGET_LITTLE_NAME     "elf32-mn10200"
 #define ELF_ARCH               bfd_arch_mn10200
@@ -221,6 +490,7 @@ mn10200_info_to_howto (abfd, cache_ptr, dst)
 
 #define elf_info_to_howto      mn10200_info_to_howto
 #define elf_info_to_howto_rel  0
+#define elf_backend_relocate_section mn10200_elf_relocate_section
 
 #define elf_symbol_leading_char '_'