* elf64-mips.c (mips_elf64_howto_table_rela): Add support for
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index 2695217f4eb143ca921c84bcc9326f65f2b72490..794d329fe80be3f7f24120dddece95d80cc9c3ae 100644 (file)
@@ -1,6 +1,6 @@
 /* Matsushita 10300 specific support for 32-bit ELF
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007 Free Software Foundation, Inc.
+   2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -917,32 +917,10 @@ mn10300_elf_check_relocs (bfd *abfd,
                     section in dynobj and make room for this reloc.  */
                  if (sreloc == NULL)
                    {
-                     const char * name;
-
-                     name = (bfd_elf_string_from_elf_section
-                             (abfd,
-                              elf_elfheader (abfd)->e_shstrndx,
-                              elf_section_data (sec)->rel_hdr.sh_name));
-                     if (name == NULL)
-                       goto fail;
-
-                     BFD_ASSERT (CONST_STRNEQ (name, ".rela")
-                                 && streq (bfd_get_section_name (abfd, sec), name + 5));
-
-                     sreloc = bfd_get_section_by_name (dynobj, name);
+                     sreloc = _bfd_elf_make_dynamic_reloc_section
+                       (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
                      if (sreloc == NULL)
-                       {
-                         flagword flags;
-
-                         flags = (SEC_HAS_CONTENTS | SEC_READONLY
-                              | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-                         if ((sec->flags & SEC_ALLOC) != 0)
-                           flags |= SEC_ALLOC | SEC_LOAD;
-                         sreloc = bfd_make_section_with_flags (dynobj, name, flags);
-                         if (sreloc == NULL
-                             || ! bfd_set_section_alignment (dynobj, sreloc, 2))
-                           goto fail;
-                       }
+                       goto fail;
                    }
 
                  sreloc->size += sizeof (Elf32_External_Rela);
@@ -1108,22 +1086,10 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
             time.  */
          if (sreloc == NULL)
            {
-             const char * name;
-
-             name = (bfd_elf_string_from_elf_section
-                     (input_bfd,
-                      elf_elfheader (input_bfd)->e_shstrndx,
-                      elf_section_data (input_section)->rel_hdr.sh_name));
-             if (name == NULL)
+             sreloc = _bfd_elf_get_dynamic_reloc_section
+               (input_bfd, input_section, /*rela?*/ TRUE);
+             if (sreloc == NULL)
                return FALSE;
-
-             BFD_ASSERT (CONST_STRNEQ (name, ".rela")
-                         && streq (bfd_get_section_name (input_bfd,
-                                                         input_section),
-                                   name + 5));
-
-             sreloc = bfd_get_section_by_name (dynobj, name);
-             BFD_ASSERT (sreloc != NULL);
            }
 
          skip = FALSE;
@@ -1212,7 +1178,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       value -= offset;
       value += addend;
 
-      if ((long) value > 0xff || (long) value < -0x100)
+      if ((long) value > 0x7f || (long) value < -0x80)
        return bfd_reloc_overflow;
 
       bfd_put_8 (input_bfd, value, hit_data);
@@ -1224,7 +1190,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       value -= offset;
       value += addend;
 
-      if ((long) value > 0xffff || (long) value < -0x10000)
+      if ((long) value > 0x7fff || (long) value < -0x8000)
        return bfd_reloc_overflow;
 
       bfd_put_16 (input_bfd, value, hit_data);
@@ -1264,7 +1230,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       value -= offset;
       value += addend;
 
-      if ((long) value > 0xffff || (long) value < -0x10000)
+      if ((long) value > 0x7fff || (long) value < -0x8000)
        return bfd_reloc_overflow;
 
       bfd_put_16 (input_bfd, value, hit_data);
@@ -1296,7 +1262,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
                                        ".got")->output_section->vma;
       value += addend;
 
-      if ((long) value > 0xffff || (long) value < -0x10000)
+      if ((long) value > 0x7fff || (long) value < -0x8000)
        return bfd_reloc_overflow;
 
       bfd_put_16 (input_bfd, value, hit_data);
@@ -1345,7 +1311,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       value -= offset;
       value += addend;
 
-      if ((long) value > 0xffff || (long) value < -0x10000)
+      if ((long) value > 0x7fff || (long) value < -0x8000)
        return bfd_reloc_overflow;
 
       bfd_put_16 (input_bfd, value, hit_data);
@@ -1433,7 +1399,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
        }
       else if (r_type == R_MN10300_GOT16)
        {
-         if ((long) value > 0xffff || (long) value < -0x10000)
+         if ((long) value > 0x7fff || (long) value < -0x8000)
            return bfd_reloc_overflow;
 
          bfd_put_16 (input_bfd, value, hit_data);
@@ -1527,7 +1493,7 @@ mn10300_elf_relocate_section (bfd *output_bfd,
                      /* _32 relocs in executables force _COPY relocs,
                         such that the address of the symbol ends up
                         being local.  */
-                     && !info->executable                    
+                     && !info->executable
                      && !SYMBOL_REFERENCES_LOCAL (info, hh)
                      && ((input_section->flags & SEC_ALLOC) != 0
                          /* DWARF will emit R_MN10300_32 relocations
@@ -2107,6 +2073,10 @@ mn10300_elf_relax_section (bfd *abfd,
   asection *section = sec;
   bfd_vma align_gap_adjustment;
 
+  if (link_info->relocatable)
+    (*link_info->callbacks->einfo)
+      (_("%P%F: --relax and -r may not be used together\n"));
+
   /* Assume nothing changes.  */
   *again = FALSE;
 
@@ -2736,7 +2706,7 @@ mn10300_elf_relax_section (bfd *abfd,
          bfd_vma aend = irel->r_offset;
 
          aend = BFD_ALIGN (aend, 1 << irel->r_addend);
-         adj = 2*adj - adj - 1;
+         adj = 2 * adj - adj - 1;
 
          /* Record the biggest adjustmnet.  Skip any alignment at the
             end of our section.  */
@@ -2751,6 +2721,8 @@ mn10300_elf_relax_section (bfd *abfd,
   for (irel = internal_relocs; irel < irelend; irel++)
     {
       bfd_vma symval;
+      bfd_signed_vma jump_offset;
+      asection *sym_sec = NULL;
       struct elf32_mn10300_link_hash_entry *h = NULL;
 
       /* If this isn't something that can be relaxed, then ignore
@@ -2790,7 +2762,6 @@ mn10300_elf_relax_section (bfd *abfd,
       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
        {
          Elf_Internal_Sym *isym;
-         asection *sym_sec = NULL;
          const char *sym_name;
          char *new_name;
 
@@ -2810,15 +2781,32 @@ mn10300_elf_relax_section (bfd *abfd,
                                                      isym->st_name);
 
          if ((sym_sec->flags & SEC_MERGE)
-             && ELF_ST_TYPE (isym->st_info) == STT_SECTION
              && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
            {
-             bfd_vma saved_addend;
-
-             saved_addend = irel->r_addend;
-             symval = _bfd_elf_rela_local_sym (abfd, isym, & sym_sec, irel);
-             symval += irel->r_addend;
-             irel->r_addend = saved_addend;
+             symval = isym->st_value;
+
+             /* GAS may reduce relocations against symbols in SEC_MERGE
+                sections to a relocation against the section symbol when
+                the original addend was zero.  When the reloc is against
+                a section symbol we should include the addend in the
+                offset passed to _bfd_merged_section_offset, since the
+                location of interest is the original symbol.  On the
+                other hand, an access to "sym+addend" where "sym" is not
+                a section symbol should not include the addend;  Such an
+                access is presumed to be an offset from "sym";  The
+                location of interest is just "sym".  */
+             if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
+               symval += irel->r_addend;
+
+             symval = _bfd_merged_section_offset (abfd, & sym_sec,
+                                                  elf_section_data (sym_sec)->sec_info,
+                                                  symval);
+
+             if (ELF_ST_TYPE (isym->st_info) != STT_SECTION)
+               symval += irel->r_addend;
+
+             symval += sym_sec->output_section->vma
+               + sym_sec->output_offset - irel->r_addend;
            }
          else
            symval = (isym->st_value
@@ -2858,6 +2846,8 @@ mn10300_elf_relax_section (bfd *abfd,
          if (h->root.root.u.def.section->output_section == NULL)
            continue;
 
+         sym_sec = h->root.root.u.def.section->output_section;
+
          symval = (h->root.root.u.def.value
                    + h->root.root.u.def.section->output_section->vma
                    + h->root.root.u.def.section->output_offset);
@@ -2960,10 +2950,15 @@ mn10300_elf_relax_section (bfd *abfd,
 
          /* See if the value will fit in 16 bits, note the high value is
             0x7fff + 2 as the target will be two bytes closer if we are
-            able to relax.  */
+            able to relax, if it's in the same section.  */
+         if (sec->output_section == sym_sec->output_section)
+           jump_offset = 0x8001;
+         else
+           jump_offset = 0x7fff;
+
          /* Account for jumps across alignment boundaries using
             align_gap_adjustment.  */
-         if (value < 0x8001 - align_gap_adjustment
+         if ((bfd_signed_vma) value < jump_offset - (bfd_signed_vma) align_gap_adjustment
              && ((bfd_signed_vma) value > -0x8000 + (bfd_signed_vma) align_gap_adjustment))
            {
              unsigned char code;
This page took 0.030401 seconds and 4 git commands to generate.