From 3cac04d8e3b8c61b6067a85ac50cc7e661d34a06 Mon Sep 17 00:00:00 2001 From: dim Date: Sat, 12 Oct 2013 16:11:57 +0000 Subject: [PATCH] MFC r255931: Fix a bug in ld, where indirect symbols are not handled properly during linking of a shared library, leading to corrupt indexes in the dynamic symbol table. This should fix the multimedia/ffmpegthumbnailer port. Reported by: swills git-svn-id: svn://svn.freebsd.org/base/stable/8@256384 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- contrib/binutils/bfd/elflink.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/contrib/binutils/bfd/elflink.c b/contrib/binutils/bfd/elflink.c index 2b43bc190..3cbf661f2 100644 --- a/contrib/binutils/bfd/elflink.c +++ b/contrib/binutils/bfd/elflink.c @@ -438,9 +438,25 @@ bfd_elf_record_link_assignment (bfd *output_bfd ATTRIBUTE_UNUSED, if (h->root.type == bfd_link_hash_undefweak || h->root.type == bfd_link_hash_undefined) h->root.type = bfd_link_hash_new; - - if (h->root.type == bfd_link_hash_new) + else if (h->root.type == bfd_link_hash_new) h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; + else if (h->root.type == bfd_link_hash_indirect) + { + const struct elf_backend_data *bed = get_elf_backend_data (output_bfd); + struct elf_link_hash_entry *hv = h; + do + hv = (struct elf_link_hash_entry *) hv->root.u.i.link; + while (hv->root.type == bfd_link_hash_indirect + || hv->root.type == bfd_link_hash_warning); + h->root.type = bfd_link_hash_undefined; + hv->root.type = bfd_link_hash_indirect; + hv->root.u.i.link = (struct bfd_link_hash_entry *) h; + (*bed->elf_backend_copy_indirect_symbol) (info, h, hv); + } + else if (h->root.type == bfd_link_hash_warning) + { + abort (); + } /* If this symbol is being provided by the linker script, and it is currently defined by a dynamic object, but not by a regular @@ -1142,10 +1158,10 @@ _bfd_elf_merge_symbol (bfd *abfd, case, we make the versioned symbol point to the normal one. */ const struct elf_backend_data *bed = get_elf_backend_data (abfd); flip->root.type = h->root.type; + flip->root.u.undef.abfd = h->root.u.undef.abfd; h->root.type = bfd_link_hash_indirect; h->root.u.i.link = (struct bfd_link_hash_entry *) flip; (*bed->elf_backend_copy_indirect_symbol) (bed, flip, h); - flip->root.u.undef.abfd = h->root.u.undef.abfd; if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) { h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC; -- 2.45.0