2004-01-28 H.J. Lu * elflink.c (_bfd_elf_merge_symbol): Properly handle undefined symbols with non-default visibility. --- bfd/elflink.c.vsb 2003-12-04 10:43:10.000000000 -0800 +++ bfd/elflink.c 2004-01-28 12:24:26.000000000 -0800 @@ -843,8 +843,43 @@ _bfd_elf_merge_symbol (bfd *abfd, object, we remove the old definition. */ if ((*sym_hash)->root.type == bfd_link_hash_indirect) h = *sym_hash; - h->root.type = bfd_link_hash_new; - h->root.u.undef.abfd = NULL; + + if ((h->root.und_next || info->hash->undefs_tail == &h->root) + && bfd_is_und_section (sec)) + { + /* If the new symbol is undefined and the old symbol was + also undefined before, we need to handle it ourselves and + make sure _bfd_generic_link_add_one_symbol doesn't mess + up the linker hash table undefs list. */ + + if (h->root.und_next) + { + /* First make sure it is on the linker hash table undefs + list. */ + struct bfd_link_hash_entry *undef; + + for (undef = info->hash->undefs; + undef != NULL && undef != &h->root; + undef = undef->und_next); + + if (undef != NULL) + { + /* Add it to the undefs list if needed. */ + h->root.und_next = NULL; + bfd_link_add_undef (info->hash, &h->root); + } + } + + h->root.type = bfd_link_hash_undefined; + /* FIXME: What if the new symbol is weak undefined? */ + h->root.u.undef.abfd = abfd; + } + else + { + h->root.type = bfd_link_hash_new; + h->root.u.undef.abfd = NULL; + } + if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) { h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC;