aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-09-09 12:16:23 +0930
committerAlan Modra <amodra@gmail.com>2020-09-09 12:36:59 +0930
commitfb7331ae2b551247a33e8da5387ebc910c4a7308 (patch)
tree63a9cb66e0e78845d346425e3df1894ae943fa64 /ld
parent7671fe54f3a0c8c41098ad8fc32588a9e281c92c (diff)
downloadgdb-fb7331ae2b551247a33e8da5387ebc910c4a7308.zip
gdb-fb7331ae2b551247a33e8da5387ebc910c4a7308.tar.gz
gdb-fb7331ae2b551247a33e8da5387ebc910c4a7308.tar.bz2
lto-18 test
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.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog9
-rw-r--r--ld/testsuite/ld-plugin/lto-18.out1
-rw-r--r--ld/testsuite/ld-plugin/lto-18a.c22
-rw-r--r--ld/testsuite/ld-plugin/lto-18b.c10
-rw-r--r--ld/testsuite/ld-plugin/lto-18c.c10
-rw-r--r--ld/testsuite/ld-plugin/lto-18d.c1
-rw-r--r--ld/testsuite/ld-plugin/lto.exp25
7 files changed, 74 insertions, 4 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 1f80479..27df4a0 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2020-09-09 Alan Modra <amodra@gmail.com>
+
+ * 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.
+
2020-09-08 Jozef Lawrynowicz <jozef.l@mittosystems.com>
* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
diff --git a/ld/testsuite/ld-plugin/lto-18.out b/ld/testsuite/ld-plugin/lto-18.out
new file mode 100644
index 0000000..d00491f
--- /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 0000000..477386a
--- /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 0000000..0ae3a20
--- /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 0000000..90cc81b
--- /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 0000000..cfb27cf
--- /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 684d1db..0479e3e 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