Update ARC instruction data-base.
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index 428de4c9e07ffd34d7d82a351031873eef344976..949f14aa018ad75de45bb006b75bab7ca26567e8 100644 (file)
@@ -1,6 +1,5 @@
 /* Matsushita 10300 specific support for 32-bit ELF
-   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1996-2016 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -143,11 +142,11 @@ static reloc_howto_type elf_mn10300_howto_table[] =
   /* Dummy relocation.  Does nothing.  */
   HOWTO (R_MN10300_NONE,
         0,
-        2,
-        16,
+        3,
+        0,
         FALSE,
         0,
-        complain_overflow_bitfield,
+        complain_overflow_dont,
         bfd_elf_generic_reloc,
         "R_MN10300_NONE",
         FALSE,
@@ -604,7 +603,7 @@ static reloc_howto_type elf_mn10300_howto_table[] =
         0xffffffff,            /* src_mask */
         0xffffffff,            /* dst_mask */
         FALSE),                /* pcrel_offset */
-  
+
   HOWTO (R_MN10300_SYM_DIFF,   /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
@@ -690,10 +689,12 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
   asection * s;
   struct elf_link_hash_entry * h;
   const struct elf_backend_data * bed = get_elf_backend_data (abfd);
+  struct elf_link_hash_table *htab;
   int ptralign;
 
   /* This function may be called more than once.  */
-  if (bfd_get_section_by_name (abfd, ".got") != NULL)
+  htab = elf_hash_table (info);
+  if (htab->sgot != NULL)
     return TRUE;
 
   switch (bed->s->arch_size)
@@ -721,7 +722,8 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
   if (bed->plt_readonly)
     pltflags |= SEC_READONLY;
 
-  s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
+  s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
+  htab->splt = s;
   if (s == NULL
       || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
     return FALSE;
@@ -732,19 +734,21 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
     {
       h = _bfd_elf_define_linkage_sym (abfd, info, s,
                                       "_PROCEDURE_LINKAGE_TABLE_");
-      elf_hash_table (info)->hplt = h;
+      htab->hplt = h;
       if (h == NULL)
        return FALSE;
     }
 
-  s = bfd_make_section_with_flags (abfd, ".got", flags);
+  s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
+  htab->sgot = s;
   if (s == NULL
       || ! bfd_set_section_alignment (abfd, s, ptralign))
     return FALSE;
 
   if (bed->want_got_plt)
     {
-      s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
+      s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
+      htab->sgotplt = s;
       if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, ptralign))
        return FALSE;
@@ -755,7 +759,7 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
      because we don't want to define the symbol if we are not creating
      a global offset table.  */
   h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
-  elf_hash_table (info)->hgot = h;
+  htab->hgot = h;
   if (h == NULL)
     return FALSE;
 
@@ -802,7 +806,13 @@ mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   unsigned int r_type;
 
   r_type = ELF32_R_TYPE (dst->r_info);
-  BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX);
+  if (r_type >= R_MN10300_MAX)
+    {
+      (*_bfd_error_handler) (_("%B: unrecognised MN10300 reloc number: %d"),
+                            abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      r_type = R_MN10300_NONE;
+    }
   cache_ptr->howto = elf_mn10300_howto_table + r_type;
 }
 
@@ -820,7 +830,7 @@ elf_mn10300_tls_transition (struct bfd_link_info *        info,
       && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE)
     return R_MN10300_TLS_GOTIE;
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     return r_type;
 
   if (! (sec->flags & SEC_CODE))
@@ -1051,7 +1061,7 @@ mn10300_elf_check_relocs (bfd *abfd,
   srelgot = NULL;
   sreloc  = NULL;
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     return TRUE;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
@@ -1079,6 +1089,10 @@ mn10300_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 = 1;
        }
 
       r_type = ELF32_R_TYPE (rel->r_info);
@@ -1139,10 +1153,10 @@ mn10300_elf_check_relocs (bfd *abfd,
 
        case R_MN10300_TLS_IE:
        case R_MN10300_TLS_GOTIE:
-         if (info->shared)
+         if (bfd_link_pic (info))
            info->flags |= DF_STATIC_TLS;
          /* Fall through */
-         
+
        case R_MN10300_TLS_GD:
        case R_MN10300_GOT32:
        case R_MN10300_GOT24:
@@ -1160,24 +1174,22 @@ mn10300_elf_check_relocs (bfd *abfd,
 
          if (sgot == NULL)
            {
-             sgot = bfd_get_section_by_name (dynobj, ".got");
+             sgot = htab->root.sgot;
              BFD_ASSERT (sgot != NULL);
            }
 
          if (srelgot == NULL
-             && (h != NULL || info->shared))
+             && (h != NULL || bfd_link_pic (info)))
            {
-             srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+             srelgot = bfd_get_linker_section (dynobj, ".rela.got");
              if (srelgot == NULL)
                {
-                 srelgot = bfd_make_section_with_flags (dynobj,
-                                                        ".rela.got",
-                                                        (SEC_ALLOC
-                                                         | SEC_LOAD
-                                                         | SEC_HAS_CONTENTS
-                                                         | SEC_IN_MEMORY
-                                                         | SEC_LINKER_CREATED
-                                                         | SEC_READONLY));
+                 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+                                   | SEC_IN_MEMORY | SEC_LINKER_CREATED
+                                   | SEC_READONLY);
+                 srelgot = bfd_make_section_anyway_with_flags (dynobj,
+                                                               ".rela.got",
+                                                               flags);
                  if (srelgot == NULL
                      || ! bfd_set_section_alignment (dynobj, srelgot, 2))
                    goto fail;
@@ -1256,7 +1268,7 @@ mn10300_elf_check_relocs (bfd *abfd,
 
              local_got_offsets[r_symndx] = sgot->size;
 
-             if (info->shared)
+             if (bfd_link_pic (info))
                {
                  /* If we are generating a shared object, we need to
                     output a R_MN10300_RELATIVE reloc so that the dynamic
@@ -1320,7 +1332,7 @@ mn10300_elf_check_relocs (bfd *abfd,
        need_shared_relocs:
          /* If we are creating a shared library, then we
             need to copy the reloc into the shared library.  */
-         if (info->shared
+         if (bfd_link_pic (info)
              && (sec->flags & SEC_ALLOC) != 0
              /* Do not generate a dynamic reloc for a
                 reloc associated with a SYM_DIFF operation.  */
@@ -1453,7 +1465,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
     case R_MN10300_GOTOFF32:
     case R_MN10300_GOTOFF24:
     case R_MN10300_GOTOFF16:
-      if (info->shared
+      if (bfd_link_pic (info)
          && (input_section->flags & SEC_ALLOC) != 0
          && h != NULL
          && ! SYMBOL_REFERENCES_LOCAL (info, h))
@@ -1462,7 +1474,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       /* Issue 2052223:
         Taking the address of a protected function in a shared library
         is illegal.  Issue an error message here.  */
-      if (info->shared
+      if (bfd_link_pic (info)
          && (input_section->flags & SEC_ALLOC) != 0
          && h != NULL
          && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED
@@ -1520,7 +1532,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       return bfd_reloc_ok;
 
     case R_MN10300_32:
-      if (info->shared
+      if (bfd_link_pic (info)
          /* Do not generate relocs when an R_MN10300_32 has been used
             with an R_MN10300_SYM_DIFF to compute a difference of two
             symbols.  */
@@ -1669,8 +1681,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
        return bfd_reloc_dangerous;
 
       /* Use global offset table as symbol value.  */
-      value = bfd_get_section_by_name (dynobj,
-                                      ".got")->output_section->vma;
+      value = htab->root.sgot->output_section->vma;
       value -= (input_section->output_section->vma
                + input_section->output_offset);
       value -= offset;
@@ -1684,8 +1695,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
        return bfd_reloc_dangerous;
 
       /* Use global offset table as symbol value.  */
-      value = bfd_get_section_by_name (dynobj,
-                                      ".got")->output_section->vma;
+      value = htab->root.sgot->output_section->vma;
       value -= (input_section->output_section->vma
                + input_section->output_offset);
       value -= offset;
@@ -1701,8 +1711,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       if (dynobj == NULL)
        return bfd_reloc_dangerous;
 
-      value -= bfd_get_section_by_name (dynobj,
-                                       ".got")->output_section->vma;
+      value -= htab->root.sgot->output_section->vma;
       value += addend;
 
       bfd_put_32 (input_bfd, value, hit_data);
@@ -1712,8 +1721,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       if (dynobj == NULL)
        return bfd_reloc_dangerous;
 
-      value -= bfd_get_section_by_name (dynobj,
-                                       ".got")->output_section->vma;
+      value -= htab->root.sgot->output_section->vma;
       value += addend;
 
       if ((long) value > 0x7fffff || (long) value < -0x800000)
@@ -1728,8 +1736,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       if (dynobj == NULL)
        return bfd_reloc_dangerous;
 
-      value -= bfd_get_section_by_name (dynobj,
-                                       ".got")->output_section->vma;
+      value -= htab->root.sgot->output_section->vma;
       value += addend;
 
       if ((long) value > 0x7fff || (long) value < -0x8000)
@@ -1747,8 +1754,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
          if (dynobj == NULL)
            return bfd_reloc_dangerous;
 
-         splt = bfd_get_section_by_name (dynobj, ".plt");
-
+         splt = htab->root.splt;
          value = (splt->output_section->vma
                   + splt->output_offset
                   + h->plt.offset) - value;
@@ -1771,8 +1777,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
          if (dynobj == NULL)
            return bfd_reloc_dangerous;
 
-         splt = bfd_get_section_by_name (dynobj, ".plt");
-
+         splt = htab->root.splt;
          value = (splt->output_section->vma
                   + splt->output_offset
                   + h->plt.offset) - value;
@@ -1803,15 +1808,14 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       if (dynobj == NULL)
        return bfd_reloc_dangerous;
 
-      sgot = bfd_get_section_by_name (dynobj, ".got");
-
+      sgot = htab->root.sgot;
       BFD_ASSERT (sgot != NULL);
       value = htab->tls_ldm_got.offset + sgot->output_offset;
       bfd_put_32 (input_bfd, value, hit_data);
 
       if (!htab->tls_ldm_got.rel_emitted)
        {
-         asection * srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+         asection * srelgot = bfd_get_linker_section (dynobj, ".rela.got");
          Elf_Internal_Rela rel;
 
          BFD_ASSERT (srelgot != NULL);
@@ -1843,8 +1847,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
       if (dynobj == NULL)
        return bfd_reloc_dangerous;
 
-      sgot = bfd_get_section_by_name (dynobj, ".got");
-
+      sgot = htab->root.sgot;
       if (r_type == R_MN10300_TLS_GD)
        value = dtpoff (info, value);
 
@@ -1887,12 +1890,12 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
            {
              bfd_put_32 (output_bfd, value, sgot->contents + off);
 
-             if (info->shared)
+             if (bfd_link_pic (info))
                {
                  asection * srelgot;
                  Elf_Internal_Rela outrel;
 
-                 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+                 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
                  BFD_ASSERT (srelgot != NULL);
 
                  outrel.r_offset = (sgot->output_section->vma
@@ -2013,7 +2016,7 @@ mn10300_elf_relocate_section (bfd *output_bfd,
       bfd_reloc_status_type r;
       int tls_r_type;
       bfd_boolean unresolved_reloc = FALSE;
-      bfd_boolean warned;
+      bfd_boolean warned, ignored;
       struct elf_link_hash_entry * hh;
 
       relocation = 0;
@@ -2036,7 +2039,7 @@ mn10300_elf_relocate_section (bfd *output_bfd,
          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
                                   r_symndx, symtab_hdr, sym_hashes,
                                   hh, sec, relocation,
-                                  unresolved_reloc, warned);
+                                  unresolved_reloc, warned, ignored);
        }
       h = elf_mn10300_hash_entry (hh);
 
@@ -2088,7 +2091,7 @@ mn10300_elf_relocate_section (bfd *output_bfd,
                      /* _32 relocs in executables force _COPY relocs,
                         such that the address of the symbol ends up
                         being local.  */
-                     && !info->executable
+                     && !bfd_link_executable (info)
                      && !SYMBOL_REFERENCES_LOCAL (info, hh)
                      && ((input_section->flags & SEC_ALLOC) != 0
                          /* DWARF will emit R_MN10300_32 relocations
@@ -2102,7 +2105,7 @@ mn10300_elf_relocate_section (bfd *output_bfd,
               obscure cases sec->output_section will be NULL.  */
            relocation = 0;
 
-         else if (!info->relocatable && unresolved_reloc
+         else if (!bfd_link_relocatable (info) && unresolved_reloc
                   && _bfd_elf_section_offset (output_bfd, info, input_section,
                                               rel->r_offset) != (bfd_vma) -1)
 
@@ -2115,11 +2118,11 @@ mn10300_elf_relocate_section (bfd *output_bfd,
               h->root.root.root.string);
        }
 
-      if (sec != NULL && elf_discarded_section (sec))
+      if (sec != NULL && discarded_section (sec))
        RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
-                                        rel, relend, howto, contents);
+                                        rel, 1, relend, howto, 0, contents);
 
-      if (info->relocatable)
+      if (bfd_link_relocatable (info))
        continue;
 
       r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
@@ -2431,7 +2434,7 @@ mn10300_elf_relax_delete_bytes (bfd *abfd,
         serve to keep the section artifically inflated.  */
       if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN)
        --irelend;
-      
+
       /* The deletion must stop at the next ALIGN reloc for an aligment
         power larger than, or not a multiple of, the number of bytes we
         are deleting.  */
@@ -2662,7 +2665,7 @@ mn10300_elf_relax_section (bfd *abfd,
   asection *section = sec;
   bfd_vma align_gap_adjustment;
 
-  if (link_info->relocatable)
+  if (bfd_link_relocatable (link_info))
     (*link_info->callbacks->einfo)
       (_("%P%F: --relax and -r may not be used together\n"));
 
@@ -2682,7 +2685,7 @@ mn10300_elf_relax_section (bfd *abfd,
       /* Iterate over all the input bfds.  */
       for (input_bfd = link_info->input_bfds;
           input_bfd != NULL;
-          input_bfd = input_bfd->link_next)
+          input_bfd = input_bfd->link.next)
        {
          /* We're going to need all the symbols for each bfd.  */
          symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -3025,7 +3028,7 @@ mn10300_elf_relax_section (bfd *abfd,
         a "call" instruction.  */
       for (input_bfd = link_info->input_bfds;
           input_bfd != NULL;
-          input_bfd = input_bfd->link_next)
+          input_bfd = input_bfd->link.next)
        {
          /* We're going to need all the local symbols for each bfd.  */
          symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -3284,7 +3287,7 @@ mn10300_elf_relax_section (bfd *abfd,
   /* We don't have to do anything for a relocatable link, if
      this section does not have relocs, or if this is not a
      code section.  */
-  if (link_info->relocatable
+  if (bfd_link_relocatable (link_info)
       || (sec->flags & SEC_RELOC) == 0
       || sec->reloc_count == 0
       || (sec->flags & SEC_CODE) == 0)
@@ -3390,7 +3393,7 @@ mn10300_elf_relax_section (bfd *abfd,
                                                      isym->st_name);
 
          if ((sym_sec->flags & SEC_MERGE)
-             && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
+             && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
            {
              symval = isym->st_value;
 
@@ -3486,9 +3489,7 @@ mn10300_elf_relax_section (bfd *abfd,
            {
              asection * splt;
 
-             splt = bfd_get_section_by_name (elf_hash_table (link_info)
-                                             ->dynobj, ".plt");
-
+             splt = hash_table->root.splt;
              value = ((splt->output_section->vma
                        + splt->output_offset
                        + h->root.plt.offset)
@@ -3928,9 +3929,7 @@ mn10300_elf_relax_section (bfd *abfd,
            {
              asection * sgot;
 
-             sgot = bfd_get_section_by_name (elf_hash_table (link_info)
-                                             ->dynobj, ".got");
-
+             sgot = hash_table->root.sgot;
              if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
                {
                  value = sgot->output_offset;
@@ -4605,6 +4604,21 @@ _bfd_mn10300_copy_indirect_symbol (struct bfd_link_info *        info,
   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
 }
 
+/* Destroy an mn10300 ELF linker hash table.  */
+
+static void
+elf32_mn10300_link_hash_table_free (bfd *obfd)
+{
+  struct elf32_mn10300_link_hash_table *ret
+    = (struct elf32_mn10300_link_hash_table *) obfd->link.hash;
+
+  obfd->link.hash = &ret->static_hash_table->root.root;
+  _bfd_elf_link_hash_table_free (obfd);
+  obfd->is_linker_output = TRUE;
+  obfd->link.hash = &ret->root.root;
+  _bfd_elf_link_hash_table_free (obfd);
+}
+
 /* Create an mn10300 ELF linker hash table.  */
 
 static struct bfd_link_hash_table *
@@ -4613,27 +4627,12 @@ elf32_mn10300_link_hash_table_create (bfd *abfd)
   struct elf32_mn10300_link_hash_table *ret;
   bfd_size_type amt = sizeof (* ret);
 
-  ret = bfd_malloc (amt);
+  ret = bfd_zmalloc (amt);
   if (ret == NULL)
     return NULL;
 
-  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
-                                     elf32_mn10300_link_hash_newfunc,
-                                     sizeof (struct elf32_mn10300_link_hash_entry),
-                                     MN10300_ELF_DATA))
-    {
-      free (ret);
-      return NULL;
-    }
-
-  ret->flags = 0;
-  ret->tls_ldm_got.refcount = 0;
-  ret->tls_ldm_got.offset = -1;
-  ret->tls_ldm_got.got_allocated = 0;
-  ret->tls_ldm_got.rel_emitted = 0;
-
   amt = sizeof (struct elf_link_hash_table);
-  ret->static_hash_table = bfd_malloc (amt);
+  ret->static_hash_table = bfd_zmalloc (amt);
   if (ret->static_hash_table == NULL)
     {
       free (ret);
@@ -4649,21 +4648,25 @@ elf32_mn10300_link_hash_table_create (bfd *abfd)
       free (ret);
       return NULL;
     }
-  return & ret->root.root;
-}
 
-/* Free an mn10300 ELF linker hash table.  */
+  abfd->is_linker_output = FALSE;
+  abfd->link.hash = NULL;
+  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
+                                     elf32_mn10300_link_hash_newfunc,
+                                     sizeof (struct elf32_mn10300_link_hash_entry),
+                                     MN10300_ELF_DATA))
+    {
+      abfd->is_linker_output = TRUE;
+      abfd->link.hash = &ret->static_hash_table->root.root;
+      _bfd_elf_link_hash_table_free (abfd);
+      free (ret);
+      return NULL;
+    }
+  ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free;
 
-static void
-elf32_mn10300_link_hash_table_free (struct bfd_link_hash_table *hash)
-{
-  struct elf32_mn10300_link_hash_table *ret
-    = (struct elf32_mn10300_link_hash_table *) hash;
+  ret->tls_ldm_got.offset = -1;
 
-  _bfd_generic_link_hash_table_free
-    ((struct bfd_link_hash_table *) ret->static_hash_table);
-  _bfd_generic_link_hash_table_free
-    ((struct bfd_link_hash_table *) ret);
+  return & ret->root.root;
 }
 
 static unsigned long
@@ -4773,11 +4776,11 @@ static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
 
 /* Return size of the first PLT entry.  */
 #define elf_mn10300_sizeof_plt0(info) \
-  (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
+  (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
 
 /* Return size of a PLT entry.  */
 #define elf_mn10300_sizeof_plt(info) \
-  (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
+  (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
 
 /* Return offset of the PLT0 address in an absolute PLT entry.  */
 #define elf_mn10300_plt_plt0_offset(info) 16
@@ -4810,6 +4813,7 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   flagword   flags;
   asection * s;
   const struct elf_backend_data * bed = get_elf_backend_data (abfd);
+  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   int ptralign = 0;
 
   switch (bed->s->arch_size)
@@ -4832,10 +4836,11 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
           | SEC_LINKER_CREATED);
 
-  s = bfd_make_section_with_flags (abfd,
-                                  (bed->default_use_rela_p
-                                   ? ".rela.plt" : ".rel.plt"),
-                                  flags | SEC_READONLY);
+  s = bfd_make_section_anyway_with_flags (abfd,
+                                         (bed->default_use_rela_p
+                                          ? ".rela.plt" : ".rel.plt"),
+                                         flags | SEC_READONLY);
+  htab->root.srelplt = s;
   if (s == NULL
       || ! bfd_set_section_alignment (abfd, s, ptralign))
     return FALSE;
@@ -4843,32 +4848,6 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   if (! _bfd_mn10300_elf_create_got_section (abfd, info))
     return FALSE;
 
-  {
-    const char * secname;
-    char *       relname;
-    flagword     secflags;
-    asection *   sec;
-
-    for (sec = abfd->sections; sec; sec = sec->next)
-      {
-       secflags = bfd_get_section_flags (abfd, sec);
-       if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
-           || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
-         continue;
-
-       secname = bfd_get_section_name (abfd, sec);
-       relname = bfd_malloc (strlen (secname) + 6);
-       strcpy (relname, ".rela");
-       strcat (relname, secname);
-
-       s = bfd_make_section_with_flags (abfd, relname,
-                                        flags | SEC_READONLY);
-       if (s == NULL
-           || ! bfd_set_section_alignment (abfd, s, ptralign))
-         return FALSE;
-      }
-  }
-
   if (bed->want_dynbss)
     {
       /* The .dynbss section is a place to put symbols which are defined
@@ -4877,8 +4856,8 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
         image and use a R_*_COPY reloc to tell the dynamic linker to
         initialize them at run time.  The linker script puts the .dynbss
         section into the .bss section of the final image.  */
-      s = bfd_make_section_with_flags (abfd, ".dynbss",
-                                      SEC_ALLOC | SEC_LINKER_CREATED);
+      s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
+                                             SEC_ALLOC | SEC_LINKER_CREATED);
       if (s == NULL)
        return FALSE;
 
@@ -4893,12 +4872,12 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
         be needed, we can discard it later.  We will never need this
         section when generating a shared object, since they do not use
         copy relocs.  */
-      if (! info->shared)
+      if (! bfd_link_pic (info))
        {
-         s = bfd_make_section_with_flags (abfd,
-                                          (bed->default_use_rela_p
-                                           ? ".rela.bss" : ".rel.bss"),
-                                          flags | SEC_READONLY);
+         s = bfd_make_section_anyway_with_flags (abfd,
+                                                 (bed->default_use_rela_p
+                                                  ? ".rela.bss" : ".rel.bss"),
+                                                 flags | SEC_READONLY);
          if (s == NULL
              || ! bfd_set_section_alignment (abfd, s, ptralign))
            return FALSE;
@@ -4918,10 +4897,11 @@ static bfd_boolean
 _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
                                        struct elf_link_hash_entry * h)
 {
+  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   bfd * dynobj;
   asection * s;
 
-  dynobj = elf_hash_table (info)->dynobj;
+  dynobj = htab->root.dynobj;
 
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
@@ -4937,7 +4917,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
   if (h->type == STT_FUNC
       || h->needs_plt)
     {
-      if (! info->shared
+      if (! bfd_link_pic (info)
          && !h->def_dynamic
          && !h->ref_dynamic)
        {
@@ -4957,7 +4937,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
            return FALSE;
        }
 
-      s = bfd_get_section_by_name (dynobj, ".plt");
+      s = htab->root.splt;
       BFD_ASSERT (s != NULL);
 
       /* If this is the first .plt entry, make room for the special
@@ -4970,7 +4950,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
         location in the .plt.  This is required to make function
         pointers compare as equal between the normal executable and
         the shared library.  */
-      if (! info->shared
+      if (! bfd_link_pic (info)
          && !h->def_regular)
        {
          h->root.u.def.section = s;
@@ -4984,12 +4964,12 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * 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");
+      s = htab->root.sgotplt;
       BFD_ASSERT (s != NULL);
       s->size += 4;
 
       /* We also need to make an entry in the .rela.plt section.  */
-      s = bfd_get_section_by_name (dynobj, ".rela.plt");
+      s = bfd_get_linker_section (dynobj, ".rela.plt");
       BFD_ASSERT (s != NULL);
       s->size += sizeof (Elf32_External_Rela);
 
@@ -5015,7 +4995,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
      only references to the symbol are via the global offset table.
      For such cases we need not do anything here; the relocations will
      be handled correctly by relocate_section.  */
-  if (info->shared)
+  if (bfd_link_pic (info))
     return TRUE;
 
   /* If there are no references to this symbol that do not use the
@@ -5033,7 +5013,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
      both the dynamic object and the regular object will refer to the
      same memory location for the variable.  */
 
-  s = bfd_get_section_by_name (dynobj, ".dynbss");
+  s = bfd_get_linker_section (dynobj, ".dynbss");
   BFD_ASSERT (s != NULL);
 
   /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
@@ -5044,13 +5024,13 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
     {
       asection * srel;
 
-      srel = bfd_get_section_by_name (dynobj, ".rela.bss");
+      srel = bfd_get_linker_section (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
       srel->size += sizeof (Elf32_External_Rela);
       h->needs_copy = 1;
     }
 
-  return _bfd_elf_adjust_dynamic_copy (h, s);
+  return _bfd_elf_adjust_dynamic_copy (info, h, s);
 }
 
 /* Set the sizes of the dynamic sections.  */
@@ -5066,15 +5046,15 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
   bfd_boolean relocs;
   bfd_boolean reltext;
 
-  dynobj = elf_hash_table (info)->dynobj;
+  dynobj = htab->root.dynobj;
   BFD_ASSERT (dynobj != NULL);
 
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (info->executable)
+      if (bfd_link_executable (info))
        {
-         s = bfd_get_section_by_name (dynobj, ".interp");
+         s = bfd_get_linker_section (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
@@ -5087,14 +5067,14 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
         not actually use these entries.  Reset the size of .rela.got,
         which will cause it to get stripped from the output file
         below.  */
-      s = bfd_get_section_by_name (dynobj, ".rela.got");
+      s = htab->root.sgot;
       if (s != NULL)
        s->size = 0;
     }
 
   if (htab->tls_ldm_got.refcount > 0)
     {
-      s = bfd_get_section_by_name (dynobj, ".rela.got");
+      s = bfd_get_linker_section (dynobj, ".rela.got");
       BFD_ASSERT (s != NULL);
       s->size += sizeof (Elf32_External_Rela);
     }
@@ -5194,7 +5174,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
         but we must add the entries now so that we get the correct
         size for the .dynamic section.  The DT_DEBUG entry is filled
         in by the dynamic linker and used by the debugger.  */
-      if (! info->shared)
+      if (! bfd_link_pic (info))
        {
          if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
            return FALSE;
@@ -5237,9 +5217,10 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
                                        struct elf_link_hash_entry * h,
                                        Elf_Internal_Sym * sym)
 {
+  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   bfd * dynobj;
 
-  dynobj = elf_hash_table (info)->dynobj;
+  dynobj = htab->root.dynobj;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
@@ -5255,9 +5236,9 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
 
       BFD_ASSERT (h->dynindx != -1);
 
-      splt = bfd_get_section_by_name (dynobj, ".plt");
-      sgot = bfd_get_section_by_name (dynobj, ".got.plt");
-      srel = bfd_get_section_by_name (dynobj, ".rela.plt");
+      splt = htab->root.splt;
+      sgot = htab->root.sgotplt;
+      srel = bfd_get_linker_section (dynobj, ".rela.plt");
       BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
 
       /* Get the index in the procedure linkage table which
@@ -5273,7 +5254,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
       got_offset = (plt_index + 3) * 4;
 
       /* Fill in the entry in the procedure linkage table.  */
-      if (! info->shared)
+      if (! bfd_link_pic (info))
        {
          memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
                  elf_mn10300_sizeof_plt (info));
@@ -5334,8 +5315,8 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
       Elf_Internal_Rela rel;
 
       /* This symbol has an entry in the global offset table.  Set it up.  */
-      sgot = bfd_get_section_by_name (dynobj, ".got");
-      srel = bfd_get_section_by_name (dynobj, ".rela.got");
+      sgot = htab->root.sgot;
+      srel = bfd_get_linker_section (dynobj, ".rela.got");
       BFD_ASSERT (sgot != NULL && srel != NULL);
 
       rel.r_offset = (sgot->output_section->vma
@@ -5376,7 +5357,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
             the symbol was forced to be local because of a version file.
             The entry in the global offset table will already have been
             initialized in the relocate_section function.  */
-         if (info->shared
+         if (bfd_link_pic (info)
              && (info->symbolic || h->dynindx == -1)
              && h->def_regular)
            {
@@ -5412,8 +5393,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
                  && (h->root.type == bfd_link_hash_defined
                      || h->root.type == bfd_link_hash_defweak));
 
-      s = bfd_get_section_by_name (h->root.u.def.section->owner,
-                                  ".rela.bss");
+      s = bfd_get_linker_section (dynobj, ".rela.bss");
       BFD_ASSERT (s != NULL);
 
       rel.r_offset = (h->root.u.def.value
@@ -5428,7 +5408,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
     }
 
   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
-  if (streq (h->root.root.string, "_DYNAMIC")
+  if (h == elf_hash_table (info)->hdynamic
       || h == elf_hash_table (info)->hgot)
     sym->st_shndx = SHN_ABS;
 
@@ -5444,12 +5424,12 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
   bfd *      dynobj;
   asection * sgot;
   asection * sdyn;
+  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
 
-  dynobj = elf_hash_table (info)->dynobj;
-
-  sgot = bfd_get_section_by_name (dynobj, ".got.plt");
+  dynobj = htab->root.dynobj;
+  sgot = htab->root.sgotplt;
   BFD_ASSERT (sgot != NULL);
-  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
 
   if (elf_hash_table (info)->dynamic_sections_created)
     {
@@ -5514,10 +5494,10 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
        }
 
       /* Fill in the first entry in the procedure linkage table.  */
-      splt = bfd_get_section_by_name (dynobj, ".plt");
+      splt = htab->root.splt;
       if (splt && splt->size > 0)
        {
-         if (info->shared)
+         if (bfd_link_pic (info))
            {
              memcpy (splt->contents, elf_mn10300_pic_plt_entry,
                      elf_mn10300_sizeof_plt (info));
@@ -5569,7 +5549,9 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
    properly.  */
 
 static enum elf_reloc_type_class
-_bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela *rela)
+_bfd_mn10300_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
+                                  const asection *rel_sec ATTRIBUTE_UNUSED,
+                                  const Elf_Internal_Rela *rela)
 {
   switch ((int) ELF32_R_TYPE (rela->r_info))
     {
@@ -5592,7 +5574,7 @@ mn10300_elf_mkobject (bfd *abfd)
 #define bfd_elf32_mkobject     mn10300_elf_mkobject
 
 #ifndef ELF_ARCH
-#define TARGET_LITTLE_SYM      bfd_elf32_mn10300_vec
+#define TARGET_LITTLE_SYM      mn10300_elf32_vec
 #define TARGET_LITTLE_NAME     "elf32-mn10300"
 #define ELF_ARCH               bfd_arch_mn10300
 #define ELF_TARGET_ID          MN10300_ELF_DATA
@@ -5613,8 +5595,6 @@ mn10300_elf_mkobject (bfd *abfd)
                                mn10300_elf_get_relocated_section_contents
 #define bfd_elf32_bfd_link_hash_table_create \
                                elf32_mn10300_link_hash_table_create
-#define bfd_elf32_bfd_link_hash_table_free \
-                               elf32_mn10300_link_hash_table_free
 
 #ifndef elf_symbol_leading_char
 #define elf_symbol_leading_char '_'
This page took 0.038581 seconds and 4 git commands to generate.