diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2011-05-25 17:41:32 +0000 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2011-05-25 17:41:32 +0000 |
commit | 946593d19f203b02efd45b5102dd2787d9418e24 (patch) | |
tree | 5988de1a80f005860c0712a8679edb872e9063de /bfd | |
parent | f6cc7b1a4ec26e3f629949c4834945d6bcbc7267 (diff) | |
download | binutils-redhat-946593d19f203b02efd45b5102dd2787d9418e24.tar.gz |
Handle STT_GNU_IFUNC symols when building shared library.
bfd/
2012-05-25 H.J. Lu <hongjiu.lu@intel.com>
Backport from mainline
2012-01-06 H.J. Lu <hongjiu.lu@intel.com>
PR ld/12366
PR ld/12371
* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Properly
handle symbols marked with regular reference, but not non-GOT
reference when building shared library.
* elf32-i386.c (elf_i386_gc_sweep_hook): Properly handle
local and global STT_GNU_IFUNC symols when building shared
library.
* elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise.
ld/testsuite/
2012-05-25 H.J. Lu <hongjiu.lu@intel.com>
Backport from mainline
2012-01-06 H.J. Lu <hongjiu.lu@intel.com>
PR ld/12366
PR ld/12371
* ld-ifunc/ifunc-10-i386.s: Add more tests.
* ld-ifunc/ifunc-10-x86-64.s: Likewise.
* ld-ifunc/ifunc-11-i386.s: Likewise.
* ld-ifunc/ifunc-11-x86-64.s: Likewise.
* ld-ifunc/ifunc-12-i386.d: New.
* ld-ifunc/ifunc-12-i386.s: Likewise.
* ld-ifunc/ifunc-12-x86-64.d: Likewise.
* ld-ifunc/ifunc-12-x86-64.s: Likewise.
* ld-ifunc/ifunc-13-i386.d: Likewise.
* ld-ifunc/ifunc-13-x86-64.d: Likewise.
* ld-ifunc/ifunc-13a-i386.s: Likewise.
* ld-ifunc/ifunc-13a-x86-64.s: Likewise.
* ld-ifunc/ifunc-13b-i386.s: Likewise.
* ld-ifunc/ifunc-13b-x86-64.s: Likewise.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 16 | ||||
-rw-r--r-- | bfd/elf-ifunc.c | 27 | ||||
-rw-r--r-- | bfd/elf32-i386.c | 32 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 35 |
4 files changed, 77 insertions, 33 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 64bdff6c93..bcc02f3bf1 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,19 @@ +2012-05-25 H.J. Lu <hongjiu.lu@intel.com> + + Backport from mainline + 2012-01-06 H.J. Lu <hongjiu.lu@intel.com> + + PR ld/12366 + PR ld/12371 + * elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Properly + handle symbols marked with regular reference, but not non-GOT + reference when building shared library. + + * elf32-i386.c (elf_i386_gc_sweep_hook): Properly handle + local and global STT_GNU_IFUNC symols when building shared + library. + * elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise. + 2011-05-23 DJ Delorie <dj@redhat.com> * elf32-rx.c (rx_elf_object_p): When reading an RX object in, undo diff --git a/bfd/elf-ifunc.c b/bfd/elf-ifunc.c index 760fc26c1a..17b23c2ffc 100644 --- a/bfd/elf-ifunc.c +++ b/bfd/elf-ifunc.c @@ -190,10 +190,29 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info, /* Support garbage collection against STT_GNU_IFUNC symbols. */ if (h->plt.refcount <= 0 && h->got.refcount <= 0) { - h->got = htab->init_got_offset; - h->plt = htab->init_plt_offset; - *head = NULL; - return TRUE; + /* When building shared library, we need to handle the case + where it is marked with regular reference, but not non-GOT + reference. It may happen if we didn't see STT_GNU_IFUNC + symbol at the time when checking relocations. */ + bfd_size_type count = 0; + + if (info->shared + && !h->non_got_ref + && h->ref_regular) + { + for (p = *head; p != NULL; p = p->next) + count += p->count; + if (count != 0) + h->non_got_ref = 1; + } + + if (count == 0) + { + h->got = htab->init_got_offset; + h->plt = htab->init_plt_offset; + *head = NULL; + return TRUE; + } } /* Return and discard space for dynamic relocations against it if diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 1071f015d0..bd349e1083 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1807,23 +1807,10 @@ elf_i386_gc_sweep_hook (bfd *abfd, r_symndx = ELF32_R_SYM (rel->r_info); if (r_symndx >= symtab_hdr->sh_info) { - struct elf_i386_link_hash_entry *eh; - struct elf_dyn_relocs **pp; - struct elf_dyn_relocs *p; - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; - eh = (struct elf_i386_link_hash_entry *) h; - - for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) - if (p->sec == sec) - { - /* Everything must go for SEC. */ - *pp = p->next; - break; - } } else { @@ -1843,6 +1830,22 @@ elf_i386_gc_sweep_hook (bfd *abfd, } } + if (h) + { + struct elf_i386_link_hash_entry *eh; + struct elf_dyn_relocs **pp; + struct elf_dyn_relocs *p; + + eh = (struct elf_i386_link_hash_entry *) h; + for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) + if (p->sec == sec) + { + /* Everything must go for SEC. */ + *pp = p->next; + break; + } + } + r_type = ELF32_R_TYPE (rel->r_info); if (! elf_i386_tls_transition (info, abfd, sec, NULL, symtab_hdr, sym_hashes, @@ -1883,7 +1886,8 @@ elf_i386_gc_sweep_hook (bfd *abfd, case R_386_32: case R_386_PC32: - if (info->shared) + if (info->shared + && (h == NULL || h->type != STT_GNU_IFUNC)) break; /* Fall through */ diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 09af249dfe..04c74550be 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -1645,23 +1645,10 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, r_symndx = ELF64_R_SYM (rel->r_info); if (r_symndx >= symtab_hdr->sh_info) { - struct elf64_x86_64_link_hash_entry *eh; - struct elf_dyn_relocs **pp; - struct elf_dyn_relocs *p; - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; - eh = (struct elf64_x86_64_link_hash_entry *) h; - - for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) - if (p->sec == sec) - { - /* Everything must go for SEC. */ - *pp = p->next; - break; - } } else { @@ -1682,7 +1669,24 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, } } - r_type = ELF64_R_TYPE (rel->r_info); + if (h) + { + struct elf64_x86_64_link_hash_entry *eh; + struct elf_dyn_relocs **pp; + struct elf_dyn_relocs *p; + + eh = (struct elf64_x86_64_link_hash_entry *) h; + + for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) + if (p->sec == sec) + { + /* Everything must go for SEC. */ + *pp = p->next; + break; + } + } + + r_type = ELF32_R_TYPE (rel->r_info); if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL, symtab_hdr, sym_hashes, &r_type, GOT_UNKNOWN, @@ -1733,7 +1737,8 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, case R_X86_64_PC16: case R_X86_64_PC32: case R_X86_64_PC64: - if (info->shared) + if (info->shared + && (h == NULL || h->type != STT_GNU_IFUNC)) break; /* Fall thru */ |