gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index ffd873d7b3d24e4b422d1f6b4eb5616bf9e70084..696514ab054c64824f6a81392748046b85608d33 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-2020 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -98,9 +97,9 @@ struct elf32_mn10300_link_hash_table
   struct
   {
     bfd_signed_vma  refcount;
-    bfd_vma         offset;
-    char            got_allocated;
-    char            rel_emitted;
+    bfd_vma        offset;
+    char           got_allocated;
+    char           rel_emitted;
   } tls_ldm_got;
 };
 
@@ -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,
@@ -612,7 +611,7 @@ static reloc_howto_type elf_mn10300_howto_table[] =
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont,/* complain_on_overflow */
-        NULL,                  /* special handler.  */
+        NULL,                  /* special handler.  */
         "R_MN10300_SYM_DIFF",  /* name */
         FALSE,                 /* partial_inplace */
         0xffffffff,            /* src_mask */
@@ -626,7 +625,7 @@ static reloc_howto_type elf_mn10300_howto_table[] =
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont,/* complain_on_overflow */
-        NULL,                  /* special handler.  */
+        NULL,                  /* special handler.  */
         "R_MN10300_ALIGN",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -726,7 +725,7 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
   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))
+      || !bfd_set_section_alignment (s, bed->plt_alignment))
     return FALSE;
 
   /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
@@ -743,7 +742,7 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
   s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
   htab->sgot = s;
   if (s == NULL
-      || ! bfd_set_section_alignment (abfd, s, ptralign))
+      || !bfd_set_section_alignment (s, ptralign))
     return FALSE;
 
   if (bed->want_got_plt)
@@ -751,7 +750,7 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
       s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
       htab->sgotplt = s;
       if (s == NULL
-         || ! bfd_set_section_alignment (abfd, s, ptralign))
+         || !bfd_set_section_alignment (s, ptralign))
        return FALSE;
     }
 
@@ -799,24 +798,32 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
 
 /* Set the howto pointer for an MN10300 ELF reloc.  */
 
-static void
-mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
+static bfd_boolean
+mn10300_info_to_howto (bfd *abfd,
                       arelent *cache_ptr,
                       Elf_Internal_Rela *dst)
 {
   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)
+    {
+      /* xgettext:c-format */
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                         abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return FALSE;
+    }
   cache_ptr->howto = elf_mn10300_howto_table + r_type;
+  return TRUE;
 }
 
 static int
-elf_mn10300_tls_transition (struct bfd_link_info *        info,
-                           int                           r_type,
+elf_mn10300_tls_transition (struct bfd_link_info *       info,
+                           int                           r_type,
                            struct elf_link_hash_entry *  h,
-                           asection *                    sec,
-                           bfd_boolean                   counting)
+                           asection *                    sec,
+                           bfd_boolean                   counting)
 {
   bfd_boolean is_local;
 
@@ -825,7 +832,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))
@@ -882,11 +889,11 @@ tpoff (struct bfd_link_info * info, bfd_vma address)
    this reloc and the PLT reloc.  */
 
 static int
-mn10300_do_tls_transition (bfd *         input_bfd,
-                          unsigned int  r_type,
-                          unsigned int  tls_r_type,
-                          bfd_byte *    contents,
-                          bfd_vma       offset)
+mn10300_do_tls_transition (bfd *        input_bfd,
+                          unsigned int  r_type,
+                          unsigned int  tls_r_type,
+                          bfd_byte *    contents,
+                          bfd_vma       offset)
 {
   bfd_byte *op = contents + offset;
   int gotreg = 0;
@@ -956,13 +963,13 @@ mn10300_do_tls_transition (bfd *         input_bfd,
        accordingly, copying the operands as needed.  The conversions
        we do are as follows (IE,GOTIE,LE):
 
-                  1111 1100  1010 01Dn  [-- abs32 --]  MOV (x@indntpoff),Dn
-                  1111 1100  0000 DnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),Dn
-                  1111 1100  1100 11Dn  [-- abs32 --]  MOV x@tpoff,Dn
+                  1111 1100  1010 01Dn  [-- abs32 --]  MOV (x@indntpoff),Dn
+                  1111 1100  0000 DnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),Dn
+                  1111 1100  1100 11Dn  [-- abs32 --]  MOV x@tpoff,Dn
 
-                  1111 1100  1010 00An  [-- abs32 --]  MOV (x@indntpoff),An
-                  1111 1100  0010 AnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),An
-                  1111 1100  1101 11An  [-- abs32 --]  MOV x@tpoff,An
+                  1111 1100  1010 00An  [-- abs32 --]  MOV (x@indntpoff),An
+                  1111 1100  0010 AnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),An
+                  1111 1100  1101 11An  [-- abs32 --]  MOV x@tpoff,An
 
        1111 1110  0000 1110  Rnnn Xxxx  [-- abs32 --]  MOV (x@indntpoff),Rn
        1111 1110  0000 1010  Rnnn Rmmm  [-- abs32 --]  MOV (x@indntpoff,Rm),Rn
@@ -1017,9 +1024,10 @@ mn10300_do_tls_transition (bfd *         input_bfd,
       break;
 
     default:
-      (*_bfd_error_handler)
-       (_("%s: Unsupported transition from %s to %s"),
-        bfd_get_filename (input_bfd),
+      _bfd_error_handler
+       /* xgettext:c-format */
+       (_("%pB: unsupported transition from %s to %s"),
+        input_bfd,
         elf_mn10300_howto_table[r_type].name,
         elf_mn10300_howto_table[tls_r_type].name);
       break;
@@ -1056,7 +1064,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;
@@ -1128,9 +1136,7 @@ mn10300_elf_check_relocs (bfd *abfd,
        /* This relocation describes which C++ vtable entries are actually
           used.  Record for later use during GC.  */
        case R_MN10300_GNU_VTENTRY:
-         BFD_ASSERT (h != NULL);
-         if (h != NULL
-             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            goto fail;
          break;
 
@@ -1144,7 +1150,7 @@ 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 */
 
@@ -1160,32 +1166,12 @@ mn10300_elf_check_relocs (bfd *abfd,
            case R_MN10300_TLS_IE:
            case R_MN10300_TLS_GOTIE: tls_type = GOT_TLS_IE; break;
            case R_MN10300_TLS_GD:    tls_type = GOT_TLS_GD; break;
-           default:                  tls_type = GOT_NORMAL; break;
+           default:                  tls_type = GOT_NORMAL; break;
            }
 
-         if (sgot == NULL)
-           {
-             sgot = htab->root.sgot;
-             BFD_ASSERT (sgot != NULL);
-           }
-
-         if (srelgot == NULL
-             && (h != NULL || info->shared))
-           {
-             srelgot = bfd_get_linker_section (dynobj, ".rela.got");
-             if (srelgot == NULL)
-               {
-                 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;
-               }
-           }
+         sgot = htab->root.sgot;
+         srelgot = htab->root.srelgot;
+         BFD_ASSERT (sgot != NULL && srelgot != NULL);
 
          if (r_type == R_MN10300_TLS_LD)
            {
@@ -1205,8 +1191,9 @@ mn10300_elf_check_relocs (bfd *abfd,
                    /* Transition GD->IE.  */
                    tls_type = GOT_TLS_IE;
                  else
-                   (*_bfd_error_handler)
-                     (_("%B: %s' accessed both as normal and thread local symbol"),
+                   _bfd_error_handler
+                     /* xgettext:c-format */
+                     (_("%pB: %s' accessed both as normal and thread local symbol"),
                       abfd, h ? h->root.root.string : "<local>");
                }
 
@@ -1259,7 +1246,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
@@ -1323,7 +1310,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.  */
@@ -1385,7 +1372,7 @@ mn10300_elf_check_relocs (bfd *abfd,
 
   result = TRUE;
  fail:
-  if (isymbuf != NULL)
+  if (symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
 
   return result;
@@ -1456,16 +1443,17 @@ 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))
        return bfd_reloc_dangerous;
+      /* Fall through.  */
     case R_MN10300_GOT32:
       /* 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
@@ -1523,11 +1511,11 @@ 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.  */
-         && is_sym_diff_reloc == FALSE
+         && !is_sym_diff_reloc
          /* Also, do not generate a reloc when the symbol associated
             with the R_MN10300_32 reloc is absolute - there is no
             need for a run time computation in this case.  */
@@ -1806,7 +1794,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
 
       if (!htab->tls_ldm_got.rel_emitted)
        {
-         asection * srelgot = bfd_get_linker_section (dynobj, ".rela.got");
+         asection *srelgot = htab->root.srelgot;
          Elf_Internal_Rela rel;
 
          BFD_ASSERT (srelgot != NULL);
@@ -1881,12 +1869,11 @@ 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;
+                 asection *srelgot = htab->root.srelgot;;
                  Elf_Internal_Rela outrel;
 
-                 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
                  BFD_ASSERT (srelgot != NULL);
 
                  outrel.r_offset = (sgot->output_section->vma
@@ -2007,7 +1994,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;
@@ -2030,7 +2017,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);
 
@@ -2082,7 +2069,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
@@ -2096,15 +2083,17 @@ 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)
 
-           (*_bfd_error_handler)
-             (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
+           _bfd_error_handler
+             /* xgettext:c-format */
+             (_("%pB(%pA+%#" PRIx64 "): "
+                "unresolvable %s relocation against symbol `%s'"),
               input_bfd,
               input_section,
-              (long) rel->r_offset,
+              (uint64_t) rel->r_offset,
               howto->name,
               h->root.root.root.string);
        }
@@ -2113,7 +2102,7 @@ mn10300_elf_relocate_section (bfd *output_bfd,
        RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
                                         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,
@@ -2136,24 +2125,20 @@ mn10300_elf_relocate_section (bfd *output_bfd,
              name = (bfd_elf_string_from_elf_section
                      (input_bfd, symtab_hdr->sh_link, sym->st_name));
              if (name == NULL || *name == '\0')
-               name = bfd_section_name (input_bfd, sec);
+               name = bfd_section_name (sec);
            }
 
          switch (r)
            {
            case bfd_reloc_overflow:
-             if (! ((*info->callbacks->reloc_overflow)
-                    (info, (h ? &h->root.root : NULL), name,
-                     howto->name, (bfd_vma) 0, input_bfd,
-                     input_section, rel->r_offset)))
-               return FALSE;
+             (*info->callbacks->reloc_overflow)
+               (info, (h ? &h->root.root : NULL), name, howto->name,
+                (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
              break;
 
            case bfd_reloc_undefined:
-             if (! ((*info->callbacks->undefined_symbol)
-                    (info, name, input_bfd, input_section,
-                     rel->r_offset, TRUE)))
-               return FALSE;
+             (*info->callbacks->undefined_symbol)
+               (info, name, input_bfd, input_section, rel->r_offset, TRUE);
              break;
 
            case bfd_reloc_outofrange:
@@ -2169,7 +2154,8 @@ mn10300_elf_relocate_section (bfd *output_bfd,
                msg = _("error: inappropriate relocation type for shared"
                        " library (did you forget -fpic?)");
              else if (r_type == R_MN10300_GOT32)
-               msg = _("%B: taking the address of protected function"
+               /* xgettext:c-format */
+               msg = _("%pB: taking the address of protected function"
                        " '%s' cannot be done when making a shared library");
              else
                msg = _("internal error: suspicious relocation type used"
@@ -2426,7 +2412,7 @@ mn10300_elf_relax_delete_bytes (bfd *abfd,
       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
+      /* The deletion must stop at the next ALIGN reloc for an alignment
         power larger than, or not a multiple of, the number of bytes we
         are deleting.  */
       for (; irel < irelend; irel++)
@@ -2606,7 +2592,7 @@ mn10300_elf_symbol_address_p (bfd *abfd,
 
    There are quite a few relaxing opportunities available on the mn10300:
 
-       * calls:32 -> calls:16                                     2 bytes
+       * calls:32 -> calls:16                                     2 bytes
        * call:32  -> call:16                                      2 bytes
 
        * call:32 -> calls:32                                      1 byte
@@ -2656,7 +2642,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"));
 
@@ -2676,7 +2662,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;
@@ -2757,7 +2743,7 @@ mn10300_elf_relax_section (bfd *abfd,
                          /* A local symbol.  */
                          Elf_Internal_Sym *isym;
                          struct elf_link_hash_table *elftab;
-                         bfd_size_type amt;
+                         size_t amt;
 
                          isym = isymbuf + r_index;
                          if (isym->st_shndx == SHN_UNDEF)
@@ -2858,7 +2844,7 @@ mn10300_elf_relax_section (bfd *abfd,
                          && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
                        {
                          struct elf_link_hash_table *elftab;
-                         bfd_size_type amt;
+                         size_t amt;
                          struct elf_link_hash_entry **lhashes = hashes;
 
                          /* Skip a local symbol if it aliases a
@@ -2926,8 +2912,7 @@ mn10300_elf_relax_section (bfd *abfd,
                }
 
              /* Cache or free any memory we allocated for the relocs.  */
-             if (internal_relocs != NULL
-                 && elf_section_data (section)->relocs != internal_relocs)
+             if (elf_section_data (section)->relocs != internal_relocs)
                free (internal_relocs);
              internal_relocs = NULL;
 
@@ -3019,7 +3004,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;
@@ -3083,7 +3068,7 @@ mn10300_elf_relax_section (bfd *abfd,
                  const char *sym_name;
                  char *new_name;
                  struct elf_link_hash_table *elftab;
-                 bfd_size_type amt;
+                 size_t amt;
 
                  if (isym->st_shndx != sec_shndx)
                    continue;
@@ -3236,8 +3221,7 @@ mn10300_elf_relax_section (bfd *abfd,
                }
 
              /* Cache or free any memory we allocated for the relocs.  */
-             if (internal_relocs != NULL
-                 && elf_section_data (section)->relocs != internal_relocs)
+             if (elf_section_data (section)->relocs != internal_relocs)
                free (internal_relocs);
              internal_relocs = NULL;
 
@@ -3278,7 +3262,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)
@@ -4405,21 +4389,17 @@ mn10300_elf_relax_section (bfd *abfd,
        }
     }
 
-  if (internal_relocs != NULL
-      && elf_section_data (sec)->relocs != internal_relocs)
+  if (elf_section_data (sec)->relocs != internal_relocs)
     free (internal_relocs);
 
   return TRUE;
 
  error_return:
-  if (isymbuf != NULL
-      && symtab_hdr->contents != (unsigned char *) isymbuf)
+  if (symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
-  if (contents != NULL
-      && elf_section_data (section)->this_hdr.contents != contents)
+  if (elf_section_data (section)->this_hdr.contents != contents)
     free (contents);
-  if (internal_relocs != NULL
-      && elf_section_data (section)->relocs != internal_relocs)
+  if (elf_section_data (section)->relocs != internal_relocs)
     free (internal_relocs);
 
   return FALSE;
@@ -4508,9 +4488,8 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
                                          isymbuf, sections))
        goto error_return;
 
-      if (sections != NULL)
-       free (sections);
-      if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
+      free (sections);
+      if (symtab_hdr->contents != (unsigned char *) isymbuf)
        free (isymbuf);
       if (internal_relocs != elf_section_data (input_section)->relocs)
        free (internal_relocs);
@@ -4519,12 +4498,10 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
   return data;
 
  error_return:
-  if (sections != NULL)
-    free (sections);
-  if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
+  free (sections);
+  if (symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
-  if (internal_relocs != NULL
-      && internal_relocs != elf_section_data (input_section)->relocs)
+  if (internal_relocs != elf_section_data (input_section)->relocs)
     free (internal_relocs);
   return NULL;
 }
@@ -4570,9 +4547,9 @@ elf32_mn10300_link_hash_newfunc (struct bfd_hash_entry *entry,
 }
 
 static void
-_bfd_mn10300_copy_indirect_symbol (struct bfd_link_info *        info,
-                                  struct elf_link_hash_entry *  dir,
-                                  struct elf_link_hash_entry *  ind)
+_bfd_mn10300_copy_indirect_symbol (struct bfd_link_info *       info,
+                                  struct elf_link_hash_entry *  dir,
+                                  struct elf_link_hash_entry *  ind)
 {
   struct elf32_mn10300_link_hash_entry * edir;
   struct elf32_mn10300_link_hash_entry * eind;
@@ -4595,29 +4572,33 @@ _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 *
 elf32_mn10300_link_hash_table_create (bfd *abfd)
 {
   struct elf32_mn10300_link_hash_table *ret;
-  bfd_size_type amt = sizeof (* ret);
+  size_t amt = sizeof (* ret);
 
   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->tls_ldm_got.offset = -1;
-
   amt = sizeof (struct elf_link_hash_table);
   ret->static_hash_table = bfd_zmalloc (amt);
   if (ret->static_hash_table == NULL)
@@ -4635,21 +4616,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_elf_link_hash_table_free
-    ((struct bfd_link_hash_table *) ret->static_hash_table);
-  _bfd_elf_link_hash_table_free
-    ((struct bfd_link_hash_table *) ret);
+  return & ret->root.root;
 }
 
 static unsigned long
@@ -4673,9 +4658,8 @@ elf_mn10300_mach (flagword flags)
    file.  This gets the MN10300 architecture right based on the machine
    number.  */
 
-static void
-_bfd_mn10300_elf_final_write_processing (bfd *abfd,
-                                        bfd_boolean linker ATTRIBUTE_UNUSED)
+static bfd_boolean
+_bfd_mn10300_elf_final_write_processing (bfd *abfd)
 {
   unsigned long val;
 
@@ -4697,6 +4681,7 @@ _bfd_mn10300_elf_final_write_processing (bfd *abfd,
 
   elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
   elf_elfheader (abfd)->e_flags |= val;
+  return _bfd_elf_final_write_processing (abfd);
 }
 
 static bfd_boolean
@@ -4711,8 +4696,10 @@ _bfd_mn10300_elf_object_p (bfd *abfd)
    object file when linking.  */
 
 static bfd_boolean
-_bfd_mn10300_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+_bfd_mn10300_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
+
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
     return TRUE;
@@ -4759,11 +4746,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
@@ -4825,7 +4812,7 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
                                          flags | SEC_READONLY);
   htab->root.srelplt = s;
   if (s == NULL
-      || ! bfd_set_section_alignment (abfd, s, ptralign))
+      || !bfd_set_section_alignment (s, ptralign))
     return FALSE;
 
   if (! _bfd_mn10300_elf_create_got_section (abfd, info))
@@ -4855,14 +4842,14 @@ _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_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))
+             || !bfd_set_section_alignment (s, ptralign))
            return FALSE;
        }
     }
@@ -4889,7 +4876,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
              && (h->needs_plt
-                 || h->u.weakdef != NULL
+                 || h->is_weakalias
                  || (h->def_dynamic
                      && h->ref_regular
                      && !h->def_regular)));
@@ -4900,7 +4887,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)
        {
@@ -4933,7 +4920,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;
@@ -4952,7 +4939,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
       s->size += 4;
 
       /* We also need to make an entry in the .rela.plt section.  */
-      s = bfd_get_linker_section (dynobj, ".rela.plt");
+      s = htab->root.srelplt;
       BFD_ASSERT (s != NULL);
       s->size += sizeof (Elf32_External_Rela);
 
@@ -4962,12 +4949,12 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
      real definition first, and we can just use the same value.  */
-  if (h->u.weakdef != NULL)
+  if (h->is_weakalias)
     {
-      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
-                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
-      h->root.u.def.section = h->u.weakdef->root.u.def.section;
-      h->root.u.def.value = h->u.weakdef->root.u.def.value;
+      struct elf_link_hash_entry *def = weakdef (h);
+      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
+      h->root.u.def.section = def->root.u.def.section;
+      h->root.u.def.value = def->root.u.def.value;
       return TRUE;
     }
 
@@ -4978,7 +4965,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
@@ -5013,7 +5000,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
       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.  */
@@ -5035,7 +5022,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
   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) && !info->nointerp)
        {
          s = bfd_get_linker_section (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -5057,7 +5044,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
 
   if (htab->tls_ldm_got.refcount > 0)
     {
-      s = bfd_get_linker_section (dynobj, ".rela.got");
+      s = htab->root.srelgot;
       BFD_ASSERT (s != NULL);
       s->size += sizeof (Elf32_External_Rela);
     }
@@ -5077,7 +5064,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
 
       /* It's OK to base decisions on the section name, because none
         of the dynobj section names depend upon the input files.  */
-      name = bfd_get_section_name (dynobj, s);
+      name = bfd_section_name (s);
 
       if (streq (name, ".plt"))
        {
@@ -5103,8 +5090,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
                     entry.  The entries in the .rela.plt section
                     really apply to the .got section, which we
                     created ourselves and so know is not readonly.  */
-                 outname = bfd_get_section_name (output_bfd,
-                                                 s->output_section);
+                 outname = bfd_section_name (s->output_section);
                  target = bfd_get_section_by_name (output_bfd, outname + 5);
                  if (target != NULL
                      && (target->flags & SEC_READONLY) != 0
@@ -5157,7 +5143,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;
@@ -5207,11 +5193,11 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
 
   if (h->plt.offset != (bfd_vma) -1)
     {
-      asection *        splt;
-      asection *        sgot;
-      asection *        srel;
-      bfd_vma           plt_index;
-      bfd_vma           got_offset;
+      asection *       splt;
+      asection *       sgot;
+      asection *       srel;
+      bfd_vma          plt_index;
+      bfd_vma          got_offset;
       Elf_Internal_Rela rel;
 
       /* This symbol has an entry in the procedure linkage table.  Set
@@ -5221,7 +5207,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
 
       splt = htab->root.splt;
       sgot = htab->root.sgotplt;
-      srel = bfd_get_linker_section (dynobj, ".rela.plt");
+      srel = htab->root.srelplt;
       BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
 
       /* Get the index in the procedure linkage table which
@@ -5237,7 +5223,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));
@@ -5293,13 +5279,13 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
 
   if (h->got.offset != (bfd_vma) -1)
     {
-      asection *        sgot;
-      asection *        srel;
+      asection *       sgot;
+      asection *       srel;
       Elf_Internal_Rela rel;
 
       /* This symbol has an entry in the global offset table.  Set it up.  */
       sgot = htab->root.sgot;
-      srel = bfd_get_linker_section (dynobj, ".rela.got");
+      srel = htab->root.srelgot;
       BFD_ASSERT (sgot != NULL && srel != NULL);
 
       rel.r_offset = (sgot->output_section->vma
@@ -5340,7 +5326,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)
            {
@@ -5368,7 +5354,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
 
   if (h->needs_copy)
     {
-      asection *        s;
+      asection *       s;
       Elf_Internal_Rela rel;
 
       /* This symbol needs a copy reloc.  Set it up.  */
@@ -5416,7 +5402,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
 
   if (elf_hash_table (info)->dynamic_sections_created)
     {
-      asection *           splt;
+      asection *          splt;
       Elf32_External_Dyn * dyncon;
       Elf32_External_Dyn * dynconend;
 
@@ -5428,7 +5414,6 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
-         const char * name;
          asection * s;
 
          bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
@@ -5439,40 +5424,21 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
              break;
 
            case DT_PLTGOT:
-             name = ".got";
+             s = htab->root.sgot;
              goto get_vma;
 
            case DT_JMPREL:
-             name = ".rela.plt";
+             s = htab->root.srelplt;
            get_vma:
-             s = bfd_get_section_by_name (output_bfd, name);
-             BFD_ASSERT (s != NULL);
-             dyn.d_un.d_ptr = s->vma;
+             dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
 
            case DT_PLTRELSZ:
-             s = bfd_get_section_by_name (output_bfd, ".rela.plt");
-             BFD_ASSERT (s != NULL);
+             s = htab->root.srelplt;
              dyn.d_un.d_val = s->size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
-
-           case DT_RELASZ:
-             /* My reading of the SVR4 ABI indicates that the
-                procedure linkage table relocs (DT_JMPREL) should be
-                included in the overall relocs (DT_RELA).  This is
-                what Solaris does.  However, UnixWare can not handle
-                that case.  Therefore, we override the DT_RELASZ entry
-                here to make it not include the JMPREL relocs.  Since
-                the linker script arranges for .rela.plt to follow all
-                other relocation sections, we don't have to worry
-                about changing the DT_RELA entry.  */
-             s = bfd_get_section_by_name (output_bfd, ".rela.plt");
-             if (s != NULL)
-               dyn.d_un.d_val -= s->size;
-             bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
-             break;
            }
        }
 
@@ -5480,7 +5446,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
       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));
@@ -5557,7 +5523,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
@@ -5567,7 +5533,7 @@ mn10300_elf_mkobject (bfd *abfd)
 #endif
 
 #define elf_info_to_howto              mn10300_info_to_howto
-#define elf_info_to_howto_rel          0
+#define elf_info_to_howto_rel          NULL
 #define elf_backend_can_gc_sections    1
 #define elf_backend_rela_normal                1
 #define elf_backend_check_relocs       mn10300_elf_check_relocs
@@ -5578,8 +5544,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 '_'
@@ -5600,8 +5564,7 @@ mn10300_elf_mkobject (bfd *abfd)
   _bfd_mn10300_elf_adjust_dynamic_symbol
 #define elf_backend_size_dynamic_sections \
   _bfd_mn10300_elf_size_dynamic_sections
-#define elf_backend_omit_section_dynsym \
-  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
+#define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
 #define elf_backend_finish_dynamic_symbol \
   _bfd_mn10300_elf_finish_dynamic_symbol
 #define elf_backend_finish_dynamic_sections \
@@ -5615,5 +5578,6 @@ mn10300_elf_mkobject (bfd *abfd)
 #define elf_backend_plt_readonly       1
 #define elf_backend_want_plt_sym       0
 #define elf_backend_got_header_size    12
+#define elf_backend_dtrel_excludes_plt 1
 
 #include "elf32-target.h"
This page took 0.038195 seconds and 4 git commands to generate.