PATCH: Call set_plugin_error with dlerror ()

H.J. Lu hjl.tools@gmail.com
Thu Nov 22 03:46:00 GMT 2012


On Wed, Nov 21, 2012 at 7:09 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Nov 21, 2012 at 5:41 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>> Hi,
>>
>> This patch changes linker error message from:
>>
>> [hjl@gnu-mic-2 asan-1]$
>> /export/build/gnu/gcc-asan/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-asan/build-x86_64-linux/gcc/ -flto -o x x.o
>> /usr/local/x86_64-unknown-linux-gnu/bin/ld: /export/build/gnu/gcc-asan/build-x86_64-linux/gcc/liblto_plugin.so: error in plugin cleanup (ignored)
>> /usr/local/x86_64-unknown-linux-gnu/bin/ld: /export/build/gnu/gcc-asan/build-x86_64-linux/gcc/liblto_plugin.so: error loading plugin
>> collect2: error: ld returned 1 exit status
>> [hjl@gnu-mic-2 asan-1]$
>>
>> to
>>
>> /export/home/hjl/bugs/gcc/asan-1/ld: /export/build/gnu/gcc-asan/build-x86_64-linux/gcc/liblto_plugin.so: undefined symbol: __asan_report_load8: error loading plugin
>> /export/home/hjl/bugs/gcc/asan-1/ld: /export/build/gnu/gcc-asan/build-x86_64-linux/gcc/liblto_plugin.so: undefined symbol: __asan_report_load8: error in plugin cleanup (ignored)
>>
>> OK to install?
>>
>> Thanks.
>>
>> H.J.
>> ---
>> 2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>         * plugin.c (dlerror): New.
>>         (plugin_opt_plugin): Call set_plugin_error with dlerror ().
>
> An improved patch to also handle dlsym error.
>
>
> --
> H.J.
> ---
> 2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>
>
>         * plugin.c (dl_error): New.
>         (plugin_opt_plugin): Call set_plugin_error with dl_error () on
>         dlopen error.
>         (plugin_load_plugins): Call set_plugin_error with dl_error ()
>         on dlsym error.
>

Another improvement.  Now I got

./ld: error loading plugin:
/export/build/gnu/gcc-asan/build-x86_64-linux/prev-gcc/liblto_plugin.so:
undefined symbol: __asan_report_load8
collect2: error: ld returned 1 exit status


-- 
H.J.
--
2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>

	* lexsup.c (parse_args): Don't check plugin_opt_plugin return.

	* plugin.c (dl_error): New.
	(plugin_opt_plugin): Change return type to void.  Stop on
	dleopen error and report error with dl_error ().
	(plugin_load_plugins): Call set_plugin_error with dl_error ()
	on dlsym error.

	* plugin.h (plugin_opt_plugin): Change return type to void.
diff --git a/ld/lexsup.c b/ld/lexsup.c
index c6baebe..be8a897 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -954,9 +954,7 @@ parse_args (unsigned argc, char **argv)
 	  break;
 #ifdef ENABLE_PLUGINS
 	case OPTION_PLUGIN:
-	  if (plugin_opt_plugin (optarg))
-	    einfo (_("%P%F: %s: error loading plugin\n"),
-		   plugin_error_plugin ());
+	  plugin_opt_plugin (optarg);
 	  break;
 	case OPTION_PLUGIN_OPT:
 	  if (plugin_opt_plugin_arg (optarg))
diff --git a/ld/plugin.c b/ld/plugin.c
index 8902ef4..be27602 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -155,6 +155,20 @@ dlclose (void *handle)

 #endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */

+#ifdef HAVE_DLFCN_H
+static const char *
+dl_error (const char *plugin ATTRIBUTE_UNUSED)
+{
+  return dlerror ();
+}
+#else
+static const char *
+dl_error (const * char plugin)
+{
+  return plugin;
+}
+#endif
+
 /* Helper function for exiting with error status.  */
 static int
 set_plugin_error (const char *plugin)
@@ -178,7 +192,7 @@ plugin_error_plugin (void)
 }

 /* Handle -plugin arg: find and load plugin, or return error.  */
-int
+void
 plugin_opt_plugin (const char *plugin)
 {
   plugin_t *newplug;
@@ -188,7 +202,7 @@ plugin_opt_plugin (const char *plugin)
   newplug->name = plugin;
   newplug->dlhandle = dlopen (plugin, RTLD_NOW);
   if (!newplug->dlhandle)
-    return set_plugin_error (plugin);
+    einfo (_("%P%F: error loading plugin: %s\n"), dl_error (plugin));

   /* Chain on end, so when we run list it is in command-line order.  */
   *plugins_tail_chain_ptr = newplug;
@@ -197,7 +211,6 @@ plugin_opt_plugin (const char *plugin)
   /* Record it as current plugin for receiving args.  */
   last_plugin = newplug;
   last_plugin_args_tail_chain_ptr = &newplug->args;
-  return 0;
 }

 /* Accumulate option arguments for last-loaded plugin, or return
@@ -806,7 +819,7 @@ plugin_load_plugins (void)
       if (!onloadfn)
 	onloadfn = (ld_plugin_onload) dlsym (curplug->dlhandle, "_onload");
       if (!onloadfn)
-	return set_plugin_error (curplug->name);
+	return set_plugin_error (dl_error (curplug->name));
       set_tv_plugin_args (curplug, &my_tv[tv_header_size]);
       called_plugin = curplug;
       rv = (*onloadfn) (my_tv);
diff --git a/ld/plugin.h b/ld/plugin.h
index dc32295..a1c7690 100644
--- a/ld/plugin.h
+++ b/ld/plugin.h
@@ -32,8 +32,8 @@ extern bfd_boolean no_more_claiming;
    to include the plugin-api.h header in order to use this file.  */
 struct ld_plugin_input_file;

-/* Handle -plugin arg: find and load plugin, or return error.  */
-extern int plugin_opt_plugin (const char *plugin);
+/* Handle -plugin arg: find and load plugin.  */
+extern void plugin_opt_plugin (const char *plugin);

 /* Accumulate option arguments for last-loaded plugin, or return
    error if none.  */



More information about the Binutils mailing list