PR ld/13991
[deliverable/binutils-gdb.git] / bfd / elf32-frv.c
index 6d0d7e483383906e6aeca16e58e3b3da2a5e4c27..57de3c02f21c1bbe80e31179031123fbdfdcc337 100644 (file)
@@ -1,29 +1,30 @@
 /* FRV-specific support for 32-bit ELF.
-   Copyright 2002, 2003, 2004, 2005, 2006, 2007
+   Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
-This file is part of BFD, the Binary File Descriptor library.
+   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
-(at your option) any later version.
+   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 3 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-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.  */
+   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.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
 #include "elf/frv.h"
-#include "elf/dwarf2.h"
+#include "dwarf2.h"
 #include "hashtab.h"
 
 /* Forward declarations.  */
@@ -881,8 +882,9 @@ struct frvfdpic_elf_link_hash_table
 
 /* Get the FRV ELF linker hash table from a link_info structure.  */
 
-#define frvfdpic_hash_table(info) \
-  ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
+#define frvfdpic_hash_table(p) \
+  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
+  == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
 
 #define frvfdpic_got_section(info) \
   (frvfdpic_hash_table (info)->sgot)
@@ -1005,7 +1007,8 @@ frvfdpic_elf_link_hash_table_create (bfd *abfd)
 
   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
                                      _bfd_elf_link_hash_newfunc,
-                                     sizeof (struct elf_link_hash_entry)))
+                                     sizeof (struct elf_link_hash_entry),
+                                     FRV_ELF_DATA))
     {
       free (ret);
       return NULL;
@@ -1340,26 +1343,9 @@ _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
 static unsigned
 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
 {
-  struct elf_segment_map *m;
-  Elf_Internal_Phdr *p;
-
-  /* Find the segment that contains the output_section.  */
-  for (m = elf_tdata (output_bfd)->segment_map,
-        p = elf_tdata (output_bfd)->phdr;
-       m != NULL;
-       m = m->next, p++)
-    {
-      int i;
-
-      for (i = m->count - 1; i >= 0; i--)
-       if (m->sections[i] == osec)
-         break;
-
-      if (i >= 0)
-       break;
-    }
+  Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
 
-  return p - elf_tdata (output_bfd)->phdr;
+  return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
 }
 
 inline static bfd_boolean
@@ -1413,7 +1399,8 @@ _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
        dynindx = entry->d.h->dynindx;
       else
        {
-         if (sec->output_section
+         if (sec
+             && sec->output_section
              && ! bfd_is_abs_section (sec->output_section)
              && ! bfd_is_und_section (sec->output_section))
            dynindx = elf_section_data (sec->output_section)->dynindx;
@@ -1695,8 +1682,9 @@ _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
             of the section.  For a non-local function, it's
             disregarded.  */
          lowword = ad;
-         if (entry->symndx == -1 && entry->d.h->dynindx != -1
-             && entry->d.h->dynindx == idx)
+         if (sec == NULL
+             || (entry->symndx == -1 && entry->d.h->dynindx != -1
+                 && entry->d.h->dynindx == idx))
            highword = 0;
          else
            highword = _frvfdpic_osec_to_segment
@@ -2782,7 +2770,7 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
       bfd_reloc_status_type r;
-      const char * name = NULL;
+      const char *name;
       int r_type;
       asection *osec;
       struct frvfdpic_relocs_info *picrel;
@@ -2808,7 +2796,8 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
 
          name = bfd_elf_string_from_elf_section
            (input_bfd, symtab_hdr->sh_link, sym->st_name);
-         name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
+         if (name == NULL || name[0] == 0)
+           name = bfd_section_name (input_bfd, sec);
        }
       else
        {
@@ -2820,18 +2809,12 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
                                   h, sec, relocation,
                                   unresolved_reloc, warned);
          osec = sec;
+         name = h->root.root.string;
        }
 
-      if (sec != NULL && elf_discarded_section (sec))
-       {
-         /* For relocs against symbols from removed linkonce sections,
-            or sections discarded by a linker script, we just want the
-            section contents zeroed.  Avoid any special processing.  */
-         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
-         rel->r_info = 0;
-         rel->r_addend = 0;
-         continue;
-       }
+      if (sec != NULL && discarded_section (sec))
+       RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+                                        rel, relend, howto, contents);
 
       if (info->relocatable)
        continue;
@@ -2901,8 +2884,9 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
                                                      osec, sym,
                                                      rel->r_addend))
            {
-             (*_bfd_error_handler)
-               (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
+             info->callbacks->einfo
+               (_("%H: relocation to `%s+%v'"
+                  " may have caused the error above\n"),
                 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
              return FALSE;
            }
@@ -2912,11 +2896,15 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
        default:
        non_fdpic:
          picrel = NULL;
-         if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
+         if (h
+             && ! FRVFDPIC_SYM_LOCAL (info, h)
+             && _bfd_elf_section_offset (output_bfd, info, input_section,
+                                         rel->r_offset) != (bfd_vma) -1)
            {
-             info->callbacks->warning
-               (info, _("relocation references symbol not defined in the module"),
-                name, input_bfd, input_section, rel->r_offset);
+             info->callbacks->einfo
+               (_("%H: relocation references symbol"
+                  " not defined in the module\n"),
+                input_bfd, input_section, rel->r_offset);
              return FALSE;
            }
          break;
@@ -2989,10 +2977,9 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a call instruction?  */
            if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GETTLSOFF not applied to a call instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3031,10 +3018,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this an lddi instruction?  */
            if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GOTTLSDESC12"
+                    " not applied to an lddi instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3102,10 +3089,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a sethi instruction?  */
            if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GOTTLSDESCHI"
+                    " not applied to a sethi instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3139,11 +3126,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a setlo or setlos instruction?  */
            if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GOTTLSDESCLO"
-                    " not applied to a setlo or setlos instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GOTTLSDESCLO"
+                    " not applied to a setlo or setlos instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3187,10 +3173,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this an ldd instruction?  */
            if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_TLSDESC_RELAX"
+                    " not applied to an ldd instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3271,11 +3257,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a calll or callil instruction?  */
            if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GETTLSOFF_RELAX"
-                    " not applied to a calll instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GETTLSOFF_RELAX"
+                    " not applied to a calll instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3326,10 +3311,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this an ldi instruction?  */
            if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GOTTLSOFF12"
+                    " not applied to an ldi instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3356,10 +3341,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a sethi instruction?  */
            if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GOTTLSOFFHI"
+                    " not applied to a sethi instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3385,11 +3370,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a setlo or setlos instruction?  */
            if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_GOTTLSOFFLO"
-                    " not applied to a setlo or setlos instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_GOTTLSOFFLO"
+                    " not applied to a setlo or setlos instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3416,10 +3400,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this an ld instruction?  */
            if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_TLSOFF_RELAX"
+                    " not applied to an ld instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3461,10 +3445,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a sethi instruction?  */
            if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("%H: R_FRV_TLSMOFFHI"
+                    " not applied to a sethi instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3488,11 +3472,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
            /* Is this a setlo or setlos instruction?  */
            if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
              {
-               r = info->callbacks->warning
-                 (info,
-                  _("R_FRV_TLSMOFFLO"
-                    " not applied to a setlo or setlos instruction"),
-                  name, input_bfd, input_section, rel->r_offset);
+               info->callbacks->einfo
+                 (_("R_FRV_TLSMOFFLO"
+                    " not applied to a setlo or setlos instruction\n"),
+                  input_bfd, input_section, rel->r_offset);
                return FALSE;
              }
 
@@ -3610,9 +3593,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
                  {
                    if (addend)
                      {
-                       info->callbacks->warning
-                         (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
-                          name, input_bfd, input_section, rel->r_offset);
+                       info->callbacks->einfo
+                         (_("%H: R_FRV_FUNCDESC references dynamic symbol"
+                            " with nonzero addend\n"),
+                          input_bfd, input_section, rel->r_offset);
                        return FALSE;
                      }
                    dynindx = h->dynindx;
@@ -3644,51 +3628,61 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
                                                input_section->output_section)
                         & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
                      {
+                       bfd_vma offset;
+
                        if (_frvfdpic_osec_readonly_p (output_bfd,
                                                       input_section
                                                       ->output_section))
                          {
-                           info->callbacks->warning
-                             (info,
-                              _("cannot emit fixups in read-only section"),
-                              name, input_bfd, input_section, rel->r_offset);
+                           info->callbacks->einfo
+                             (_("%H: cannot emit fixups"
+                                " in read-only section\n"),
+                              input_bfd, input_section, rel->r_offset);
                            return FALSE;
                          }
-                       _frvfdpic_add_rofixup (output_bfd,
-                                              frvfdpic_gotfixup_section
-                                              (info),
-                                              _bfd_elf_section_offset
-                                              (output_bfd, info,
-                                               input_section, rel->r_offset)
-                                              + input_section
-                                              ->output_section->vma
-                                              + input_section->output_offset,
-                                              picrel);
+
+                       offset = _bfd_elf_section_offset
+                         (output_bfd, info,
+                          input_section, rel->r_offset);
+
+                       if (offset != (bfd_vma)-1)
+                         _frvfdpic_add_rofixup (output_bfd,
+                                                frvfdpic_gotfixup_section
+                                                (info),
+                                                offset + input_section
+                                                ->output_section->vma
+                                                + input_section->output_offset,
+                                                picrel);
                      }
                  }
                else if ((bfd_get_section_flags (output_bfd,
                                                 input_section->output_section)
                          & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
                  {
+                   bfd_vma offset;
+
                    if (_frvfdpic_osec_readonly_p (output_bfd,
                                                   input_section
                                                   ->output_section))
                      {
-                       info->callbacks->warning
-                         (info,
-                          _("cannot emit dynamic relocations in read-only section"),
-                          name, input_bfd, input_section, rel->r_offset);
+                       info->callbacks->einfo
+                         (_("%H: cannot emit dynamic relocations"
+                            " in read-only section\n"),
+                          input_bfd, input_section, rel->r_offset);
                        return FALSE;
                      }
-                   _frvfdpic_add_dyn_reloc (output_bfd,
-                                            frvfdpic_gotrel_section (info),
-                                            _bfd_elf_section_offset
-                                            (output_bfd, info,
-                                             input_section, rel->r_offset)
-                                            + input_section
-                                            ->output_section->vma
-                                            + input_section->output_offset,
-                                            r_type, dynindx, addend, picrel);
+
+                   offset = _bfd_elf_section_offset
+                     (output_bfd, info,
+                      input_section, rel->r_offset);
+
+                   if (offset != (bfd_vma)-1)
+                     _frvfdpic_add_dyn_reloc (output_bfd,
+                                              frvfdpic_gotrel_section (info),
+                                              offset + input_section
+                                              ->output_section->vma
+                                              + input_section->output_offset,
+                                              r_type, dynindx, addend, picrel);
                  }
                else
                  addend += frvfdpic_got_section (info)->output_section->vma;
@@ -3720,9 +3714,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
              {
                if (addend && r_type == R_FRV_FUNCDESC_VALUE)
                  {
-                   info->callbacks->warning
-                     (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
-                      name, input_bfd, input_section, rel->r_offset);
+                   info->callbacks->einfo
+                     (_("%H: R_FRV_FUNCDESC_VALUE"
+                        " references dynamic symbol with nonzero addend\n"),
+                      input_bfd, input_section, rel->r_offset);
                    return FALSE;
                  }
                dynindx = h->dynindx;
@@ -3761,33 +3756,34 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
                                                   input_section
                                                   ->output_section))
                      {
-                       info->callbacks->warning
-                         (info,
-                          _("cannot emit fixups in read-only section"),
-                          name, input_bfd, input_section, rel->r_offset);
+                       info->callbacks->einfo
+                         (_("%H: cannot emit fixups in read-only section\n"),
+                          input_bfd, input_section, rel->r_offset);
                        return FALSE;
                      }
                    if (!h || h->root.type != bfd_link_hash_undefweak)
                      {
-                       _frvfdpic_add_rofixup (output_bfd,
-                                              frvfdpic_gotfixup_section
-                                              (info),
-                                              _bfd_elf_section_offset
-                                              (output_bfd, info,
-                                               input_section, rel->r_offset)
-                                              + input_section
-                                              ->output_section->vma
-                                              + input_section->output_offset,
-                                              picrel);
-                       if (r_type == R_FRV_FUNCDESC_VALUE)
-                         _frvfdpic_add_rofixup
-                           (output_bfd,
-                            frvfdpic_gotfixup_section (info),
-                            _bfd_elf_section_offset
-                            (output_bfd, info,
-                             input_section, rel->r_offset)
-                            + input_section->output_section->vma
-                            + input_section->output_offset + 4, picrel);
+                       bfd_vma offset = _bfd_elf_section_offset
+                         (output_bfd, info,
+                          input_section, rel->r_offset);
+
+                       if (offset != (bfd_vma)-1)
+                         {
+                           _frvfdpic_add_rofixup (output_bfd,
+                                                  frvfdpic_gotfixup_section
+                                                  (info),
+                                                  offset + input_section
+                                                  ->output_section->vma
+                                                  + input_section->output_offset,
+                                                  picrel);
+                           if (r_type == R_FRV_FUNCDESC_VALUE)
+                             _frvfdpic_add_rofixup
+                               (output_bfd,
+                                frvfdpic_gotfixup_section (info),
+                                offset
+                                + input_section->output_section->vma
+                                + input_section->output_offset + 4, picrel);
+                         }
                      }
                  }
              }
@@ -3797,25 +3793,30 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
                                            input_section->output_section)
                     & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
                  {
+                   bfd_vma offset;
+
                    if (_frvfdpic_osec_readonly_p (output_bfd,
                                                   input_section
                                                   ->output_section))
                      {
-                       info->callbacks->warning
-                         (info,
-                          _("cannot emit dynamic relocations in read-only section"),
-                          name, input_bfd, input_section, rel->r_offset);
+                       info->callbacks->einfo
+                         (_("%H: cannot emit dynamic relocations"
+                            " in read-only section\n"),
+                          input_bfd, input_section, rel->r_offset);
                        return FALSE;
                      }
-                   _frvfdpic_add_dyn_reloc (output_bfd,
-                                            frvfdpic_gotrel_section (info),
-                                            _bfd_elf_section_offset
-                                            (output_bfd, info,
-                                             input_section, rel->r_offset)
-                                            + input_section
-                                            ->output_section->vma
-                                            + input_section->output_offset,
-                                            r_type, dynindx, addend, picrel);
+
+                   offset = _bfd_elf_section_offset
+                     (output_bfd, info,
+                      input_section, rel->r_offset);
+
+                   if (offset != (bfd_vma)-1)
+                     _frvfdpic_add_dyn_reloc (output_bfd,
+                                              frvfdpic_gotrel_section (info),
+                                              offset + input_section
+                                              ->output_section->vma
+                                              + input_section->output_offset,
+                                              r_type, dynindx, addend, picrel);
                  }
                else if (osec)
                  addend += osec->output_section->vma;
@@ -3957,10 +3958,10 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
          if (silence_segment_error == 1)
            silence_segment_error =
              (strlen (input_bfd->filename) == 6
-              && strcmp (input_bfd->filename, "crt0.o") == 0)
+              && filename_cmp (input_bfd->filename, "crt0.o") == 0)
              || (strlen (input_bfd->filename) > 6
-                 && strcmp (input_bfd->filename
-                            + strlen (input_bfd->filename) - 7,
+                 && filename_cmp (input_bfd->filename
+                                  + strlen (input_bfd->filename) - 7,
                             "/crt0.o") == 0)
              ? -1 : 0;
          if (!silence_segment_error
@@ -3969,16 +3970,9 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
              && !(picrel && picrel->symndx == -1
                   && picrel->d.h->root.type == bfd_link_hash_undefined))
            {
-             if (info->shared || info->pie)
-               (*_bfd_error_handler)
-                 (_("%B(%A+0x%lx): reloc against `%s': %s"),
-                  input_bfd, input_section, (long)rel->r_offset, name,
-                  _("relocation references a different segment"));
-             else
-               info->callbacks->warning
-                 (info,
-                  _("relocation references a different segment"),
-                  name, input_bfd, input_section, rel->r_offset);
+             info->callbacks->einfo
+               (_("%H: reloc against `%s' references a different segment\n"),
+                input_bfd, input_section, rel->r_offset, name);
            }
          if (!silence_segment_error && (info->shared || info->pie))
            return FALSE;
@@ -4126,9 +4120,9 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
 
          if (msg)
            {
-             (*_bfd_error_handler)
-               (_("%B(%A+0x%lx): reloc against `%s': %s"),
-                input_bfd, input_section, (long)rel->r_offset, name, msg);
+             info->callbacks->einfo
+               (_("%H: reloc against `%s': %s\n"),
+                input_bfd, input_section, rel->r_offset, name, msg);
              return FALSE;
            }
 
@@ -5601,6 +5595,119 @@ elf32_frvfdpic_always_size_sections (bfd *output_bfd,
   return TRUE;
 }
 
+/* Check whether any of the relocations was optimized away, and
+   subtract it from the relocation or fixup count.  */
+static bfd_boolean
+_frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec,
+                                 struct bfd_link_info *info,
+                                 
+                                 bfd_boolean *changed)
+{
+  Elf_Internal_Shdr *symtab_hdr;
+  struct elf_link_hash_entry **sym_hashes;
+  Elf_Internal_Rela *rel, *erel;
+
+  if ((sec->flags & SEC_RELOC) == 0
+      || sec->reloc_count == 0)
+    return TRUE;
+
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  sym_hashes = elf_sym_hashes (abfd);
+
+  rel = elf_section_data (sec)->relocs;
+
+  /* Now examine each relocation.  */
+  for (erel = rel + sec->reloc_count; rel < erel; rel++)
+    {
+      struct elf_link_hash_entry *h;
+      unsigned long r_symndx;
+      struct frvfdpic_relocs_info *picrel;
+      struct _frvfdpic_dynamic_got_info *dinfo;
+
+      if (ELF32_R_TYPE (rel->r_info) != R_FRV_32
+         && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC)
+       continue;
+
+      if (_bfd_elf_section_offset (sec->output_section->owner,
+                                  info, sec, rel->r_offset)
+         != (bfd_vma)-1)
+       continue;
+
+      r_symndx = ELF32_R_SYM (rel->r_info);
+      if (r_symndx < symtab_hdr->sh_info)
+       h = NULL;
+      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 != NULL)
+       picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
+                                                 abfd, h,
+                                                 rel->r_addend, NO_INSERT);
+      else
+       picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info),
+                                                abfd, r_symndx,
+                                                rel->r_addend, NO_INSERT);
+
+      if (! picrel)
+       return FALSE;
+
+      *changed = TRUE;
+      dinfo = frvfdpic_dynamic_got_plt_info (info);
+
+      _frvfdpic_count_relocs_fixups (picrel, dinfo, TRUE);
+      if (ELF32_R_TYPE (rel->r_info) == R_FRV_32)
+       picrel->relocs32--;
+      else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
+       picrel->relocsfd--;
+      _frvfdpic_count_relocs_fixups (picrel, dinfo, FALSE);
+    }
+
+  return TRUE;
+}
+
+static bfd_boolean
+frvfdpic_elf_discard_info (bfd *ibfd,
+                          struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED,
+                          struct bfd_link_info *info)
+{
+  bfd_boolean changed = FALSE;
+  asection *s;
+  bfd *obfd = NULL;
+
+  /* Account for relaxation of .eh_frame section.  */
+  for (s = ibfd->sections; s; s = s->next)
+    if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
+      {
+       if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed))
+         return FALSE;
+       obfd = s->output_section->owner;
+      }
+
+  if (changed)
+    {
+      struct _frvfdpic_dynamic_got_plt_info gpinfo;
+
+      memset (&gpinfo, 0, sizeof (gpinfo));
+      memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info),
+             sizeof (gpinfo.g));
+
+      /* Clear GOT and PLT assignments.  */
+      htab_traverse (frvfdpic_relocs_info (info),
+                    _frvfdpic_reset_got_plt_entries,
+                    NULL);
+
+      if (!_frvfdpic_size_got_plt (obfd, &gpinfo))
+       return FALSE;
+    }
+
+  return TRUE;
+}
+
 /* Look for opportunities to relax TLS relocations.  We can assume
    we're linking the main executable or a static-tls library, since
    otherwise we wouldn't have got here.  */
@@ -5622,6 +5729,10 @@ elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
 {
   struct _frvfdpic_dynamic_got_plt_info gpinfo;
 
+  if (info->relocatable)
+    (*info->callbacks->einfo)
+      (_("%P%F: --relax and -r may not be used together\n"));
+
   /* If we return early, we didn't change anything.  */
   *again = FALSE;
 
@@ -5765,8 +5876,8 @@ elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
              != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
            {
            error:
-             (*_bfd_error_handler)
-               ("LINKER BUG: .rofixup section size mismatch");
+             info->callbacks->einfo
+               ("LINKER BUG: .rofixup section size mismatch\n");
              return FALSE;
            }
 
@@ -5774,7 +5885,8 @@ elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
                                       FALSE, FALSE, TRUE);
          if (hend
              && (hend->type == bfd_link_hash_defined
-                 || hend->type == bfd_link_hash_defweak))
+                 || hend->type == bfd_link_hash_defweak)
+             && hend->u.def.section->output_section != NULL)
            {
              bfd_vma value =
                frvfdpic_gotfixup_section (info)->output_section->vma
@@ -6045,7 +6157,7 @@ elf32_frv_check_relocs (abfd, info, sec, relocs)
      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;
   bfd *dynobj;
@@ -6056,9 +6168,6 @@ elf32_frv_check_relocs (abfd, info, sec, relocs)
 
   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;
 
   dynobj = elf_hash_table (info)->dynobj;
   rel_end = relocs + sec->reloc_count;
@@ -6266,7 +6375,9 @@ elf32_frv_check_relocs (abfd, info, sec, relocs)
         /* This relocation describes which C++ vtable entries are actually
            used.  Record for later use during GC.  */
         case R_FRV_GNU_VTENTRY:
-          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+          BFD_ASSERT (h != NULL);
+          if (h != NULL
+              && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
             return FALSE;
           break;
 
@@ -6285,8 +6396,8 @@ elf32_frv_check_relocs (abfd, info, sec, relocs)
 
        default:
        bad_reloc:
-         (*_bfd_error_handler)
-           (_("%B: unsupported relocation type %i"),
+         info->callbacks->einfo
+           (_("%B: unsupported relocation type %i\n"),
             abfd, ELF32_R_TYPE (rel->r_info));
          return FALSE;
         }
@@ -6357,6 +6468,10 @@ frv_elf_copy_private_bfd_data (ibfd, obfd)
 
   elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
   elf_flags_init (obfd) = TRUE;
+
+  /* Copy object attributes.  */
+  _bfd_elf_copy_obj_attributes (ibfd, obfd);
+
   return TRUE;
 }
 
@@ -6719,7 +6834,7 @@ frv_elf_print_private_bfd_data (abfd, 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_FRV_CPU_MASK)
     {
@@ -6810,7 +6925,7 @@ elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
 
        /* `pr_pid' is at offset 24.  */
-       elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
+       elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
 
        /* `pr_reg' is at offset 72.  */
        offset = 72;
@@ -6869,6 +6984,7 @@ elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   return TRUE;
 }
 #define ELF_ARCH               bfd_arch_frv
+#define ELF_TARGET_ID          FRV_ELF_DATA
 #define ELF_MACHINE_CODE       EM_CYGNUS_FRV
 #define ELF_MAXPAGESIZE                0x1000
 
@@ -6952,6 +7068,9 @@ elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 #define elf_backend_finish_dynamic_sections \
                elf32_frvfdpic_finish_dynamic_sections
 
+#undef elf_backend_discard_info
+#define elf_backend_discard_info \
+               frvfdpic_elf_discard_info
 #undef elf_backend_can_make_relative_eh_frame
 #define elf_backend_can_make_relative_eh_frame \
                frvfdpic_elf_use_relative_eh_frame
This page took 0.038012 seconds and 4 git commands to generate.