aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
diff options
context:
space:
mode:
authorDave Korn <dave.korn@artimi.com>2010-10-14 01:31:33 +0000
committerDave Korn <dave.korn@artimi.com>2010-10-14 01:31:33 +0000
commit5d3236eea075e471b90b4d89bc459645abe9f50c (patch)
tree2f7cc493bbaaf54cbf2f08b4deda9e518da7f361 /ld/testsuite
parentc2a41a512856084bbcd0cad73c54d886c5d4fa7d (diff)
downloadgdb-5d3236eea075e471b90b4d89bc459645abe9f50c.zip
gdb-5d3236eea075e471b90b4d89bc459645abe9f50c.tar.gz
gdb-5d3236eea075e471b90b4d89bc459645abe9f50c.tar.bz2
Applied patch series for LD plugin interface (six parts).
[PATCH] Add infrastructure for plugin API; functionality to follow. include/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 1/6). * plugin-api.h (LDPT_GNU_LD_VERSION): New ld_plugin_tag enum member. ld/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 1/6). * configure.in: Add AC_CHECKs for file io and dlfcn headers and functions and AC_SEARCH for -ldl. (enable_plugins): New shell variable set if above tests find dlopen functionality. (ENABLE_PLUGINS): Add related automake conditional. * configure: Regenerate. * config.in: Likewise. * Makefile.am (PLUGIN_C): Declare plugin C source file, conditional on ENABLE_PLUGINS being defined. (PLUGIN_H): Likewise for header file. (PLUGIN_OBJECT): Likewise for object file. (PLUGIN_CFLAGS): Likewise -D flag required to compile plugin support. (AM_CPPFLAGS): Use PLUGIN_CFLAGS. (CFILES): Use PLUGIN_C. (HFILES): Use PLUGIN_H. (OFILES): Use PLUGIN_OBJECT. (ld_new_SOURCES): Use PLUGIN_C. (noinst_LTLIBRARIES)[ENABLE_PLUGINS]: Declare test plugin. (libldtestplug_la_SOURCES)[ENABLE_PLUGINS]: Add automake definition for test plugin. (libldtestplug_la_CFLAGS)[ENABLE_PLUGINS]: Likewise. (libldtestplug_la_LDFLAGS)[ENABLE_PLUGINS]: Likewise. * Makefile.in: Regenerate. * sysdep.h: Include stdarg.h, unistd.h and one of fcntl.h or sys/file.h where available. Include dlfcn.h when ENABLE_PLUGINS. (O_RDONLY): Supply default definition likewise to bfd's sysdep.h (O_WRONLY): Likewise. (O_RDWR): Likewise. (O_ACCMODE): Likewise. (O_BINARY): Likewise. (SEEK_SET): Likewise. (SEEK_CUR): Likewise. (SEEK_END): Likewise. * ldmisc.c (vfinfo): Make non-static. Add %p format char. * ldmisc.h (vfinfo): Declare extern prototype. * lexsup.c (enum option_values)[ENABLE_PLUGINS]: Add new entries for OPTION_PLUGIN and OPTION_PLUGIN_OPT. (ld_options[])[ENABLE_PLUGINS]: Add option data for the above two. (parse_args)[ENABLE_PLUGINS]: Handle them, and load all plugins once option parsing is complete. * ldmain.c (main)[ENABLE_PLUGINS]: Call plugin cleanup hooks just after lang_finish. * plugin.c: New source file. * plugin.h: Likewise new header. * testplug.c: New source file. ld/testsuite/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 1/6). * ld-bootstrap/bootstrap.exp: Skip static tests also if LD plugins are enabled. * lib/ld-lib.exp (proc regexp_diff): Extend verbose debug output. (proc set_file_contents): Write a file with the supplied content. (run_ld_link_tests): Add new 'ld' action to test linker output. (proc check_plugin_api_available): Return true if linker under test supports the plugin API. * ld-plugin/func.c: New test source file. * ld-plugin/main.c: Likewise. * ld-plugin/text.c: Likewise. * ld-plugin/plugin-1.d: New dump test output pattern script. * ld-plugin/plugin-2.d: Likewise. * ld-plugin/plugin-3.d: Likewise. * ld-plugin/plugin-4.d: Likewise. * ld-plugin/plugin-5.d: Likewise. * ld-plugin/plugin.exp: New test control script. --- [PATCH] Implement claim file and all symbols read hooks and add symbols callback. ld/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 2/6). * ldfile.c (ldfile_try_open_bfd)[ENABLE_PLUGINS]: Don't return early during compat checks if they pass, instead offer any successfully opened and accepted file to the plugin claim file hooks chain. Create a dummy bfd to accept symbols added by the plugin, if the plugin claims the file. * ldlang.c (lang_process)[ENABLE_PLUGINS]: Call plugin all symbols read hook chain before ldemul_after_open. * ldlang.h (struct lang_input_statement_struct): Add new single-bit 'claimed' flag. * plugin.c (IRONLY_SUFFIX): New macro for dummy bfd file suffix. (IRONLY_SUFFIX_LEN): Length of the above string. (plugin_get_ir_dummy_bfd): New function to create the dummy bfd used to store symbols for ir-only files. (is_ir_dummy_bfd): New function to check if a bfd is ir-only. (asymbol_from_plugin_symbol): New function converts symbol formats. (add_symbols): Call it to convert plugin syms to bfd syms and add them to the dummy bfd. * plugin.h: Add missing include guards. (plugin_get_ir_dummy_bfd): Add prototype. (is_ir_dummy_bfd): Likewise. * testplug.c (TV_MESSAGE): New helper macro. (struct claim_file): New struct. (claim_file_t): New typedef. (tag_names[]): Make static and const. (claimfiles_list): New variable. (claimfiles_tail_chain_ptr): Likewise. (last_claimfile): Likewise. (record_claim_file): Record a file to claim on a singly-linked list. (parse_symdefstr): Parse an ASCII representation of a symbol from a plugin option into the fields of a struct ld_plugin_symbol. (record_claimed_file_symbol): Use it to parse plugin option for adding a symbol. (parse_option): Parse claim file and add symbol options. (dump_tv_tag): Use TV_MESSAGE. (onload): Likewise. (onclaim_file): Make static. Use TV_MESSAGE. Scan list of files to claim and claim this file if required, adding any symbols specified. (onall_symbols_read): Make static and use TV_MESSAGE. (oncleanup): Likewise. ld/testsuite/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 2/6). * ld-plugin/plugin-3.d: Enable regexes for new functionality. * ld-plugin/plugin-5.d: Likewise. * ld-plugin/plugin-6.d: New testcase. * ld-plugin/plugin-7.d: Likewise. * ld-plugin/plugin.exp: Use 'nm' on compiled test objects to determine whether symbols in plugin arguments need an underscore prefix. Add new plugin-6.d and plugin-7.d testcases. --- [PATCH] Implement get symbols callback. ld/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 3/6). * ldmain.c (notice)[ENABLE_PLUGINS]: Call plugin_notice. * plugin.c (non_ironly_hash): Add new bfd hash table. (plugin_load_plugins): Exit early if no plugins to load. If plugins do load successfully, set notice_all flag in link info. (get_symbols): Implement. (plugin_load_plugins): Exit early if no plugins to load, else after loading plugins successfully enable notice_all mode. (init_non_ironly_hash): Lazily init non_ironly_hash table. (plugin_notice): Record symbols referenced from non-IR files in the non_ironly_hash. Suppress tracing, cref generation and nocrossrefs tracking for symbols from dummy IR bfds. * plugin.h: Fix formatting. (plugin_notice): Add prototype. * testplug.c (dumpresolutions): New global var. (parse_options): Accept "dumpresolutions". (onall_symbols_read): Get syms and dump resolutions if it was given. ld/testsuite/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 3/6). * ld-plugin/plugin-8.d: New testcase. * ld-plugin/plugin.exp: Invoke it. --- [PATCH] Implement add input file, add input lib and set extra lib path callbacks. ld/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 4/6). * ldlang.c (lang_process)[ENABLE_PLUGINS]: Move invocation of plugin_call_all_symbols_read to before setting of gc_sym_list, and open any new input files that may have been added during it. * ldmain.c (multiple_definition)[ENABLE_PLUGINS]: Call out to plugin_multiple_definition and let it have first say over what to do with the clashing definitions. * plugin.c (no_more_claiming): New boolean variable. (plugin_cached_allow_multiple_defs): Likewise. (add_input_file): Implement. (add_input_library): Likewise. (set_extra_library_path): Likewise. (plugin_call_claim_file): Don't do anything when no_more_claiming set. (plugin_call_all_symbols_read): Set it. Disable link info "allow_multiple_definition" flag, but cache its value. (plugin_multiple_definition): New function. * plugin.h (plugin_multiple_definition): Add prototype. * testplug.c (addfile_enum_t): New enumerated typedef. (add_file_t): New struct typedef. (addfiles_list): New variable. (addfiles_tail_chain_ptr): Likewise. (record_add_file): New function. (parse_option): Parse "add:", "lib:" and "dir:" options and call it. (onall_symbols_read): Iterate the list of new files, libs and dirs, adding them. ld/testsuite/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 4/6). * ld-plugin/plugin-9.d: New testcase. * ld-plugin/plugin.exp: Invoke it. --- [PATCH] Add ELF symbol visibility support to plugin interface. ld/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 5/6). * plugin.c (asymbol_from_plugin_symbol): If the bfd is an ELF bfd, find the elf symbol data and set the visibility in the st_other field. ld/testsuite/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 5/6). * ld-plugin/plugin-ignore.d: New dump test control script. * ld-plugin/plugin-vis-1.d: Likewise. * ld-plugin/plugin.exp: Add list of ELF-only tests and run them if testing on an ELF target. --- [PATCH] Add archive support to plugin interface. bfd/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 6/6). * aoutx.h (aout_link_check_ar_symbols): Take new "subsbfd" reference parameter and pass it when invoking add_archive_element callback. (aout_link_check_archive_element): Handle substitute bfd if it was set during add_archive_element callback in the above. * cofflink.c (coff_link_check_ar_symbols): Take new "subsbfd" reference parameter and pass it when invoking add_archive_element callback. (coff_link_check_archive_element): Handle substitute bfd if it was set during add_archive_element callback in the above. * ecoff.c (read_ext_syms_and_strs): New function holds symbol-reading code factored-out from ecoff_link_check_archive_element. (reread_ext_syms_and_strs): Clear old symbols and call it. (ecoff_link_check_archive_element): Use the above. Handle substitute BFD if one is set by add_archive_element callback. (ecoff_link_add_archive_symbols): Likewise allow bfd substitution. * elflink.c (elf_link_add_archive_symbols): Likewise. * linker.c (generic_link_check_archive_element): Likewise. * pdp11.c (aout_link_check_ar_symbols): Take new "subsbfd" reference parameter and pass it when invoking add_archive_element callback. (aout_link_check_archive_element): Handle substitute bfd if it was set during add_archive_element callback in the above. * vms-alpha.c (alpha_vms_link_add_archive_symbols): Handle substitute BFD if one is set by add_archive_element callback. * xcofflink.c (xcoff_link_check_dynamic_ar_symbols): Take new "subsbfd" reference parameter and pass it when invoking add_archive_element callback. (xcoff_link_check_ar_symbols): Likewise. (xcoff_link_check_archive_element): Handle bfd substitution if it was set by callback in the above. include/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 6/6). * bfdlink.h (struct_bfd_link_callbacks): Document new argument to add_archive_element callback used to return a replacement bfd which is to be added to the hash table in place of the original element. ld/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 6/6). * ldlang.c (load_symbols): Handle bfd subsitution when calling the add_archive_element callback. * ldmain.c (add_archive_element)[ENABLE_PLUGINS]: Offer the archive member to the plugins and if claimed set "subsbfd" output parameter to point to the dummy IR-only BFD. ld/testsuite/ChangeLog: 2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com> Apply LD plugin patch series (part 6/6). * ld-plugin/plugin-10.d: New dump test control script. * ld-plugin/plugin-11.d: Likewise. * ld-plugin/plugin.exp: Run them. ---
Diffstat (limited to 'ld/testsuite')
-rw-r--r--ld/testsuite/ChangeLog58
-rw-r--r--ld/testsuite/ld-bootstrap/bootstrap.exp5
-rw-r--r--ld/testsuite/ld-plugin/func.c7
-rw-r--r--ld/testsuite/ld-plugin/main.c13
-rw-r--r--ld/testsuite/ld-plugin/plugin-1.d18
-rw-r--r--ld/testsuite/ld-plugin/plugin-10.d36
-rw-r--r--ld/testsuite/ld-plugin/plugin-11.d40
-rw-r--r--ld/testsuite/ld-plugin/plugin-2.d21
-rw-r--r--ld/testsuite/ld-plugin/plugin-3.d22
-rw-r--r--ld/testsuite/ld-plugin/plugin-4.d23
-rw-r--r--ld/testsuite/ld-plugin/plugin-5.d29
-rw-r--r--ld/testsuite/ld-plugin/plugin-6.d31
-rw-r--r--ld/testsuite/ld-plugin/plugin-7.d30
-rw-r--r--ld/testsuite/ld-plugin/plugin-8.d34
-rw-r--r--ld/testsuite/ld-plugin/plugin-9.d35
-rw-r--r--ld/testsuite/ld-plugin/plugin-ignore.d1
-rw-r--r--ld/testsuite/ld-plugin/plugin-vis-1.d9
-rw-r--r--ld/testsuite/ld-plugin/plugin.exp169
-rw-r--r--ld/testsuite/ld-plugin/text.c3
-rw-r--r--ld/testsuite/lib/ld-lib.exp52
20 files changed, 633 insertions, 3 deletions
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 42ab622..654446c 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,61 @@
+2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com>
+
+ Apply LD plugin patch series (part 6/6).
+ * ld-plugin/plugin-10.d: New dump test control script.
+ * ld-plugin/plugin-11.d: Likewise.
+ * ld-plugin/plugin.exp: Run them.
+
+2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com>
+
+ Apply LD plugin patch series (part 5/6).
+ * ld-plugin/plugin-ignore.d: New dump test control script.
+ * ld-plugin/plugin-vis-1.d: Likewise.
+ * ld-plugin/plugin.exp: Add list of ELF-only tests and run them if
+ testing on an ELF target.
+
+2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com>
+
+ Apply LD plugin patch series (part 4/6).
+ * ld-plugin/plugin-9.d: New testcase.
+ * ld-plugin/plugin.exp: Invoke it.
+
+2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com>
+
+ Apply LD plugin patch series (part 3/6).
+ * ld-plugin/plugin-8.d: New testcase.
+ * ld-plugin/plugin.exp: Invoke it.
+
+2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com>
+
+ Apply LD plugin patch series (part 2/6).
+ * ld-plugin/plugin-3.d: Enable regexes for new functionality.
+ * ld-plugin/plugin-5.d: Likewise.
+ * ld-plugin/plugin-6.d: New testcase.
+ * ld-plugin/plugin-7.d: Likewise.
+ * ld-plugin/plugin.exp: Use 'nm' on compiled test objects to determine
+ whether symbols in plugin arguments need an underscore prefix. Add
+ new plugin-6.d and plugin-7.d testcases.
+
+2010-10-14 Dave Korn <dave.korn.cygwin@gmail.com>
+
+ Apply LD plugin patch series (part 1/6).
+ * ld-bootstrap/bootstrap.exp: Skip static tests also if LD plugins
+ are enabled.
+ * lib/ld-lib.exp (proc regexp_diff): Extend verbose debug output.
+ (proc set_file_contents): Write a file with the supplied content.
+ (run_ld_link_tests): Add new 'ld' action to test linker output.
+ (proc check_plugin_api_available): Return true if linker under test
+ supports the plugin API.
+ * ld-plugin/func.c: New test source file.
+ * ld-plugin/main.c: Likewise.
+ * ld-plugin/text.c: Likewise.
+ * ld-plugin/plugin-1.d: New dump test output pattern script.
+ * ld-plugin/plugin-2.d: Likewise.
+ * ld-plugin/plugin-3.d: Likewise.
+ * ld-plugin/plugin-4.d: Likewise.
+ * ld-plugin/plugin-5.d: Likewise.
+ * ld-plugin/plugin.exp: New test control script.
+
2010-10-11 Alan Modra <amodra@gmail.com>
* ld-elf/orphan-region.d: xfail frv-*-*.
diff --git a/ld/testsuite/ld-bootstrap/bootstrap.exp b/ld/testsuite/ld-bootstrap/bootstrap.exp
index ecc760a..74b6a5c 100644
--- a/ld/testsuite/ld-bootstrap/bootstrap.exp
+++ b/ld/testsuite/ld-bootstrap/bootstrap.exp
@@ -40,6 +40,11 @@ if [info exists plugins] then {
set plugins "no"
}
+# LD can have plugin support even if BFD does not.
+if [check_plugin_api_available] {
+ set plugins "yes"
+}
+
# Bootstrap ld. First link the object files together using -r, in
# order to test -r. Then link the result into an executable, ld1, to
# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
diff --git a/ld/testsuite/ld-plugin/func.c b/ld/testsuite/ld-plugin/func.c
new file mode 100644
index 0000000..8c668db
--- /dev/null
+++ b/ld/testsuite/ld-plugin/func.c
@@ -0,0 +1,7 @@
+
+extern int retval;
+
+int func (void)
+{
+ return retval;
+}
diff --git a/ld/testsuite/ld-plugin/main.c b/ld/testsuite/ld-plugin/main.c
new file mode 100644
index 0000000..2d64617
--- /dev/null
+++ b/ld/testsuite/ld-plugin/main.c
@@ -0,0 +1,13 @@
+
+extern int printf (const char *fmt, ...);
+
+extern const char *text;
+extern int func (void);
+
+int retval = 0;
+
+int main (int argc, const char **argv)
+{
+ printf ("%s\n", text);
+ return func ();
+}
diff --git a/ld/testsuite/ld-plugin/plugin-1.d b/ld/testsuite/ld-plugin/plugin-1.d
new file mode 100644
index 0000000..0ce0794
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-1.d
@@ -0,0 +1,18 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_NULL value 0x0 \(0\)
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-10.d b/ld/testsuite/ld-plugin/plugin-10.d
new file mode 100644
index 0000000..7e3c3bb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-10.d
@@ -0,0 +1,36 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_OPTION 'claim:tmpdir/func.o'
+tv\[19\]: LDPT_OPTION 'sym:_?func::0:0:0'
+tv\[20\]: LDPT_OPTION 'sym:_?func2::0:0:0'
+tv\[21\]: LDPT_OPTION 'dumpresolutions'
+tv\[22\]: LDPT_OPTION 'add:tmpdir/func.o'
+tv\[23\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.* not claimed
+hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
+#...
+hook called: claim_file tmpdir/libtext.a \[@.* not claimed
+#...
+hook called: all symbols read.
+Sym: '_?func' Resolution: LDPR_PREVAILING_DEF
+Sym: '_?func2' Resolution: LDPR_PREVAILING_DEF_IRONLY
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-11.d b/ld/testsuite/ld-plugin/plugin-11.d
new file mode 100644
index 0000000..927cffd
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-11.d
@@ -0,0 +1,40 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_OPTION 'claim:tmpdir/func.o'
+tv\[19\]: LDPT_OPTION 'sym:_?func::0:0:0'
+tv\[20\]: LDPT_OPTION 'sym:_?func2::0:0:0'
+tv\[21\]: LDPT_OPTION 'dumpresolutions'
+tv\[22\]: LDPT_OPTION 'add:tmpdir/func.o'
+tv\[23\]: LDPT_OPTION 'claim:tmpdir/libtext.a'
+tv\[24\]: LDPT_OPTION 'sym:_?text::0:0:0'
+tv\[25\]: LDPT_OPTION 'add:tmpdir/text.o'
+tv\[26\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.* not claimed
+hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
+#...
+hook called: claim_file tmpdir/libtext.a \[@.* CLAIMED
+#...
+hook called: all symbols read.
+Sym: '_?func' Resolution: LDPR_PREVAILING_DEF
+Sym: '_?func2' Resolution: LDPR_PREVAILING_DEF_IRONLY
+Sym: '_?text' Resolution: LDPR_PREVAILING_DEF
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-2.d b/ld/testsuite/ld-plugin/plugin-2.d
new file mode 100644
index 0000000..677f8fb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-2.d
@@ -0,0 +1,21 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'failonload'
+tv\[16\]: LDPT_NULL value 0x0 \(0\)
+#...
+.*ld.*:.*ldtestplug.*: error loading plugin
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-3.d b/ld/testsuite/ld-plugin/plugin-3.d
new file mode 100644
index 0000000..73aba1b
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-3.d
@@ -0,0 +1,22 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[16\]: LDPT_OPTION 'failallsymbolsread'
+tv\[17\]: LDPT_NULL value 0x0 \(0\)
+#...
+.*ld.*:.*ldtestplug.*: plugin reported error after all symbols read
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-4.d b/ld/testsuite/ld-plugin/plugin-4.d
new file mode 100644
index 0000000..580cbac
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-4.d
@@ -0,0 +1,23 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'failcleanup'
+tv\[16\]: LDPT_OPTION 'registercleanup'
+tv\[17\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: cleanup.
+.*ld.*:.*ldtestplug.*: error in plugin cleanup \(ignored\)
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-5.d b/ld/testsuite/ld-plugin/plugin-5.d
new file mode 100644
index 0000000..c0ffa66
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-5.d
@@ -0,0 +1,29 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.*
+hook called: claim_file tmpdir/func.o \[@0/.*
+hook called: claim_file tmpdir/text.o \[@0/.*
+#...
+hook called: all symbols read.
+#...
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-6.d b/ld/testsuite/ld-plugin/plugin-6.d
new file mode 100644
index 0000000..cb9257d
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-6.d
@@ -0,0 +1,31 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_OPTION 'claim:tmpdir/func.o'
+tv\[19\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.* not claimed
+hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
+hook called: claim_file tmpdir/text.o \[@0/.* not claimed
+#...
+hook called: all symbols read.
+tmpdir/main.o: In function `main':
+.*ld/testsuite/ld-plugin/main.c:12: undefined reference to `func'
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-7.d b/ld/testsuite/ld-plugin/plugin-7.d
new file mode 100644
index 0000000..75f25e0
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-7.d
@@ -0,0 +1,30 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_OPTION 'claim:tmpdir/func.o'
+tv\[19\]: LDPT_OPTION 'sym:_?func::0:0:0'
+tv\[20\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.* not claimed
+hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
+hook called: claim_file tmpdir/text.o \[@0/.* not claimed
+#...
+hook called: all symbols read.
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-8.d b/ld/testsuite/ld-plugin/plugin-8.d
new file mode 100644
index 0000000..e72b039
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-8.d
@@ -0,0 +1,34 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_OPTION 'claim:tmpdir/func.o'
+tv\[19\]: LDPT_OPTION 'sym:_?func::0:0:0'
+tv\[20\]: LDPT_OPTION 'sym:_?func2::0:0:0'
+tv\[21\]: LDPT_OPTION 'dumpresolutions'
+tv\[22\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.* not claimed
+hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
+hook called: claim_file tmpdir/text.o \[@0/.* not claimed
+#...
+hook called: all symbols read.
+Sym: '_?func' Resolution: LDPR_PREVAILING_DEF
+Sym: '_?func2' Resolution: LDPR_PREVAILING_DEF_IRONLY
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-9.d b/ld/testsuite/ld-plugin/plugin-9.d
new file mode 100644
index 0000000..b74f4a6
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-9.d
@@ -0,0 +1,35 @@
+Hello from testplugin.
+tv\[0\]: LDPT_MESSAGE func@0x.*
+tv\[1\]: LDPT_API_VERSION value 0x1 \(1\)
+tv\[2\]: LDPT_GNU_LD_VERSION value 0x.*
+tv\[3\]: LDPT_LINKER_OUTPUT value 0x1 \(1\)
+tv\[4\]: LDPT_OUTPUT_NAME 'tmpdir/main.x'
+tv\[5\]: LDPT_REGISTER_CLAIM_FILE_HOOK func@0x.*
+tv\[6\]: LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK func@0x.*
+tv\[7\]: LDPT_REGISTER_CLEANUP_HOOK func@0x.*
+tv\[8\]: LDPT_ADD_SYMBOLS func@0x.*
+tv\[9\]: LDPT_GET_INPUT_FILE func@0x.*
+tv\[10\]: LDPT_RELEASE_INPUT_FILE func@0x.*
+tv\[11\]: LDPT_GET_SYMBOLS func@0x.*
+tv\[12\]: LDPT_ADD_INPUT_FILE func@0x.*
+tv\[13\]: LDPT_ADD_INPUT_LIBRARY func@0x.*
+tv\[14\]: LDPT_SET_EXTRA_LIBRARY_PATH func@0x.*
+tv\[15\]: LDPT_OPTION 'registerclaimfile'
+tv\[16\]: LDPT_OPTION 'registerallsymbolsread'
+tv\[17\]: LDPT_OPTION 'registercleanup'
+tv\[18\]: LDPT_OPTION 'claim:tmpdir/func.o'
+tv\[19\]: LDPT_OPTION 'sym:_?func::0:0:0'
+tv\[20\]: LDPT_OPTION 'sym:_?func2::0:0:0'
+tv\[21\]: LDPT_OPTION 'dumpresolutions'
+tv\[22\]: LDPT_OPTION 'add:tmpdir/func.o'
+tv\[23\]: LDPT_NULL value 0x0 \(0\)
+#...
+hook called: claim_file tmpdir/main.o \[@0/.* not claimed
+hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
+hook called: claim_file tmpdir/text.o \[@0/.* not claimed
+#...
+hook called: all symbols read.
+Sym: '_?func' Resolution: LDPR_PREVAILING_DEF
+Sym: '_?func2' Resolution: LDPR_PREVAILING_DEF_IRONLY
+hook called: cleanup.
+#...
diff --git a/ld/testsuite/ld-plugin/plugin-ignore.d b/ld/testsuite/ld-plugin/plugin-ignore.d
new file mode 100644
index 0000000..875ac51
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-ignore.d
@@ -0,0 +1 @@
+#pass
diff --git a/ld/testsuite/ld-plugin/plugin-vis-1.d b/ld/testsuite/ld-plugin/plugin-vis-1.d
new file mode 100644
index 0000000..41f4971
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-vis-1.d
@@ -0,0 +1,9 @@
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
diff --git a/ld/testsuite/ld-plugin/plugin.exp b/ld/testsuite/ld-plugin/plugin.exp
new file mode 100644
index 0000000..796cb0e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin.exp
@@ -0,0 +1,169 @@
+# 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
+}
+
+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 testobjfiles "$HOSTING_CRT0 tmpdir/main.o tmpdir/func.o tmpdir/text.o"
+set testobjfiles_notext "$HOSTING_CRT0 tmpdir/main.o tmpdir/func.o"
+set libs "$LIBS $HOSTING_LIBS"
+
+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 { ![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
+} else {
+ # 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 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 \
+ $testobjfiles $libs" "" "" {{ld plugin-ignore.d} \
+ {readelf -s plugin-vis-1.d}} "main.x" ] \
+]
+
+if { $failed_compile != 0 } {
+ foreach testitem $plugin_tests {
+ unresolved [lindex $testitem 0]
+ }
+ if { [is_elf_format] } {
+ foreach testitem $plugin_extra_elf_tests {
+ unresolved [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
+}
diff --git a/ld/testsuite/ld-plugin/text.c b/ld/testsuite/ld-plugin/text.c
new file mode 100644
index 0000000..6d02114
--- /dev/null
+++ b/ld/testsuite/ld-plugin/text.c
@@ -0,0 +1,3 @@
+
+const char *text = "Hello world!\n";
+
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index a586fba..e5e19eb 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1151,6 +1151,7 @@ proc regexp_diff { file_1 file_2 } {
} else {
verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
if ![regexp "^$line_b$" "$line_a"] {
+ verbose "regexp_diff match failure\n" 3
send_log "regexp_diff match failure\n"
send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
set differences 1
@@ -1185,6 +1186,12 @@ proc file_contents { filename } {
return $contents
}
+proc set_file_contents { filename contents } {
+ set file [open $filename w]
+ puts $file "$contents"
+ close $file
+}
+
# Create an archive using ar
#
proc ar_simple_create { ar aropts target objects } {
@@ -1211,6 +1218,10 @@ proc ar_simple_create { ar aropts target objects } {
# objdump: Apply objdump options on result. Compare with regex (last arg).
# nm: Apply nm options on result. Compare with regex (last arg).
# readelf: Apply readelf options on result. Compare with regex (last arg).
+# ld: Don't apply anything on result. Compare output during linking with
+# regex (second arg). Note that this *must* be the first action if it
+# is to be used at all; in all other cases, any output from the linker
+# during linking is treated as a sign of an error and FAILs the test.
#
proc run_ld_link_tests { ldtests } {
global ld
@@ -1225,6 +1236,7 @@ proc run_ld_link_tests { ldtests } {
global CC
global CFLAGS
global runtests
+ global exec_output
foreach testitem $ldtests {
set testname [lindex $testitem 0]
@@ -1242,6 +1254,8 @@ proc run_ld_link_tests { ldtests } {
set objfiles {}
set is_unresolved 0
set failed 0
+ set maybe_failed 0
+ set ld_output ""
# verbose -log "Testname is $testname"
# verbose -log "ld_options is $ld_options"
@@ -1284,8 +1298,8 @@ proc run_ld_link_tests { ldtests } {
set failed 0
}
} elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] } {
- fail $testname
- set failed 1
+ set maybe_failed 1
+ set ld_output "$exec_output"
} else {
set failed 0
}
@@ -1306,6 +1320,8 @@ proc run_ld_link_tests { ldtests } {
{ set dump_prog $nm }
readelf
{ set dump_prog $READELF }
+ ld
+ { set dump_prog "ld" }
default
{
perror "Unrecognized action $action"
@@ -1314,7 +1330,21 @@ proc run_ld_link_tests { ldtests } {
}
}
- if { $dump_prog != "" } {
+ if { $action == "ld" } {
+ set dumpfile [lindex $actionlist 1]
+ verbose "dumpfile is $dumpfile"
+ set_file_contents "tmpdir/ld.messages" "$ld_output"
+ verbose "ld.messages has '[file_contents tmpdir/ld.messages]'"
+ if { [regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$dumpfile"] } then {
+ verbose "output is $ld_output" 2
+ set failed 1
+ break
+ }
+ set maybe_failed 0
+ } elseif { $maybe_failed != 0 } {
+ set failed 1
+ break
+ } elseif { $dump_prog != "" } {
set dumpfile [lindex $actionlist 2]
set binary $dump_prog
@@ -1720,6 +1750,22 @@ proc check_gc_sections_available { } {
return $gc_sections_available_saved
}
+# Returns true if the target ld supports the plugin API.
+proc check_plugin_api_available { } {
+ global plugin_api_available_saved
+ global ld
+ if {![info exists plugin_api_available_saved]} {
+ # Check if the ld used by gcc supports --plugin.
+ set ld_output [remote_exec host $ld "--help"]
+ if { [ string first "-plugin" $ld_output ] >= 0 } {
+ set plugin_api_available_saved 1
+ } else {
+ set plugin_api_available_saved 0
+ }
+ }
+ return $plugin_api_available_saved
+}
+
# Check if the assembler supports CFI statements.
proc check_as_cfi { } {