Rename u.weakdef and make it a circular list
[deliverable/binutils-gdb.git] / bfd / elf32-score.c
index ce9c3777559620ee7a99b9ee978544a1512587fd..455f8cb0b375b42fc94092e30da475550589baa2 100644 (file)
@@ -1,5 +1,5 @@
 /* 32-bit ELF support for S+core.
-   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+   Copyright (C) 2006-2017 Free Software Foundation, Inc.
    Contributed by
    Brain.lin (brain.lin@sunplusct.com)
    Mei Ligang (ligang@sunnorth.com.cn)
@@ -227,14 +227,14 @@ static bfd_vma
 score3_bfd_getl48 (const void *p)
 {
   const bfd_byte *addr = p;
-  unsigned long long v;
-
-  v = (unsigned long long) addr[4];
-  v |= (unsigned long long) addr[5] << 8;
-  v |= (unsigned long long) addr[2] << 16;
-  v |= (unsigned long long) addr[3] << 24;
-  v |= (unsigned long long) addr[0] << 32;
-  v |= (unsigned long long) addr[1] << 40;
+  bfd_uint64_t v;
+
+  v = (bfd_uint64_t) addr[4];
+  v |= (bfd_uint64_t) addr[5] << 8;
+  v |= (bfd_uint64_t) addr[2] << 16;
+  v |= (bfd_uint64_t) addr[3] << 24;
+  v |= (bfd_uint64_t) addr[0] << 32;
+  v |= (bfd_uint64_t) addr[1] << 40;
   return v;
 }
 
@@ -1429,7 +1429,8 @@ score_elf_create_got_section (bfd *abfd,
   /* We have to use an alignment of 2**4 here because this is hardcoded
      in the function stub generation and in the linker script.  */
   s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
-   if (s == NULL
+  elf_hash_table (info)->sgot = s;
+  if (s == NULL
       || ! bfd_set_section_alignment (abfd, s, 4))
     return FALSE;
 
@@ -1446,6 +1447,7 @@ score_elf_create_got_section (bfd *abfd,
   h->non_elf = 0;
   h->def_regular = 1;
   h->type = STT_OBJECT;
+  elf_hash_table (info)->hgot = h;
 
   if (bfd_link_pic (info) && ! bfd_elf_link_record_dynamic_symbol (info, h))
     return FALSE;
@@ -1515,7 +1517,7 @@ score_elf_create_local_got_entry (bfd *abfd,
     {
       (*loc)->gotidx = -1;
       /* We didn't allocate enough space in the GOT.  */
-      (*_bfd_error_handler)
+      _bfd_error_handler
         (_("not enough GOT space for local GOT entries"));
       bfd_set_error (bfd_error_bad_value);
       return NULL;
@@ -2032,11 +2034,9 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
     {
       const Elf_Internal_Rela *relend;
       const Elf_Internal_Rela *lo16_rel;
-      const struct elf_backend_data *bed;
       bfd_vma lo_value = 0;
 
-      bed = get_elf_backend_data (output_bfd);
-      relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel;
+      relend = relocs + input_section->reloc_count;
       lo16_rel = score_elf_next_relocation (input_bfd, R_SCORE_GOT_LO16, rel, relend);
       if ((local_p) && (lo16_rel != NULL))
         {
@@ -2165,7 +2165,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
       if ((offset & 0x1000000) != 0)
         offset |= 0xfe000000;
       value += offset;
-      abs_value = abs (value - rel_addr);
+      abs_value = value - rel_addr;
       if ((abs_value & 0xfe000000) != 0)
         return bfd_reloc_overflow;
       addend = (addend & ~howto->src_mask)
@@ -2241,7 +2241,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
       if ((offset & 0x800) != 0)        /* Offset is negative.  */
         offset |= 0xfffff000;
       value += offset;
-      abs_value = abs (value - rel_addr);
+      abs_value = value - rel_addr;
       if ((abs_value & 0xfffff000) != 0)
         return bfd_reloc_overflow;
       addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
@@ -2667,12 +2667,11 @@ s3_bfd_score_elf_relocate_section (bfd *output_bfd,
             }
           else if (!bfd_link_relocatable (info))
             {
-              if (! ((*info->callbacks->undefined_symbol)
-                     (info, h->root.root.root.string, input_bfd,
-                      input_section, rel->r_offset,
-                      (info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
-                      || ELF_ST_VISIBILITY (h->root.other))))
-                return bfd_reloc_undefined;
+             (*info->callbacks->undefined_symbol)
+               (info, h->root.root.root.string, input_bfd,
+                input_section, rel->r_offset,
+                (info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
+                || ELF_ST_VISIBILITY (h->root.other));
               relocation = 0;
             }
         }
@@ -2718,16 +2717,14 @@ s3_bfd_score_elf_relocate_section (bfd *output_bfd,
               /* If the overflowing reloc was to an undefined symbol,
                  we have already printed one error message and there
                  is no point complaining again.  */
-              if (((!h) || (h->root.root.type != bfd_link_hash_undefined))
-                  && (!((*info->callbacks->reloc_overflow)
-                        (info, NULL, name, howto->name, (bfd_vma) 0,
-                         input_bfd, input_section, rel->r_offset))))
-                return FALSE;
+             if (!h || h->root.root.type != bfd_link_hash_undefined)
+               (*info->callbacks->reloc_overflow)
+                 (info, 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:
@@ -2749,12 +2746,11 @@ s3_bfd_score_elf_relocate_section (bfd *output_bfd,
 
             default:
               msg = _("internal error: unknown error");
-              /* fall through */
+              /* Fall through.  */
 
             common_error:
-              if (!((*info->callbacks->warning)
-                    (info, msg, name, input_bfd, input_section, rel->r_offset)))
-                return FALSE;
+             (*info->callbacks->warning) (info, msg, name, input_bfd,
+                                          input_section, rel->r_offset);
               break;
             }
         }
@@ -2771,7 +2767,6 @@ s3_bfd_score_elf_check_relocs (bfd *abfd,
                                asection *sec,
                                const Elf_Internal_Rela *relocs)
 {
-  const char *name;
   bfd *dynobj;
   Elf_Internal_Shdr *symtab_hdr;
   struct elf_link_hash_entry **sym_hashes;
@@ -2781,7 +2776,6 @@ s3_bfd_score_elf_check_relocs (bfd *abfd,
   const Elf_Internal_Rela *rel_end;
   asection *sgot;
   asection *sreloc;
-  const struct elf_backend_data *bed;
 
   if (bfd_link_relocatable (info))
     return TRUE;
@@ -2791,8 +2785,6 @@ s3_bfd_score_elf_check_relocs (bfd *abfd,
   sym_hashes = elf_sym_hashes (abfd);
   extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
 
-  name = bfd_get_section_name (abfd, sec);
-
   if (dynobj == NULL)
     {
       sgot = NULL;
@@ -2812,8 +2804,7 @@ s3_bfd_score_elf_check_relocs (bfd *abfd,
     }
 
   sreloc = NULL;
-  bed = get_elf_backend_data (abfd);
-  rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel;
+  rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; ++rel)
     {
       unsigned long r_symndx;
@@ -2829,7 +2820,9 @@ s3_bfd_score_elf_check_relocs (bfd *abfd,
         }
       else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
         {
-          (*_bfd_error_handler) (_("%s: Malformed reloc detected for section %s"), abfd, name);
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%B: Malformed reloc detected for section %A"), abfd, sec);
           bfd_set_error (bfd_error_bad_value);
           return FALSE;
         }
@@ -2845,7 +2838,7 @@ s3_bfd_score_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;
             }
         }
 
@@ -2885,9 +2878,10 @@ s3_bfd_score_elf_check_relocs (bfd *abfd,
         case R_SCORE_CALL15:
           if (h == NULL)
             {
-              (*_bfd_error_handler)
-                (_("%B: CALL15 reloc at 0x%lx not against global symbol"),
-                 abfd, (unsigned long) rel->r_offset);
+             _bfd_error_handler
+               /* xgettext:c-format */
+                (_("%B: CALL15 reloc at %#Lx not against global symbol"),
+                 abfd, rel->r_offset);
               bfd_set_error (bfd_error_bad_value);
               return FALSE;
             }
@@ -3104,7 +3098,7 @@ s3_bfd_score_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)));
 
   /* If this symbol is defined in a dynamic object, we need to copy
@@ -3163,12 +3157,12 @@ s3_bfd_score_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;
     }
 
@@ -3269,7 +3263,7 @@ s3_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (!bfd_link_pic (info) && !info->nointerp)
+      if (bfd_link_executable (info) && !info->nointerp)
         {
           s = bfd_get_linker_section (dynobj, ".interp");
           BFD_ASSERT (s != NULL);
@@ -3618,21 +3612,18 @@ s3_bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
           switch (dyn.d_tag)
             {
             case DT_RELENT:
-              s = score_elf_rel_dyn_section (dynobj, FALSE);
-              BFD_ASSERT (s != NULL);
               dyn.d_un.d_val = SCORE_ELF_REL_SIZE (dynobj);
               break;
 
             case DT_STRSZ:
               /* Rewrite DT_STRSZ.  */
-              dyn.d_un.d_val = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
-                    break;
+              dyn.d_un.d_val
+                = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
+              break;
 
             case DT_PLTGOT:
-              name = ".got";
-              s = bfd_get_section_by_name (output_bfd, name);
-              BFD_ASSERT (s != NULL);
-              dyn.d_un.d_ptr = s->vma;
+              s = elf_hash_table (info)->sgot;
+              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
               break;
 
             case DT_SCORE_BASE_ADDRESS:
@@ -3660,14 +3651,13 @@ s3_bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
                 }
               /* In case if we don't have global got symbols we default
                   to setting DT_SCORE_GOTSYM to the same value as
-                  DT_SCORE_SYMTABNO, so we just fall through.  */
+                  DT_SCORE_SYMTABNO.  */
+             /* Fall through.  */
 
             case DT_SCORE_SYMTABNO:
               name = ".dynsym";
               elemsize = SCORE_ELF_SYM_SIZE (output_bfd);
-              s = bfd_get_section_by_name (output_bfd, name);
-              BFD_ASSERT (s != NULL);
-
+              s = bfd_get_linker_section (dynobj, name);
               dyn.d_un.d_val = s->size / elemsize;
               break;
 
@@ -4024,12 +4014,13 @@ s3_elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
 }
 
 static bfd_boolean
-s3_elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+s3_elf32_score_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   flagword in_flags;
   flagword out_flags;
 
-  if (!_bfd_generic_verify_endian_match (ibfd, obfd))
+  if (!_bfd_generic_verify_endian_match (ibfd, info))
     return FALSE;
 
   in_flags  = elf_elfheader (ibfd)->e_flags;
@@ -4057,9 +4048,8 @@ s3_elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
     }
 
   if (((in_flags & EF_SCORE_PIC) != 0) != ((out_flags & EF_SCORE_PIC) != 0))
-    {
-      (*_bfd_error_handler) (_("%B: warning: linking PIC files with non-PIC files"), ibfd);
-    }
+    _bfd_error_handler
+      (_("%B: warning: linking PIC files with non-PIC files"), ibfd);
 
   /* FIXME: Maybe dependency fix compatibility should be checked here.  */
 
@@ -4399,12 +4389,12 @@ elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
 }
 
 static bfd_boolean
-elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+elf32_score_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
-  if (bfd_get_mach (obfd) == bfd_mach_score3)
-    return s3_elf32_score_merge_private_bfd_data (ibfd, obfd);
+  if (bfd_get_mach (info->output_bfd) == bfd_mach_score3)
+    return s3_elf32_score_merge_private_bfd_data (ibfd, info);
   else
-    return s7_elf32_score_merge_private_bfd_data (ibfd, obfd);
+    return s7_elf32_score_merge_private_bfd_data (ibfd, info);
 }
 
 static bfd_boolean
This page took 0.032882 seconds and 4 git commands to generate.