public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* lto-18 test
@ 2020-09-09  3:06 Alan Modra
  2020-09-09 13:41 ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2020-09-09  3:06 UTC (permalink / raw)
  To: binutils

Demonstrates a reason to use IR symbols when deciding an --as-needed
library should be loaded.

	* testsuite/ld-plugin/lto-18a.c,
	* testsuite/ld-plugin/lto-18b.c,
	* testsuite/ld-plugin/lto-18c.c,
	* testsuite/ld-plugin/lto-18d.c,
	* testsuite/ld-plugin/lto-18.out: New test.
	* testsuite/ld-plugin/lto.exp: Run it.

diff --git a/ld/testsuite/ld-plugin/lto-18.out b/ld/testsuite/ld-plugin/lto-18.out
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-18.out
@@ -0,0 +1 @@
+1
diff --git a/ld/testsuite/ld-plugin/lto-18a.c b/ld/testsuite/ld-plugin/lto-18a.c
new file mode 100644
index 0000000000..477386af8c
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-18a.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+extern int select ();
+extern int f1 (int);
+extern int f2 (int);
+
+int main (void)
+{
+  switch (select ())
+    {
+    case 1:
+      printf ("%d\n", f1 (3));
+      break;
+    case 2:
+      printf ("%d\n", f2 (4));
+      break;
+    default:
+      printf ("%d\n", f2 (0));
+      break;
+    }
+  return 0;
+}
diff --git a/ld/testsuite/ld-plugin/lto-18b.c b/ld/testsuite/ld-plugin/lto-18b.c
new file mode 100644
index 0000000000..0ae3a20c14
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-18b.c
@@ -0,0 +1,10 @@
+int select (void) { return 1; }
+
+extern int f2 (int);
+
+int f1 (int x)
+{
+  if (x > 0)
+    return x * f2 (x - 1);
+  return 1;
+}
diff --git a/ld/testsuite/ld-plugin/lto-18c.c b/ld/testsuite/ld-plugin/lto-18c.c
new file mode 100644
index 0000000000..90cc81bea3
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-18c.c
@@ -0,0 +1,10 @@
+int select (void) { return 2; }
+
+extern int f1 (int);
+
+int f2 (int x)
+{
+  if (x > 0)
+    return x * f1 (x - 1);
+  return 1;
+}
diff --git a/ld/testsuite/ld-plugin/lto-18d.c b/ld/testsuite/ld-plugin/lto-18d.c
new file mode 100644
index 0000000000..cfb27cf38a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-18d.c
@@ -0,0 +1 @@
+int select (void) { return 0; }
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 684d1db314..0479e3e403 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -404,6 +404,15 @@ set lto_link_elf_tests [list \
    "-shared -Wl,--exclude-libs,ALL tmpdir/pr25618a.o tmpdir/pr25618.a" \
    "-fpic" \
    {dummy.c} {{readelf {--dyn-syms --wide} pr25618.d}} "pr25618.so" "c++"] \
+  [list {liblto-18b.so} \
+   {-shared} {-O2 -fpic} \
+   {lto-18b.c} {} {liblto-18b.so}] \
+  [list {liblto-18c.so} \
+   {-shared} {-O2 -fpic} \
+   {lto-18c.c} {} {liblto-18c.so}] \
+  [list {lto-18d.o} \
+   {} {-flto -O2} \
+   {lto-18d.c} {} {}] \
 ]
 
 # PR 14918 checks that libgcc is not spuriously included in a shared link of
@@ -412,11 +421,11 @@ 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*-*-*"] } {
-    set lto_link_elf_tests [concat $lto_link_elf_tests [list \
+    lappend lto_link_elf_tests [list \
   [list "PR ld/14918" \
    "-flto" "-flto" \
    {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
-  ]]
+  ]
 }
 
 # PR 12982 checks that an executable stack is not created by default
@@ -424,11 +433,11 @@ if { ! [istarget "arm*-*-*"] } {
 # executable stack for syscall restarts and signal returns, so we
 # skip this test for that target.
 if { ! [istarget "hppa*-*-*"] } {
-    set lto_link_elf_tests [concat $lto_link_elf_tests [list \
+    lappend lto_link_elf_tests [list \
   [list "PR ld/12982" \
    "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
    {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
-  ]]
+  ]
 }
 
 # Check final symbols in executables.
@@ -569,6 +578,14 @@ set lto_run_elf_shared_tests [list \
   [list {pr22220b} \
    {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
    {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
+  [list {lto-18 (1)} \
+   {-flto -fuse-linker-plugin} {} \
+   {lto-18a.c} {lto-18-1.exe} {lto-18.out} {-flto -O2} {c} {} \
+   {tmpdir/lto-18d.o -Wl,--as-needed,-R,tmpdir -Ltmpdir -llto-18b -llto-18c}] \
+  [list {lto-18 (2)} \
+   {-flto -fuse-linker-plugin} {} \
+   {lto-18a.c} {lto-18-2.exe} {lto-18.out} {-flto -O2} {c} {} \
+   {-Wl,--as-needed,-R,tmpdir -Ltmpdir -llto-18b -llto-18c tmpdir/lto-18d.o}] \
 ]
 
 # LTO run-time tests for ELF

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: lto-18 test
  2020-09-09  3:06 lto-18 test Alan Modra
@ 2020-09-09 13:41 ` H.J. Lu
  2020-09-09 13:50   ` H.J. Lu
  2020-09-09 14:03   ` Alan Modra
  0 siblings, 2 replies; 7+ messages in thread
From: H.J. Lu @ 2020-09-09 13:41 UTC (permalink / raw)
  To: Alan Modra; +Cc: Binutils

On Tue, Sep 8, 2020 at 8:08 PM Alan Modra via Binutils
<binutils@sourceware.org> wrote:
>
> Demonstrates a reason to use IR symbols when deciding an --as-needed
> library should be loaded.
>
>         * testsuite/ld-plugin/lto-18a.c,
>         * testsuite/ld-plugin/lto-18b.c,
>         * testsuite/ld-plugin/lto-18c.c,
>         * testsuite/ld-plugin/lto-18d.c,
>         * testsuite/ld-plugin/lto-18.out: New test.
>         * testsuite/ld-plugin/lto.exp: Run it.
>

This exposed an --as-needed bug:

https://sourceware.org/bugzilla/show_bug.cgi?id=26590

which has nothing to do with LTO.

-- 
H.J.

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

* Re: lto-18 test
  2020-09-09 13:41 ` H.J. Lu
@ 2020-09-09 13:50   ` H.J. Lu
  2020-09-09 14:10     ` Alan Modra
  2020-09-09 14:03   ` Alan Modra
  1 sibling, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2020-09-09 13:50 UTC (permalink / raw)
  To: Alan Modra; +Cc: Binutils

On Wed, Sep 9, 2020 at 6:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Sep 8, 2020 at 8:08 PM Alan Modra via Binutils
> <binutils@sourceware.org> wrote:
> >
> > Demonstrates a reason to use IR symbols when deciding an --as-needed
> > library should be loaded.

I believe that liblto-18c.so should have liblto-18b.so in DT_NEEDED.

> >         * testsuite/ld-plugin/lto-18a.c,
> >         * testsuite/ld-plugin/lto-18b.c,
> >         * testsuite/ld-plugin/lto-18c.c,
> >         * testsuite/ld-plugin/lto-18d.c,
> >         * testsuite/ld-plugin/lto-18.out: New test.
> >         * testsuite/ld-plugin/lto.exp: Run it.
> >
>
> This exposed an --as-needed bug:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=26590
>
> which has nothing to do with LTO.

-- 
H.J.

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

* Re: lto-18 test
  2020-09-09 13:41 ` H.J. Lu
  2020-09-09 13:50   ` H.J. Lu
@ 2020-09-09 14:03   ` Alan Modra
  2020-09-09 14:09     ` H.J. Lu
  1 sibling, 1 reply; 7+ messages in thread
From: Alan Modra @ 2020-09-09 14:03 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils

On Wed, Sep 09, 2020 at 06:41:22AM -0700, H.J. Lu wrote:
> On Tue, Sep 8, 2020 at 8:08 PM Alan Modra via Binutils
> <binutils@sourceware.org> wrote:
> >
> > Demonstrates a reason to use IR symbols when deciding an --as-needed
> > library should be loaded.
> >
> >         * testsuite/ld-plugin/lto-18a.c,
> >         * testsuite/ld-plugin/lto-18b.c,
> >         * testsuite/ld-plugin/lto-18c.c,
> >         * testsuite/ld-plugin/lto-18d.c,
> >         * testsuite/ld-plugin/lto-18.out: New test.
> >         * testsuite/ld-plugin/lto.exp: Run it.
> >
> 
> This exposed an --as-needed bug:

No, it didn't.

> https://sourceware.org/bugzilla/show_bug.cgi?id=26590

So you change the testcase in such a way that the first object file no
longer needs the first shared library.  ld correctly decides that the
first library isn't needed.  That's how --as-needed is supposed to
work.

> which has nothing to do with LTO.

Indeed it does.  The lto-18 testcase as written compiles and links
fine without LTO.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: lto-18 test
  2020-09-09 14:03   ` Alan Modra
@ 2020-09-09 14:09     ` H.J. Lu
  0 siblings, 0 replies; 7+ messages in thread
From: H.J. Lu @ 2020-09-09 14:09 UTC (permalink / raw)
  To: Alan Modra; +Cc: Binutils

On Wed, Sep 9, 2020 at 7:03 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Wed, Sep 09, 2020 at 06:41:22AM -0700, H.J. Lu wrote:
> > On Tue, Sep 8, 2020 at 8:08 PM Alan Modra via Binutils
> > <binutils@sourceware.org> wrote:
> > >
> > > Demonstrates a reason to use IR symbols when deciding an --as-needed
> > > library should be loaded.
> > >
> > >         * testsuite/ld-plugin/lto-18a.c,
> > >         * testsuite/ld-plugin/lto-18b.c,
> > >         * testsuite/ld-plugin/lto-18c.c,
> > >         * testsuite/ld-plugin/lto-18d.c,
> > >         * testsuite/ld-plugin/lto-18.out: New test.
> > >         * testsuite/ld-plugin/lto.exp: Run it.
> > >
> >
> > This exposed an --as-needed bug:
>
> No, it didn't.
>
> > https://sourceware.org/bugzilla/show_bug.cgi?id=26590
>
> So you change the testcase in such a way that the first object file no
> longer needs the first shared library.  ld correctly decides that the
> first library isn't needed.  That's how --as-needed is supposed to
> work.
>
> > which has nothing to do with LTO.
>
> Indeed it does.  The lto-18 testcase as written compiles and links
> fine without LTO.

f1 reference in IR is removed by LTO, which I did by hand.  The
requirement of liblto-18b.so doesn't come from IR, but comes from
liblto-18c.so.

-- 
H.J.

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

* Re: lto-18 test
  2020-09-09 13:50   ` H.J. Lu
@ 2020-09-09 14:10     ` Alan Modra
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Modra @ 2020-09-09 14:10 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils

On Wed, Sep 09, 2020 at 06:50:17AM -0700, H.J. Lu wrote:
> On Wed, Sep 9, 2020 at 6:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Tue, Sep 8, 2020 at 8:08 PM Alan Modra via Binutils
> > <binutils@sourceware.org> wrote:
> > >
> > > Demonstrates a reason to use IR symbols when deciding an --as-needed
> > > library should be loaded.
> 
> I believe that liblto-18c.so should have liblto-18b.so in DT_NEEDED.

Testcases are often not very nice.  Neglecting DT_NEEDED doesn't make
the testcase invalid.  (And liblto-18b.so should have liblto-18c.so in
DT_NEEDED.)

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: lto-18 test
@ 2020-09-10  9:27 Alan Modra
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Modra @ 2020-09-10  9:27 UTC (permalink / raw)
  To: binutils

Extend the test a little to archives, not that we expect this to
fail.  Nor has the lto-18 test ever failed without -flto.

	* testsuite/ld-plugin/lto-18b.c (select): Remove.
	* testsuite/ld-plugin/lto-18c.c (select): Remove.
	* testsuite/ld-plugin/lto.exp: Build archives for lto-18 too,
	and run static versions of the test.

diff --git a/ld/testsuite/ld-plugin/lto-18b.c b/ld/testsuite/ld-plugin/lto-18b.c
index 0ae3a20c14..ca78bbf216 100644
--- a/ld/testsuite/ld-plugin/lto-18b.c
+++ b/ld/testsuite/ld-plugin/lto-18b.c
@@ -1,5 +1,3 @@
-int select (void) { return 1; }
-
 extern int f2 (int);
 
 int f1 (int x)
diff --git a/ld/testsuite/ld-plugin/lto-18c.c b/ld/testsuite/ld-plugin/lto-18c.c
index 90cc81bea3..5ade283917 100644
--- a/ld/testsuite/ld-plugin/lto-18c.c
+++ b/ld/testsuite/ld-plugin/lto-18c.c
@@ -1,5 +1,3 @@
-int select (void) { return 2; }
-
 extern int f1 (int);
 
 int f2 (int x)
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 0479e3e403..abb712575f 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -407,9 +407,15 @@ set lto_link_elf_tests [list \
   [list {liblto-18b.so} \
    {-shared} {-O2 -fpic} \
    {lto-18b.c} {} {liblto-18b.so}] \
+  [list {liblto-18b.a} \
+   "$plug_opt" {-flto -O2} \
+   {lto-18b.c} {} {liblto-18b.a}] \
   [list {liblto-18c.so} \
    {-shared} {-O2 -fpic} \
    {lto-18c.c} {} {liblto-18c.so}] \
+  [list {liblto-18c.a} \
+   "$plug_opt" {-flto -O2} \
+   {lto-18c.c} {} {liblto-18c.a}] \
   [list {lto-18d.o} \
    {} {-flto -O2} \
    {lto-18d.c} {} {}] \
@@ -586,6 +592,14 @@ set lto_run_elf_shared_tests [list \
    {-flto -fuse-linker-plugin} {} \
    {lto-18a.c} {lto-18-2.exe} {lto-18.out} {-flto -O2} {c} {} \
    {-Wl,--as-needed,-R,tmpdir -Ltmpdir -llto-18b -llto-18c tmpdir/lto-18d.o}] \
+  [list {lto-18 (3)} \
+   {-static -flto -fuse-linker-plugin} {} \
+   {lto-18a.c} {lto-18-3.exe} {lto-18.out} {-flto -O2} {c} {} \
+   {tmpdir/lto-18d.o -Ltmpdir -llto-18b -llto-18c}] \
+  [list {lto-18 (4)} \
+   {-static -flto -fuse-linker-plugin} {} \
+   {lto-18a.c} {lto-18-4.exe} {lto-18.out} {-flto -O2} {c} {} \
+   { -Ltmpdir -llto-18b -llto-18c tmpdir/lto-18d.o}] \
 ]
 
 # LTO run-time tests for ELF

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2020-09-10  9:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09  3:06 lto-18 test Alan Modra
2020-09-09 13:41 ` H.J. Lu
2020-09-09 13:50   ` H.J. Lu
2020-09-09 14:10     ` Alan Modra
2020-09-09 14:03   ` Alan Modra
2020-09-09 14:09     ` H.J. Lu
2020-09-10  9:27 Alan Modra

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).