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>
Tue, 2 Feb 2021 09:39:42 +0000 (20:09 +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 (_bfd_elf_add_default_symbol): Add override parameter.
Use when handling default versioned symbol.  Rename existing
override variable to nondef_override and use for non-default
versioned symbol.
(elf_link_add_object_symbols): Adjust call to suit.  Don't
pull in as-needed libraries when override is set.
ld/
* 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.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
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 e0fa5a3bf4a3beec2e599259fe6954c928b03b6c..d65c56d009bf33133518129ac345e48d50285dea 100644 (file)
@@ -1,3 +1,13 @@
+2021-02-02  Alan Modra  <amodra@gmail.com>
+
+       PR 27311
+       * elflink.c (_bfd_elf_add_default_symbol): Add override parameter.
+       Use when handling default versioned symbol.  Rename existing
+       override variable to nondef_override and use for non-default
+       versioned symbol.
+       (elf_link_add_object_symbols): Adjust call to suit.  Don't
+       pull in as-needed libraries when override is set.
+
 2021-02-01  Emery Hemingway  <ehmry@posteo.net>
 
        * config.bfd: Add *-*-genode* as a target for AArch64 and x86.
index 3a3ca3b04f7ac5276b20c17e9eb8a9c82f46e8fa..7ac38cac6913c87742a1141216dc9378b5976212 100644 (file)
@@ -1850,7 +1850,8 @@ _bfd_elf_add_default_symbol (bfd *abfd,
                             asection *sec,
                             bfd_vma value,
                             bfd **poldbfd,
-                            bfd_boolean *dynsym)
+                            bfd_boolean *dynsym,
+                            bfd **override)
 {
   bfd_boolean type_change_ok;
   bfd_boolean size_change_ok;
@@ -1861,7 +1862,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
   const struct elf_backend_data *bed;
   bfd_boolean collect;
   bfd_boolean dynamic;
-  bfd *override;
+  bfd *nondef_override;
   char *p;
   size_t len, shortlen;
   asection *tmp_sec;
@@ -1921,7 +1922,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
   matched = TRUE;
   tmp_sec = sec;
   if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &tmp_sec, &value,
-                             &hi, poldbfd, NULL, NULL, &skip, &override,
+                             &hi, poldbfd, NULL, NULL, &skip, override,
                              &type_change_ok, &size_change_ok, &matched))
     return FALSE;
 
@@ -1953,7 +1954,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
        goto nondefault;
     }
 
-  if (! override)
+  if (!*override)
     {
       /* Add the default symbol if not performing a relocatable link.  */
       if (! bfd_link_relocatable (info))
@@ -2080,7 +2081,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
   size_change_ok = FALSE;
   tmp_sec = sec;
   if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &tmp_sec, &value,
-                             &hi, poldbfd, NULL, NULL, &skip, &override,
+                             &hi, poldbfd, NULL, NULL, &skip, &nondef_override,
                              &type_change_ok, &size_change_ok, &matched))
     return FALSE;
 
@@ -2104,7 +2105,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
       else
        return TRUE;
     }
-  else if (override)
+  else if (nondef_override)
     {
       /* Here SHORTNAME is a versioned name, so we don't expect to see
         the type of override we do in the case above unless it is
@@ -5089,7 +5090,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
              && !(hi != h
                   && hi->versioned == versioned_hidden))
            if (!_bfd_elf_add_default_symbol (abfd, info, h, name, isym,
-                                             sec, value, &old_bfd, &dynsym))
+                                             sec, value, &old_bfd, &dynsym,
+                                             &override))
              goto error_free_vers;
 
          /* Check the alignment when a common symbol is involved. This
@@ -5272,6 +5274,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
              }
 
          if (!add_needed
+             && !override
              && matched
              && definition
              && ((dynsym
index 6cf9d7007cdf370414b3c4a983017dde71d1b3b5..450137a1bda896c4ad92c21f00872e54692432a9 100644 (file)
@@ -1,3 +1,13 @@
+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-02-01  Emery Hemingway  <ehmry@posteo.net>
 
        * configure.tgt: Add *-*-genode* as a target for AArch64 and x86.
index dbda6c4465dfbd3da1976e6f60aa40fa43eadddf..324adcd00ceb4aa08aa8eb7c3861e174080f1db7 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;
+}