Check corrupt VTENTRY entry in bfd_elf_gc_record_vtentry
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index 25f1668634779cf19e593941ba0a983113b951d8..f0ef8eb0bed52baef5f324f3e9b8c3a8a261b6f5 100644 (file)
@@ -1,5 +1,5 @@
 /* Matsushita 10300 specific support for 32-bit ELF
-   Copyright (C) 1996-2016 Free Software Foundation, Inc.
+   Copyright (C) 1996-2019 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -97,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;
 };
 
@@ -611,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 */
@@ -625,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 */
@@ -798,8 +798,8 @@ 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)
 {
@@ -808,20 +808,22 @@ mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_MN10300_MAX)
     {
-      _bfd_error_handler (_("%B: unrecognised MN10300 reloc number: %d"),
+      /* xgettext:c-format */
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
                          abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
-      r_type = R_MN10300_NONE;
+      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;
 
@@ -887,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;
@@ -961,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
@@ -1023,8 +1025,9 @@ mn10300_do_tls_transition (bfd *         input_bfd,
 
     default:
       _bfd_error_handler
-       (_("%s: Unsupported transition from %s to %s"),
-        bfd_get_filename (input_bfd),
+       /* 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;
@@ -1089,10 +1092,6 @@ 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);
@@ -1137,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;
 
@@ -1169,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 || bfd_link_pic (info)))
-           {
-             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)
            {
@@ -1215,7 +1192,8 @@ mn10300_elf_check_relocs (bfd *abfd,
                    tls_type = GOT_TLS_IE;
                  else
                    _bfd_error_handler
-                     (_("%B: %s' accessed both as normal and thread local symbol"),
+                     /* xgettext:c-format */
+                     (_("%pB: %s' accessed both as normal and thread local symbol"),
                       abfd, h ? h->root.root.string : "<local>");
                }
 
@@ -1394,7 +1372,7 @@ mn10300_elf_check_relocs (bfd *abfd,
 
   result = TRUE;
  fail:
-  if (isymbuf != NULL)
+  if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
 
   return result;
@@ -1537,7 +1515,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
          /* 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.  */
@@ -1816,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);
@@ -1893,10 +1871,9 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto,
 
              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
@@ -2111,10 +2088,12 @@ mn10300_elf_relocate_section (bfd *output_bfd,
                                               rel->r_offset) != (bfd_vma) -1)
 
            _bfd_error_handler
-             (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
+             /* 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);
        }
@@ -2175,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"
@@ -2432,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++)
@@ -2612,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
@@ -4576,9 +4556,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;
@@ -4725,8 +4705,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;
@@ -4903,7 +4885,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)));
@@ -4966,7 +4948,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);
 
@@ -4976,12 +4958,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;
     }
 
@@ -5049,7 +5031,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 (bfd_link_executable (info))
+      if (bfd_link_executable (info) && !info->nointerp)
        {
          s = bfd_get_linker_section (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -5071,7 +5053,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);
     }
@@ -5221,11 +5203,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
@@ -5235,7 +5217,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
@@ -5307,13 +5289,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
@@ -5382,7 +5364,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.  */
@@ -5430,7 +5412,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;
 
@@ -5442,7 +5424,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);
@@ -5453,38 +5434,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_linker_section (dynobj, name);
              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_linker_section (dynobj, ".rela.plt");
+             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_linker_section (dynobj, ".rela.plt");
-             if (s != NULL)
-               dyn.d_un.d_val -= s->size;
-             bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
-             break;
            }
        }
 
@@ -5579,7 +5543,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
@@ -5610,8 +5574,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 \
@@ -5625,5 +5588,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.035035 seconds and 4 git commands to generate.