nds32: Rename __BIT() to N32_BIT().
[deliverable/binutils-gdb.git] / bfd / elfxx-x86.c
index 4f6b09e1d0a7f80b21df1c0af27ad1f09daf23e6..c41dbeff762419d775566c7e14e2b80d3c416784 100644 (file)
@@ -107,10 +107,7 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h,
 
   plt_entry_size = htab->plt.plt_entry_size;
 
-  resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
-                                                     bed->target_id,
-                                                     eh->has_got_reloc,
-                                                     eh);
+  resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
 
   /* Clear the reference count of function pointer relocations if
      symbol isn't a normal function.  */
@@ -731,13 +728,11 @@ elf_i386_is_reloc_section (const char *secname)
   return CONST_STRNEQ (secname, ".rel");
 }
 
-#ifdef BFD64
 static bfd_boolean
 elf_x86_64_is_reloc_section (const char *secname)
 {
   return CONST_STRNEQ (secname, ".rela");
 }
-#endif
 
 /* Create an x86 ELF linker hash table.  */
 
@@ -762,8 +757,6 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
       return NULL;
     }
 
-#ifdef BFD64
-  /* NB: If BFD64 isn't defined, only i386 will be supported.  */
   if (bed->target_id == X86_64_ELF_DATA)
     {
       ret->is_reloc_section = elf_x86_64_is_reloc_section;
@@ -775,18 +768,13 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
     }
   if (ABI_64_P (abfd))
     {
-      ret->r_info = elf64_r_info;
-      ret->r_sym = elf64_r_sym;
       ret->sizeof_reloc = sizeof (Elf64_External_Rela);
       ret->pointer_r_type = R_X86_64_64;
       ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
       ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
     }
   else
-#endif
     {
-      ret->r_info = elf32_r_info;
-      ret->r_sym = elf32_r_sym;
       if (bed->target_id == X86_64_ELF_DATA)
        {
          ret->sizeof_reloc = sizeof (Elf32_External_Rela);
@@ -854,12 +842,28 @@ _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
       htab = elf_x86_hash_table (info, bed->target_id);
       if (htab)
        {
-         struct elf_link_hash_entry *h
-           = elf_link_hash_lookup (elf_hash_table (info),
+         struct elf_link_hash_entry *h;
+
+         h = elf_link_hash_lookup (elf_hash_table (info),
                                    htab->tls_get_addr,
                                    FALSE, FALSE, FALSE);
          if (h != NULL)
-           ((struct elf_x86_link_hash_entry *) h)->tls_get_addr = 1;
+           elf_x86_hash_entry (h)->tls_get_addr = 1;
+
+         /* "__ehdr_start" will be defined by linker as a hidden symbol
+            later if it is referenced and not defined.  */
+         h = elf_link_hash_lookup (elf_hash_table (info),
+                                   "__ehdr_start",
+                                   FALSE, FALSE, FALSE);
+         if (h != NULL
+             && (h->root.type == bfd_link_hash_new
+                 || h->root.type == bfd_link_hash_undefined
+                 || h->root.type == bfd_link_hash_undefweak
+                 || h->root.type == bfd_link_hash_common))
+           {
+             elf_x86_hash_entry (h)->local_ref = 2;
+             elf_x86_hash_entry (h)->linker_def = 1;
+           }
        }
     }
 
@@ -1439,19 +1443,12 @@ bfd_boolean
 _bfd_x86_elf_fixup_symbol (struct bfd_link_info *info,
                           struct elf_link_hash_entry *h)
 {
-  if (h->dynindx != -1)
+  if (h->dynindx != -1
+      && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, elf_x86_hash_entry (h)))
     {
-      const struct elf_backend_data *bed
-       = get_elf_backend_data (info->output_bfd);
-      if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
-                                          bed->target_id,
-                                          elf_x86_hash_entry (h)->has_got_reloc,
-                                          elf_x86_hash_entry (h)))
-       {
-         h->dynindx = -1;
-         _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
-                                 h->dynstr_index);
-       }
+      h->dynindx = -1;
+      _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+                             h->dynstr_index);
     }
   return TRUE;
 }
@@ -1680,8 +1677,9 @@ bfd_boolean
 _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info *info,
                                           struct elf_link_hash_entry *h)
 {
-  struct elf_x86_link_hash_entry *eh
-    = (struct elf_x86_link_hash_entry *) h;
+  struct elf_x86_link_hash_entry *eh = elf_x86_hash_entry (h);
+  struct elf_x86_link_hash_table *htab
+    = (struct elf_x86_link_hash_table *) info->hash;
 
   if (eh->local_ref > 1)
     return TRUE;
@@ -1690,13 +1688,18 @@ _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info *info,
     return FALSE;
 
   /* Unversioned symbols defined in regular objects can be forced local
-     by linker version script.  A weak undefined symbol can fored local
-     if it has non-default visibility or "-z nodynamic-undefined-weak"
-     is used.  */
+     by linker version script.  A weak undefined symbol is forced local
+     if
+     1. It has non-default visibility.  Or
+     2. When building executable, there is no dynamic linker.  Or
+     3. or "-z nodynamic-undefined-weak" is used.
+   */
   if (SYMBOL_REFERENCES_LOCAL (info, h)
-      || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
-          || info->dynamic_undefined_weak == 0)
-         && h->root.type == bfd_link_hash_undefweak)
+      || (h->root.type == bfd_link_hash_undefweak
+         && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             || (bfd_link_executable (info)
+                 && htab->interp == NULL)
+             || info->dynamic_undefined_weak == 0))
       || ((h->def_regular || ELF_COMMON_DEF_P (h))
          && h->versioned == unversioned
          && info->version_info != NULL
@@ -2115,8 +2118,7 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
 
 bfd *
 _bfd_x86_elf_link_setup_gnu_properties
-  (struct bfd_link_info *info,
-   struct elf_x86_plt_layout_table *plt_layout)
+  (struct bfd_link_info *info, struct elf_x86_init_table *init_table)
 {
   bfd_boolean normal_target;
   bfd_boolean lazy_plt;
@@ -2188,16 +2190,18 @@ error_alignment:
 
   pbfd = _bfd_elf_link_setup_gnu_properties (info);
 
-  if (bfd_link_relocatable (info))
-    return pbfd;
-
   bed = get_elf_backend_data (info->output_bfd);
 
   htab = elf_x86_hash_table (info, bed->target_id);
   if (htab == NULL)
     return pbfd;
 
-  htab->is_vxworks = plt_layout->is_vxworks;
+  htab->is_vxworks = init_table->is_vxworks;
+  htab->r_info = init_table->r_info;
+  htab->r_sym = init_table->r_sym;
+
+  if (bfd_link_relocatable (info))
+    return pbfd;
 
   use_ibt_plt = info->ibtplt || info->ibt;
   if (!use_ibt_plt && pbfd != NULL)
@@ -2254,24 +2258,24 @@ error_alignment:
      still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
      canonical function address.  */
   htab->plt.has_plt0 = 1;
-  normal_target = plt_layout->normal_target;
+  normal_target = init_table->normal_target;
 
   if (normal_target)
     {
       if (use_ibt_plt)
        {
-         htab->lazy_plt = plt_layout->lazy_ibt_plt;
-         htab->non_lazy_plt = plt_layout->non_lazy_ibt_plt;
+         htab->lazy_plt = init_table->lazy_ibt_plt;
+         htab->non_lazy_plt = init_table->non_lazy_ibt_plt;
        }
       else
        {
-         htab->lazy_plt = plt_layout->lazy_plt;
-         htab->non_lazy_plt = plt_layout->non_lazy_plt;
+         htab->lazy_plt = init_table->lazy_plt;
+         htab->non_lazy_plt = init_table->non_lazy_plt;
        }
     }
   else
     {
-      htab->lazy_plt = plt_layout->lazy_plt;
+      htab->lazy_plt = init_table->lazy_plt;
       htab->non_lazy_plt = NULL;
     }
 
This page took 0.026331 seconds and 4 git commands to generate.