mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
9e2278f567
PR ld/12672 bfd/ * bfd.c (BFD_PLUGIN): Define. (BFD_FLAGS_SAVED, BFD_FLAGS_FOR_BFD_USE_MASK): Add BFD_PLUGIN. * bfd-in2.h: Regenerate. * elflink.c (elf_link_output_extsym): Strip undefined plugin syms. * opncls.c (bfd_make_readable): Don't lose original bfd flags. ld/ * ldfile.c (ldfile_try_open_bfd): Don't attempt any plugin action when no_more_claiming. * ldmain.c (add_archive_element): Likewise. (multiple_definition): Remove plugin_multiple_definition call. (notice): Remove plugin_notice call. * ldlang.c (lang_list_insert_after, void lang_list_remove_tail): Move. Delete prototype. (plugin_insert): New static var. (open_input_bfds): Only rescan libs after plugin insert point. (lang_gc_sections): Omit plugin claimed files. (lang_process): Set plugin_insert. Only rescan when plugin adds objects. * plugin.h (no_more_claiming): Declare. (plugin_notice, plugin_multiple_definition): Don't declare. * plugin.c: Formatting. (orig_notice_all, orig_allow_multiple_defs, orig_callbacks, plugin_callbacks): New static vars. (no_more_claiming): Make global. (plugin_cached_allow_multiple_defs): Delete. (plugin_get_ir_dummy_bfd): Set SEC_EXCLUDE on dummy .text section, use newer bfd_make_section variant. Make COMMON section too. Error handling. Correct setting of gp size. (asymbol_from_plugin_symbol): Properly cast last arg of concat. (message): Likewise for ACONCAT. (asymbol_from_plugin_symbol): Use our COMMON section. (get_symbols): When report_plugin_symbols, show visibility too. (init_non_ironly_hash): Move. Don't test non_ironly_hash. (plugin_load_plugins): Save state of linker callbacks, set up to call plugin_notice instead. Call init_non_ironly_hash here. (plugin_call_all_symbols_read): Set plugin_multiple_definition in plugin callbacks. (plugin_notice): Rewrite. (plugin_multiple_definition): Make static, call original callback. ld/testsuite/ * ld-plugin/plugin-7.d: Adjust for plugin changes. * ld-plugin/plugin-8.d: Likewise. * ld-plugin/plugin.exp: Pass --verbose=2 for visibility test, and compare ld output to.. * ld-plugin/plugin-12.d: New.
184 lines
7.0 KiB
Plaintext
184 lines
7.0 KiB
Plaintext
# Expect script for ld-plugin tests
|
|
# Copyright 2010
|
|
# 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 to be configured in.
|
|
if ![check_plugin_api_available] {
|
|
return
|
|
}
|
|
|
|
# And a compiler to be available.
|
|
set can_compile 1
|
|
set failure_kind "unresolved"
|
|
if { [which $CC] == 0 } {
|
|
# Don't fail immediately,
|
|
set can_compile 0
|
|
set failure_kind "unsupported"
|
|
}
|
|
|
|
pass "plugin API enabled"
|
|
|
|
global base_dir
|
|
|
|
# Look for the name we can dlopen in the test plugin's libtool control script.
|
|
set plugin_name [file_contents "$base_dir/libldtestplug.la"]
|
|
set plugin_name [regsub "'.*" [regsub ".*dlname='" "$plugin_name" ""] ""]
|
|
verbose "plugin name is '$plugin_name'"
|
|
|
|
# Use libtool to find full path to 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" 3
|
|
# Look for "objdir=.libs"
|
|
regexp -line "^objdir=.*$" "$lt_config" lt_objdir
|
|
verbose "lt_objdir line is '$lt_objdir'" 3
|
|
set lt_objdir [regsub "objdir=" "$lt_objdir" ""]
|
|
set plugin_path "$base_dir/$lt_objdir/$plugin_name"
|
|
verbose "Full plugin path $plugin_path" 2
|
|
|
|
set regclm "-plugin-opt registerclaimfile"
|
|
set regas "-plugin-opt registerallsymbolsread"
|
|
set regcln "-plugin-opt registercleanup"
|
|
|
|
# In order to define symbols in plugin options in the list of tests below,
|
|
# we need to know if the platform prepends an underscore to C symbols,
|
|
# which we find out by compiling the test objects now. If there is any
|
|
# error compiling, we defer reporting it until after the list of tests has
|
|
# been initialised, so that we can use the names in the list to report;
|
|
# otherwise, we scan one of the files with 'nm' and look for a known symbol
|
|
# in the output to see if it is prefixed or not.
|
|
set failed_compile 0
|
|
set _ ""
|
|
set plugin_nm_output ""
|
|
if { $can_compile && \
|
|
(![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] \
|
|
|| ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] \
|
|
|| ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o]) } {
|
|
# Defer fail until we have list of tests set.
|
|
set failed_compile 1
|
|
}
|
|
|
|
if { $can_compile && !$failed_compile } {
|
|
# Find out if symbols have prefix on this platform before setting tests.
|
|
catch "exec $NM tmpdir/func.o" plugin_nm_output
|
|
if { [regexp "_func" "$plugin_nm_output"] } {
|
|
set _ "_"
|
|
}
|
|
}
|
|
|
|
set testobjfiles "tmpdir/main.o tmpdir/func.o tmpdir/text.o"
|
|
set testobjfiles_notext "tmpdir/main.o tmpdir/func.o"
|
|
# Rather than having libs we just define dummy values for anything
|
|
# we may need to link a target exe; we aren't going to run it anyway.
|
|
set libs "[ld_simple_link_defsyms] --defsym ${_}printf=${_}main --defsym ${_}puts=${_}main"
|
|
|
|
set plugin_tests [list \
|
|
[list "load plugin" "-plugin $plugin_path \
|
|
$testobjfiles $libs" "" "" {{ld plugin-1.d}} "main.x" ] \
|
|
[list "fail plugin onload" "-plugin $plugin_path -plugin-opt failonload \
|
|
$testobjfiles $libs" "" "" {{ld plugin-2.d}} "main.x" ] \
|
|
[list "fail plugin allsymbolsread" "-plugin $plugin_path $regas \
|
|
-plugin-opt failallsymbolsread \
|
|
$testobjfiles $libs" "" "" {{ld plugin-3.d}} "main.x" ] \
|
|
[list "fail plugin cleanup" "-plugin $plugin_path -plugin-opt failcleanup \
|
|
$regcln \
|
|
$testobjfiles $libs" "" "" {{ld plugin-4.d}} "main.x" ] \
|
|
[list "plugin all hooks" "-plugin $plugin_path $regclm $regas $regcln \
|
|
$testobjfiles $libs" "" "" {{ld plugin-5.d}} "main.x" ] \
|
|
[list "plugin claimfile lost symbol" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
$testobjfiles $libs" "" "" {{ld plugin-6.d}} "main.x" ] \
|
|
[list "plugin claimfile replace symbol" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
-plugin-opt sym:${_}func::0:0:0 \
|
|
$testobjfiles $libs" "" "" {{ld plugin-7.d}} "main.x" ] \
|
|
[list "plugin claimfile resolve symbol" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
-plugin-opt sym:${_}func::0:0:0 \
|
|
-plugin-opt sym:${_}func2::0:0:0 \
|
|
-plugin-opt dumpresolutions \
|
|
$testobjfiles $libs" "" "" {{ld plugin-8.d}} "main.x" ] \
|
|
[list "plugin claimfile replace file" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
-plugin-opt sym:${_}func::0:0:0 \
|
|
-plugin-opt sym:${_}func2::0:0:0 \
|
|
-plugin-opt dumpresolutions \
|
|
-plugin-opt add:tmpdir/func.o \
|
|
$testobjfiles $libs" "" "" {{ld plugin-9.d}} "main.x" ] \
|
|
]
|
|
|
|
set plugin_lib_tests [list \
|
|
[list "plugin ignore lib" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
-plugin-opt sym:${_}func::0:0:0 \
|
|
-plugin-opt sym:${_}func2::0:0:0 \
|
|
-plugin-opt dumpresolutions \
|
|
-plugin-opt add:tmpdir/func.o \
|
|
$testobjfiles_notext -Ltmpdir -ltext $libs" "" "" {{ld plugin-10.d}} "main.x" ] \
|
|
[list "plugin claimfile replace lib" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
-plugin-opt sym:${_}func::0:0:0 \
|
|
-plugin-opt sym:${_}func2::0:0:0 \
|
|
-plugin-opt dumpresolutions \
|
|
-plugin-opt add:tmpdir/func.o \
|
|
-plugin-opt claim:tmpdir/libtext.a \
|
|
-plugin-opt sym:${_}text::0:0:0 \
|
|
-plugin-opt add:tmpdir/text.o \
|
|
$testobjfiles_notext -Ltmpdir -ltext $libs" "" "" {{ld plugin-11.d}} "main.x" ] \
|
|
]
|
|
|
|
set plugin_extra_elf_tests [list \
|
|
[list "plugin set symbol visibility" "-plugin $plugin_path $regclm \
|
|
$regas $regcln -plugin-opt claim:tmpdir/func.o \
|
|
-plugin-opt sym:${_}func::0:0:0 \
|
|
-plugin-opt sym:${_}func1::0:1:0 \
|
|
-plugin-opt sym:${_}func2::0:2:0 \
|
|
-plugin-opt sym:${_}func3::0:3:0 \
|
|
-plugin-opt dumpresolutions \
|
|
-plugin-opt add:tmpdir/func.o \
|
|
$testobjfiles $libs --verbose=2" "" "" {{ld plugin-12.d}} "main.x" ] \
|
|
]
|
|
|
|
if { !$can_compile || $failed_compile } {
|
|
foreach testitem $plugin_tests {
|
|
$failure_kind [lindex $testitem 0]
|
|
}
|
|
if { [is_elf_format] } {
|
|
foreach testitem $plugin_extra_elf_tests {
|
|
$failure_kind [lindex $testitem 0]
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
run_ld_link_tests $plugin_tests
|
|
|
|
if { [is_elf_format] } {
|
|
run_ld_link_tests $plugin_extra_elf_tests
|
|
}
|
|
|
|
if ![ar_simple_create $ar "" "tmpdir/libtext.a" "tmpdir/text.o"] {
|
|
foreach testitem $plugin_lib_tests {
|
|
unresolved [lindex $testitem 0]
|
|
}
|
|
} else {
|
|
run_ld_link_tests $plugin_lib_tests
|
|
}
|