ld: Skip libdep plugin if not all plugin hooks are available
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 16 Dec 2020 21:40:42 +0000 (13:40 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 16 Dec 2020 21:40:51 +0000 (13:40 -0800)
Skip plugin if not all required plugin hooks are available.

2020-12-16  Howard Chu <hyc@symas.com>
    H.J. Lu  <hongjiu.lu@intel.com>

PR ld/27081
* libdep_plugin.c (onload): Skip if not all required plugin hooks
are available.
* 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/ChangeLog
ld/libdep_plugin.c
ld/testsuite/config/default.exp
ld/testsuite/ld-elf/elf.exp
ld/testsuite/ld-elf/pr26391.fd [new file with mode: 0644]

index 46acbd904ddbc6591243d4dd2b2c95265c5086e2..34d58d4fcbbe0ac785d7010dbe9f6c0089cc19c6 100644 (file)
@@ -1,3 +1,13 @@
+2020-12-16  Howard Chu <hyc@symas.com>
+           H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27081
+       * libdep_plugin.c (onload): Skip if not all required plugin hooks
+       are available.
+       * 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.
+
 2020-12-16  Alan Modra  <amodra@gmail.com>
 
        * ld.h (ld_config_type): Delete maxpagesize and commonpagesize.
index 2a7fdc4d0bf5d8d4b8a47f90aef1843a552e7095..b81364fdca598e6bc5f3817d956d164fa27047d0 100644 (file)
@@ -339,27 +339,14 @@ onload (struct ld_plugin_tv *tv)
   while ((tv++)->tv_tag != LDPT_NULL);
 
   /* Register hooks.  */
-  if (!tv_register_claim_file)
+  if (tv_register_claim_file
+      && tv_register_all_symbols_read
+      && tv_register_cleanup)
     {
-      TV_MESSAGE (LDPL_FATAL, "No register_claim_file hook");
-      fflush (NULL);
-      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_claim_file) (onclaim_file);
+      (*tv_register_all_symbols_read) (onall_symbols_read);
+      (*tv_register_cleanup) (oncleanup);
     }
-  (*tv_register_cleanup) (oncleanup);
   fflush (NULL);
   return LDPS_OK;
 }
index f711fb792e3c848e2b7152968913381c56a3e9a6..a8ad1fdb6f00edc75cb53d01b117e0b9076fa01a 100644 (file)
@@ -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 ""
+}
index e08a6f5febdbf27762e5edf5451a5190eab24b65..a58b17b512642fc8e3d9e76c933233abd4cbab5c 100644 (file)
@@ -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 (file)
index 0000000..1921cd6
--- /dev/null
@@ -0,0 +1,4 @@
+#failif
+#...
+bfd plugin: No register_all_symbols_read hook
+#...