[ARC] Fix setting private elf flags when parsing .cpu.
[deliverable/binutils-gdb.git] / bfd / elf32-or1k.c
index 2353d0d50347354f1bbe8ea6633f32502a40c8a8..1daa7b6a5182d5416e252e286297f171be61b7fe 100644 (file)
@@ -1,5 +1,5 @@
 /* Or1k-specific support for 32-bit ELF.
-   Copyright 2001-2014 Free Software Foundation, Inc.
+   Copyright (C) 2001-2016 Free Software Foundation, Inc.
    Contributed for OR32 by Johan Rydberg, jrydberg@opencores.org
 
    PIC parts added by Stefan Kristiansson, stefan.kristiansson@saunalahti.fi,
@@ -60,8 +60,8 @@ static reloc_howto_type or1k_elf_howto_table[] =
   /* This reloc does nothing.  */
   HOWTO (R_OR1K_NONE,           /* type */
          0,                     /* rightshift */
-         2,                     /* size (0 = byte, 1 = short, 2 = long) */
-         32,                    /* bitsize */
+         3,                     /* size (0 = byte, 1 = short, 2 = long) */
+         0,                     /* bitsize */
          FALSE,                 /* pc_relative */
          0,                     /* bitpos */
          complain_overflow_dont, /* complain_on_overflow */
@@ -199,7 +199,7 @@ static reloc_howto_type or1k_elf_howto_table[] =
          FALSE,                 /* partial_inplace */
          0,                     /* src_mask */
          0xffffffff,            /* dst_mask */
-         FALSE),                /* pcrel_offset */
+         TRUE),                 /* pcrel_offset */
 
   HOWTO (R_OR1K_16_PCREL,
          0,                     /* rightshift */
@@ -213,7 +213,7 @@ static reloc_howto_type or1k_elf_howto_table[] =
          FALSE,                 /* partial_inplace */
          0,                     /* src_mask */
          0xffff,                /* dst_mask */
-         FALSE),                /* pcrel_offset */
+         TRUE),                 /* pcrel_offset */
 
   HOWTO (R_OR1K_8_PCREL,
          0,                     /* rightshift */
@@ -227,7 +227,7 @@ static reloc_howto_type or1k_elf_howto_table[] =
          FALSE,                 /* partial_inplace */
          0,                     /* src_mask */
          0xff,                  /* dst_mask */
-         FALSE),                /* pcrel_offset */
+         TRUE),                 /* pcrel_offset */
 
    HOWTO (R_OR1K_GOTPC_HI16,    /* Type.  */
          16,                    /* Rightshift.  */
@@ -704,7 +704,7 @@ or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
 {
   unsigned int i;
 
-  for (i = ARRAY_SIZE (or1k_reloc_map); --i;)
+  for (i = ARRAY_SIZE (or1k_reloc_map); i--;)
     if (or1k_reloc_map[i].bfd_reloc_val == code)
       return & or1k_elf_howto_table[or1k_reloc_map[i].or1k_reloc_val];
 
@@ -738,7 +738,11 @@ or1k_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
   unsigned int r_type;
 
   r_type = ELF32_R_TYPE (dst->r_info);
-  BFD_ASSERT (r_type < (unsigned int) R_OR1K_max);
+  if (r_type >= (unsigned int) R_OR1K_max)
+    {
+      _bfd_error_handler (_("%B: invalid OR1K reloc number: %d"), abfd, r_type);
+      r_type = 0;
+    }
   cache_ptr->howto = & or1k_elf_howto_table[r_type];
 }
 
@@ -875,7 +879,7 @@ or1k_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;
 
       switch (howto->type)
@@ -905,12 +909,11 @@ or1k_elf_relocate_section (bfd *output_bfd,
               BFD_ASSERT (off != (bfd_vma) -1);
 
               dyn = htab->root.dynamic_sections_created;
-              if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
-                  || (info->shared
-                      && (info->symbolic
-                          || h->dynindx == -1
-                          || h->forced_local)
-                      && h->def_regular))
+              if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
+                                                    bfd_link_pic (info),
+                                                    h)
+                  || (bfd_link_pic (info)
+                      && SYMBOL_REFERENCES_LOCAL (info, h)))
                 {
                   /* This is actually a static link, or it is a
                      -Bsymbolic link and the symbol is defined
@@ -958,7 +961,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
                 {
                   /* Write entry in GOT.  */
                   bfd_put_32 (output_bfd, relocation, sgot->contents + off);
-                  if (info->shared)
+                  if (bfd_link_pic (info))
                     {
                       asection *srelgot;
                       Elf_Internal_Rela outrel;
@@ -1011,16 +1014,13 @@ or1k_elf_relocate_section (bfd *output_bfd,
                 || (input_section->flags & SEC_ALLOC) == 0)
               break;
 
-            if ((info->shared
+            if ((bfd_link_pic (info)
                  && (h == NULL
                      || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
                      || h->root.type != bfd_link_hash_undefweak)
-                 && (!howto->pc_relative
-                     || (h != NULL
-                         && h->dynindx != -1
-                         && (!info->symbolic
-                             || !h->def_regular))))
-                || (!info->shared
+                && (howto->type != R_OR1K_INSN_REL_26
+                    || !SYMBOL_CALLS_LOCAL (info, h)))
+                || (!bfd_link_pic (info)
                     && h != NULL
                     && h->dynindx != -1
                     && !h->non_got_ref
@@ -1140,7 +1140,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
             /* Dynamic entries will require relocations. if we do not need
                them we will just use the default R_OR1K_NONE and
                not set anything.  */
-            dynamic = info->shared
+            dynamic = bfd_link_pic (info)
              || (sec && (sec->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && (h->root.type == bfd_link_hash_defweak || !h->def_regular));
@@ -1421,7 +1421,7 @@ or1k_elf_check_relocs (bfd *abfd,
   bfd *dynobj;
   asection *sreloc = NULL;
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     return TRUE;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
@@ -1576,7 +1576,7 @@ or1k_elf_check_relocs (bfd *abfd,
         case R_OR1K_32:
           /* R_OR1K_16? */
           {
-            if (h != NULL && !info->shared)
+            if (h != NULL && !bfd_link_pic (info))
               {
                 /* We may need a copy reloc.  */
                 h->non_got_ref = 1;
@@ -1609,14 +1609,14 @@ or1k_elf_check_relocs (bfd *abfd,
                dynamic library if we manage to avoid copy relocs for the
                symbol.  */
 
-            if ((info->shared
+            if ((bfd_link_pic (info)
                  && (sec->flags & SEC_ALLOC) != 0
                  && (ELF32_R_TYPE (rel->r_info) != R_OR1K_INSN_REL_26
                      || (h != NULL
-                         && (! info->symbolic
+                         && (!SYMBOLIC_BIND (info, h)
                              || h->root.type == bfd_link_hash_defweak
                              || !h->def_regular))))
-                || (!info->shared
+                || (!bfd_link_pic (info)
                     && (sec->flags & SEC_ALLOC) != 0
                     && h != NULL
                     && (h->root.type == bfd_link_hash_defweak
@@ -1812,7 +1812,7 @@ or1k_elf_finish_dynamic_sections (bfd *output_bfd,
       splt = htab->splt;
       if (splt && splt->size > 0)
         {
-          if (info->shared)
+          if (bfd_link_pic (info))
             {
               bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0,
                           splt->contents);
@@ -1913,7 +1913,7 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
       got_addr = got_offset;
 
       /* Fill in the entry in the procedure linkage table.  */
-      if (! info->shared)
+      if (! bfd_link_pic (info))
         {
           got_addr += htab->sgotplt->output_section->vma
             + htab->sgotplt->output_offset;
@@ -1991,11 +1991,7 @@ or1k_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
-          && (info->symbolic
-              || h->dynindx == -1
-              || h->forced_local)
-          && h->def_regular)
+      if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
         {
           rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
           rela.r_addend = (h->root.u.def.value
@@ -2095,7 +2091,7 @@ or1k_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
           && h->root.type != bfd_link_hash_undefweak
@@ -2134,7 +2130,7 @@ or1k_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
@@ -2197,7 +2193,7 @@ or1k_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);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
@@ -2233,7 +2229,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
             return FALSE;
         }
 
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
+      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
         {
           asection *s = htab->splt;
 
@@ -2249,7 +2245,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
              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;
@@ -2305,7 +2301,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
       else
         s->size += 4;
       dyn = htab->root.dynamic_sections_created;
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
+      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
         {
           if (tls_type == TLS_GD)
             htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
@@ -2325,11 +2321,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
      space for pc-relative relocs that have become local due to symbol
      visibility changes.  */
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     {
-      if (h->def_regular
-          && (h->forced_local
-              || info->symbolic))
+      if (SYMBOL_CALLS_LOCAL (info, h))
         {
           struct elf_or1k_dyn_relocs **pp;
 
@@ -2453,7 +2447,7 @@ or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   if (htab->root.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_section_by_name (dynobj, ".interp");
           BFD_ASSERT (s != NULL);
@@ -2524,7 +2518,7 @@ or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
                 s->size += 8;
               else
                 s->size += 4;
-              if (info->shared)
+              if (bfd_link_pic (info))
                 {
                   if (local_tls_type != NULL && *local_tls_type == TLS_GD)
                     srel->size += 2 * sizeof (Elf32_External_Rela);
@@ -2613,7 +2607,7 @@ or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-     if (info->executable)
+     if (bfd_link_executable (info))
        {
          if (! add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
@@ -2674,11 +2668,11 @@ or1k_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
   htab->splt = bfd_get_section_by_name (dynobj, ".plt");
   htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
   htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
-  if (!info->shared)
+  if (!bfd_link_pic (info))
     htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
 
   if (!htab->splt || !htab->srelplt || !htab->sdynbss
-      || (!info->shared && !htab->srelbss))
+      || (!bfd_link_pic (info) && !htab->srelbss))
     abort ();
 
   return TRUE;
This page took 0.067256 seconds and 4 git commands to generate.