commit: d73d6d120ffc9ed75faca235ab07f831190075bd Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Wed Apr 9 02:24:02 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed Apr 9 02:24:02 2025 +0000 URL: https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d73d6d12
9999: add H.J.'s fix for earlier revert Signed-off-by: Sam James <sam <AT> gentoo.org> ...t-lto-Fix-symlookup-in-archives-vs-shared.patch | 168 ------------------- ...-LTO-archive-member-only-for-the-earlier-.patch | 186 +++++++++++++++++++++ 2 files changed, 186 insertions(+), 168 deletions(-) diff --git a/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch b/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch deleted file mode 100644 index d8386fc..0000000 --- a/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch +++ /dev/null @@ -1,168 +0,0 @@ -From ba77d9675b2af359875bc5ef785616c18285060b Mon Sep 17 00:00:00 2001 -Message-ID: <ba77d9675b2af359875bc5ef785616c18285060b.1744072567.git....@gentoo.org> -From: Sam James <[email protected]> -Date: Tue, 8 Apr 2025 01:35:58 +0100 -Subject: [PATCH] Revert "[lto] Fix symlookup in archives vs shared" - -This reverts commit 2707d55e539ef323dd14a1293e762bf3d9739ee7. - -Bug: https://sourceware.org/PR32846 ---- - bfd/elflink.c | 44 +++++++------------------------ - ld/testsuite/ld-plugin/lto-20.ver | 1 - - ld/testsuite/ld-plugin/lto-20a.c | 2 -- - ld/testsuite/ld-plugin/lto-20b.c | 11 -------- - ld/testsuite/ld-plugin/lto.exp | 10 ------- - 5 files changed, 10 insertions(+), 58 deletions(-) - delete mode 100644 ld/testsuite/ld-plugin/lto-20.ver - delete mode 100644 ld/testsuite/ld-plugin/lto-20a.c - delete mode 100644 ld/testsuite/ld-plugin/lto-20b.c - -diff --git a/bfd/elflink.c b/bfd/elflink.c -index a76e8e38da7..13993527e3e 100644 ---- a/bfd/elflink.c -+++ b/bfd/elflink.c -@@ -4965,7 +4965,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) - asection *sec, *new_sec; - flagword flags; - const char *name; -- const char *defvername; - bool must_copy_name = false; - struct elf_link_hash_entry *h; - struct elf_link_hash_entry *hi; -@@ -5142,7 +5141,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) - old_alignment = 0; - old_bfd = NULL; - new_sec = sec; -- defvername = NULL; - - if (is_elf_hash_table (&htab->root)) - { -@@ -5261,7 +5259,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) - default version of the symbol. */ - if ((iver.vs_vers & VERSYM_HIDDEN) == 0 - && isym->st_shndx != SHN_UNDEF) -- *p++ = ELF_VER_CHR, defvername = name; -+ *p++ = ELF_VER_CHR; - memcpy (p, verstr, verlen + 1); - - name = newname; -@@ -5711,15 +5709,9 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) - } - else if (dynamic - && h->root.u.def.section->owner == abfd) -- { -- /* Add this symbol to first hash if this shared -- object has the first definition. */ -- elf_link_add_to_first_hash (abfd, info, name, must_copy_name); -- /* And if it was the default symbol version definition, -- also add the short name. */ -- if (defvername) -- elf_link_add_to_first_hash (abfd, info, defvername, false); -- } -+ /* Add this symbol to first hash if this shared -+ object has the first definition. */ -+ elf_link_add_to_first_hash (abfd, info, name, must_copy_name); - } - } - } -@@ -6281,28 +6273,12 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info) - - if (h->type == bfd_link_hash_undefined) - { -- if (is_elf_hash_table (info->hash)) -- { -- /* If the archive element has already been loaded then one -- of the symbols defined by that element might have been -- made undefined due to being in a discarded section. */ -- if (((struct elf_link_hash_entry *) h)->indx == -3) -- continue; -- -- /* In the pre-LTO-plugin pass we must not mistakenly -- include this archive member if an earlier BFD -- defined this symbol. */ -- struct elf_link_hash_table *htab = elf_hash_table (info); -- if (htab->first_hash) -- { -- struct elf_link_first_hash_entry *e -- = ((struct elf_link_first_hash_entry *) -- bfd_hash_lookup (htab->first_hash, symdef->name, -- false, false)); -- if (e && e->abfd != abfd) -- continue; -- } -- } -+ /* If the archive element has already been loaded then one -+ of the symbols defined by that element might have been -+ made undefined due to being in a discarded section. */ -+ if (is_elf_hash_table (info->hash) -+ && ((struct elf_link_hash_entry *) h)->indx == -3) -+ continue; - } - else if (h->type == bfd_link_hash_common) - { -diff --git a/ld/testsuite/ld-plugin/lto-20.ver b/ld/testsuite/ld-plugin/lto-20.ver -deleted file mode 100644 -index ac906ac4ad1..00000000000 ---- a/ld/testsuite/ld-plugin/lto-20.ver -+++ /dev/null -@@ -1 +0,0 @@ --FOO { global: foo; }; -diff --git a/ld/testsuite/ld-plugin/lto-20a.c b/ld/testsuite/ld-plugin/lto-20a.c -deleted file mode 100644 -index 3d6dac96752..00000000000 ---- a/ld/testsuite/ld-plugin/lto-20a.c -+++ /dev/null -@@ -1,2 +0,0 @@ --extern int foo (); --int main () { return foo (); } -diff --git a/ld/testsuite/ld-plugin/lto-20b.c b/ld/testsuite/ld-plugin/lto-20b.c -deleted file mode 100644 -index ba123cbe38b..00000000000 ---- a/ld/testsuite/ld-plugin/lto-20b.c -+++ /dev/null -@@ -1,11 +0,0 @@ --extern int printf (const char *, ...); --int foo () --{ --#ifdef SHARED -- printf ("PASS\n"); -- return 0; --#else -- printf ("FAIL\n"); -- return 1; --#endif --} -diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp -index 93491902674..556bbe9beea 100644 ---- a/ld/testsuite/ld-plugin/lto.exp -+++ b/ld/testsuite/ld-plugin/lto.exp -@@ -477,12 +477,6 @@ set lto_link_elf_tests [list \ - [list {liblto-19.so} \ - {-shared tmpdir/lto-19b.o tmpdir/liblto-19.a} {-O2 -fPIC} \ - {dummy.c} {} {liblto-19.so}] \ -- [list {liblto-20_static.a} \ -- {} {-fPIC} \ -- {lto-20b.c} {} {liblto-20_static.a}] \ -- [list {liblto-20.so} \ -- {-shared -Wl,--version-script=lto-20.ver} {-DSHARED -fPIC} \ -- {lto-20b.c} {} {liblto-20.so}] \ - [list {pr26806.so} \ - {-shared} {-fpic -O2 -flto} \ - {pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \ -@@ -886,10 +880,6 @@ set lto_run_elf_shared_tests [list \ - {-Wl,--as-needed,-R,tmpdir} {} \ - {lto-19c.c} {lto-19.exe} {pass.out} {-flto -O2} {c} {} \ - {tmpdir/liblto-19.so tmpdir/liblto-19.a}] \ -- [list {lto-20} \ -- {-Wl,--as-needed,-R,tmpdir} {} \ -- {lto-20a.c} {lto-20.exe} {pass.out} {-flto} {c} {} \ -- {tmpdir/liblto-20.so tmpdir/liblto-20_static.a -Wl,--no-as-needed}] \ - [list {pr31482a} \ - {-Wl,--no-as-needed,-R,tmpdir} {} \ - {pr31482a.c} {pr31482a.exe} {pass.out} {-flto} {c} {} \ - -base-commit: 2707d55e539ef323dd14a1293e762bf3d9739ee7 --- -2.49.0 - diff --git a/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch b/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch new file mode 100644 index 0000000..1eb52fc --- /dev/null +++ b/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch @@ -0,0 +1,186 @@ +https://inbox.sourceware.org/binutils/[email protected]/ + +From b6ccbf6faecf5e2d43d776fab90f0a5d673a2817 Mon Sep 17 00:00:00 2001 +Message-ID: <b6ccbf6faecf5e2d43d776fab90f0a5d673a2817.1744165403.git....@gentoo.org> +From: "H.J. Lu" <[email protected]> +Date: Tue, 8 Apr 2025 13:10:02 -0700 +Subject: [PATCH] ld: Skip the LTO archive member only for the earlier DSO + +commit 2707d55e539ef323dd14a1293e762bf3d9739ee7 +Author: Michael Matz <[email protected]> +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 <[email protected]> +--- + bfd/elflink.c | 8 +++++--- + ld/testsuite/ld-plugin/lto.exp | 32 +++++++++++++++++++++++++++++++ + ld/testsuite/ld-plugin/pr32846a.c | 6 ++++++ + ld/testsuite/ld-plugin/pr32846b.c | 4 ++++ + ld/testsuite/ld-plugin/pr32846c.c | 6 ++++++ + ld/testsuite/ld-plugin/pr32846d.c | 12 ++++++++++++ + ld/testsuite/ld-plugin/pr32846e.c | 4 ++++ + 7 files changed, 69 insertions(+), 3 deletions(-) + create mode 100644 ld/testsuite/ld-plugin/pr32846a.c + create mode 100644 ld/testsuite/ld-plugin/pr32846b.c + create mode 100644 ld/testsuite/ld-plugin/pr32846c.c + create mode 100644 ld/testsuite/ld-plugin/pr32846d.c + create mode 100644 ld/testsuite/ld-plugin/pr32846e.c + +diff --git a/bfd/elflink.c b/bfd/elflink.c +index a76e8e38da7..2ac12144990 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 93491902674..726dd933329 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 00000000000..8c161711bd9 +--- /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 00000000000..9776a372d7a +--- /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 00000000000..f87cffb8865 +--- /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 00000000000..c6f41021adf +--- /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 00000000000..c4e5e56f4f6 +--- /dev/null ++++ b/ld/testsuite/ld-plugin/pr32846e.c +@@ -0,0 +1,4 @@ ++void ++mkdir_p (void) ++{ ++} + +base-commit: faaee6b411411f3c1f45768d7ac15559fd27b980 +-- +2.49.0 +
