Allow plugin syms to mark as-needed shared libs needed
authorAlan Modra <amodra@gmail.com>
Fri, 4 Sep 2020 04:24:21 +0000 (13:54 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 4 Sep 2020 04:36:44 +0000 (14:06 +0930)
We must tell LTO about symbols in all shared libraries loaded.  That
means we can't load extra shared libraries after LTO recompilation, at
least, not those that affect the set of symbols that LTO cares about,
the IR symbols.

This change will likely result in complaints about --as-needed
libraries being loaded unnecessarily, but being correct is more
important than being optimal.  One of the PR15146 tests regresses, and
while that could be hidden by disabling the missing dso message by
making it conditional on h->root.non_ir_ref_regular, that would just
be sweeping a problem under the rug.

bfd/
PR 15146
PR 26314
PR 26530
* elflink.c (elf_link_add_object_symbols): Do set def_regular
and ref_regular for IR symbols.  Don't clear dynsym, allowing
IR symbols to load --as-needed shared libraries, but prevent
IR symbols from becoming dynamic.
ld/
* testsuite/ld-plugin/lto.exp: Don't run pr15146 tests.
* testsuite/ld-plugin/pr15146.d: Delete.
* testsuite/ld-plugin/pr15146a.c: Delete.
* testsuite/ld-plugin/pr15146b.c: Delete.
* testsuite/ld-plugin/pr15146c.c: Delete.
* testsuite/ld-plugin/pr15146d.c: Delete.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr15146.d [deleted file]
ld/testsuite/ld-plugin/pr15146a.c [deleted file]
ld/testsuite/ld-plugin/pr15146b.c [deleted file]
ld/testsuite/ld-plugin/pr15146c.c [deleted file]
ld/testsuite/ld-plugin/pr15146d.c [deleted file]

index 1b58f9517ce5d856cc8455bc6db746530ba6d93a..a431f8f14dbef0492ee18f5e07b6415d3dc982d2 100644 (file)
@@ -1,3 +1,13 @@
+2020-09-04  Alan Modra  <amodra@gmail.com>
+
+       PR 15146
+       PR 26314
+       PR 26530
+       * elflink.c (elf_link_add_object_symbols): Do set def_regular
+       and ref_regular for IR symbols.  Don't clear dynsym, allowing
+       IR symbols to load --as-needed shared libraries, but prevent
+       IR symbols from becoming dynamic.
+
 2020-09-03  Nick Clifton  <nickc@redhat.com>
 
        PR 26521
index 5c085b14b79cd5f04ea0b871c8a207fbf779f8f8..1384c1a46b83b55876b6a73dbcba0386a458063b 100644 (file)
@@ -4977,11 +4977,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
             object and a shared object.  */
          bfd_boolean dynsym = FALSE;
 
-         /* Plugin symbols aren't normal.  Don't set def_regular or
-            ref_regular for them, or make them dynamic.  */
-         if ((abfd->flags & BFD_PLUGIN) != 0)
-           ;
-         else if (! dynamic)
+         if (! dynamic)
            {
              if (! definition)
                {
@@ -5162,10 +5158,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
              && !bfd_link_relocatable (info))
            dynsym = FALSE;
 
-         /* Nor should we make plugin symbols dynamic.  */
-         if ((abfd->flags & BFD_PLUGIN) != 0)
-           dynsym = FALSE;
-
          if (definition)
            {
              h->target_internal = isym->st_target_internal;
@@ -5192,7 +5184,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
                }
            }
 
-         if (dynsym && h->dynindx == -1)
+         if (dynsym && (abfd->flags & BFD_PLUGIN) == 0 && h->dynindx == -1)
            {
              if (! bfd_elf_link_record_dynamic_symbol (info, h))
                goto error_free_vers;
index 0fcbf0d6c21226394280aaee92facd529b49dbf6..0a11b79c67443fa8831f65a251b7533b2c773eda 100644 (file)
@@ -1,3 +1,12 @@
+2020-09-04  Alan Modra  <amodra@gmail.com>
+
+       * testsuite/ld-plugin/lto.exp: Don't run pr15146 tests.
+       * testsuite/ld-plugin/pr15146.d: Delete.
+       * testsuite/ld-plugin/pr15146a.c: Delete.
+       * testsuite/ld-plugin/pr15146b.c: Delete.
+       * testsuite/ld-plugin/pr15146c.c: Delete.
+       * testsuite/ld-plugin/pr15146d.c: Delete.
+
 2020-09-03  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/config/default.exp: Change NOSANTIZE_CFLAGS to
index adad1e4895ca82de49645932786b71c50ac12af9..684d1db314ad8bfe8e4256e5c3cff9221a7c716c 100644 (file)
@@ -320,21 +320,6 @@ set lto_link_elf_tests [list \
   [list "PR ld/13244" \
    "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
    {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
-  [list "Build libpr15146a.a" \
-   "$plug_opt" "-flto -O2" \
-   {pr15146a.c} {} "lib15146a.a"] \
-  [list "Build pr15146b.so" \
-   "-shared" "-O2 -fpic" \
-   {pr15146b.c} {} "pr15146b.so" "c"] \
-  [list "Build pr15146c.so" \
-   "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic $no_lto" \
-   {pr15146c.c} {} "pr15146c.so" "c"] \
-  [list "PR ld/15146 (1)" \
-   "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
-   {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
-  [list "Build libpr15146d.a" \
-   "$plug_opt" "-flto -O2" \
-   {pr15146d.c} {} "lib15146d.a"] \
   [list "Build libpr16746a.a" \
    "" "" \
    {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
@@ -605,13 +590,6 @@ run_cc_link_tests $lto_compile_elf_tests
 # Restrict these to ELF targets that support shared libs and PIC.
 if { [is_elf_format] && [check_lto_shared_available] } {
     run_cc_link_tests $lto_link_elf_tests
-    set testname "PR ld/15146 (2)"
-    set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
-    if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
-       pass $testname
-    } {
-       fail $testname
-    }
     set testname "PR ld/16746 (3)"
     set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
     if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
diff --git a/ld/testsuite/ld-plugin/pr15146.d b/ld/testsuite/ld-plugin/pr15146.d
deleted file mode 100644 (file)
index 48d4b85..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#failif
-#...
- +0x[0-9a-f]+ +\(NEEDED\) +Shared library: +\[.*pr15146b.so\]
-#...
diff --git a/ld/testsuite/ld-plugin/pr15146a.c b/ld/testsuite/ld-plugin/pr15146a.c
deleted file mode 100644 (file)
index a22860a..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-extern int xxx;
-
-int
-bar (void)
-{
-  return xxx;
-}
-
-int
-main ()
-{ 
-  return 0;
-}
diff --git a/ld/testsuite/ld-plugin/pr15146b.c b/ld/testsuite/ld-plugin/pr15146b.c
deleted file mode 100644 (file)
index 90eb21e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-int xxx = 3;
diff --git a/ld/testsuite/ld-plugin/pr15146c.c b/ld/testsuite/ld-plugin/pr15146c.c
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/ld/testsuite/ld-plugin/pr15146d.c b/ld/testsuite/ld-plugin/pr15146d.c
deleted file mode 100644 (file)
index ba1e0ab..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-extern int xxx;
-
-int
-main ()
-{ 
-  return xxx;
-}
This page took 0.035838 seconds and 4 git commands to generate.