aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'ld/testsuite/ld-plugin')
-rw-r--r--ld/testsuite/ld-plugin/lto-20.ver1
-rw-r--r--ld/testsuite/ld-plugin/lto-20a.c2
-rw-r--r--ld/testsuite/ld-plugin/lto-20b.c11
-rw-r--r--ld/testsuite/ld-plugin/lto-binutils.exp358
-rw-r--r--ld/testsuite/ld-plugin/lto.exp47
-rw-r--r--ld/testsuite/ld-plugin/pr25618a.h1
-rw-r--r--ld/testsuite/ld-plugin/pr25618b.h1
-rw-r--r--ld/testsuite/ld-plugin/pr32846a.c6
-rw-r--r--ld/testsuite/ld-plugin/pr32846b.c4
-rw-r--r--ld/testsuite/ld-plugin/pr32846c.c6
-rw-r--r--ld/testsuite/ld-plugin/pr32846d.c12
-rw-r--r--ld/testsuite/ld-plugin/pr32846e.c4
-rw-r--r--ld/testsuite/ld-plugin/strip-1a-fat.c1
-rw-r--r--ld/testsuite/ld-plugin/strip-1a-fat.rd6
-rw-r--r--ld/testsuite/ld-plugin/strip-1a-s-all.nd3
-rw-r--r--ld/testsuite/ld-plugin/strip-1a.c4
-rw-r--r--ld/testsuite/ld-plugin/strip-1b-fat.c1
-rw-r--r--ld/testsuite/ld-plugin/strip-1b-fat.rd5
-rw-r--r--ld/testsuite/ld-plugin/strip-1b.c3
19 files changed, 471 insertions, 5 deletions
diff --git a/ld/testsuite/ld-plugin/lto-20.ver b/ld/testsuite/ld-plugin/lto-20.ver
new file mode 100644
index 0000000..ac906ac
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-20.ver
@@ -0,0 +1 @@
+FOO { global: foo; };
diff --git a/ld/testsuite/ld-plugin/lto-20a.c b/ld/testsuite/ld-plugin/lto-20a.c
new file mode 100644
index 0000000..3d6dac9
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-20a.c
@@ -0,0 +1,2 @@
+extern int foo ();
+int main () { return foo (); }
diff --git a/ld/testsuite/ld-plugin/lto-20b.c b/ld/testsuite/ld-plugin/lto-20b.c
new file mode 100644
index 0000000..ba123cb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-20b.c
@@ -0,0 +1,11 @@
+extern int printf (const char *, ...);
+int foo ()
+{
+#ifdef SHARED
+ printf ("PASS\n");
+ return 0;
+#else
+ printf ("FAIL\n");
+ return 1;
+#endif
+}
diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
new file mode 100644
index 0000000..5b4e0a1
--- /dev/null
+++ b/ld/testsuite/ld-plugin/lto-binutils.exp
@@ -0,0 +1,358 @@
+# Expect script for binutils tests with LTO
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# Make sure that binutils can correctly handle LTO IR in ELF.
+
+if { !([istarget *-*-linux*]
+ || [istarget arm*-*-uclinuxfdpiceabi]
+ || [istarget *-*-nacl*]
+ || [istarget *-*-gnu*]) || [istarget *ecoff] } then {
+ return
+}
+
+# Check to see if the C and C++ compilers work
+if { ![check_compiler_available] || [which $CXX_FOR_TARGET] == 0 } {
+ return
+}
+
+# These tests require plugin and LTO.
+if { ![check_plugin_api_available]
+ || ![check_lto_available] } {
+ return
+}
+
+set lto_fat ""
+set lto_no_fat ""
+if { [check_lto_fat_available] } {
+ set lto_fat "-ffat-lto-objects"
+ set lto_no_fat "-fno-fat-lto-objects"
+ set no_lto "-fno-lto"
+}
+
+# List contains test-items:
+# 0:program name
+# 1:program options
+# 2:input file
+# 3:output file
+# 4:action list (optional)
+#
+proc run_lto_binutils_test { lto_tests } {
+ global srcdir
+ global subdir
+ global nm
+ global objcopy
+ global objdump
+ global READELF
+ global strip
+ global plug_opt
+
+ foreach testitem $lto_tests {
+ set prog_name [lindex $testitem 0]
+ set prog_options [lindex $testitem 1]
+ set input tmpdir/[lindex $testitem 2]
+ set output tmpdir/[lindex $testitem 3]
+ set actions [lindex $testitem 4]
+ set objfiles {}
+ set is_unresolved 0
+ set failed 0
+
+# eval set prog \$$prog_name
+ switch -- $prog_name {
+ objcopy
+ {
+ set prog $objcopy
+ set prog_output "$output"
+ }
+ strip
+ {
+ set prog $strip
+ set prog_output "-o $output"
+ }
+ default
+ {
+ perror "Unrecognized action $action"
+ set is_unresolved 1
+ break
+ }
+ }
+
+ # Don't leave previous output around
+ if { $output ne "tmpdir/" } {
+ remote_file host delete $output
+ }
+
+ append prog_options " $plug_opt"
+
+ set cmd_options "$prog_options $prog_output $input"
+ set test_name "$prog_name $cmd_options"
+
+ set cmd "$prog $cmd_options"
+ send_log "$cmd\n"
+ set got [remote_exec host "$cmd"]
+ if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+ send_log "$got\n"
+ fail "$test_name"
+ continue
+ }
+
+ if { $failed == 0 } {
+ foreach actionlist $actions {
+ set action [lindex $actionlist 0]
+ set progopts [lindex $actionlist 1]
+
+ # There are actions where we run regexp_diff on the
+ # output, and there are other actions (presumably).
+ # Handling of the former look the same.
+ set dump_prog ""
+ switch -- $action {
+ objdump
+ { set dump_prog $objdump }
+ nm
+ { set dump_prog $nm }
+ readelf
+ { set dump_prog $READELF }
+ default
+ {
+ perror "Unrecognized action $action"
+ set is_unresolved 1
+ break
+ }
+ }
+
+ if { $dump_prog != "" } {
+ set dumpfile [lindex $actionlist 2]
+ set binary $dump_prog
+
+ # Ensure consistent sorting of symbols
+ if {[info exists env(LC_ALL)]} {
+ set old_lc_all $env(LC_ALL)
+ }
+ set env(LC_ALL) "C"
+ set cmd "$binary $progopts $output > tmpdir/dump.out"
+ send_log "$cmd\n"
+ catch "exec $cmd" comp_output
+ if {[info exists old_lc_all]} {
+ set env(LC_ALL) $old_lc_all
+ } else {
+ unset env(LC_ALL)
+ }
+ set comp_output [prune_warnings $comp_output]
+
+ if ![string match "" $comp_output] then {
+ send_log "$comp_output\n"
+ set failed 1
+ break
+ }
+
+ if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/$dumpfile"] } then {
+ verbose -log "output is [file_contents "tmpdir/dump.out"]" 2
+ set failed 1
+ break
+ }
+ }
+ }
+ }
+
+ if { $failed } {
+ fail $test_name
+ } elseif { $is_unresolved } {
+ unresolved $test_name
+ } else {
+ pass $test_name
+ }
+ }
+}
+
+run_cc_link_tests [list \
+ [list \
+ "Build strip-1a.o" \
+ "" \
+ "-O2 -flto $lto_no_fat" \
+ { strip-1a.c } \
+ ] \
+ [list \
+ "Build libstrip-1a.a" \
+ "$plug_opt" \
+ "-O2 -flto $lto_no_fat" \
+ { strip-1a.c } \
+ {} \
+ "libstrip-1a.a" \
+ ] \
+ [list \
+ "Build strip-1a-fat.o" \
+ "" \
+ "-O2 -flto $lto_fat" \
+ { strip-1a-fat.c } \
+ ] \
+ [list \
+ "Build libstrip-1a-fat.a" \
+ "$plug_opt" \
+ "-O2 -flto $lto_fat" \
+ { strip-1a-fat.c } \
+ {} \
+ "libstrip-1a-fat.a" \
+ ] \
+]
+
+run_lto_binutils_test [list \
+ [list \
+ "strip" \
+ "--strip-unneeded" \
+ "libstrip-1a.a" \
+ "libstrip-1a-s.a" \
+ ] \
+ [list \
+ "strip" \
+ "--strip-unneeded" \
+ "strip-1a.o" \
+ "strip-1a-s.o" \
+ ] \
+ [list \
+ "strip" \
+ "--strip-unneeded -R .gnu.*lto_* -N __gnu_lto_v1" \
+ "libstrip-1a-fat.a" \
+ "libstrip-1a-fat-s.a" \
+ {{readelf -SW strip-1a-fat.rd}} \
+ ] \
+ [list \
+ "strip" \
+ "--strip-unneeded -R .gnu.*lto_* -N __gnu_lto_v1" \
+ "strip-1a-fat.o" \
+ "strip-1a-fat-s.o" \
+ {{readelf -SW strip-1a-fat.rd}} \
+ ] \
+ [list \
+ "strip" \
+ "--strip-unneeded -R .gnu.debuglto_*" \
+ "libstrip-1a-fat.a" \
+ "libstrip-1b-fat-s.a" \
+ {{readelf -SW strip-1b-fat.rd}} \
+ ] \
+ [list \
+ "strip" \
+ "--strip-unneeded -R .gnu.debuglto_*" \
+ "strip-1a-fat.o" \
+ "strip-1b-fat-s.o" \
+ {{readelf -SW strip-1b-fat.rd}} \
+ ] \
+]
+
+if { [check_lto_fat_available] } {
+ run_lto_binutils_test [list \
+ [list \
+ "strip" \
+ "-R .gnu.*lto_* -N __gnu_lto_v1" \
+ "strip-1a.o" \
+ "strip-1a-s-all.o" \
+ {{nm -n strip-1a-s-all.nd}} \
+ ] \
+ [list \
+ "strip" \
+ "-R .gnu.*lto_* -N __gnu_lto_v1" \
+ "libstrip-1a.a" \
+ "libstrip-1a-s-all.a" \
+ {{nm -n strip-1a-s-all.nd}} \
+ ] \
+ ]
+}
+
+run_cc_link_tests [list \
+ [list \
+ "Build strip-1a (strip-1a.o)" \
+ "" \
+ "-O2 -flto $lto_no_fat" \
+ { strip-1b.c } \
+ {} \
+ "libstrip-1a" \
+ "C" \
+ "tmpdir/strip-1a.o" \
+ ] \
+ [list \
+ "Build strip-1b (strip-1a-s.o)" \
+ "" \
+ "-O2 -flto $lto_no_fat" \
+ { strip-1b.c } \
+ {} \
+ "libstrip-1b" \
+ "C" \
+ "tmpdir/strip-1a-s.o" \
+ ] \
+ [list \
+ "Build strip-1c (libstrip-1a.a)" \
+ "" \
+ "-O2 -flto $lto_no_fat" \
+ { strip-1b.c } \
+ {} \
+ "libstrip-1c" \
+ "C" \
+ "tmpdir/libstrip-1a.a" \
+ ] \
+ [list \
+ "Build strip-1d (libstrip-1a-s.a)" \
+ "" \
+ "-O2 -flto $lto_no_fat" \
+ { strip-1b.c } \
+ {} \
+ "libstrip-1d" \
+ "C" \
+ "tmpdir/libstrip-1a-s.a" \
+ ] \
+ [list \
+ "Build strip-1e (strip-1a-fat-s.o)" \
+ "" \
+ "-O2 -flto $lto_fat" \
+ { strip-1b-fat.c } \
+ {} \
+ "libstrip-1e" \
+ "C" \
+ "tmpdir/strip-1a-fat-s.o" \
+ ] \
+ [list \
+ "Build strip-1f (libstrip-1a-fat-s.a)" \
+ "" \
+ "-O2 -flto $lto_fat" \
+ { strip-1b-fat.c } \
+ {} \
+ "libstrip-1f" \
+ "C" \
+ "tmpdir/libstrip-1a-fat-s.a" \
+ ] \
+ [list \
+ "Build strip-1g (strip-1b-fat-s.o)" \
+ "" \
+ "-O2 -flto $lto_fat" \
+ { strip-1b-fat.c } \
+ {} \
+ "libstrip-1g" \
+ "C" \
+ "tmpdir/strip-1b-fat-s.o" \
+ ] \
+ [list \
+ "Build strip-1h (libstrip-1b-fat-s.a)" \
+ "" \
+ "-O2 -flto $lto_fat" \
+ { strip-1b-fat.c } \
+ {} \
+ "libstrip-1h" \
+ "C" \
+ "tmpdir/libstrip-1b-fat-s.a" \
+ ] \
+]
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 556bbe9..f0d0954 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -477,6 +477,12 @@ set lto_link_elf_tests [list \
[list {liblto-19.so} \
{-shared tmpdir/lto-19b.o tmpdir/liblto-19.a} {-O2 -fPIC} \
{dummy.c} {} {liblto-19.so}] \
+ [list {liblto-20_static.a} \
+ {} {-fPIC} \
+ {lto-20b.c} {} {liblto-20_static.a}] \
+ [list {liblto-20.so} \
+ {-shared -Wl,--version-script=lto-20.ver} {-DSHARED -fPIC} \
+ {lto-20b.c} {} {liblto-20.so}] \
[list {pr26806.so} \
{-shared} {-fpic -O2 -flto} \
{pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \
@@ -880,6 +886,10 @@ set lto_run_elf_shared_tests [list \
{-Wl,--as-needed,-R,tmpdir} {} \
{lto-19c.c} {lto-19.exe} {pass.out} {-flto -O2} {c} {} \
{tmpdir/liblto-19.so tmpdir/liblto-19.a}] \
+ [list {lto-20} \
+ {-Wl,--as-needed,-R,tmpdir} {} \
+ {lto-20a.c} {lto-20.exe} {pass.out} {-flto} {c} {} \
+ {tmpdir/liblto-20.so tmpdir/liblto-20_static.a -Wl,--no-as-needed}] \
[list {pr31482a} \
{-Wl,--no-as-needed,-R,tmpdir} {} \
{pr31482a.c} {pr31482a.exe} {pass.out} {-flto} {c} {} \
@@ -1148,9 +1158,8 @@ remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
run_dump_test "lto-10r"
remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
set testname "nm mixed object"
-set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
-if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
- set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
+if { $plug_opt != "" } {
+ set exec_output [run_host_cmd "$NM" "$plug_opt tmpdir/lto-10.o"]
if { [ regexp "(D|T) main" $exec_output ] } {
pass $testname
} else {
@@ -1202,6 +1211,38 @@ if { [is_elf_format] } {
if { [is_elf_format] && [check_lto_shared_available] } {
run_ld_link_exec_tests $lto_run_elf_shared_tests
+ if { [check_lto_fat_available] } {
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr32846a.a" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846a.c pr32846b.c} {} "libpr32846a.a" \
+ ] \
+ [list \
+ "Build libpr32846b.a" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846a.c pr32846b.c pr32846c.c} {} "libpr32846b.a" \
+ ] \
+ [list \
+ "Build pr32846d.o" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846d.c} {} \
+ ] \
+ [list \
+ "Build pr32846e.o" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846e.c} {} \
+ ] \
+ [list \
+ "Build pr32846" \
+ "-shared -fPIC -O2 -flto $lto_no_fat -Wl,--no-undefined \
+ tmpdir/pr32846d.o tmpdir/libpr32846a.a \
+ tmpdir/libpr32846b.a tmpdir/pr32846e.o" \
+ "-O2 -fPIC -flto $lto_no_fat" \
+ {dummy.c} {} "pr32846" \
+ ] \
+ ] \
+ }
}
proc pr20103 {cflags libs} {
diff --git a/ld/testsuite/ld-plugin/pr25618a.h b/ld/testsuite/ld-plugin/pr25618a.h
index 9bf857c..04be194 100644
--- a/ld/testsuite/ld-plugin/pr25618a.h
+++ b/ld/testsuite/ld-plugin/pr25618a.h
@@ -1,2 +1 @@
-#pragma once
__attribute__((visibility("default"))) int bar();
diff --git a/ld/testsuite/ld-plugin/pr25618b.h b/ld/testsuite/ld-plugin/pr25618b.h
index cd80074..65e72a0 100644
--- a/ld/testsuite/ld-plugin/pr25618b.h
+++ b/ld/testsuite/ld-plugin/pr25618b.h
@@ -1,2 +1 @@
-#pragma once
__attribute__((visibility("default"))) int foo();
diff --git a/ld/testsuite/ld-plugin/pr32846a.c b/ld/testsuite/ld-plugin/pr32846a.c
new file mode 100644
index 0000000..8c16171
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846a.c
@@ -0,0 +1,6 @@
+extern void mkdir_p (void);
+void
+mkdir_parents (void)
+{
+ mkdir_p ();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846b.c b/ld/testsuite/ld-plugin/pr32846b.c
new file mode 100644
index 0000000..9776a37
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846b.c
@@ -0,0 +1,4 @@
+void
+hash_new (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr32846c.c b/ld/testsuite/ld-plugin/pr32846c.c
new file mode 100644
index 0000000..f87cffb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846c.c
@@ -0,0 +1,6 @@
+extern void hash_new (void);
+void
+kmod_new (void)
+{
+ hash_new();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846d.c b/ld/testsuite/ld-plugin/pr32846d.c
new file mode 100644
index 0000000..c6f4102
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846d.c
@@ -0,0 +1,12 @@
+extern void kmod_new (void);
+extern void mkdir_parents (void);
+void
+do_lsmod (void)
+{
+ kmod_new ();
+}
+void
+do_static_nodes (void)
+{
+ mkdir_parents();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846e.c b/ld/testsuite/ld-plugin/pr32846e.c
new file mode 100644
index 0000000..c4e5e56
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846e.c
@@ -0,0 +1,4 @@
+void
+mkdir_p (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.c b/ld/testsuite/ld-plugin/strip-1a-fat.c
new file mode 100644
index 0000000..03b2a5c
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1a-fat.c
@@ -0,0 +1 @@
+#include "strip-1a.c"
diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.rd b/ld/testsuite/ld-plugin/strip-1a-fat.rd
new file mode 100644
index 0000000..aefe1c5
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1a-fat.rd
@@ -0,0 +1,6 @@
+#failif
+#...
+Section Headers:
+#...
+ \[[ 0-9]+\] \.gnu.lto_.*
+#...
diff --git a/ld/testsuite/ld-plugin/strip-1a-s-all.nd b/ld/testsuite/ld-plugin/strip-1a-s-all.nd
new file mode 100644
index 0000000..612ba6a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1a-s-all.nd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]* C _?__gnu_lto_slim
+#pass
diff --git a/ld/testsuite/ld-plugin/strip-1a.c b/ld/testsuite/ld-plugin/strip-1a.c
new file mode 100644
index 0000000..d84af20
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1a.c
@@ -0,0 +1,4 @@
+extern void foo2(void);
+extern void foo3(void);
+void foo1(void) { foo3(); }
+int main(void) { foo2(); }
diff --git a/ld/testsuite/ld-plugin/strip-1b-fat.c b/ld/testsuite/ld-plugin/strip-1b-fat.c
new file mode 100644
index 0000000..1a2e4d2
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1b-fat.c
@@ -0,0 +1 @@
+#include "strip-1b.c"
diff --git a/ld/testsuite/ld-plugin/strip-1b-fat.rd b/ld/testsuite/ld-plugin/strip-1b-fat.rd
new file mode 100644
index 0000000..e3a266f
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1b-fat.rd
@@ -0,0 +1,5 @@
+#...
+Section Headers:
+#...
+ \[[ 0-9]+\] \.gnu.lto_.*
+#pass
diff --git a/ld/testsuite/ld-plugin/strip-1b.c b/ld/testsuite/ld-plugin/strip-1b.c
new file mode 100644
index 0000000..967872a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1b.c
@@ -0,0 +1,3 @@
+extern void foo1(void);
+void foo2(void) { foo1(); }
+void foo3(void) {}