]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR27311, ld.bfd (symbol from plugin): undefined reference
authorAlan Modra <amodra@gmail.com>
Tue, 2 Feb 2021 04:35:14 +0000 (15:05 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 3 Feb 2021 08:10:39 +0000 (18:40 +1030)
A default versioned symbol definition in a shared library is
overridden by an unversioned definition in a regular object file, and
thus should not be reason to make an as-needed library needed.

bfd/
PR 27311
* elflink.c (elf_link_add_object_symbols): Don't pull in as-needed
libraries when H is an indirect symbol after calling
_bfd_elf_add_default_symbol.
ld/
* testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so):
Link with --as-needed.

* testsuite/ld-plugin/pr27311.d,
* testsuite/ld-plugin/pr27311.ver,
* testsuite/ld-plugin/pr27311a.c,
* testsuite/ld-plugin/pr27311b.c,
* testsuite/ld-plugin/pr27311c.c: New testcase.
* testsuite/ld-plugin/lto.exp: Run it.  Correct PR14918 and
PR12982 entries.

(cherry picked from commit 9918bff7cf2a566aaa2036d2242a61c140652dc7)
(cherry picked from commit 6955136728a68365bbb5e6e1327dff1654b2a0ca)
(cherry picked from commit f01fb44c0621b064996493bb5acd5077646ea84e)

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-ifunc/ifunc.exp
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr27311.d [new file with mode: 0644]
ld/testsuite/ld-plugin/pr27311.ver [new file with mode: 0644]
ld/testsuite/ld-plugin/pr27311a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr27311b.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr27311c.c [new file with mode: 0644]

index 08d28999487bd7bf2ac3660f2ae31a327994ae78..e2a34164f695643d6eed76a25d399756153603c9 100644 (file)
@@ -1,3 +1,10 @@
+2021-02-03  Alan Modra  <amodra@gmail.com>
+
+       PR 27311
+       * elflink.c (elf_link_add_object_symbols): Don't pull in as-needed
+       libraries when H is an indirect symbol after calling
+       _bfd_elf_add_default_symbol.
+
 2021-01-28  Alan Modra  <amodra@gmail.com>
 
        PR 27259
index e7b96f8ca86622933a8d17e04cdd13d0e01e1bc0..da288f3f2accba955fbaca003aa535b354fe7b86 100644 (file)
@@ -5274,6 +5274,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
          if (!add_needed
              && matched
              && definition
+             && h->root.type != bfd_link_hash_indirect
              && ((dynsym
                   && h->ref_regular_nonweak)
                  || (old_bfd != NULL
index ff2ee9668ceeae3e51197b5eaafebde40eaf2d7c..fbb7d5094f270d586dc512c6254b7ecc242058e2 100644 (file)
@@ -1,3 +1,19 @@
+2021-02-03  Alan Modra  <amodra@gmail.com>
+
+       Apply from mainline
+       2021-02-03  Alan Modra  <amodra@gmail.com>
+       * testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so):
+       Link with --as-needed.
+
+       2021-02-02  Alan Modra  <amodra@gmail.com>
+       * testsuite/ld-plugin/pr27311.d,
+       * testsuite/ld-plugin/pr27311.ver,
+       * testsuite/ld-plugin/pr27311a.c,
+       * testsuite/ld-plugin/pr27311b.c,
+       * testsuite/ld-plugin/pr27311c.c: New testcase.
+       * testsuite/ld-plugin/lto.exp: Run it.  Correct PR14918 and
+       PR12982 entries.
+
 2021-01-28  Alan Modra  <amodra@gmail.com>
 
        PR 27259
index 9d3ace6521639383393ad647ad6c63276a806d9e..45b47d7d6a85a456ed52f328d6fded5e1669c02f 100644 (file)
@@ -397,7 +397,7 @@ run_cc_link_tests [list \
     ] \
     [list \
        "Build libpr16467b.so" \
-       "-shared tmpdir/pr16467b.o tmpdir/libpr16467a.so \
+       "-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467a.so \
         -Wl,--version-script=pr16467b.map" \
        "-fPIC" \
        { dummy.c } \
@@ -422,7 +422,7 @@ run_cc_link_tests [list \
     ] \
     [list \
        "Build libpr16467bn.so" \
-       "-shared tmpdir/pr16467b.o tmpdir/libpr16467an.so \
+       "-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467an.so \
         -Wl,--version-script=pr16467b.map" \
        "-fPIC" \
        { dummy.c } \
index 3c129760498605d51dd4e67bf335677263aefb29..878d9e776aeb01e21b863e749f358efe58b4381a 100644 (file)
@@ -415,6 +415,18 @@ set lto_link_elf_tests [list \
   [list {pr26806.so} \
    {-shared} {-fpic -O2 -flto} \
    {pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \
+  [list {pr27311a.so} \
+   {-shared -Wl,--version-script=pr27311.ver} {-fPIC} \
+   {pr27311a.c} {} {pr27311a.so}] \
+  [list {pr27311b.so} \
+   {-shared -Wl,--no-as-needed tmpdir/pr27311a.so} {-fPIC} \
+   {pr27311b.c} {} {pr27311b.so}] \
+  [list {pr27311c.o} \
+   {} {-flto} \
+   {pr27311c.c} {} {} {c}] \
+  [list {pr27311} \
+   {tmpdir/pr27311c.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \
+   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311}] \
 ]
 
 # PR 14918 checks that libgcc is not spuriously included in a shared link of
@@ -423,11 +435,10 @@ set lto_link_elf_tests [list \
 # __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
 # test fails.  Hence this code to skip the test.
 if { ! [istarget "arm*-*-*"] } {
-    lappend lto_link_elf_tests [list \
+    lappend lto_link_elf_tests \
   [list "PR ld/14918" \
    "-flto" "-flto" \
-   {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
-  ]
+   {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"]
 }
 
 # PR 12982 checks that an executable stack is not created by default
@@ -435,11 +446,10 @@ if { ! [istarget "arm*-*-*"] } {
 # executable stack for syscall restarts and signal returns, so we
 # skip this test for that target.
 if { ! [istarget "hppa*-*-*"] } {
-    lappend lto_link_elf_tests [list \
+    lappend lto_link_elf_tests \
   [list "PR ld/12982" \
    "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
-   {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
-  ]
+   {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"]
 }
 
 # Check final symbols in executables.
diff --git a/ld/testsuite/ld-plugin/pr27311.d b/ld/testsuite/ld-plugin/pr27311.d
new file mode 100644 (file)
index 0000000..debf41c
--- /dev/null
@@ -0,0 +1,4 @@
+#failif
+#...
+.* _*inlib1.*
+#...
diff --git a/ld/testsuite/ld-plugin/pr27311.ver b/ld/testsuite/ld-plugin/pr27311.ver
new file mode 100644 (file)
index 0000000..324daf0
--- /dev/null
@@ -0,0 +1,3 @@
+LIBFOO {
+  *;
+};
diff --git a/ld/testsuite/ld-plugin/pr27311a.c b/ld/testsuite/ld-plugin/pr27311a.c
new file mode 100644 (file)
index 0000000..3149847
--- /dev/null
@@ -0,0 +1 @@
+void inlib1(void) {}
diff --git a/ld/testsuite/ld-plugin/pr27311b.c b/ld/testsuite/ld-plugin/pr27311b.c
new file mode 100644 (file)
index 0000000..ed9c8a7
--- /dev/null
@@ -0,0 +1 @@
+void inlib2(void) {}
diff --git a/ld/testsuite/ld-plugin/pr27311c.c b/ld/testsuite/ld-plugin/pr27311c.c
new file mode 100644 (file)
index 0000000..6712499
--- /dev/null
@@ -0,0 +1,5 @@
+void inlib1(void) {}
+int main()
+{
+  return 0;
+}