summaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2014-12-13 23:37:22 -0800
committerH.J. Lu <hjl.tools@gmail.com>2014-12-13 23:44:39 -0800
commit3e5d8b05745a9fa1d9ad120459143e6e36cfbde0 (patch)
tree6c270d1f1a21daaff04f1d3a7d2bba0db7ddb01f /bfd
parent27cef631a78b56f8ad030ba6231432e04cc1838e (diff)
downloadbinutils-3e5d8b05745a9fa1d9ad120459143e6e36cfbde0.tar.gz
binutils-3e5d8b05745a9fa1d9ad120459143e6e36cfbde0.tar.bz2
binutils-3e5d8b05745a9fa1d9ad120459143e6e36cfbde0.zip
Handle weak alias for PIE with copy reloc
When there is a weak symbol with a real definition, the processor independent code will have arranged for us to see the real definition first. We need to copy the needs_copy bit from the real definition and check it when allowing copy reloc in PIE. bfd/ PR ld/17689 * elf64-x86-64.c (elf_x86_64_link_hash_entry): Add needs_copy. Change has_bnd_reloc to bit field. (elf_x86_64_link_hash_newfunc): Initialize needs_copy and has_bnd_reloc to 0. (elf_x86_64_check_relocs): Set has_bnd_reloc to 1 instead of TRUE. (elf_x86_64_adjust_dynamic_symbol): Copy needs_copy from the real definition to a weak symbol. (elf_x86_64_allocate_dynrelocs): Also check needs_copy of a weak symbol for PIE when discarding space for relocs against symbols which turn out to need copy relocs. (elf_x86_64_relocate_section): Also check needs_copy of a weak symbol for PIE with copy reloc. ld/testsuite/ PR ld/17689 * ld-x86-64/pr17689.out: New file. * ld-x86-64/pr17689.rd: Likewise. * ld-x86-64/pr17689a.c: Likewise. * ld-x86-64/pr17689b.S: Likewise. * ld-x86-64/x86-64.exp: Run PR ld/17689 tests.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog22
-rw-r--r--bfd/elf64-x86-64.c27
2 files changed, 42 insertions, 7 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3942b4e0389..0ebd6d7103b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,25 @@
+2014-12-13 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/17689
+ * elf64-x86-64.c (elf_x86_64_link_hash_entry): Add needs_copy.
+ Change has_bnd_reloc to bit field.
+ (elf_x86_64_link_hash_newfunc): Initialize needs_copy and
+ has_bnd_reloc to 0.
+ (elf_x86_64_check_relocs): Set has_bnd_reloc to 1 instead
+ of TRUE.
+ (elf_x86_64_adjust_dynamic_symbol): Copy needs_copy from the
+ real definition to a weak symbol.
+ (elf_x86_64_allocate_dynrelocs): Also check needs_copy of a
+ weak symbol for PIE when discarding space for relocs against
+ symbols which turn out to need copy relocs.
+ (elf_x86_64_relocate_section): Also check needs_copy of a
+ weak symbol for PIE with copy reloc.
+
+2014-12-12 Alan Modra <amodra@gmail.com>
+
+ PR 15228
+ * elflink.c (_bfd_elf_adjust_dynamic_copy): Call bfd_set_error.
+
2014-12-10 Alan Modra <amodra@gmail.com>
* dwarf2.c (read_address): Check bfd_target_elf_flavour before
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index e4dd80b19a8..fefb08c341c 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -757,8 +757,15 @@ struct elf_x86_64_link_hash_entry
(GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
unsigned char tls_type;
+ /* TRUE if a weak symbol with a real definition needs a copy reloc.
+ When there is a weak symbol with a real definition, the processor
+ independent code will have arranged for us to see the real
+ definition first. We need to copy the needs_copy bit from the
+ real definition and check it when allowing copy reloc in PIE. */
+ unsigned int needs_copy : 1;
+
/* TRUE if symbol has at least one BND relocation. */
- bfd_boolean has_bnd_reloc;
+ unsigned int has_bnd_reloc : 1;
/* Information about the second PLT entry. Filled when has_bnd_reloc is
set. */
@@ -892,7 +899,8 @@ elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
eh = (struct elf_x86_64_link_hash_entry *) entry;
eh->dyn_relocs = NULL;
eh->tls_type = GOT_UNKNOWN;
- eh->has_bnd_reloc = FALSE;
+ eh->needs_copy = 0;
+ eh->has_bnd_reloc = 0;
eh->plt_bnd.offset = (bfd_vma) -1;
eh->tlsdesc_got = (bfd_vma) -1;
}
@@ -1655,7 +1663,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
&& (get_elf_x86_64_backend_data (abfd)
== &elf_x86_64_arch_bed))
{
- elf_x86_64_hash_entry (h)->has_bnd_reloc = TRUE;
+ elf_x86_64_hash_entry (h)->has_bnd_reloc = 1;
/* Create the second PLT for Intel MPX support. */
if (htab->plt_bnd == NULL)
@@ -2347,7 +2355,11 @@ elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
h->root.u.def.section = h->u.weakdef->root.u.def.section;
h->root.u.def.value = h->u.weakdef->root.u.def.value;
if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
- h->non_got_ref = h->u.weakdef->non_got_ref;
+ {
+ eh = (struct elf_x86_64_link_hash_entry *) h;
+ h->non_got_ref = h->u.weakdef->non_got_ref;
+ eh->needs_copy = h->u.weakdef->needs_copy;
+ }
return TRUE;
}
@@ -2668,7 +2680,7 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
/* For PIE, discard space for relocs against symbols which
turn out to need copy relocs. */
else if (info->executable
- && h->needs_copy
+ && (h->needs_copy || eh->needs_copy)
&& h->def_dynamic
&& !h->def_regular)
eh->dyn_relocs = NULL;
@@ -3985,7 +3997,8 @@ elf_x86_64_relocate_section (bfd *output_bfd,
defined locally or for a branch. */
fail = !h->def_regular && !branch;
}
- else if (!(info->executable && h->needs_copy))
+ else if (!(info->executable
+ && (h->needs_copy || eh->needs_copy)))
{
/* Symbol doesn't need copy reloc and isn't referenced
locally. We only allow branch to symbol with
@@ -4048,7 +4061,7 @@ direct:
if ((info->shared
&& !(info->executable
&& h != NULL
- && h->needs_copy
+ && (h->needs_copy || eh->needs_copy)
&& IS_X86_64_PCREL_TYPE (r_type))
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT