aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-undefined
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2015-07-15 18:37:30 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2015-08-04 10:00:05 +0100
commit0a61824343c98b9440fe13752f800d65f765c4c1 (patch)
treeb4a6e80aed76a598ca778adb188cc257c8c74a46 /ld/testsuite/ld-undefined
parent96e9210fd6fecc1926559dbfa45e7c7c59f7d821 (diff)
downloadgdb-0a61824343c98b9440fe13752f800d65f765c4c1.zip
gdb-0a61824343c98b9440fe13752f800d65f765c4c1.tar.gz
gdb-0a61824343c98b9440fe13752f800d65f765c4c1.tar.bz2
ld: Add '--require-defined' command line option.
Add a new command line option '--require-defined' to the linker. This option operates identically to the '--undefined' option, except that if the symbol is not defined in the final output file then the linker will exit with an error. When making use of --gc-section, or just when trying to pull in parts of a library, it is not uncommon for a user to use the '--undefined' command line option to specify a symbol that the user then expects to be defined by one of the object files supplied to the link. However, if for any reason the symbol is not satisfied by an object provided to the link the user will be left with an undefined symbol in the output file, instead of a defined symbol. In some cases the above behaviour is what the user wants, in other cases though we can do better. The '--require-defined' option tries to fill this gap. The symbol passed to the '--require-defined' option is treated exactly as if the symbol was passed to '--undefined', however, before the linker exits a check is made that all symbols passed to '--require-defined' are actually defined, if any are not then the link will fail with an error. ld/ChangeLog: * ld.texinfo (Options): Document --require-defined option. * ldlang.c (struct require_defined_symbol): New structure. (require_defined_symbol_list): New variable. (ldlang_add_require_defined): New function. (ldlang_check_require_defined_symbols): New function. (lang_process): Check required symbols are defined. * ldlang.h (ldlang_add_require_defined): Declare. * ldlex.h (enum option_values): Add OPTION_REQUIRE_DEFINED_SYMBOL. * lexsup.c (ld_options): Add '--require-defined' entry. (parse_args): Handle '--require-defined' entry. * NEWS: Mention new '--require-defined' option. ld/testsuite/ChangeLog: * ld-undefined/require-defined-1.d: New file. * ld-undefined/require-defined-2.d: New file. * ld-undefined/require-defined-3.d: New file. * ld-undefined/require-defined-4.d: New file. * ld-undefined/require-defined-5.d: New file. * ld-undefined/require-defined.exp: New file. * ld-undefined/require-defined.s: New file.
Diffstat (limited to 'ld/testsuite/ld-undefined')
-rw-r--r--ld/testsuite/ld-undefined/require-defined-1.d4
-rw-r--r--ld/testsuite/ld-undefined/require-defined-2.d8
-rw-r--r--ld/testsuite/ld-undefined/require-defined-3.d8
-rw-r--r--ld/testsuite/ld-undefined/require-defined-4.d8
-rw-r--r--ld/testsuite/ld-undefined/require-defined-5.d10
-rw-r--r--ld/testsuite/ld-undefined/require-defined.exp58
-rw-r--r--ld/testsuite/ld-undefined/require-defined.s9
7 files changed, 105 insertions, 0 deletions
diff --git a/ld/testsuite/ld-undefined/require-defined-1.d b/ld/testsuite/ld-undefined/require-defined-1.d
new file mode 100644
index 0000000..12b0cf5
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined-1.d
@@ -0,0 +1,4 @@
+#name: Check require-defined with an undefined symbol
+#source: require-defined.s
+#ld: -e _start --gc-sections --require-defined=xxx
+#error: required symbol `xxx' not defined
diff --git a/ld/testsuite/ld-undefined/require-defined-2.d b/ld/testsuite/ld-undefined/require-defined-2.d
new file mode 100644
index 0000000..e770eea
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined-2.d
@@ -0,0 +1,8 @@
+#name: Check require-defined can require a symbol from an object
+#source: require-defined.s
+#ld: -e _start --gc-sections --require-defined=bar
+#nm: -n
+
+#...
+[0-9a-f]+ T bar
+#...
diff --git a/ld/testsuite/ld-undefined/require-defined-3.d b/ld/testsuite/ld-undefined/require-defined-3.d
new file mode 100644
index 0000000..c61ed34
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined-3.d
@@ -0,0 +1,8 @@
+#name: Check require-defined does no error on a defined symbol
+#source: require-defined.s
+#ld: -e _start --require-defined=bar
+#nm: -n
+
+#...
+[0-9a-f]+ T bar
+#...
diff --git a/ld/testsuite/ld-undefined/require-defined-4.d b/ld/testsuite/ld-undefined/require-defined-4.d
new file mode 100644
index 0000000..2922c99
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined-4.d
@@ -0,0 +1,8 @@
+#name: Check require-defined can require a symbol from an archive
+#source: require-defined.s
+#ld: -e _start --require-defined=foo tmpdir/libfoo.a
+#nm: -n
+
+#...
+[0-9a-f]+ T foo
+#...
diff --git a/ld/testsuite/ld-undefined/require-defined-5.d b/ld/testsuite/ld-undefined/require-defined-5.d
new file mode 100644
index 0000000..ea288a9
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined-5.d
@@ -0,0 +1,10 @@
+#name: Check require-defined can require two symbols
+#source: require-defined.s
+#ld: -e _start --gc-sections --require-defined=bar --require-defined=foo tmpdir/libfoo.a
+#nm: -n
+
+#...
+[0-9a-f]+ T foo
+#...
+[0-9a-f]+ T bar
+#... \ No newline at end of file
diff --git a/ld/testsuite/ld-undefined/require-defined.exp b/ld/testsuite/ld-undefined/require-defined.exp
new file mode 100644
index 0000000..16013dc
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined.exp
@@ -0,0 +1,58 @@
+# Expect script for ld --undefined and --require-defined testing.
+# Copyright (C) 2015 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.
+#
+
+# Some of these tests use --gc-sections. For now we don't attempt any
+# if --gc-sections is unavailable, as most major targets do support
+# this option.
+if ![check_gc_sections_available] {
+ unsupported "require-defined testing"
+ return
+}
+
+# The following targets all fail these tests for reasons that appear
+# to be unrelated to the test themselves (for example some of these
+# targets require more complex linker scripts). Given the small
+# number of targets, I'm just skipping the tests in these cases.]
+if { [istarget "powerpcle-*-*"] \
+ || [istarget "cris-axis-elf"] \
+ || [istarget "ns32k-*-netbsd"] \
+ || [istarget "*-*-coff"] \
+ || [istarget "*-*-xcoff"] \
+ || [istarget "*-*-*aout*"] \
+ || [istarget "*-*-*aix*"] } {
+ unsupported "require-defined testing"
+ return
+}
+
+set build_tests {
+ {"Build libfoo.a"
+ "" "" ""
+ {entry.s} {} "libfoo.a"}
+}
+
+run_ld_link_tests $build_tests
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/require-defined*.d]]
+foreach t $test_list {
+ # We need to strip the ".d", but can leave the dirname.
+ verbose [file rootname $t]
+ run_dump_test [file rootname $t]
+}
diff --git a/ld/testsuite/ld-undefined/require-defined.s b/ld/testsuite/ld-undefined/require-defined.s
new file mode 100644
index 0000000..2bda640
--- /dev/null
+++ b/ld/testsuite/ld-undefined/require-defined.s
@@ -0,0 +1,9 @@
+ .text
+ .global _start
+_start:
+ .word 0
+
+ .section .text.1, "ax"
+ .global bar
+bar:
+ .word 0