public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR27311, ld.bfd (symbol from plugin): undefined reference
@ 2021-02-02  9:58 Alan Modra
  2021-02-03  2:38 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2021-02-02  9:58 UTC (permalink / raw)
  To: binutils

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.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 3a3ca3b04f7..7ac38cac691 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index dbda6c4465d..324adcd00ce 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -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
index 00000000000..debf41cdc7f
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr27311.d
@@ -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
index 00000000000..324daf0c5b6
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr27311.ver
@@ -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
index 00000000000..314984781db
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr27311a.c
@@ -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
index 00000000000..ed9c8a7048e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr27311b.c
@@ -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
index 00000000000..6712499130e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr27311c.c
@@ -0,0 +1,5 @@
+void inlib1(void) {}
+int main()
+{
+  return 0;
+}

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PR27311, ld.bfd (symbol from plugin): undefined reference
  2021-02-02  9:58 PR27311, ld.bfd (symbol from plugin): undefined reference Alan Modra
@ 2021-02-03  2:38 ` Alan Modra
  2021-02-03  8:05   ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2021-02-03  2:38 UTC (permalink / raw)
  To: binutils

On Tue, Feb 02, 2021 at 08:28:46PM +1030, Alan Modra wrote:
> 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.

Eh well, that one introduced a regression with the pr16467 testcases
if you happen to be using a compiler that defaults to --as-needed.

bfd/
	PR 27311
	* elflink.c (_bfd_elf_add_default_symbol): Clear override when
	undecorated symbol will have a different version.
ld/
	* testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so):
	Link with --as-needed.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 7ac38cac691..5af32ef0a81 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1946,12 +1946,16 @@ _bfd_elf_add_default_symbol (bfd *abfd,
 	  if (hi->verinfo.vertree != NULL && hide)
 	    {
 	      (*bed->elf_backend_hide_symbol) (info, hi, TRUE);
+	      *override = FALSE;
 	      goto nondefault;
 	    }
 	}
       if (hi->verinfo.vertree != NULL
 	  && strcmp (p + 1 + (p[1] == '@'), hi->verinfo.vertree->name) != 0)
-	goto nondefault;
+	{
+	  *override = FALSE;
+	  goto nondefault;
+	}
     }
 
   if (!*override)
diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
index 9d3ace65216..45b47d7d6a8 100644
--- a/ld/testsuite/ld-ifunc/ifunc.exp
+++ b/ld/testsuite/ld-ifunc/ifunc.exp
@@ -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 } \

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PR27311, ld.bfd (symbol from plugin): undefined reference
  2021-02-03  2:38 ` Alan Modra
@ 2021-02-03  8:05   ` Alan Modra
  2021-02-04  6:20     ` PR27311, (symbol from plugin): undefined reference, hidden sym Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2021-02-03  8:05 UTC (permalink / raw)
  To: binutils

This:
+	      && h->root.type != bfd_link_hash_indirect
does exactly the same as making decisions based on an override in
_bfd_elf_add_default_symbol, and is simpler.  I should have written
it this way in the first patch in this series.

	PR 27311
	* elflink.c (_bfd_elf_add_default_symbol): Revert last two changes.
	(elf_link_add_object_symbols): Test for H not an indirect symbol
	after calling _bfd_elf_add_default_symbol.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 5af32ef0a81..82c705015db 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1850,8 +1850,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
 			     asection *sec,
 			     bfd_vma value,
 			     bfd **poldbfd,
-			     bfd_boolean *dynsym,
-			     bfd **override)
+			     bfd_boolean *dynsym)
 {
   bfd_boolean type_change_ok;
   bfd_boolean size_change_ok;
@@ -1862,7 +1861,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
   const struct elf_backend_data *bed;
   bfd_boolean collect;
   bfd_boolean dynamic;
-  bfd *nondef_override;
+  bfd *override;
   char *p;
   size_t len, shortlen;
   asection *tmp_sec;
@@ -1922,7 +1921,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;
 
@@ -1946,19 +1945,15 @@ _bfd_elf_add_default_symbol (bfd *abfd,
 	  if (hi->verinfo.vertree != NULL && hide)
 	    {
 	      (*bed->elf_backend_hide_symbol) (info, hi, TRUE);
-	      *override = FALSE;
 	      goto nondefault;
 	    }
 	}
       if (hi->verinfo.vertree != NULL
 	  && strcmp (p + 1 + (p[1] == '@'), hi->verinfo.vertree->name) != 0)
-	{
-	  *override = FALSE;
-	  goto nondefault;
-	}
+	goto nondefault;
     }
 
-  if (!*override)
+  if (!override)
     {
       /* Add the default symbol if not performing a relocatable link.  */
       if (! bfd_link_relocatable (info))
@@ -2085,7 +2080,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, &nondef_override,
+			      &hi, poldbfd, NULL, NULL, &skip, &override,
 			      &type_change_ok, &size_change_ok, &matched))
     return FALSE;
 
@@ -2109,7 +2104,7 @@ _bfd_elf_add_default_symbol (bfd *abfd,
       else
 	return TRUE;
     }
-  else if (nondef_override)
+  else if (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
@@ -5094,8 +5089,7 @@ 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,
-					      &override))
+					      sec, value, &old_bfd, &dynsym))
 	      goto error_free_vers;
 
 	  /* Check the alignment when a common symbol is involved. This
@@ -5278,9 +5272,9 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 	      }
 
 	  if (!add_needed
-	      && !override
 	      && matched
 	      && definition
+	      && h->root.type != bfd_link_hash_indirect
 	      && ((dynsym
 		   && h->ref_regular_nonweak)
 		  || (old_bfd != NULL

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* PR27311, (symbol from plugin): undefined reference, hidden sym
  2021-02-03  8:05   ` Alan Modra
@ 2021-02-04  6:20     ` Alan Modra
  2021-02-04 13:18       ` [PATCH] ld: Restore PR ld/15146 tests H.J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2021-02-04  6:20 UTC (permalink / raw)
  To: binutils

After LTO recompilation we more or less want to ignore IR symbols.

bfd/
	PR 27311
	* elflink.c (elf_link_add_object_symbols): Don't pull in as-needed
	libraries for IR references on pass over libraries after LTO
	recompilation.
ld/
	* testsuite/ld-plugin/pr27311d.c: New test.
	* testsuite/ld-plugin/lto.exp: Rename pr27311 to pr27311-1, compile
	and link new test as pr27311-2.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index b8c29250a2c..291cec0df25 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -5279,6 +5279,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		   && h->ref_regular_nonweak)
 		  || (old_bfd != NULL
 		      && (old_bfd->flags & BFD_PLUGIN) != 0
+		      && !info->lto_all_symbols_read
 		      && bind != STB_WEAK)
 		  || (h->ref_dynamic_nonweak
 		      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 324adcd00ce..c96617f9e9e 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -424,9 +424,15 @@ set lto_link_elf_tests [list \
   [list {pr27311c.o} \
    {} {-flto} \
    {pr27311c.c} {} {} {c}] \
-  [list {pr27311} \
+  [list {pr27311d.o} \
+   {} {-flto} \
+   {pr27311d.c} {} {} {c}] \
+  [list {pr27311-1} \
    {tmpdir/pr27311c.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \
-   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311}] \
+   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311-1}] \
+  [list {pr27311-2} \
+   {tmpdir/pr27311d.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \
+   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311-2}] \
 ]
 
 # PR 14918 checks that libgcc is not spuriously included in a shared link of
diff --git a/ld/testsuite/ld-plugin/pr27311d.c b/ld/testsuite/ld-plugin/pr27311d.c
new file mode 100644
index 00000000000..11e4ba4d6dd
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr27311d.c
@@ -0,0 +1,5 @@
+__attribute__((visibility("hidden"))) void inlib1(void) {}
+int main()
+{
+  return 0;
+}

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] ld: Restore PR ld/15146 tests
  2021-02-04  6:20     ` PR27311, (symbol from plugin): undefined reference, hidden sym Alan Modra
@ 2021-02-04 13:18       ` H.J. Lu
  0 siblings, 0 replies; 5+ messages in thread
From: H.J. Lu @ 2021-02-04 13:18 UTC (permalink / raw)
  To: Alan Modra; +Cc: Binutils

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

On Wed, Feb 3, 2021 at 10:40 PM Alan Modra via Binutils
<binutils@sourceware.org> wrote:
>
> After LTO recompilation we more or less want to ignore IR symbols.
>
> bfd/
>         PR 27311
>         * elflink.c (elf_link_add_object_symbols): Don't pull in as-needed
>         libraries for IR references on pass over libraries after LTO
>         recompilation.
> ld/
>         * testsuite/ld-plugin/pr27311d.c: New test.
>         * testsuite/ld-plugin/lto.exp: Rename pr27311 to pr27311-1, compile
>         and link new test as pr27311-2.
>

This patch also fixed PR ld/15146.  I am checking this patch into
master and 2.36 branches to restore PR ld/15146 tests.

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-ld-Restore-PR-ld-15146-tests.patch --]
[-- Type: text/x-patch, Size: 5189 bytes --]

From 37707bd8221c2e3f7676de8bee0c42ce3ab38c77 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 4 Feb 2021 05:11:37 -0800
Subject: [PATCH] ld: Restore PR ld/15146 tests

commit 7d409ac001cce916661d345bff01ed589991e762
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Feb 4 13:56:34 2021 +1030

    PR27311, (symbol from plugin): undefined reference, hidden sym

fixed PR ld/15146.  Restore PR ld/15146 tests.

	PR ld/15146
	* testsuite/ld-plugin/lto.exp: Run PR ld/15146 tests.
	* testsuite/ld-plugin/pr15146.d: Restored.
	* testsuite/ld-plugin/pr15146a.c: Likewise.
	* testsuite/ld-plugin/pr15146b.c: Likewise.
	* testsuite/ld-plugin/pr15146c.c: Likewise.
	* testsuite/ld-plugin/pr15146d.c: Likewise.
---
 ld/ChangeLog                      | 10 ++++++++++
 ld/testsuite/ld-plugin/lto.exp    | 22 ++++++++++++++++++++++
 ld/testsuite/ld-plugin/pr15146.d  |  4 ++++
 ld/testsuite/ld-plugin/pr15146a.c | 13 +++++++++++++
 ld/testsuite/ld-plugin/pr15146b.c |  1 +
 ld/testsuite/ld-plugin/pr15146c.c |  0
 ld/testsuite/ld-plugin/pr15146d.c |  7 +++++++
 7 files changed, 57 insertions(+)
 create mode 100644 ld/testsuite/ld-plugin/pr15146.d
 create mode 100644 ld/testsuite/ld-plugin/pr15146a.c
 create mode 100644 ld/testsuite/ld-plugin/pr15146b.c
 create mode 100644 ld/testsuite/ld-plugin/pr15146c.c
 create mode 100644 ld/testsuite/ld-plugin/pr15146d.c

diff --git a/ld/ChangeLog b/ld/ChangeLog
index cf5217b6c7..3cd2be0add 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,13 @@
+2021-02-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/15146
+	* testsuite/ld-plugin/lto.exp: Run PR ld/15146 tests.
+	* testsuite/ld-plugin/pr15146.d: Restored.
+	* testsuite/ld-plugin/pr15146a.c: Likewise.
+	* testsuite/ld-plugin/pr15146b.c: Likewise.
+	* testsuite/ld-plugin/pr15146c.c: Likewise.
+	* testsuite/ld-plugin/pr15146d.c: Likewise.
+
 2021-02-04  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-plugin/pr27311d.c: New test.
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index c96617f9e9..33e5c19a23 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -304,6 +304,21 @@ 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"] \
@@ -637,6 +652,13 @@ 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
new file mode 100644
index 0000000000..48d4b85446
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15146.d
@@ -0,0 +1,4 @@
+#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
new file mode 100644
index 0000000000..d85fe973cb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15146a.c
@@ -0,0 +1,13 @@
+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
new file mode 100644
index 0000000000..90eb21ea55
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15146b.c
@@ -0,0 +1 @@
+int xxx = 3;
diff --git a/ld/testsuite/ld-plugin/pr15146c.c b/ld/testsuite/ld-plugin/pr15146c.c
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/ld/testsuite/ld-plugin/pr15146d.c b/ld/testsuite/ld-plugin/pr15146d.c
new file mode 100644
index 0000000000..3986ff6245
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15146d.c
@@ -0,0 +1,7 @@
+extern int xxx;
+
+int
+main ()
+{
+  return xxx;
+}
-- 
2.29.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-04 13:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02  9:58 PR27311, ld.bfd (symbol from plugin): undefined reference Alan Modra
2021-02-03  2:38 ` Alan Modra
2021-02-03  8:05   ` Alan Modra
2021-02-04  6:20     ` PR27311, (symbol from plugin): undefined reference, hidden sym Alan Modra
2021-02-04 13:18       ` [PATCH] ld: Restore PR ld/15146 tests H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).