aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2024-06-26 13:17:25 +0100
committerNick Clifton <nickc@redhat.com>2024-06-26 13:17:25 +0100
commit057a2b4c4b57ef495dd32c9087e4af28bda41737 (patch)
tree786c186658cf26b13839680cc6d36b1b6d6ffc07 /ld/testsuite
parentcbccccfdf19a388abb10579aea42c8b35c25c933 (diff)
downloadgdb-057a2b4c4b57ef495dd32c9087e4af28bda41737.zip
gdb-057a2b4c4b57ef495dd32c9087e4af28bda41737.tar.gz
gdb-057a2b4c4b57ef495dd32c9087e4af28bda41737.tar.bz2
Revert: 35fd2ddeb1d90f1750401cfb6d01fe055656b88d
PR 20814
Diffstat (limited to 'ld/testsuite')
-rw-r--r--ld/testsuite/ld-plugin/libdep-a.c7
-rw-r--r--ld/testsuite/ld-plugin/libdep-b.c5
-rw-r--r--ld/testsuite/ld-plugin/libdep-main.c7
-rw-r--r--ld/testsuite/ld-plugin/libdep.exp123
4 files changed, 142 insertions, 0 deletions
diff --git a/ld/testsuite/ld-plugin/libdep-a.c b/ld/testsuite/ld-plugin/libdep-a.c
new file mode 100644
index 0000000..5a01ce8
--- /dev/null
+++ b/ld/testsuite/ld-plugin/libdep-a.c
@@ -0,0 +1,7 @@
+extern int g (void);
+
+int
+f (void)
+{
+ return g();
+}
diff --git a/ld/testsuite/ld-plugin/libdep-b.c b/ld/testsuite/ld-plugin/libdep-b.c
new file mode 100644
index 0000000..d2ca7e0
--- /dev/null
+++ b/ld/testsuite/ld-plugin/libdep-b.c
@@ -0,0 +1,5 @@
+int
+g (void)
+{
+ return 4;
+}
diff --git a/ld/testsuite/ld-plugin/libdep-main.c b/ld/testsuite/ld-plugin/libdep-main.c
new file mode 100644
index 0000000..7563a7d
--- /dev/null
+++ b/ld/testsuite/ld-plugin/libdep-main.c
@@ -0,0 +1,7 @@
+extern int f (void);
+
+int
+main (void)
+{
+ return f();
+}
diff --git a/ld/testsuite/ld-plugin/libdep.exp b/ld/testsuite/ld-plugin/libdep.exp
new file mode 100644
index 0000000..e0afcfc
--- /dev/null
+++ b/ld/testsuite/ld-plugin/libdep.exp
@@ -0,0 +1,123 @@
+# Expect script for ld-plugin LIBDEP tests
+# Copyright (C) 2024 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.
+
+# These tests require the plugin API.
+if { ![check_plugin_api_available] } {
+ return
+}
+
+# Check to see if the C compiler works
+# FIXME: This is being lazy, we could create assembler equivalents instead.
+if { ![check_compiler_available] } {
+ return
+}
+
+proc run_test { } {
+ global CC_FOR_TARGET
+ global srcdir
+ global subdir
+ global ar
+ global ld
+ global libdep
+ global base_dir
+
+ set testname "libdep test"
+
+ # Create temporary directories if they do not already exist.
+ file mkdir -p libdep-a libdep-b
+
+ # Delete old versions of the files we are about to build, just in case.
+ file delete libdep-a/a.o libdep-a/liba.a libdep-b/b.o libdep-b/libc.a libdep-main.o
+
+ # Build object files.
+ if {![ld_compile $CC_FOR_TARGET $srcdir/$subdir/libdep-a.c libdep-a/a.o]} {
+ fail "$testname: could not compile source file 1"
+ return
+ }
+ if {![ld_compile $CC_FOR_TARGET $srcdir/$subdir/libdep-b.c libdep-b/b.o]} {
+ fail "$testname: could not compile source file 2"
+ return
+ }
+ if {![ld_compile $CC_FOR_TARGET $srcdir/$subdir/libdep-main.c libdep-main.o]} {
+ fail "$testname: could not compile source file 3"
+ return
+ }
+
+ # Create static archives from the objects.
+
+ # For the first archive we add a libdep element that loads the second library.
+ if {![ar_simple_create $ar {--record-libdeps "-Llibdep-b -lc"} libdep-a/liba.a libdep-a/a.o]} {
+ fail "$testname: could not create archive 1"
+ return
+ }
+
+ # For the second archive we choose a name - libc.a - that is likely to clash
+ # with a system library. This will help to check that the library loaded by
+ # following the libdep element in the first library is the one that we expect.
+ if {![ar_simple_create $ar {} libdep-b/libc.a libdep-b/b.o]} {
+ fail "$testname: could not create archive 2"
+ return
+ }
+
+ # Find the libdep plugin.
+ # Use libtool to find the path to the plugin rather
+ # than worrying about run paths or anything like that.
+ catch "exec $base_dir/libtool --config" lt_config
+ verbose "Full lt config: $lt_config" 2
+ # Look for "objdir=.libs"
+ regexp -line "^objdir=.*$" "$lt_config" lt_objdir
+ verbose "lt_objdir line is '$lt_objdir'" 2
+ set lt_objdir [regsub "objdir=" "$lt_objdir" ""]
+
+ if { [ file exists "$base_dir/$lt_objdir/libdep.so" ] } {
+ set libdep "$base_dir/$lt_objdir/libdep.so"
+ } else {
+ # FIXME: Check in the system bfd-plugin directory ?
+ fail "$testname - could not locate libdep plugin"
+ }
+
+ verbose "Full plugin path: $libdep" 1
+
+ # Link the main object file with the liba.a library.
+ # Use the libdep plugin to read the __.LIBDEP element in the liba.a library
+ # and so bring in the libdep-b.o object file from the libc.a library.
+ # Failure to locate the libc.a library, or loading the wrong libc.a library
+ # will result in an unresolved reference error.
+ set exec_output [run_host_cmd "$ld" "-plugin $libdep -o libdep.exe libdep-main.o -L libdep-a -la -e 0"]
+ set exec_output [prune_warnings $exec_output]
+
+ set expected_output "got deps for library libdep-a/liba.a: -Llibdep-b -lc"
+
+ if ![string match $expected_output $exec_output] then {
+ fail "$testname: did not get expected output from the linker"
+ return
+ }
+
+ regsub -all "$expected_output" $exec_output "\\1" exec_output
+
+ if {![string match "" $exec_output]} {
+ fail "$testname: unexpected output from linker: $exec_output"
+ return
+ }
+
+ pass "$testname"
+}
+
+run_test