0a61824343
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.
58 lines
2 KiB
Text
58 lines
2 KiB
Text
# 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]
|
|
}
|