From 32f73ea9955bc4ddaa83fd5477e76196dc4cdb96 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 16 Dec 2020 06:22:46 -0800 Subject: [PATCH] ld: Call plugin hooks only if they are available Call tv_register_all_symbols_read and tv_register_cleanup only if they are set. PR ld/27081 * libdep_plugin.c (onload): Call tv_register_all_symbols_read and tv_register_cleanup only if they are set. * testsuite/config/default.exp (dep_plug_opt): New. * testsuite/ld-elf/elf.exp: Pass $dep_plug_opt to nm. * testsuite/ld-elf/pr26391.fd: New file. --- ld/libdep_plugin.c | 18 ++++-------------- ld/testsuite/config/default.exp | 8 ++++++++ ld/testsuite/ld-elf/elf.exp | 5 ++++- ld/testsuite/ld-elf/pr26391.fd | 4 ++++ 4 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr26391.fd diff --git a/ld/libdep_plugin.c b/ld/libdep_plugin.c index 2a7fdc4d0b..37ad7c7f97 100644 --- a/ld/libdep_plugin.c +++ b/ld/libdep_plugin.c @@ -346,20 +346,10 @@ onload (struct ld_plugin_tv *tv) return LDPS_ERR; } (*tv_register_claim_file) (onclaim_file); - if (!tv_register_all_symbols_read) - { - TV_MESSAGE (LDPL_FATAL, "No register_all_symbols_read hook"); - fflush (NULL); - return LDPS_ERR; - } - (*tv_register_all_symbols_read) (onall_symbols_read); - if (!tv_register_cleanup) - { - TV_MESSAGE (LDPL_FATAL, "No register_cleanup hook"); - fflush (NULL); - return LDPS_ERR; - } - (*tv_register_cleanup) (oncleanup); + if (tv_register_all_symbols_read) + (*tv_register_all_symbols_read) (onall_symbols_read); + if (tv_register_cleanup) + (*tv_register_cleanup) (oncleanup); fflush (NULL); return LDPS_OK; } diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp index f711fb792e..a8ad1fdb6f 100644 --- a/ld/testsuite/config/default.exp +++ b/ld/testsuite/config/default.exp @@ -443,3 +443,11 @@ if { [check_compiler_available] } { } } } + +if {[file exists .libs/libdep.so]} { + set dep_plug_opt "--plugin .libs/libdep.so" +} elseif {[file exists .libs/libdep.dll]} { + set dep_plug_opt "--plugin .libs/libdep.dll" +} else { + set dep_plug_opt "" +} diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index e08a6f5feb..a58b17b512 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -415,7 +415,10 @@ run_ld_link_tests [list \ "" \ "" \ {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ - {{nm "" pr26391.nd}} \ + [list \ + [list "nm" "$dep_plug_opt" "pr26391.nd"] \ + [list "nm" "$dep_plug_opt" "pr26391.fd"] \ + ] \ "pr26391-5.o" \ "-fno-function-sections" \ ] \ diff --git a/ld/testsuite/ld-elf/pr26391.fd b/ld/testsuite/ld-elf/pr26391.fd new file mode 100644 index 0000000000..1921cd6c70 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26391.fd @@ -0,0 +1,4 @@ +#failif +#... +bfd plugin: No register_all_symbols_read hook +#... -- 2.29.2