aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2025-04-08 13:10:02 -0700
committerH.J. Lu <hjl.tools@gmail.com>2025-04-10 10:29:28 -0700
commit2cec91421e603699aa8f446d1ae44e873c4965f8 (patch)
treebab348266539700afd331557eba326c44fa050e1
parentfd152d90be8d8d901f601ca99e253d39bf220011 (diff)
downloadbinutils-2cec91421e603699aa8f446d1ae44e873c4965f8.zip
binutils-2cec91421e603699aa8f446d1ae44e873c4965f8.tar.gz
binutils-2cec91421e603699aa8f446d1ae44e873c4965f8.tar.bz2
ld: Skip the LTO archive member only for the earlier DSO
commit 2707d55e539ef323dd14a1293e762bf3d9739ee7 Author: Michael Matz <matz@suse.de> Date: Mon Mar 31 15:57:08 2025 +0200 skipped the LTO archive member even when the earlier item is also an archive. Instead, skip the LTO archive member only if the earlier item is a shared library. bfd/ PR ld/32846 PR ld/32854 * elflink.c (elf_link_add_archive_symbols): Skip the LTO archive member only if the earlier item is a shared library. ld/ PR ld/32846 PR ld/32854 * testsuite/ld-plugin/lto.exp: Run ld/32846 test. * testsuite/ld-plugin/pr32846a.c: New file. * testsuite/ld-plugin/pr32846b.c: Likewise. * testsuite/ld-plugin/pr32846c.c: Likewise. * testsuite/ld-plugin/pr32846d.c: Likewise. * testsuite/ld-plugin/pr32846e.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
-rw-r--r--bfd/elflink.c8
-rw-r--r--ld/testsuite/ld-plugin/lto.exp32
-rw-r--r--ld/testsuite/ld-plugin/pr32846a.c6
-rw-r--r--ld/testsuite/ld-plugin/pr32846b.c4
-rw-r--r--ld/testsuite/ld-plugin/pr32846c.c6
-rw-r--r--ld/testsuite/ld-plugin/pr32846d.c12
-rw-r--r--ld/testsuite/ld-plugin/pr32846e.c4
7 files changed, 69 insertions, 3 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 549b7b7..919f2a7 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6290,8 +6290,8 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
continue;
/* In the pre-LTO-plugin pass we must not mistakenly
- include this archive member if an earlier BFD
- defined this symbol. */
+ include this archive member if an earlier shared
+ library defined this symbol. */
struct elf_link_hash_table *htab = elf_hash_table (info);
if (htab->first_hash)
{
@@ -6299,7 +6299,9 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
= ((struct elf_link_first_hash_entry *)
bfd_hash_lookup (htab->first_hash, symdef->name,
false, false));
- if (e && e->abfd != abfd)
+ if (e
+ && (e->abfd->flags & DYNAMIC) != 0
+ && e->abfd != abfd)
continue;
}
}
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 9349190..726dd93 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -1212,6 +1212,38 @@ if { [is_elf_format] } {
if { [is_elf_format] && [check_lto_shared_available] } {
run_ld_link_exec_tests $lto_run_elf_shared_tests
+ if { [check_lto_fat_available] } {
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr32846a.a" \
+ "$plug_opt" "-O2 -flto $lto_no_fat" \
+ {pr32846a.c pr32846b.c} {} "libpr32846a.a" \
+ ] \
+ [list \
+ "Build libpr32846b.a" \
+ "$plug_opt" "-O2 -flto $lto_no_fat" \
+ {pr32846a.c pr32846b.c pr32846c.c} {} "libpr32846b.a" \
+ ] \
+ [list \
+ "Build pr32846d.o" \
+ "$plug_opt" "-O2 -flto $lto_no_fat" \
+ {pr32846d.c} {} \
+ ] \
+ [list \
+ "Build pr32846e.o" \
+ "$plug_opt" "-O2 -flto $lto_no_fat" \
+ {pr32846e.c} {} \
+ ] \
+ [list \
+ "Build pr32846" \
+ "-shared -fPIC -O2 -flto $lto_no_fat -Wl,--no-undefined \
+ tmpdir/pr32846d.o tmpdir/libpr32846a.a \
+ tmpdir/libpr32846b.a tmpdir/pr32846e.o" \
+ "-O2 -fPIC -flto $lto_no_fat" \
+ {dummy.c} {} "pr32846" \
+ ] \
+ ] \
+ }
}
proc pr20103 {cflags libs} {
diff --git a/ld/testsuite/ld-plugin/pr32846a.c b/ld/testsuite/ld-plugin/pr32846a.c
new file mode 100644
index 0000000..8c16171
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846a.c
@@ -0,0 +1,6 @@
+extern void mkdir_p (void);
+void
+mkdir_parents (void)
+{
+ mkdir_p ();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846b.c b/ld/testsuite/ld-plugin/pr32846b.c
new file mode 100644
index 0000000..9776a37
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846b.c
@@ -0,0 +1,4 @@
+void
+hash_new (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr32846c.c b/ld/testsuite/ld-plugin/pr32846c.c
new file mode 100644
index 0000000..f87cffb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846c.c
@@ -0,0 +1,6 @@
+extern void hash_new (void);
+void
+kmod_new (void)
+{
+ hash_new();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846d.c b/ld/testsuite/ld-plugin/pr32846d.c
new file mode 100644
index 0000000..c6f4102
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846d.c
@@ -0,0 +1,12 @@
+extern void kmod_new (void);
+extern void mkdir_parents (void);
+void
+do_lsmod (void)
+{
+ kmod_new ();
+}
+void
+do_static_nodes (void)
+{
+ mkdir_parents();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846e.c b/ld/testsuite/ld-plugin/pr32846e.c
new file mode 100644
index 0000000..c4e5e56
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846e.c
@@ -0,0 +1,4 @@
+void
+mkdir_p (void)
+{
+}