PR22150, ld keeps a version reference for gc'd symbols
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
index 7d388018d3796a121ef90d3c91b76554cf15d043..2661f2b891b7ead0651c4e89e8f7f71946cc8f8f 100644 (file)
@@ -1,5 +1,5 @@
 /* CRIS-specific support for 32-bit ELF.
-   Copyright (C) 2000-2016 Free Software Foundation, Inc.
+   Copyright (C) 2000-2017 Free Software Foundation, Inc.
    Contributed by Axis Communications AB.
    Written by Hans-Peter Nilsson, based on elf32-fr30.c
    PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
@@ -1301,7 +1301,7 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
                if (h == NULL)
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("%B, section %A: relocation %s with non-zero addend %d"
+                   (_("%B, section %A: relocation %s with non-zero addend %Ld"
                       " against local symbol"),
                     input_bfd,
                     input_section,
@@ -1310,7 +1310,7 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
                else
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("%B, section %A: relocation %s with non-zero addend %d"
+                   (_("%B, section %A: relocation %s with non-zero addend %Ld"
                       " against symbol `%s'"),
                     input_bfd,
                     input_section,
@@ -1657,7 +1657,7 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
                 to pass us these kinds of things.  */
              _bfd_error_handler
                /* xgettext:c-format */
-               (_("%B, section %A: relocation %s with non-zero addend %d"
+               (_("%B, section %A: relocation %s with non-zero addend %Ld"
                   " against symbol `%s'"),
                 input_bfd,
                 input_section,
@@ -1810,7 +1810,7 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
                 things.  */
              _bfd_error_handler
                /* xgettext:c-format */
-               (_("%B, section %A: relocation %s with non-zero addend %d"
+               (_("%B, section %A: relocation %s with non-zero addend %Ld"
                   " against symbol `%s'"),
                 input_bfd,
                 input_section,
@@ -2057,7 +2057,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
                                Elf_Internal_Sym *sym)
 {
   struct elf_cris_link_hash_table * htab;
-  bfd *dynobj;
 
   /* Where in the plt entry to put values.  */
   int plt_off1 = 2, plt_off2 = 10, plt_off3 = 16;
@@ -2089,8 +2088,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
       plt_pic_entry = elf_cris_pic_plt_entry_v32;
     }
 
-  dynobj = htab->root.dynobj;
-
   if (h->plt.offset != (bfd_vma) -1)
     {
       asection *splt;
@@ -2278,8 +2275,10 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
                  && (h->root.type == bfd_link_hash_defined
                      || h->root.type == bfd_link_hash_defweak));
 
-      s = bfd_get_linker_section (dynobj, ".rela.bss");
-      BFD_ASSERT (s != NULL);
+      if (h->root.u.def.section == htab->root.sdynrelro)
+       s = htab->root.sreldynrelro;
+      else
+       s = htab->root.srelbss;
 
       rela.r_offset = (h->root.u.def.value
                       + h->root.u.def.section->output_section->vma
@@ -2360,20 +2359,6 @@ elf_cris_finish_dynamic_sections (bfd *output_bfd,
                dyn.d_un.d_val = s->size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
-
-           case DT_RELASZ:
-             /* The procedure linkage table relocs (DT_JMPREL) should
-                not be included in the overall relocs (DT_RELA).
-                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 = elf_hash_table (info)->srelplt;
-             if (s != NULL)
-               dyn.d_un.d_val -= s->size;
-             bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
-             break;
            }
        }
 
@@ -2729,8 +2714,9 @@ elf_cris_adjust_gotplt_to_got (struct elf_cris_link_hash_entry *h, void * p)
   struct bfd_link_info *info = (struct bfd_link_info *) p;
 
   /* A GOTPLT reloc, when activated, is supposed to be included into
-     the PLT refcount.  */
+     the PLT refcount, when the symbol isn't set-or-forced local.  */
   BFD_ASSERT (h->gotplt_refcount == 0
+             || h->root.plt.refcount == -1
              || h->gotplt_refcount <= h->root.plt.refcount);
 
   /* If nobody wanted a GOTPLT with this symbol, we're done.  */
@@ -2756,6 +2742,7 @@ elf_cris_adjust_gotplt_to_got (struct elf_cris_link_hash_entry *h, void * p)
       srelgot = elf_hash_table (info)->srelgot;
 
       /* Put accurate refcounts there.  */
+      BFD_ASSERT (h->root.got.refcount >= 0);
       h->root.got.refcount += h->gotplt_refcount;
       h->reg_got_refcount = h->gotplt_refcount;
 
@@ -2854,6 +2841,7 @@ elf_cris_adjust_dynamic_symbol (struct bfd_link_info *info,
   struct elf_cris_link_hash_table * htab;
   bfd *dynobj;
   asection *s;
+  asection *srel;
   bfd_size_type plt_entry_size;
 
   htab = elf_cris_hash_table (info);
@@ -3041,23 +3029,30 @@ elf_cris_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_linker_section (dynobj, ".dynbss");
-  BFD_ASSERT (s != NULL);
-
   /* We must generate a R_CRIS_COPY reloc to tell the dynamic linker to
      copy the initial value out of the dynamic object and into the
      runtime process image.  We need to remember the offset into the
      .rela.bss section we are going to use.  */
+
+  if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+    {
+      s = htab->root.sdynrelro;
+      srel = htab->root.sreldynrelro;
+    }
+  else
+    {
+      s = htab->root.sdynbss;
+      srel = htab->root.srelbss;
+    }
   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
     {
-      asection *srel;
-
-      srel = bfd_get_linker_section (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
       srel->size += sizeof (Elf32_External_Rela);
       h->needs_copy = 1;
     }
 
+  BFD_ASSERT (s != NULL);
+
   return _bfd_elf_adjust_dynamic_copy (info, h, s);
 }
 
@@ -3183,7 +3178,7 @@ cris_elf_check_relocs (bfd *abfd,
 
          /* PR15323, ref flags aren't set for references in the same
             object.  */
-         h->root.non_ir_ref = 1;
+         h->root.non_ir_ref_regular = 1;
        }
 
       r_type = ELF32_R_TYPE (rel->r_info);
@@ -3235,7 +3230,7 @@ cris_elf_check_relocs (bfd *abfd,
                {
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("%B, section %A:\n  v10/v32 compatible object %s"
+                   (_("%B, section %A:\n  v10/v32 compatible object"
                       " must not contain a PIC relocation"),
                     abfd, sec);
                  return FALSE;
@@ -3483,7 +3478,10 @@ cris_elf_check_relocs (bfd *abfd,
            continue;
 
          h->needs_plt = 1;
-         h->plt.refcount++;
+
+         /* If the symbol is forced local, the refcount is unavailable.  */
+         if (h->plt.refcount != -1)
+           h->plt.refcount++;
          break;
 
        case R_CRIS_8:
@@ -3801,7 +3799,8 @@ elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            }
        }
       else if (! CONST_STRNEQ (name, ".got")
-              && strcmp (name, ".dynbss") != 0)
+              && strcmp (name, ".dynbss") != 0
+              && s != htab->root.sdynrelro)
        {
          /* It's not one of our sections, so don't allocate space.  */
          continue;
@@ -4338,6 +4337,8 @@ elf_cris_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED,
 #define elf_backend_want_plt_sym       0
 #define elf_backend_got_header_size    12
 #define elf_backend_got_elt_size elf_cris_got_elt_size
+#define elf_backend_dtrel_excludes_plt 1
+#define elf_backend_want_dynrelro      1
 
 /* Later, we my want to optimize RELA entries into REL entries for dynamic
    linking and libraries (if it's a win of any significance).  Until then,
This page took 0.027746 seconds and 4 git commands to generate.