From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1039) id 0C8ED3858D20; Wed, 17 Apr 2024 00:51:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C8ED3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713315075; bh=A1iGdNlwH7DG8Rwxmc4hAIefFWkJaW4zLrMotSFVSbk=; h=From:To:Subject:Date:From; b=pWInDGm/z1UQ1Pf+Q9C2B2Jr2OQoBRIDnujurYc1d8bRS6rtqC5hH/sZPzdBKfDnj s2xdfeE0rSc41WZUwSg9xO86cW19aO0lER8cEZxbPchPBW4DBZ95FGlNs5BNIQ7RA1 C66Fa2Cd6dLE4Eou6nA18dUV1FKJW+34YHN5nplg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: H.J. Lu To: binutils-cvs@sourceware.org Subject: [binutils-gdb] elf: Skip the archive if the symbol isn't referenced X-Act-Checkin: binutils-gdb X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/master X-Git-Oldrev: 79484e95665430b6960425e5c50ffb9f90072bf4 X-Git-Newrev: c2fbf57864a2da2ceda81706a54d125ef3fce0a7 Message-Id: <20240417005115.0C8ED3858D20@sourceware.org> Date: Wed, 17 Apr 2024 00:51:15 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc2fbf57864a2= da2ceda81706a54d125ef3fce0a7 commit c2fbf57864a2da2ceda81706a54d125ef3fce0a7 Author: H.J. Lu Date: Tue Apr 16 15:48:21 2024 -0700 elf: Skip the archive if the symbol isn't referenced =20 Also skip the archive if the symbol isn't referenced by a regular objec= t. =20 bfd/ =20 PR ld/31644 * elflink.c (elf_link_add_archive_symbols): Also skip the archi= ve if the symbol isn't referenced by a regular object. =20 ld/ =20 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. Diff: --- bfd/elflink.c | 8 +++++--- ld/testsuite/ld-plugin/lto.exp | 24 ++++++++++++++++++++++++ ld/testsuite/ld-plugin/pr31644a.c | 13 +++++++++++++ ld/testsuite/ld-plugin/pr31644b.c | 7 +++++++ ld/testsuite/ld-plugin/pr31644c.c | 5 +++++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index 321e3d5e2ff..9c53bfcf7d4 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -6261,9 +6261,11 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_= link_info *info) =20 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 + =3D (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. */ diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index 35ce38731d0..7b4b3492a2f 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -579,6 +579,22 @@ set lto_link_elf_tests [list \ "" \ "pr31615d.so" \ ] \ + [list \ + "Build pr31644b.a" \ + "" \ + "" \ + {pr31644b.c} \ + "" \ + "pr31644b.a" \ + ] \ + [list \ + "Build pr31644c.so" \ + "-shared" \ + "-fPIC" \ + {pr31644c.c} \ + "" \ + "pr31644c.so" \ + ] \ ] =20 # PR 14918 checks that libgcc is not spuriously included in a shared link = of @@ -788,6 +804,14 @@ set lto_run_elf_shared_tests [list \ {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}] \ ] =20 # LTO run-time tests for ELF diff --git a/ld/testsuite/ld-plugin/pr31644a.c b/ld/testsuite/ld-plugin/pr3= 1644a.c new file mode 100644 index 00000000000..1c03a955c37 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31644a.c @@ -0,0 +1,13 @@ +#include + +void +bar (void) +{ +} + +int +main() +{ + printf ("PASS\n"); + return 0; +} diff --git a/ld/testsuite/ld-plugin/pr31644b.c b/ld/testsuite/ld-plugin/pr3= 1644b.c new file mode 100644 index 00000000000..8b23ec8f2b7 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31644b.c @@ -0,0 +1,7 @@ +extern void bar (void); + +void +foo (void) +{ + bar (); +} diff --git a/ld/testsuite/ld-plugin/pr31644c.c b/ld/testsuite/ld-plugin/pr3= 1644c.c new file mode 100644 index 00000000000..3d54205ea4d --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31644c.c @@ -0,0 +1,5 @@ +__attribute__ ((weak)) +void +foo (void) +{ +}