include/
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index 4a92a1adec2541221a64975a0f2bb3b4ea7f32c0..d882eb4f775f6223dadf0ac691fc7a13e543ad19 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
@@ -656,7 +637,7 @@ _bfd_mn10300_elf_create_got_section (abfd, info)
   elf_hash_table (info)->hgot = h;
 
   /* The first bit of the global offset table is the header.  */
-  s->_raw_size += bed->got_header_size + bed->got_symbol_offset;
+  s->size += bed->got_header_size + bed->got_symbol_offset;
 
   return TRUE;
 }
@@ -817,7 +798,7 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
                /* We have already allocated space in the .got.  */
                break;
 
-             h->got.offset = sgot->_raw_size;
+             h->got.offset = sgot->size;
 
              /* Make sure this symbol is output as a dynamic symbol.  */
              if (h->dynindx == -1)
@@ -826,7 +807,7 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
                    return FALSE;
                }
 
-             srelgot->_raw_size += sizeof (Elf32_External_Rela);
+             srelgot->size += sizeof (Elf32_External_Rela);
            }
          else
            {
@@ -852,16 +833,16 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
                /* We have already allocated space in the .got.  */
                break;
 
-             local_got_offsets[r_symndx] = sgot->_raw_size;
+             local_got_offsets[r_symndx] = sgot->size;
 
              if (info->shared)
                /* If we are generating a shared object, we need to
                   output a R_MN10300_RELATIVE reloc so that the dynamic
                   linker can adjust this GOT entry.  */
-               srelgot->_raw_size += sizeof (Elf32_External_Rela);
+               srelgot->size += sizeof (Elf32_External_Rela);
            }
 
-         sgot->_raw_size += 4;
+         sgot->size += 4;
 
          break;
 
@@ -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
@@ -954,44 +922,7 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
                    }
                }
 
-             sreloc->_raw_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;
-               }
+             sreloc->size += sizeof (Elf32_External_Rela);
            }
 
          break;
@@ -1056,7 +987,7 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
      bfd_vma addend;
      struct elf_link_hash_entry * h;
      unsigned long symndx;
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
+     struct bfd_link_info *info;
      asection *sym_sec ATTRIBUTE_UNUSED;
      int is_local ATTRIBUTE_UNUSED;
 {
@@ -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:
@@ -1112,22 +1061,10 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
 
          skip = FALSE;
 
-         if (elf_section_data (input_section)->sec_info == NULL
-             || (input_section->sec_info_type != ELF_INFO_TYPE_STABS))
-           outrel.r_offset = offset;
-         else
-           {
-             bfd_vma off;
-
-             off = (_bfd_stab_section_offset
-                    (output_bfd, & elf_hash_table (info)->stab_info,
-                     input_section,
-                     & elf_section_data (input_section)->sec_info,
-                     offset));
-             if (off == (bfd_vma) -1)
-               skip = TRUE;
-             outrel.r_offset = off;
-           }
+         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);
@@ -1142,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);
@@ -1229,81 +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;
-
-         if (elf_section_data (input_section)->sec_info == NULL
-             || (input_section->sec_info_type != ELF_INFO_TYPE_STABS))
-           outrel.r_offset = offset;
-         else
-           {
-             bfd_vma off;
-
-             off = (_bfd_stab_section_offset
-                    (output_bfd, & elf_hash_table (info)->stab_info,
-                     input_section,
-                     & elf_section_data (input_section)->sec_info,
-                     offset));
-             if (off == (bfd_vma) -1)
-               skip = TRUE;
-             outrel.r_offset = off;
-           }
-
-         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;
@@ -1442,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
@@ -1603,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.  */
@@ -1868,16 +1718,11 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
              /* Get cached copy of section contents if it exists.  */
              if (elf_section_data (section)->this_hdr.contents != NULL)
                contents = elf_section_data (section)->this_hdr.contents;
-             else if (section->_raw_size != 0)
+             else if (section->size != 0)
                {
                  /* Go get them off disk.  */
-                 contents = (bfd_byte *) bfd_malloc (section->_raw_size);
-                 if (contents == NULL)
-                   goto error_return;
-
-                 if (!bfd_get_section_contents (input_bfd, section,
-                                                contents, (file_ptr) 0,
-                                                section->_raw_size))
+                 if (!bfd_malloc_and_get_section (input_bfd, section,
+                                                  &contents))
                    goto error_return;
                }
              else
@@ -2168,7 +2013,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
              unsigned int symcount;
 
              /* Skip non-code sections and empty sections.  */
-             if ((section->flags & SEC_CODE) == 0 || section->_raw_size == 0)
+             if ((section->flags & SEC_CODE) == 0 || section->size == 0)
                continue;
 
              if (section->reloc_count != 0)
@@ -2188,13 +2033,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
              else
                {
                  /* Go get them off disk.  */
-                 contents = (bfd_byte *) bfd_malloc (section->_raw_size);
-                 if (contents == NULL)
-                   goto error_return;
-
-                 if (!bfd_get_section_contents (input_bfd, section,
-                                                contents, (file_ptr) 0,
-                                                section->_raw_size))
+                 if (!bfd_malloc_and_get_section (input_bfd, section,
+                                                  &contents))
                    goto error_return;
                }
 
@@ -2396,11 +2236,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
       || (sec->flags & SEC_CODE) == 0)
     return TRUE;
 
-  /* If this is the first time we have been called for this section,
-     initialize the cooked size.  */
-  if (sec->_cooked_size == 0)
-    sec->_cooked_size = sec->_raw_size;
-
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
 
   /* Get a copy of the native relocations.  */
@@ -2433,12 +2268,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
          else
            {
              /* Go get them off disk.  */
-             contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
-             if (contents == NULL)
-               goto error_return;
-
-             if (! bfd_get_section_contents (abfd, sec, contents,
-                                             (file_ptr) 0, sec->_raw_size))
+             if (!bfd_malloc_and_get_section (abfd, sec, &contents))
                goto error_return;
            }
        }
@@ -2462,6 +2292,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
          asection *sym_sec = NULL;
          const char *sym_name;
          char *new_name;
+         bfd_vma saved_addend;
 
          /* A local symbol.  */
          isym = isymbuf + ELF32_R_SYM (irel->r_info);
@@ -2474,13 +2305,25 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
          else
            sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
 
-         symval = (isym->st_value
-                   + sym_sec->output_section->vma
-                   + sym_sec->output_offset);
          sym_name = bfd_elf_string_from_elf_section (abfd,
                                                      symtab_hdr->sh_link,
                                                      isym->st_name);
 
+         if ((sym_sec->flags & SEC_MERGE)
+             && ELF_ST_TYPE (isym->st_info) == STT_SECTION
+             && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
+           {
+             saved_addend = irel->r_addend;
+             symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
+             symval += irel->r_addend;
+             irel->r_addend = saved_addend;
+           }
+         else
+           {
+             symval = (isym->st_value
+                       + sym_sec->output_section->vma
+                       + sym_sec->output_offset);
+           }
          /* Tack on an ID so we can uniquely identify this
             local symbol in the global hash table.  */
          new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
@@ -2779,7 +2622,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
          value += irel->r_addend;
 
          /* Do nothing if this reloc is the last byte in the section.  */
-         if (irel->r_offset == sec->_cooked_size)
+         if (irel->r_offset == sec->size)
            continue;
 
          /* See if the next instruction is an unconditional pc-relative
@@ -3612,7 +3455,7 @@ mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
      power larger than the number of bytes we are deleting.  */
 
   irelalign = NULL;
-  toaddr = sec->_cooked_size;
+  toaddr = sec->size;
 
   irel = elf_section_data (sec)->relocs;
   irelend = irel + sec->reloc_count;
@@ -3620,7 +3463,7 @@ mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
   /* Actually delete the bytes.  */
   memmove (contents + addr, contents + addr + count,
           (size_t) (toaddr - addr - count));
-  sec->_cooked_size -= count;
+  sec->size -= count;
 
   /* Adjust all the relocs.  */
   for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
@@ -3739,7 +3582,7 @@ mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
 
   memcpy (data, elf_section_data (input_section)->this_hdr.contents,
-         (size_t) input_section->_raw_size);
+         (size_t) input_section->size);
 
   if ((input_section->flags & SEC_RELOC) != 0
       && input_section->reloc_count > 0)
@@ -3848,7 +3691,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;
     }
 
@@ -4178,31 +4020,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;
        }
 
@@ -4218,8 +4057,8 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
 
       /* If this is the first .plt entry, make room for the special
         first entry.  */
-      if (s->_raw_size == 0)
-       s->_raw_size += elf_mn10300_sizeof_plt0 (info);
+      if (s->size == 0)
+       s->size += elf_mn10300_sizeof_plt0 (info);
 
       /* If this symbol is not defined in a regular file, and we are
         not generating a shared library, then set the symbol to this
@@ -4227,29 +4066,29 @@ _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->_raw_size;
+         h->root.u.def.value = s->size;
        }
 
-      h->plt.offset = s->_raw_size;
+      h->plt.offset = s->size;
 
       /* Make room for this entry.  */
-      s->_raw_size += elf_mn10300_sizeof_plt (info);
+      s->size += elf_mn10300_sizeof_plt (info);
 
       /* We also need to make an entry in the .got.plt section, which
         will be placed in the .got section by the linker script.  */
 
       s = bfd_get_section_by_name (dynobj, ".got.plt");
       BFD_ASSERT (s != NULL);
-      s->_raw_size += 4;
+      s->size += 4;
 
       /* We also need to make an entry in the .rela.plt section.  */
 
       s = bfd_get_section_by_name (dynobj, ".rela.plt");
       BFD_ASSERT (s != NULL);
-      s->_raw_size += sizeof (Elf32_External_Rela);
+      s->size += sizeof (Elf32_External_Rela);
 
       return TRUE;
     }
@@ -4257,12 +4096,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;
     }
 
@@ -4278,7 +4117,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
@@ -4304,8 +4143,8 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
 
       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
-      srel->_raw_size += sizeof (Elf32_External_Rela);
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
+      srel->size += sizeof (Elf32_External_Rela);
+      h->needs_copy = 1;
     }
 
   /* We need to figure out the alignment required for this symbol.  I
@@ -4315,8 +4154,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
     power_of_two = 3;
 
   /* Apply the required alignment.  */
-  s->_raw_size = BFD_ALIGN (s->_raw_size,
-                           (bfd_size_type) (1 << power_of_two));
+  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
   if (power_of_two > bfd_get_section_alignment (dynobj, s))
     {
       if (! bfd_set_section_alignment (dynobj, s, power_of_two))
@@ -4325,38 +4163,10 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
-  h->root.u.def.value = s->_raw_size;
+  h->root.u.def.value = s->size;
 
   /* Increment the section size to make room for the symbol.  */
-  s->_raw_size += h->size;
-
-  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->_raw_size -= s->count * sizeof (Elf32_External_Rel);
-    }
+  s->size += h->size;
 
   return TRUE;
 }
@@ -4384,7 +4194,7 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
-         s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
+         s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
        }
     }
@@ -4397,18 +4207,9 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
         below.  */
       s = bfd_get_section_by_name (dynobj, ".rela.got");
       if (s != NULL)
-       s->_raw_size = 0;
+       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.  */
@@ -4431,7 +4232,7 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
 
       if (strcmp (name, ".plt") == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            /* Strip this section if we don't need it; see the
               comment below.  */
            strip = TRUE;
@@ -4441,7 +4242,7 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
        }
       else if (strncmp (name, ".rela", 5) == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* If we don't need this section, strip it from the
                 output file.  This is mostly to handle .rela.bss and
@@ -4500,8 +4301,8 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
         section's contents are written out.  This should not happen,
         but this way if it does, we get a R_MN10300_NONE reloc
         instead of garbage.  */
-      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
-      if (s->contents == NULL && s->_raw_size != 0)
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
+      if (s->contents == NULL && s->size != 0)
        return FALSE;
     }
 
@@ -4640,7 +4441,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;
@@ -4669,7 +4470,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
@@ -4689,7 +4490,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;
@@ -4748,7 +4549,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
       BFD_ASSERT (sdyn != NULL);
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
-      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
 
       for (; dyncon < dynconend; dyncon++)
        {
@@ -4779,10 +4580,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
            case DT_PLTRELSZ:
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
              BFD_ASSERT (s != NULL);
-             if (s->_cooked_size != 0)
-               dyn.d_un.d_val = s->_cooked_size;
-             else
-               dyn.d_un.d_val = s->_raw_size;
+             dyn.d_un.d_val = s->size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
 
@@ -4798,12 +4596,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
                 about changing the DT_RELA entry.  */
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
              if (s != NULL)
-               {
-                 if (s->_cooked_size != 0)
-                   dyn.d_un.d_val -= s->_cooked_size;
-                 else
-                   dyn.d_un.d_val -= s->_raw_size;
-               }
+               dyn.d_un.d_val -= s->size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
            }
@@ -4811,7 +4604,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
 
       /* Fill in the first entry in the procedure linkage table.  */
       splt = bfd_get_section_by_name (dynobj, ".plt");
-      if (splt && splt->_raw_size > 0)
+      if (splt && splt->size > 0)
        {
          if (info->shared)
            {
@@ -4836,7 +4629,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
     }
 
   /* Fill in the first three entries in the global offset table.  */
-  if (sgot->_raw_size > 0)
+  if (sgot->size > 0)
     {
       if (sdyn == NULL)
        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
@@ -4853,6 +4646,25 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
   return TRUE;
 }
 
+/* Classify relocation types, such that combreloc can sort them
+   properly.  */
+
+static enum elf_reloc_type_class
+_bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela *rela)
+{
+  switch ((int) ELF32_R_TYPE (rela->r_info))
+    {
+    case R_MN10300_RELATIVE:
+      return reloc_class_relative;
+    case R_MN10300_JMP_SLOT:
+      return reloc_class_plt;
+    case R_MN10300_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
 #ifndef ELF_ARCH
 #define TARGET_LITTLE_SYM      bfd_elf32_mn10300_vec
 #define TARGET_LITTLE_NAME     "elf32-mn10300"
@@ -4901,6 +4713,9 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
 #define elf_backend_finish_dynamic_sections \
   _bfd_mn10300_elf_finish_dynamic_sections
 
+#define elf_backend_reloc_type_class \
+  _bfd_mn10300_elf_reloc_type_class
+
 #define elf_backend_want_got_plt       1
 #define elf_backend_plt_readonly       1
 #define elf_backend_want_plt_sym       0
This page took 0.04437 seconds and 4 git commands to generate.