sparc64 segfault in finish_dynamic_symbol
authorAlan Modra <amodra@gmail.com>
Tue, 31 May 2022 11:29:04 +0000 (20:59 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 31 May 2022 11:44:00 +0000 (21:14 +0930)
SYMBOL_REFERENCES_LOCAL can return true for undefined symbols.  This
can result in a segfault when running sparc64 ld/testsuite/ld-vsb
tests that expect a failure.

* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Don't
access u.def.section on non-default visibility undefined symbol.

bfd/elfxx-sparc.c

index 618b88589c71f3e5a8c90abb00f09996d7830d66..514db1e4c7638a34a96069932db3038d9c8d5305 100644 (file)
@@ -4416,7 +4416,10 @@ _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
          return true;
        }
 
-      if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
+      if (bfd_link_pic (info)
+         && (h->root.type == bfd_link_hash_defined
+             || h->root.type == bfd_link_hash_defweak)
+         && SYMBOL_REFERENCES_LOCAL (info, h))
        {
          asection *sec = h->root.u.def.section;
          if (h->type == STT_GNU_IFUNC)