readonly_dynrelocs
[deliverable/binutils-gdb.git] / bfd / elf32-m32r.c
index d4e4423d6210269833d661588ff3575041d55906..94bd482131d6e3e49facae61a85b1f87ad671189 100644 (file)
@@ -1757,6 +1757,24 @@ m32r_elf_copy_indirect_symbol (struct bfd_link_info *info,
 }
 
 \f
+/* Find dynamic relocs for H that apply to read-only sections.  */
+
+static asection *
+readonly_dynrelocs (struct elf_link_hash_entry *h)
+{
+  struct elf_m32r_dyn_relocs *p;
+  struct elf_m32r_link_hash_entry *eh = (struct elf_m32r_link_hash_entry *) h;
+
+  for (p = eh->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
@@ -1782,7 +1800,7 @@ m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
               && (h->needs_plt
-                  || h->u.weakdef != NULL
+                  || h->is_weakalias
                   || (h->def_dynamic
                       && h->ref_regular
                       && !h->def_regular)));
@@ -1816,12 +1834,12 @@ m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
      real definition first, and we can just use the same value.  */
-  if (h->u.weakdef != NULL)
+  if (h->is_weakalias)
     {
-      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
-                  || h->u.weakdef->root.type == bfd_link_hash_defweak);
-      h->root.u.def.section = h->u.weakdef->root.u.def.section;
-      h->root.u.def.value = h->u.weakdef->root.u.def.value;
+      struct elf_link_hash_entry *def = weakdef (h);
+      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
+      h->root.u.def.section = def->root.u.def.section;
+      h->root.u.def.value = def->root.u.def.value;
       return TRUE;
     }
 
@@ -2090,28 +2108,29 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   return TRUE;
 }
 
-/* Find any dynamic relocs that apply to read-only sections.  */
+/* Set DF_TEXTREL if we find any dynamic relocs that apply to
+   read-only sections.  */
 
 static bfd_boolean
-readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
+maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
 {
-  struct elf_m32r_link_hash_entry *eh;
-  struct elf_m32r_dyn_relocs *p;
+  asection *sec;
 
-  eh = (struct elf_m32r_link_hash_entry *) h;
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
-    {
-      asection *s = p->sec->output_section;
+  if (h->root.type == bfd_link_hash_indirect)
+    return TRUE;
 
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-        {
-          struct bfd_link_info *info = (struct bfd_link_info *) inf;
+  sec = readonly_dynrelocs (h);
+  if (sec != NULL)
+    {
+      struct bfd_link_info *info = (struct bfd_link_info *) info_p;
 
-          info->flags |= DF_TEXTREL;
+      info->flags |= DF_TEXTREL;
+      info->callbacks->minfo
+       (_("%B: dynamic relocation against `%T' in read-only section `%A'\n"),
+        sec->owner, h->root.root.string, sec);
 
-          /* Not an error, just cut short the traversal.  */
-          return FALSE;
-        }
+      /* Not an error, just cut short the traversal.  */
+      return FALSE;
     }
   return TRUE;
 }
@@ -2311,8 +2330,7 @@ m32r_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, readonly_dynrelocs,
-                                    info);
+            elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
 
           if ((info->flags & DF_TEXTREL) != 0)
             {
@@ -3540,122 +3558,6 @@ m32r_elf_gc_mark_hook (asection *sec,
   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
 }
 
-static bfd_boolean
-m32r_elf_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED,
-                       struct bfd_link_info *info ATTRIBUTE_UNUSED,
-                       asection *sec ATTRIBUTE_UNUSED,
-                       const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED)
-{
-  /* Update the got entry reference counts for the section being removed.  */
-  Elf_Internal_Shdr *symtab_hdr;
-  struct elf_link_hash_entry **sym_hashes;
-  bfd_signed_vma *local_got_refcounts;
-  const Elf_Internal_Rela *rel, *relend;
-
-  if (bfd_link_relocatable (info))
-    return TRUE;
-
-  elf_section_data (sec)->local_dynrel = NULL;
-
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-  sym_hashes = elf_sym_hashes (abfd);
-  local_got_refcounts = elf_local_got_refcounts (abfd);
-
-  relend = relocs + sec->reloc_count;
-  for (rel = relocs; rel < relend; rel++)
-    {
-      unsigned long r_symndx;
-      struct elf_link_hash_entry *h = NULL;
-
-      r_symndx = ELF32_R_SYM (rel->r_info);
-      if (r_symndx >= symtab_hdr->sh_info)
-       {
-         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;
-       }
-
-      switch (ELF32_R_TYPE (rel->r_info))
-       {
-       case R_M32R_GOT16_HI_ULO:
-       case R_M32R_GOT16_HI_SLO:
-       case R_M32R_GOT16_LO:
-       case R_M32R_GOTOFF:
-       case R_M32R_GOTOFF_HI_ULO:
-       case R_M32R_GOTOFF_HI_SLO:
-       case R_M32R_GOTOFF_LO:
-       case R_M32R_GOT24:
-       case R_M32R_GOTPC_HI_ULO:
-       case R_M32R_GOTPC_HI_SLO:
-       case R_M32R_GOTPC_LO:
-       case R_M32R_GOTPC24:
-         if (h != NULL)
-           {
-             if (h->got.refcount > 0)
-               h->got.refcount--;
-           }
-         else
-           {
-             if (local_got_refcounts && local_got_refcounts[r_symndx] > 0)
-               local_got_refcounts[r_symndx]--;
-           }
-         break;
-
-       case R_M32R_16_RELA:
-       case R_M32R_24_RELA:
-       case R_M32R_32_RELA:
-       case R_M32R_REL32:
-       case R_M32R_HI16_ULO_RELA:
-       case R_M32R_HI16_SLO_RELA:
-       case R_M32R_LO16_RELA:
-       case R_M32R_SDA16_RELA:
-       case R_M32R_10_PCREL_RELA:
-       case R_M32R_18_PCREL_RELA:
-       case R_M32R_26_PCREL_RELA:
-         if (h != NULL)
-           {
-             struct elf_m32r_link_hash_entry *eh;
-             struct elf_m32r_dyn_relocs **pp;
-             struct elf_m32r_dyn_relocs *p;
-
-             if (!bfd_link_pic (info) && h->plt.refcount > 0)
-               h->plt.refcount -= 1;
-
-             eh = (struct elf_m32r_link_hash_entry *) h;
-
-             for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-               if (p->sec == sec)
-                 {
-                   if (   ELF32_R_TYPE (rel->r_info) == R_M32R_26_PCREL_RELA
-                       || ELF32_R_TYPE (rel->r_info) == R_M32R_18_PCREL_RELA
-                       || ELF32_R_TYPE (rel->r_info) == R_M32R_10_PCREL_RELA
-                       || ELF32_R_TYPE (rel->r_info) == R_M32R_REL32)
-                     p->pc_count -= 1;
-                   p->count -= 1;
-                   if (p->count == 0)
-                     *pp = p->next;
-                   break;
-                 }
-           }
-         break;
-
-       case R_M32R_26_PLTREL:
-         if (h != NULL)
-           {
-             if (h->plt.refcount > 0)
-               h->plt.refcount--;
-           }
-         break;
-
-       default:
-         break;
-       }
-    }
-
-  return TRUE;
-}
-
 /* Look through the relocs for a section during the first phase.
    Since we don't do .gots or .plts, we just need to consider the
    virtual table relocs for gc.  */
@@ -3704,10 +3606,6 @@ m32r_elf_check_relocs (bfd *abfd,
          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;
-
-         /* PR15323, ref flags aren't set for references in the same
-            object.  */
-         h->root.non_ir_ref_regular = 1;
        }
 
       /* Some relocs require a global offset table.  */
@@ -3974,7 +3872,6 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
 #define elf_backend_add_symbol_hook            m32r_elf_add_symbol_hook
 #define elf_backend_relocate_section           m32r_elf_relocate_section
 #define elf_backend_gc_mark_hook                m32r_elf_gc_mark_hook
-#define elf_backend_gc_sweep_hook               m32r_elf_gc_sweep_hook
 #define elf_backend_check_relocs                m32r_elf_check_relocs
 
 #define elf_backend_create_dynamic_sections     m32r_elf_create_dynamic_sections
@@ -4015,6 +3912,8 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
 #define bfd_elf32_bfd_print_private_bfd_data   m32r_elf_print_private_bfd_data
 #define elf_backend_special_sections           m32r_elf_special_sections
 
+#define elf_backend_linux_prpsinfo32_ugid16    TRUE
+
 #include "elf32-target.h"
 
 #undef  ELF_MAXPAGESIZE
This page took 0.025754 seconds and 4 git commands to generate.