]> oss.titaniummirror.com Git - msp430-binutils.git/blobdiff - bfd/elf32-m32c.c
Imported binutils-2.20
[msp430-binutils.git] / bfd / elf32-m32c.c
index 6c9a82502cd2c20ef633d7f002070d0042771ea9..4de500a1c4ef490bcfe9a48b10556e88685d2055 100644 (file)
@@ -1,5 +1,5 @@
 /* M16C/M32C specific support for 32-bit ELF.
 /* M16C/M32C specific support for 32-bit ELF.
-   Copyright (C) 2005, 2006, 2007
+   Copyright (C) 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -597,7 +597,6 @@ m32c_elf_check_relocs
 {
   Elf_Internal_Shdr *           symtab_hdr;
   struct elf_link_hash_entry ** sym_hashes;
 {
   Elf_Internal_Shdr *           symtab_hdr;
   struct elf_link_hash_entry ** sym_hashes;
-  struct elf_link_hash_entry ** sym_hashes_end;
   const Elf_Internal_Rela *     rel;
   const Elf_Internal_Rela *     rel_end;
   bfd_vma *local_plt_offsets;
   const Elf_Internal_Rela *     rel;
   const Elf_Internal_Rela *     rel_end;
   bfd_vma *local_plt_offsets;
@@ -613,10 +612,6 @@ m32c_elf_check_relocs
   splt = NULL;
   dynobj = elf_hash_table(info)->dynobj;
 
   splt = NULL;
   dynobj = elf_hash_table(info)->dynobj;
 
-  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++)
     {
   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
     {
@@ -852,7 +847,7 @@ m32c_elf_print_private_bfd_data (bfd *abfd, PTR ptr)
   _bfd_elf_print_private_bfd_data (abfd, ptr);
 
   flags = elf_elfheader (abfd)->e_flags;
   _bfd_elf_print_private_bfd_data (abfd, ptr);
 
   flags = elf_elfheader (abfd)->e_flags;
-  fprintf (file, _("private flags = 0x%lx:"), (long)flags);
+  fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
 
   switch (flags & EF_M32C_CPU_MASK)
     {
 
   switch (flags & EF_M32C_CPU_MASK)
     {
@@ -1956,13 +1951,24 @@ m32c_elf_relax_delete_bytes
 
   for (; isym < isymend; isym++, shndx = (shndx ? shndx + 1 : NULL))
     {
 
   for (; isym < isymend; isym++, shndx = (shndx ? shndx + 1 : NULL))
     {
-
+      /* If the symbol is in the range of memory we just moved, we
+        have to adjust its value.  */
       if ((int) isym->st_shndx == sec_shndx
          && isym->st_value > addr
          && isym->st_value < toaddr)
        {
          isym->st_value -= count;
        }
       if ((int) isym->st_shndx == sec_shndx
          && isym->st_value > addr
          && isym->st_value < toaddr)
        {
          isym->st_value -= count;
        }
+      /* If the symbol *spans* the bytes we just deleted (i.e. it's
+        *end* is in the moved bytes but it's *start* isn't), then we
+        must adjust its size.  */
+      if ((int) isym->st_shndx == sec_shndx
+           && isym->st_value < addr
+         && isym->st_value + isym->st_size > addr
+         && isym->st_value + isym->st_size < toaddr)
+       {
+         isym->st_size -= count;
+       }
     }
 
   /* Now adjust the global symbols defined in this section.  */
     }
 
   /* Now adjust the global symbols defined in this section.  */
@@ -1977,22 +1983,41 @@ m32c_elf_relax_delete_bytes
       struct elf_link_hash_entry * sym_hash = * sym_hashes;
 
       if (sym_hash &&
       struct elf_link_hash_entry * sym_hash = * sym_hashes;
 
       if (sym_hash &&
-         (   sym_hash->root.type == bfd_link_hash_defined
+         (sym_hash->root.type == bfd_link_hash_defined
           || sym_hash->root.type == bfd_link_hash_defweak)
           || sym_hash->root.type == bfd_link_hash_defweak)
-         && sym_hash->root.u.def.section == sec
-         && sym_hash->root.u.def.value > addr
-         && sym_hash->root.u.def.value < toaddr)
+         && sym_hash->root.u.def.section == sec)
        {
        {
-         sym_hash->root.u.def.value -= count;
+         if (sym_hash->root.u.def.value > addr
+             && sym_hash->root.u.def.value < toaddr)
+           {
+             sym_hash->root.u.def.value -= count;
+           }
+         if (sym_hash->root.u.def.value < addr
+             && sym_hash->root.u.def.value + sym_hash->size > addr
+             && sym_hash->root.u.def.value + sym_hash->size < toaddr)
+           {
+             sym_hash->size -= count;
+           }
        }
     }
 
   return TRUE;
 }
        }
     }
 
   return TRUE;
 }
+\f
+/* This is for versions of gcc prior to 4.3.  */
+static unsigned int
+_bfd_m32c_elf_eh_frame_address_size (bfd *abfd, asection *sec ATTRIBUTE_UNUSED)
+{
+  if ((elf_elfheader (abfd)->e_flags & EF_M32C_CPU_MASK) == EF_M32C_CPU_M16C)
+    return 2;
+  return 4;
+}
+
 \f
 
 #define ELF_ARCH               bfd_arch_m32c
 #define ELF_MACHINE_CODE       EM_M32C
 \f
 
 #define ELF_ARCH               bfd_arch_m32c
 #define ELF_MACHINE_CODE       EM_M32C
+#define ELF_MACHINE_ALT1       EM_M32C_OLD
 #define ELF_MAXPAGESIZE                0x1000
 
 #if 0
 #define ELF_MAXPAGESIZE                0x1000
 
 #if 0
@@ -2016,6 +2041,7 @@ m32c_elf_relax_delete_bytes
   m32c_elf_finish_dynamic_sections
 
 #define elf_backend_can_gc_sections            1
   m32c_elf_finish_dynamic_sections
 
 #define elf_backend_can_gc_sections            1
+#define elf_backend_eh_frame_address_size _bfd_m32c_elf_eh_frame_address_size
 
 #define bfd_elf32_bfd_reloc_type_lookup                m32c_reloc_type_lookup
 #define bfd_elf32_bfd_reloc_name_lookup        m32c_reloc_name_lookup
 
 #define bfd_elf32_bfd_reloc_type_lookup                m32c_reloc_type_lookup
 #define bfd_elf32_bfd_reloc_name_lookup        m32c_reloc_name_lookup