powerpc64 get_opd_entry segfault
Alan Modra
amodra@gmail.com
Mon May 6 09:07:00 GMT 2013
People do silly things sometime with ld, and then expect it to not
segfault! This one was found when running ld -r on duplicated object
files. When adding function symbols for the duplicate, ld tried to
emit a multiply defined symbol error message, but on powerpc64 that
involves a call to opd_entry_value. opd_entry_value looks at .opd
relocations and uses the symbol hashes, but the symbol hashes are in
the process of being filled out. My previous elflink.c change zeroed
the hashes on allocation, so we don't see uninitialized hashes here.
* elf64-ppc.c (opd_entry_value): Handle case where symbol
hashes are not available.
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.410
diff -u -p -r1.410 elf64-ppc.c
--- bfd/elf64-ppc.c 22 Apr 2013 03:11:39 -0000 1.410
+++ bfd/elf64-ppc.c 6 May 2013 06:14:38 -0000
@@ -5665,11 +5665,30 @@ opd_entry_value (asection *opd_sec,
sym_hashes = elf_sym_hashes (opd_bfd);
rh = sym_hashes[symndx - symtab_hdr->sh_info];
- rh = elf_follow_link (rh);
- BFD_ASSERT (rh->root.type == bfd_link_hash_defined
- || rh->root.type == bfd_link_hash_defweak);
- val = rh->root.u.def.value;
- sec = rh->root.u.def.section;
+ if (rh != NULL)
+ {
+ rh = elf_follow_link (rh);
+ BFD_ASSERT (rh->root.type == bfd_link_hash_defined
+ || rh->root.type == bfd_link_hash_defweak);
+ val = rh->root.u.def.value;
+ sec = rh->root.u.def.section;
+ }
+ else
+ {
+ /* Handle the odd case where we can be called
+ during bfd_elf_link_add_symbols before the
+ symbol hashes have been fully populated. */
+ Elf_Internal_Sym *sym;
+
+ sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, 1,
+ symndx, NULL, NULL, NULL);
+ if (sym == NULL)
+ break;
+
+ val = sym->st_value;
+ sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
+ free (sym);
+ }
}
val += look->r_addend;
if (code_off != NULL)
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list