arc: Don't generate dynamic relocation for non SEC_ALLOC sections
[deliverable/binutils-gdb.git] / bfd / elf32-sh.c
index cd2c49c7f29788afdd22ceff66a8352355d77971..9ec745be199388b3183f0e67b1b6b06d5989d97d 100644 (file)
@@ -1,5 +1,5 @@
 /* Renesas / SuperH SH specific support for 32-bit ELF
-   Copyright (C) 1996-2018 Free Software Foundation, Inc.
+   Copyright (C) 1996-2020 Free Software Foundation, Inc.
    Contributed by Ian Lance Taylor, Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -30,6 +30,9 @@
 #include "libiberty.h"
 #include "../opcodes/sh-opc.h"
 
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
+
 static bfd_reloc_status_type sh_elf_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 static bfd_reloc_status_type sh_elf_ignore_reloc
@@ -164,8 +167,7 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
          if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
                                           &contents))
            {
-             if (contents != NULL)
-               free (contents);
+             free (contents);
              return bfd_reloc_outofrange;
            }
        }
@@ -200,8 +202,7 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
       end = start0;
     }
 
-  if (contents != NULL
-      && elf_section_data (symbol_section)->this_hdr.contents != contents)
+  if (elf_section_data (symbol_section)->this_hdr.contents != contents)
     free (contents);
 
   insn = bfd_get_16 (input_bfd, contents + addr);
@@ -229,11 +230,12 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
              void *data, asection *input_section, bfd *output_bfd,
              char **error_message ATTRIBUTE_UNUSED)
 {
-  unsigned long insn;
+  bfd_vma insn;
   bfd_vma sym_value;
   enum elf_sh_reloc_type r_type;
   bfd_vma addr = reloc_entry->address;
-  bfd_byte *hit_data = addr + (bfd_byte *) data;
+  bfd_size_type octets = addr * OCTETS_PER_BYTE (abfd, input_section);
+  bfd_byte *hit_data = (bfd_byte *) data + octets;
 
   r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
 
@@ -254,7 +256,7 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
     return bfd_reloc_undefined;
 
   /* PR 17512: file: 9891ca98.  */
-  if (addr * bfd_octets_per_byte (abfd) + bfd_get_reloc_size (reloc_entry->howto)
+  if (octets + bfd_get_reloc_size (reloc_entry->howto)
       > bfd_get_section_limit_octets (abfd, input_section))
     return bfd_reloc_outofrange;
 
@@ -270,7 +272,7 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
     case R_SH_DIR32:
       insn = bfd_get_32 (abfd, hit_data);
       insn += sym_value + reloc_entry->addend;
-      bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
+      bfd_put_32 (abfd, insn, hit_data);
       break;
     case R_SH_IND12W:
       insn = bfd_get_16 (abfd, hit_data);
@@ -279,12 +281,10 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
                    + input_section->output_offset
                    + addr
                    + 4);
-      sym_value += (insn & 0xfff) << 1;
-      if (insn & 0x800)
-       sym_value -= 0x1000;
-      insn = (insn & 0xf000) | (sym_value & 0xfff);
-      bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
-      if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
+      sym_value += (((insn & 0xfff) ^ 0x800) - 0x800) << 1;
+      insn = (insn & 0xf000) | ((sym_value >> 1) & 0xfff);
+      bfd_put_16 (abfd, insn, hit_data);
+      if (sym_value + 0x1000 >= 0x2000 || (sym_value & 1) != 0)
        return bfd_reloc_overflow;
       break;
     default:
@@ -809,21 +809,17 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
        }
     }
 
-  if (internal_relocs != NULL
-      && elf_section_data (sec)->relocs != internal_relocs)
+  if (elf_section_data (sec)->relocs != internal_relocs)
     free (internal_relocs);
 
   return TRUE;
 
  error_return:
-  if (isymbuf != NULL
-      && symtab_hdr->contents != (unsigned char *) isymbuf)
+  if (symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
-  if (contents != NULL
-      && elf_section_data (sec)->this_hdr.contents != contents)
+  if (elf_section_data (sec)->this_hdr.contents != contents)
     free (contents);
-  if (internal_relocs != NULL
-      && elf_section_data (sec)->relocs != internal_relocs)
+  if (elf_section_data (sec)->relocs != internal_relocs)
     free (internal_relocs);
 
   return FALSE;
@@ -1193,8 +1189,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
                         when we leave sh_coff_relax_section.  */
                      if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
                        {
-                         if (ocontents != NULL)
-                           free (ocontents);
+                         free (ocontents);
                          return FALSE;
                        }
 
@@ -1251,8 +1246,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
                         when we leave sh_coff_relax_section.  */
                      if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
                        {
-                         if (ocontents != NULL)
-                           free (ocontents);
+                         free (ocontents);
                          return FALSE;
                        }
 
@@ -1385,8 +1379,7 @@ sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
   return TRUE;
 
  error_return:
-  if (labels != NULL)
-    free (labels);
+  free (labels);
   return FALSE;
 }
 
@@ -2102,9 +2095,6 @@ struct elf_sh_link_hash_entry
 {
   struct elf_link_hash_entry root;
 
-  /* Track dynamic relocs copied for this symbol.  */
-  struct elf_dyn_relocs *dyn_relocs;
-
   bfd_signed_vma gotplt_refcount;
 
   /* A local function descriptor, for FDPIC.  The refcount counts
@@ -2238,7 +2228,6 @@ sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
                                     table, string));
   if (ret != (struct elf_sh_link_hash_entry *) NULL)
     {
-      ret->dyn_relocs = NULL;
       ret->gotplt_refcount = 0;
       ret->funcdesc.refcount = 0;
       ret->abs_funcdesc_refcount = 0;
@@ -2254,7 +2243,7 @@ static struct bfd_link_hash_table *
 sh_elf_link_hash_table_create (bfd *abfd)
 {
   struct elf_sh_link_hash_table *ret;
-  bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
+  size_t amt = sizeof (struct elf_sh_link_hash_table);
 
   ret = (struct elf_sh_link_hash_table *) bfd_zmalloc (amt);
   if (ret == (struct elf_sh_link_hash_table *) NULL)
@@ -2324,7 +2313,7 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info)
                                                         | SEC_IN_MEMORY
                                                         | SEC_LINKER_CREATED));
   if (htab->sfuncdesc == NULL
-      || ! bfd_set_section_alignment (dynobj, htab->sfuncdesc, 2))
+      || !bfd_set_section_alignment (htab->sfuncdesc, 2))
     return FALSE;
 
   htab->srelfuncdesc = bfd_make_section_anyway_with_flags (dynobj,
@@ -2335,7 +2324,7 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info)
                                                            | SEC_LINKER_CREATED
                                                            | SEC_READONLY));
   if (htab->srelfuncdesc == NULL
-      || ! bfd_set_section_alignment (dynobj, htab->srelfuncdesc, 2))
+      || !bfd_set_section_alignment (htab->srelfuncdesc, 2))
     return FALSE;
 
   /* Also create .rofixup.  */
@@ -2346,7 +2335,7 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info)
                                                        | SEC_LINKER_CREATED
                                                        | SEC_READONLY));
   if (htab->srofixup == NULL
-      || ! bfd_set_section_alignment (dynobj, htab->srofixup, 2))
+      || !bfd_set_section_alignment (htab->srofixup, 2))
     return FALSE;
 
   return TRUE;
@@ -2401,7 +2390,7 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
   htab->root.splt = s;
   if (s == NULL
-      || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
+      || !bfd_set_section_alignment (s, bed->plt_alignment))
     return FALSE;
 
   if (bed->want_plt_sym)
@@ -2433,7 +2422,7 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
                                          flags | SEC_READONLY);
   htab->root.srelplt = s;
   if (s == NULL
-      || ! bfd_set_section_alignment (abfd, s, ptralign))
+      || !bfd_set_section_alignment (s, ptralign))
     return FALSE;
 
   if (htab->root.sgot == NULL
@@ -2473,7 +2462,7 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
                                                  flags | SEC_READONLY);
          htab->srelbss = s;
          if (s == NULL
-             || ! bfd_set_section_alignment (abfd, s, ptralign))
+             || !bfd_set_section_alignment (s, ptralign))
            return FALSE;
        }
     }
@@ -2487,23 +2476,6 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   return TRUE;
 }
 \f
-/* Find dynamic relocs for H that apply to read-only sections.  */
-
-static asection *
-readonly_dynrelocs (struct elf_link_hash_entry *h)
-{
-  struct elf_dyn_relocs *p;
-
-  for (p = sh_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
-    {
-      asection *s = p->sec->output_section;
-
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-       return p->sec;
-    }
-  return NULL;
-}
-
 /* Adjust a symbol defined by a dynamic object and referenced by a
    regular object.  The current definition is in some section of the
    dynamic object, but we're not including those sections.  We have to
@@ -2592,7 +2564,7 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   /* If we don't find any dynamic relocs in read-only sections, then
      we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
-  if (0 && !readonly_dynrelocs (h))
+  if (0 && !_bfd_elf_readonly_dynrelocs (h))
     {
       h->non_got_ref = 0;
       return TRUE;
@@ -2849,7 +2821,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
        htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
     }
 
-  if (eh->dyn_relocs == NULL)
+  if (h->dyn_relocs == NULL)
     return TRUE;
 
   /* In the shared -Bsymbolic case, discard space allocated for
@@ -2864,7 +2836,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
        {
          struct elf_dyn_relocs **pp;
 
-         for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+         for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
            {
              p->count -= p->pc_count;
              p->pc_count = 0;
@@ -2879,7 +2851,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
        {
          struct elf_dyn_relocs **pp;
 
-         for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+         for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
            {
              if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
                *pp = p->next;
@@ -2890,12 +2862,12 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 
       /* Also discard relocs on undefined weak syms with non-default
         visibility.  */
-      if (eh->dyn_relocs != NULL
+      if (h->dyn_relocs != NULL
          && h->root.type == bfd_link_hash_undefweak)
        {
          if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
              || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
-           eh->dyn_relocs = NULL;
+           h->dyn_relocs = NULL;
 
          /* Make sure undefined weak symbols are output as a dynamic
             symbol in PIEs.  */
@@ -2935,13 +2907,13 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
            goto keep;
        }
 
-      eh->dyn_relocs = NULL;
+      h->dyn_relocs = NULL;
 
     keep: ;
     }
 
   /* Finally, allocate space.  */
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
+  for (p = h->dyn_relocs; p != NULL; p = p->next)
     {
       asection *sreloc = elf_section_data (p->sec)->sreloc;
       sreloc->size += p->count * sizeof (Elf32_External_Rela);
@@ -2954,33 +2926,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   return TRUE;
 }
 
-/* Set DF_TEXTREL if we find any dynamic relocs that apply to
-   read-only sections.  */
-
-static bfd_boolean
-maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
-{
-  asection *sec;
-
-  if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
-
-  sec = readonly_dynrelocs (h);
-  if (sec != NULL)
-    {
-      struct bfd_link_info *info = (struct bfd_link_info *) info_p;
-
-      info->flags |= DF_TEXTREL;
-      info->callbacks->minfo
-       (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
-        sec->owner, h->root.root.string, sec);
-
-      /* Not an error, just cut short the traversal.  */
-      return FALSE;
-    }
-  return TRUE;
-}
-
 /* This function is called after all the input files have been read,
    and the input sections have been assigned to output sections.
    It's a convenient place to determine the PLT style.  */
@@ -3211,7 +3156,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* Strip this section if we don't need it; see the
             comment below.  */
        }
-      else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
+      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
        {
          if (s->size != 0 && s != htab->root.srelplt && s != htab->srelplt2)
            relocs = TRUE;
@@ -3296,7 +3241,8 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
          if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
+           elf_link_hash_traverse (&htab->root,
+                                   _bfd_elf_maybe_set_textrel, info);
 
          if ((info->flags & DF_TEXTREL) != 0)
            {
@@ -3510,7 +3456,11 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
   unsigned isec_segment, got_segment, plt_segment, check_segment[2];
   bfd_boolean fdpic_p = FALSE;
 
-  BFD_ASSERT (is_sh_elf (input_bfd));
+  if (!is_sh_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   htab = sh_elf_hash_table (info);
   if (htab != NULL)
@@ -3557,7 +3507,6 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
       bfd_vma relocation;
       bfd_vma addend = (bfd_vma) 0;
       bfd_reloc_status_type r;
-      int seen_stt_datalabel = 0;
       bfd_vma off;
       enum got_type got_type;
       const char *symname = NULL;
@@ -3615,19 +3564,11 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
          symname = bfd_elf_string_from_elf_section
            (input_bfd, symtab_hdr->sh_link, sym->st_name);
          if (symname == NULL || *symname == '\0')
-           symname = bfd_section_name (input_bfd, sec);
+           symname = bfd_section_name (sec);
 
          relocation = (sec->output_section->vma
                        + sec->output_offset
                        + sym->st_value);
-         /* A local symbol never has STO_SH5_ISA32, so we don't need
-            datalabel processing here.  Make sure this does not change
-            without notice.  */
-         if ((sym->st_other & STO_SH5_ISA32) != 0)
-           (*info->callbacks->reloc_dangerous)
-             (info,
-              _("unexpected STO_SH5_ISA32 on local symbol is not handled"),
-              input_bfd, input_section, rel->r_offset);
 
          if (sec != NULL && discarded_section (sec))
            /* Handled below.  */
@@ -3777,14 +3718,9 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                          || sh_elf_hash_entry (h)->got_type == GOT_TLS_GD)))
                ;
              else if (sec->output_section != NULL)
-               relocation = ((h->root.u.def.value
+               relocation = (h->root.u.def.value
                              + sec->output_section->vma
-                             + sec->output_offset)
-                             /* A STO_SH5_ISA32 causes a "bitor 1" to the
-                                symbol value, unless we've seen
-                                STT_DATALABEL on the way to it.  */
-                             | ((h->other & STO_SH5_ISA32) != 0
-                                && ! seen_stt_datalabel));
+                             + sec->output_offset);
              else if (!bfd_link_relocatable (info)
                       && (_bfd_elf_section_offset (output_bfd, info,
                                                    input_section,
@@ -3809,12 +3745,13 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            ;
          else if (!bfd_link_relocatable (info))
-           (*info->callbacks->undefined_symbol)
-             (info, h->root.root.string, input_bfd,
-              input_section, rel->r_offset,
-              (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
-               || ELF_ST_VISIBILITY (h->other)));
-       }
+            info->callbacks->undefined_symbol
+             (info, h->root.root.string, input_bfd, input_section,
+              rel->r_offset,
+              (info->unresolved_syms_in_objects == RM_DIAGNOSE
+               && !info->warn_unresolved_syms)
+              || ELF_ST_VISIBILITY (h->other));
+        }
 
       if (sec != NULL && discarded_section (sec))
        RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
@@ -4694,7 +4631,15 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                       1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:.  */
 
                  offset = rel->r_offset;
-                 BFD_ASSERT (offset >= 16);
+                 if (offset < 16)
+                   {
+                     _bfd_error_handler
+                       /* xgettext:c-format */
+                       (_("%pB(%pA): offset in relocation for GD->LE translation is too small: %#" PRIx64),
+                        input_bfd, input_section, (uint64_t) offset);
+                     return FALSE;
+                   }
+
                  /* Size of GD instructions is 16 or 18.  */
                  offset -= 16;
                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
@@ -4705,17 +4650,47 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
                    }
 
-                 BFD_ASSERT ((insn & 0xff00) == 0xd400);
+                 if ((insn & 0xff00) != 0xd400)
+                   _bfd_error_handler
+                     /* xgettext:c-format */  /* The backslash is to prevent bogus trigraph detection.  */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0xd4?\?)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 2);
-                 BFD_ASSERT ((insn & 0xff00) == 0xc700);
+
+                 if ((insn & 0xff00) != 0xc700)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0xc7?\?)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 4);
-                 BFD_ASSERT ((insn & 0xff00) == 0xd100);
+                 if ((insn & 0xff00) != 0xd100)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0xd1?\?)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 6);
-                 BFD_ASSERT (insn == 0x310c);
+                 if (insn != 0x310c)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0x310c)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 8);
-                 BFD_ASSERT (insn == 0x410b);
+                 if (insn != 0x410b)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0x410b)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 10);
-                 BFD_ASSERT (insn == 0x34cc);
+                 if (insn != 0x34cc)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0x34cc)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
 
                  bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
                  bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
@@ -4728,14 +4703,32 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                  int target;
 
                  /* IE->LE transition:
-                    mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
-                    bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
+                        mov.l 1f,r0;
+                        stc gbr,rN;
+                        mov.l @(r0,r12),rM;
+                        bra 2f;
+                        add ...;
+                        .align 2;
+                      1: x@GOTTPOFF;
+                      2:
                     We change it into:
-                    mov.l .Ln,rM; stc gbr,rN; nop; ...;
-                    1: x@TPOFF; 2:.  */
+                        mov.l .Ln,rM;
+                        stc gbr,rN;
+                        nop;
+                        ...;
+                      1: x@TPOFF;
+                      2:.  */
 
                  offset = rel->r_offset;
-                 BFD_ASSERT (offset >= 16);
+                 if (offset < 16)
+                   {
+                     _bfd_error_handler
+                       /* xgettext:c-format */
+                       (_("%pB(%pA): offset in relocation for IE->LE translation is too small: %#" PRIx64),
+                        input_bfd, input_section, (uint64_t) offset);
+                     return FALSE;
+                   }
+
                  /* Size of IE instructions is 10 or 12.  */
                  offset -= 10;
                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
@@ -4746,12 +4739,28 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
                    }
 
-                 BFD_ASSERT ((insn & 0xff00) == 0xd000);
+                 if ((insn & 0xff00) != 0xd000)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0xd0??: mov.l)"),
+                      input_bfd, input_section, (uint64_t) offset, (int) insn);
+
                  target = insn & 0x00ff;
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 2);
-                 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
+                 if ((insn & 0xf0ff) != 0x0012)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0x0?12: stc)"),
+                      input_bfd, input_section, (uint64_t) (offset + 2), (int) insn);
+
                  insn = bfd_get_16 (input_bfd, contents + offset + 4);
-                 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
+                 if ((insn & 0xf0ff) != 0x00ce)
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB(%pA+%#" PRIx64 "): unexpected instruction %#04X (expected 0x0?ce: mov.l)"),
+                      input_bfd, input_section, (uint64_t) (offset + 4), (int) insn);
+
                  insn = 0xd000 | (insn & 0x0f00) | target;
                  bfd_put_16 (output_bfd, insn, contents + offset + 0);
                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
@@ -4860,7 +4869,15 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                   1: .long x@TPOFF; 2:...; 3:.  */
 
              offset = rel->r_offset;
-             BFD_ASSERT (offset >= 16);
+             if (offset < 16)
+               {
+                 _bfd_error_handler
+                   /* xgettext:c-format */
+                   (_("%pB(%pA): offset in relocation for GD->IE translation is too small: %#" PRIx64),
+                    input_bfd, input_section, (uint64_t) offset);
+                 return FALSE;
+               }
+
              /* Size of GD instructions is 16 or 18.  */
              offset -= 16;
              insn = bfd_get_16 (input_bfd, contents + offset + 0);
@@ -4920,7 +4937,15 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                   nop; nop; bra 3f; ...; 3:.  */
 
              offset = rel->r_offset;
-             BFD_ASSERT (offset >= 16);
+             if (offset < 16)
+               {
+                 _bfd_error_handler
+                   /* xgettext:c-format */
+                   (_("%pB(%pA): offset in relocation for LD->LE translation is too small: %#" PRIx64),
+                    input_bfd, input_section, (uint64_t) offset);
+                 return FALSE;
+               }
+
              /* Size of LD instructions is 16 or 18.  */
              offset -= 16;
              insn = bfd_get_16 (input_bfd, contents + offset + 0);
@@ -5078,7 +5103,7 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                    if (name == NULL)
                      return FALSE;
                    if (*name == '\0')
-                     name = bfd_section_name (input_bfd, sec);
+                     name = bfd_section_name (sec);
                  }
                (*info->callbacks->reloc_overflow)
                  (info, (h ? &h->root : NULL), name, howto->name,
@@ -5176,10 +5201,8 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
                                     isymbuf, sections))
        goto error_return;
 
-      if (sections != NULL)
-       free (sections);
-      if (isymbuf != NULL
-         && symtab_hdr->contents != (unsigned char *) isymbuf)
+      free (sections);
+      if (symtab_hdr->contents != (unsigned char *) isymbuf)
        free (isymbuf);
       if (elf_section_data (input_section)->relocs != internal_relocs)
        free (internal_relocs);
@@ -5188,13 +5211,10 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
   return data;
 
  error_return:
-  if (sections != NULL)
-    free (sections);
-  if (isymbuf != NULL
-      && symtab_hdr->contents != (unsigned char *) isymbuf)
+  free (sections);
+  if (symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
-  if (internal_relocs != NULL
-      && elf_section_data (input_section)->relocs != internal_relocs)
+  if (elf_section_data (input_section)->relocs != internal_relocs)
     free (internal_relocs);
   return NULL;
 }
@@ -5257,36 +5277,6 @@ sh_elf_copy_indirect_symbol (struct bfd_link_info *info,
   edir = (struct elf_sh_link_hash_entry *) dir;
   eind = (struct elf_sh_link_hash_entry *) ind;
 
-  if (eind->dyn_relocs != NULL)
-    {
-      if (edir->dyn_relocs != NULL)
-       {
-         struct elf_dyn_relocs **pp;
-         struct elf_dyn_relocs *p;
-
-         /* Add reloc counts against the indirect sym to the direct sym
-            list.  Merge any entries against the same section.  */
-         for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
-           {
-             struct elf_dyn_relocs *q;
-
-             for (q = edir->dyn_relocs; q != NULL; q = q->next)
-               if (q->sec == p->sec)
-                 {
-                   q->pc_count += p->pc_count;
-                   q->count += p->count;
-                   *pp = p->next;
-                   break;
-                 }
-             if (q == NULL)
-               pp = &p->next;
-           }
-         *pp = edir->dyn_relocs;
-       }
-
-      edir->dyn_relocs = eind->dyn_relocs;
-      eind->dyn_relocs = NULL;
-    }
   edir->gotplt_refcount = eind->gotplt_refcount;
   eind->gotplt_refcount = 0;
   edir->funcdesc.refcount += eind->funcdesc.refcount;
@@ -5478,9 +5468,7 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_SH_GNU_VTENTRY:
-         BFD_ASSERT (h != NULL);
-         if (h != NULL
-             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
 
@@ -5747,7 +5735,7 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
              /* If this is a global symbol, we count the number of
                 relocations we need for this symbol.  */
              if (h != NULL)
-               head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
+               head = &h->dyn_relocs;
              else
                {
                  /* Track dynamic relocs needed for local syms too.  */
@@ -5771,7 +5759,7 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
              p = *head;
              if (p == NULL || p->sec != sec)
                {
-                 bfd_size_type amt = sizeof (*p);
+                 size_t amt = sizeof (*p);
                  p = bfd_alloc (htab->root.dynobj, amt);
                  if (p == NULL)
                    return FALSE;
@@ -5949,6 +5937,10 @@ sh_elf_merge_private_data (bfd *ibfd, struct bfd_link_info *info)
 {
   bfd *obfd = info->output_bfd;
 
+  /* FIXME: What should be checked when linking shared libraries?  */
+  if ((ibfd->flags & DYNAMIC) != 0)
+    return TRUE;
+
   if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
     return TRUE;
 
@@ -6757,8 +6749,6 @@ sh_elf_encode_eh_address (bfd *abfd,
 
 #include "elf32-target.h"
 
-#undef elf_backend_modify_program_headers
-
 /* VxWorks support.  */
 #undef TARGET_BIG_SYM
 #define        TARGET_BIG_SYM                  sh_elf32_vxworks_vec
This page took 0.034766 seconds and 4 git commands to generate.