OSDN Git Service

2010-01-04 Daniel Gutson <dgutson@codesourcery.com>
[pf3gnuchains/pf3gnuchains3x.git] / bfd / elf32-m32c.c
index b188426..4de500a 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
@@ -847,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;
-  fprintf (file, _("private flags = 0x%lx:"), (long)flags);
+  fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
 
   switch (flags & EF_M32C_CPU_MASK)
     {
@@ -1951,13 +1951,24 @@ m32c_elf_relax_delete_bytes
 
   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 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.  */
@@ -1972,13 +1983,21 @@ m32c_elf_relax_delete_bytes
       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.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;
+           }
        }
     }