bfd/
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index 1dc9b14741165f357c48baf73ecf645e09719084..4470387890e5d6f4d70e0227300cb459e694a6ad 100644 (file)
@@ -52,19 +52,6 @@ bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data
    linking with -Bsymbolic.  We store the information in a field
    extending the regular ELF linker hash table.  */
 
-/* This structure keeps track of the number of PC relative relocs we
-   have copied for a given symbol.  */
-
-struct elf_mn10300_pcrel_relocs_copied
-{
-  /* Next section.  */
-  struct elf_mn10300_pcrel_relocs_copied * next;
-  /* A section in dynobj.  */
-  asection * section;
-  /* Number of relocs copied in this section.  */
-  bfd_size_type count;
-};
-
 struct elf32_mn10300_link_hash_entry {
   /* The basic elf link hash table entry.  */
   struct elf_link_hash_entry root;
@@ -90,9 +77,6 @@ struct elf32_mn10300_link_hash_entry {
      add it to the hash table to avoid computing it over and over.  */
   unsigned char movm_stack_size;
 
-  /* Number of PC relative relocs copied for this symbol.  */
-  struct elf_mn10300_pcrel_relocs_copied * pcrel_relocs_copied;
-
 /* When set, convert all "call" instructions to this target into "calls"
    instructions.  */
 #define MN10300_CONVERT_CALL_TO_CALLS 0x1
@@ -166,9 +150,6 @@ static bfd_boolean _bfd_mn10300_elf_create_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_boolean _bfd_mn10300_elf_adjust_dynamic_symbol
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
-static bfd_boolean _bfd_mn10300_elf_discard_copies
-  PARAMS ((struct elf32_mn10300_link_hash_entry *,
-          struct bfd_link_info *));
 static bfd_boolean _bfd_mn10300_elf_size_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_symbol
@@ -612,7 +593,7 @@ _bfd_mn10300_elf_create_got_section (abfd, info)
              get_elf_backend_data (abfd)->collect, &bh)))
        return FALSE;
       h = (struct elf_link_hash_entry *) bh;
-      h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
+      h->def_regular = 1;
       h->type = STT_OBJECT;
 
       if (info->shared
@@ -646,7 +627,7 @@ _bfd_mn10300_elf_create_got_section (abfd, info)
         bed->collect, &bh)))
     return FALSE;
   h = (struct elf_link_hash_entry *) bh;
-  h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
+  h->def_regular = 1;
   h->type = STT_OBJECT;
 
   if (info->shared
@@ -883,11 +864,10 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
            break;
 
-         h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+         h->needs_plt = 1;
 
          break;
 
-       case R_MN10300_32:
        case R_MN10300_24:
        case R_MN10300_16:
        case R_MN10300_8:
@@ -895,29 +875,17 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
        case R_MN10300_PCREL16:
        case R_MN10300_PCREL8:
          if (h != NULL)
-           h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
-
-         /* If we are creating a shared library, and this is a reloc
-            against a global symbol, or a non PC relative reloc
-            against a local symbol, then we need to copy the reloc
-            into the shared library.  However, if we are linking with
-            -Bsymbolic, we do not need to copy a reloc against a
-            global symbol which is defined in an object we are
-            including in the link (i.e., DEF_REGULAR is set).  At
-            this point we have not seen all the input files, so it is
-            possible that DEF_REGULAR is not set now but will be set
-            later (it is never cleared).  We account for that
-            possibility below by storing information in the
-            pcrel_relocs_copied field of the hash table entry.  */
+           h->non_got_ref = 1;
+         break;
+
+       case R_MN10300_32:
+         if (h != NULL)
+           h->non_got_ref = 1;
+
+         /* If we are creating a shared library, then we need to copy
+            the reloc into the shared library.  */
          if (info->shared
-             && (sec->flags & SEC_ALLOC) != 0
-             && (! (elf_mn10300_howto_table[ELF32_R_TYPE (rel->r_info)]
-                    .pc_relative)
-                 || (h != NULL
-                     && (! info->symbolic
-                         || h->root.type == bfd_link_hash_defweak
-                         || (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+             && (sec->flags & SEC_ALLOC) != 0)
            {
              /* When creating a shared object, we must copy these
                 reloc types into the output file.  We create a reloc
@@ -955,43 +923,6 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
                }
 
              sreloc->size += sizeof (Elf32_External_Rela);
-
-             /* If we are linking with -Bsymbolic, and this is a
-                global symbol, we count the number of PC relative
-                relocations we have entered for this symbol, so that
-                we can discard them again if the symbol is later
-                defined by a regular object.  Note that this function
-                is only called if we are using an elf_sh linker
-                hash table, which means that h is really a pointer to
-                an elf32_mn10300_link_hash_entry.  */
-             if (h != NULL
-                 && (elf_mn10300_howto_table[ELF32_R_TYPE (rel->r_info)]
-                     .pc_relative))
-               {
-                 struct elf32_mn10300_link_hash_entry *eh;
-                 struct elf_mn10300_pcrel_relocs_copied *p;
-
-                 eh = (struct elf32_mn10300_link_hash_entry *) h;
-
-                 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
-                   if (p->section == sreloc)
-                     break;
-
-                 if (p == NULL)
-                   {
-                     p = ((struct elf_mn10300_pcrel_relocs_copied *)
-                          bfd_alloc (dynobj, sizeof *p));
-                     if (p == NULL)
-                       return FALSE;
-
-                     p->next = eh->pcrel_relocs_copied;
-                     eh->pcrel_relocs_copied = p;
-                     p->section = sreloc;
-                     p->count = 0;
-                   }
-
-                 ++p->count;
-               }
            }
 
          break;
@@ -1075,6 +1006,24 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
   splt   = NULL;
   sreloc = NULL;
 
+  switch (r_type)
+    {
+    case R_MN10300_24:
+    case R_MN10300_16:
+    case R_MN10300_8:
+    case R_MN10300_PCREL8:
+    case R_MN10300_PCREL16:
+    case R_MN10300_PCREL32:
+    case R_MN10300_GOTOFF32:
+    case R_MN10300_GOTOFF24:
+    case R_MN10300_GOTOFF16:
+      if (info->shared
+         && (input_section->flags & SEC_ALLOC) != 0
+         && h != NULL
+         && ! SYMBOL_REFERENCES_LOCAL (info, h))
+       return bfd_reloc_dangerous;
+    }
+
   switch (r_type)
     {
     case R_MN10300_NONE:
@@ -1130,9 +1079,7 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
              /* h->dynindx may be -1 if this symbol was marked to
                 become local.  */
              if (h == NULL
-                 || ((info->symbolic || h->dynindx == -1)
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) != 0))
+                 || SYMBOL_REFERENCES_LOCAL (info, h))
                {
                  relocate = TRUE;
                  outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
@@ -1217,68 +1164,6 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
       return bfd_reloc_ok;
 
     case R_MN10300_PCREL32:
-      if (info->shared
-         && (input_section->flags & SEC_ALLOC) != 0
-         && h != NULL
-         && h->dynindx != -1
-         && (! info->symbolic
-             || (h->elf_link_hash_flags
-                 & ELF_LINK_HASH_DEF_REGULAR) == 0))
-       {
-         Elf_Internal_Rela outrel;
-         bfd_boolean skip;
-
-         /* When generating a shared object, these relocations
-            are copied into the output file to be resolved at run
-            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)
-               return FALSE;
-
-             BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                         && strcmp (bfd_get_section_name (input_bfd,
-                                                          input_section),
-                                    name + 5) == 0);
-
-             sreloc = bfd_get_section_by_name (dynobj, name);
-             BFD_ASSERT (sreloc != NULL);
-           }
-
-         skip = FALSE;
-         outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
-                                                    input_section, offset);
-         if (outrel.r_offset == (bfd_vma) -1)
-           skip = TRUE;
-
-         outrel.r_offset += (input_section->output_section->vma
-                             + input_section->output_offset);
-
-         if (skip)
-           memset (&outrel, 0, sizeof outrel);
-         else
-           {
-             BFD_ASSERT (h != NULL && h->dynindx != -1);
-             outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_PCREL32);
-             outrel.r_addend = addend;
-           }
-
-         bfd_elf32_swap_reloca_out (output_bfd, &outrel,
-                                    (bfd_byte *) (((Elf32_External_Rela *)
-                                                   sreloc->contents)
-                                                  + sreloc->reloc_count));
-         ++sreloc->reloc_count;
-
-         return bfd_reloc_ok;
-       }
-
       value -= (input_section->output_section->vma
                + input_section->output_offset);
       value -= offset;
@@ -1417,9 +1302,7 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
              BFD_ASSERT (off != (bfd_vma) -1);
 
              if (! elf_hash_table (info)->dynamic_sections_created
-                 || (info->shared
-                     && (info->symbolic || h->dynindx == -1)
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+                 || SYMBOL_REFERENCES_LOCAL (info, h))
                /* This is actually a static link, or it is a
                   -Bsymbolic link and the symbol is defined
                   locally, or the symbol was forced to be local
@@ -1578,24 +1461,16 @@ mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                       || r_type == R_MN10300_GOT24
                       || r_type == R_MN10300_GOT16)
                      && elf_hash_table (info)->dynamic_sections_created
-                     && (! info->shared
-                         || (! info->symbolic && h->root.dynindx != -1)
-                         || (h->root.elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0))
-                 || (info->shared
-                     && ((! info->symbolic && h->root.dynindx != -1)
-                         || (h->root.elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0)
-                     && (   r_type == R_MN10300_32
-                         || r_type == R_MN10300_PCREL32)
+                     && !SYMBOL_REFERENCES_LOCAL (info, hh))
+                 || (r_type == R_MN10300_32
+                     && !SYMBOL_REFERENCES_LOCAL (info, hh)
                      && ((input_section->flags & SEC_ALLOC) != 0
                          /* DWARF will emit R_MN10300_32 relocations
                             in its sections against symbols defined
                             externally in shared libraries.  We can't
                             do anything with them here.  */
                          || ((input_section->flags & SEC_DEBUGGING) != 0
-                             && (h->root.elf_link_hash_flags
-                                 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))))
+                             && h->root.def_dynamic)))))
            /* In these cases, we don't need the relocation
               value.  We check specially because in some
               obscure cases sec->output_section will be NULL.  */
@@ -1635,8 +1510,9 @@ mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
            case bfd_reloc_overflow:
              if (! ((*info->callbacks->reloc_overflow)
-                    (info, name, howto->name, (bfd_vma) 0,
-                     input_bfd, input_section, rel->r_offset)))
+                    (info, (h ? &h->root.root : NULL), name,
+                     howto->name, (bfd_vma) 0, input_bfd,
+                     input_section, rel->r_offset)))
                return FALSE;
              break;
 
@@ -3816,7 +3692,6 @@ elf32_mn10300_link_hash_newfunc (entry, table, string)
       ret->stack_size = 0;
       ret->movm_args = 0;
       ret->movm_stack_size = 0;
-      ret->pcrel_relocs_copied = NULL;
       ret->flags = 0;
     }
 
@@ -4146,31 +4021,28 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
 
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
-             && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
-                 || h->weakdef != NULL
-                 || ((h->elf_link_hash_flags
-                      & ELF_LINK_HASH_DEF_DYNAMIC) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_REF_REGULAR) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)));
+             && (h->needs_plt
+                 || h->u.weakdef != NULL
+                 || (h->def_dynamic
+                     && h->ref_regular
+                     && !h->def_regular)));
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later,
      when we know the address of the .got section.  */
   if (h->type == STT_FUNC
-      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
+      || h->needs_plt)
     {
       if (! info->shared
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
+         && !h->def_dynamic
+         && !h->ref_dynamic)
        {
          /* This case can occur if we saw a PLT reloc in an input
             file, but the symbol was never referred to by a dynamic
             object.  In such a case, we don't actually need to build
             a procedure linkage table, and we can just do a REL32
             reloc instead.  */
-         BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
+         BFD_ASSERT (h->needs_plt);
          return TRUE;
        }
 
@@ -4195,7 +4067,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
         pointers compare as equal between the normal executable and
         the shared library.  */
       if (! info->shared
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+         && !h->def_regular)
        {
          h->root.u.def.section = s;
          h->root.u.def.value = s->size;
@@ -4225,12 +4097,12 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
   /* 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->weakdef != NULL)
+  if (h->u.weakdef != NULL)
     {
-      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
-                 || h->weakdef->root.type == bfd_link_hash_defweak);
-      h->root.u.def.section = h->weakdef->root.u.def.section;
-      h->root.u.def.value = h->weakdef->root.u.def.value;
+      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;
       return TRUE;
     }
 
@@ -4246,7 +4118,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
 
   /* If there are no references to this symbol that do not use the
      GOT, we don't need to generate a copy reloc.  */
-  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
+  if (!h->non_got_ref)
     return TRUE;
 
   /* We must allocate the symbol in our .dynbss section, which will
@@ -4273,7 +4145,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
       srel->size += sizeof (Elf32_External_Rela);
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
+      h->needs_copy = 1;
     }
 
   /* We need to figure out the alignment required for this symbol.  I
@@ -4300,34 +4172,6 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
   return TRUE;
 }
 
-/* This function is called via elf32_mn10300_link_hash_traverse if we are
-   creating a shared object with -Bsymbolic.  It discards the space
-   allocated to copy PC relative relocs against symbols which are
-   defined in regular objects.  We allocated space for them in the
-   check_relocs routine, but we won't fill them in in the
-   relocate_section routine.  */
-
-static bfd_boolean
-_bfd_mn10300_elf_discard_copies (h, info)
-     struct elf32_mn10300_link_hash_entry *h;
-     struct bfd_link_info *info;
-{
-  struct elf_mn10300_pcrel_relocs_copied *s;
-
-  /* If a symbol has been forced local or we have found a regular
-     definition for the symbolic link case, then we won't be needing
-     any relocs.  */
-  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-      && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
-         || info->symbolic))
-    {
-      for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
-       s->section->size -= s->count * sizeof (Elf32_External_Rel);
-    }
-
-  return TRUE;
-}
-
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
@@ -4367,15 +4211,6 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
        s->size = 0;
     }
 
-  /* If this is a -Bsymbolic shared link, then we need to discard all
-     PC relative relocs against symbols defined in a regular object.
-     We allocated space for them in the check_relocs routine, but we
-     will not fill them in in the relocate_section routine.  */
-  if (info->shared && info->symbolic)
-    elf32_mn10300_link_hash_traverse (elf32_mn10300_hash_table (info),
-                                     _bfd_mn10300_elf_discard_copies,
-                                     info);
-
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
@@ -4607,7 +4442,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
                                 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
                                               + plt_index));
 
-      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+      if (!h->def_regular)
        /* Mark the symbol as undefined, rather than as defined in
           the .plt section.  Leave the value alone.  */
        sym->st_shndx = SHN_UNDEF;
@@ -4636,7 +4471,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
         initialized in the relocate_section function.  */
       if (info->shared
          && (info->symbolic || h->dynindx == -1)
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+         && h->def_regular)
        {
          rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
          rel.r_addend = (h->root.u.def.value
@@ -4656,7 +4491,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
       ++ srel->reloc_count;
     }
 
-  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
+  if (h->needs_copy)
     {
       asection *        s;
       Elf_Internal_Rela rel;
This page took 0.029524 seconds and 4 git commands to generate.