bfd: install plugin-api.h as needed
[deliverable/binutils-gdb.git] / bfd / elf32-msp430.c
index da4278267c39bca3373020c932c7a0ce8111c50a..9a5fb2a910408703dd76d77478f8d43bda7034d6 100644 (file)
@@ -1,12 +1,13 @@
 /*  MSP430-specific support for 32-bit ELF
-    Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2010
+    Free Software Foundation, Inc.
     Contributed by Dmitry Diky <diwil@mail.ru>
 
     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
+    the Free Software Foundation; either version 3 of the License, or
     (at your option) any later version.
 
     This program is distributed in the hope that it will be useful,
 
     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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+    MA 02110-1301, USA.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "libiberty.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
@@ -199,6 +201,23 @@ bfd_elf32_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
   return NULL;
 }
 
+static reloc_howto_type *
+bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                                const char *r_name)
+{
+  unsigned int i;
+
+  for (i = 0;
+       i < (sizeof (elf_msp430_howto_table)
+           / sizeof (elf_msp430_howto_table[0]));
+       i++)
+    if (elf_msp430_howto_table[i].name != NULL
+       && strcasecmp (elf_msp430_howto_table[i].name, r_name) == 0)
+      return &elf_msp430_howto_table[i];
+
+  return NULL;
+}
+
 /* Set the howto pointer for an MSP430 ELF reloc.  */
 
 static void
@@ -213,48 +232,6 @@ msp430_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
   cache_ptr->howto = &elf_msp430_howto_table[r_type];
 }
 
-static asection *
-elf32_msp430_gc_mark_hook (asection * sec,
-                          struct bfd_link_info * info ATTRIBUTE_UNUSED,
-                          Elf_Internal_Rela * rel,
-                          struct elf_link_hash_entry * h,
-                          Elf_Internal_Sym * sym)
-{
-  if (h != NULL)
-    {
-      switch (ELF32_R_TYPE (rel->r_info))
-       {
-       default:
-         switch (h->root.type)
-           {
-           case bfd_link_hash_defined:
-           case bfd_link_hash_defweak:
-             return h->root.u.def.section;
-
-           case bfd_link_hash_common:
-             return h->root.u.c.p->section;
-
-           default:
-             break;
-           }
-       }
-    }
-  else
-    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
-
-  return NULL;
-}
-
-static bfd_boolean
-elf32_msp430_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED,
-                           struct bfd_link_info * info ATTRIBUTE_UNUSED,
-                           asection * sec ATTRIBUTE_UNUSED,
-                           const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED)
-{
-  /* We don't use got and plt entries for msp430.  */
-  return TRUE;
-}
-
 /* Look through the relocs for a section during the first phase.
    Since we don't do .gots or .plts, we just need to consider the
    virtual table relocs for gc.  */
@@ -264,7 +241,7 @@ elf32_msp430_check_relocs (bfd * abfd, struct bfd_link_info * info,
                           asection * sec, const Elf_Internal_Rela * relocs)
 {
   Elf_Internal_Shdr *symtab_hdr;
-  struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
+  struct elf_link_hash_entry **sym_hashes;
   const Elf_Internal_Rela *rel;
   const Elf_Internal_Rela *rel_end;
 
@@ -273,10 +250,6 @@ elf32_msp430_check_relocs (bfd * abfd, struct bfd_link_info * info,
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
-  sym_hashes_end =
-      sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
-  if (!elf_bad_symtab (abfd))
-    sym_hashes_end -= symtab_hdr->sh_info;
 
   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
@@ -454,11 +427,9 @@ elf32_msp430_relocate_section (bfd * output_bfd ATTRIBUTE_UNUSED,
       const char *name = NULL;
       int r_type;
 
-      /* This is a final link.  */
-
       r_type = ELF32_R_TYPE (rel->r_info);
       r_symndx = ELF32_R_SYM (rel->r_info);
-      howto = elf_msp430_howto_table + ELF32_R_TYPE (rel->r_info);
+      howto = elf_msp430_howto_table + r_type;
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -483,6 +454,13 @@ elf32_msp430_relocate_section (bfd * output_bfd ATTRIBUTE_UNUSED,
                                   unresolved_reloc, warned);
        }
 
+      if (sec != NULL && elf_discarded_section (sec))
+       RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+                                        rel, relend, howto, contents);
+
+      if (info->relocatable)
+       continue;
+
       r = msp430_final_link_relocate (howto, input_bfd, input_section,
                                      contents, rel, relocation);
 
@@ -685,21 +663,6 @@ elf32_msp430_object_p (bfd * abfd)
   return bfd_default_set_arch_mach (abfd, bfd_arch_msp430, e_set);
 }
 
-static void
-elf32_msp430_post_process_headers (bfd * abfd,
-                                  struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
-{
-  Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form.  */
-
-  i_ehdrp = elf_elfheader (abfd);
-
-#ifndef ELFOSABI_STANDALONE
-#define ELFOSABI_STANDALONE    255
-#endif
-
-  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_STANDALONE;
-}
-
 /* These functions handle relaxing for the msp430.
    Relaxation required only in two cases:
     - Bad hand coding like jumps from one section to another or
@@ -830,6 +793,36 @@ msp430_elf_symbol_address_p (bfd * abfd,
   return FALSE;
 }
 
+/* Adjust all local symbols defined as '.section + 0xXXXX' (.section has sec_shndx)
+    referenced from current and other sections */
+static bfd_boolean
+msp430_elf_relax_adjust_locals(bfd * abfd, asection * sec, bfd_vma addr,
+    int count, unsigned int sec_shndx, bfd_vma toaddr)
+{
+  Elf_Internal_Shdr *symtab_hdr;
+  Elf_Internal_Rela *irel;
+  Elf_Internal_Rela *irelend;
+  Elf_Internal_Sym *isym;
+
+  irel = elf_section_data (sec)->relocs;
+  irelend = irel + sec->reloc_count;
+  symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
+  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
+  
+  for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
+    {
+      int sidx = ELF32_R_SYM(irel->r_info);
+      Elf_Internal_Sym *lsym = isym + sidx;
+      
+      /* Adjust symbols referenced by .sec+0xXX */
+      if (irel->r_addend > addr && irel->r_addend < toaddr 
+         && lsym->st_shndx == sec_shndx)
+       irel->r_addend -= count;
+    }
+  
+  return TRUE;
+}
+
 /* Delete some bytes from a section while relaxing.  */
 
 static bfd_boolean
@@ -841,22 +834,18 @@ msp430_elf_relax_delete_bytes (bfd * abfd, asection * sec, bfd_vma addr,
   bfd_byte *contents;
   Elf_Internal_Rela *irel;
   Elf_Internal_Rela *irelend;
-  Elf_Internal_Rela *irelalign;
   bfd_vma toaddr;
   Elf_Internal_Sym *isym;
   Elf_Internal_Sym *isymend;
   struct elf_link_hash_entry **sym_hashes;
   struct elf_link_hash_entry **end_hashes;
   unsigned int symcount;
+  asection *p;
 
   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
 
   contents = elf_section_data (sec)->this_hdr.contents;
 
-  /* The deletion must stop at the next ALIGN reloc for an aligment
-     power larger than the number of bytes we are deleting.  */
-
-  irelalign = NULL;
   toaddr = sec->size;
 
   irel = elf_section_data (sec)->relocs;
@@ -868,11 +857,18 @@ msp430_elf_relax_delete_bytes (bfd * abfd, asection * sec, bfd_vma addr,
   sec->size -= count;
 
   /* Adjust all the relocs.  */
+  symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
+  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
   for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
-    /* Get the new reloc address.  */
-    if ((irel->r_offset > addr && irel->r_offset < toaddr))
-      irel->r_offset -= count;
+    {
+      /* Get the new reloc address.  */
+      if ((irel->r_offset > addr && irel->r_offset < toaddr))
+       irel->r_offset -= count;
+    }
 
+  for (p = abfd->sections; p != NULL; p = p->next)
+    msp430_elf_relax_adjust_locals(abfd,p,addr,count,sec_shndx,toaddr);
+  
   /* Adjust the local symbols defined in this section.  */
   symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
   isym = (Elf_Internal_Sym *) symtab_hdr->contents;
@@ -1165,6 +1161,7 @@ error_return:
 #define ELF_MACHINE_CODE       EM_MSP430
 #define ELF_MACHINE_ALT1       EM_MSP430_OLD
 #define ELF_MAXPAGESIZE                1
+#define        ELF_OSABI               ELFOSABI_STANDALONE
 
 #define TARGET_LITTLE_SYM       bfd_elf32_msp430_vec
 #define TARGET_LITTLE_NAME     "elf32-msp430"
@@ -1172,13 +1169,11 @@ error_return:
 #define elf_info_to_howto                   msp430_info_to_howto_rela
 #define elf_info_to_howto_rel               NULL
 #define elf_backend_relocate_section         elf32_msp430_relocate_section
-#define elf_backend_gc_mark_hook             elf32_msp430_gc_mark_hook
-#define elf_backend_gc_sweep_hook            elf32_msp430_gc_sweep_hook
 #define elf_backend_check_relocs             elf32_msp430_check_relocs
 #define elf_backend_can_gc_sections          1
 #define elf_backend_final_write_processing   bfd_elf_msp430_final_write_processing
 #define elf_backend_object_p                elf32_msp430_object_p
-#define elf_backend_post_process_headers     elf32_msp430_post_process_headers
+#define elf_backend_post_process_headers     _bfd_elf_set_osabi
 #define bfd_elf32_bfd_relax_section         msp430_elf_relax_section
 
 #include "elf32-target.h"
This page took 0.030828 seconds and 4 git commands to generate.