Also skip the archive if the symbol isn't referenced by a regular object.
bfd/
PR ld/31644
* elflink.c (elf_link_add_archive_symbols): Also skip the archive
if the symbol isn't referenced by a regular object.
ld/
PR ld/31644
* testsuite/ld-plugin/lto.exp: Run PR ld/31644 tests.
* testsuite/ld-plugin/pr31644a.c: New test.
* testsuite/ld-plugin/pr31644b.c: Likewise.
* testsuite/ld-plugin/pr31644c.c: Likewise.
if (!is_elf_hash_table (info->hash))
continue;
- /* Ignore the archive if the symbol isn't defined in a
- shared object. */
- if (!((struct elf_link_hash_entry *) h)->def_dynamic)
+ struct elf_link_hash_entry *eh
+ = (struct elf_link_hash_entry *) h;
+ /* Ignore the archive if the symbol isn't referenced by a
+ regular object or isn't defined in a shared object. */
+ if (!eh->ref_regular || !eh->def_dynamic)
continue;
/* Ignore the dynamic definition if symbol is first
defined in this archive. */
"" \
"pr31615d.so" \
] \
+ [list \
+ "Build pr31644b.a" \
+ "" \
+ "" \
+ {pr31644b.c} \
+ "" \
+ "pr31644b.a" \
+ ] \
+ [list \
+ "Build pr31644c.so" \
+ "-shared" \
+ "-fPIC" \
+ {pr31644c.c} \
+ "" \
+ "pr31644c.so" \
+ ] \
]
# PR 14918 checks that libgcc is not spuriously included in a shared link of
{pr31615a.c} {pr31615b.exe} {pass.out} {-O3 -flto} {c} {} \
{-Wl,--as-needed tmpdir/pr31615c.so -Wl,--no-as-needed \
tmpdir/pr31615d.so}] \
+ [list {pr31644a} \
+ {-Wl,-R,tmpdir} {} \
+ {pr31644a.c} {pr31644a.exe} {pass.out} {-flto} {c} {} \
+ {-Wl,--no-as-needed tmpdir/pr31644b.a tmpdir/pr31644c.so}] \
+ [list {pr31644b} \
+ {-Wl,-R,tmpdir} {} \
+ {pr31644a.c} {pr31644b.exe} {pass.out} {-flto} {c} {} \
+ {-Wl,--as-needed tmpdir/pr31644b.a tmpdir/pr31644c.so}] \
]
# LTO run-time tests for ELF
--- /dev/null
+#include <stdio.h>
+
+void
+bar (void)
+{
+}
+
+int
+main()
+{
+ printf ("PASS\n");
+ return 0;
+}
--- /dev/null
+extern void bar (void);
+
+void
+foo (void)
+{
+ bar ();
+}
--- /dev/null
+__attribute__ ((weak))
+void
+foo (void)
+{
+}