This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Call set_plugin_error with dlerror ()


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.

diff --git a/ld/plugin.c b/ld/plugin.c
index 8902ef4..e8a9775 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)
@@ -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);
+    return set_plugin_error (dl_error (plugin));

   /* Chain on end, so when we run list it is in command-line order.  */
   *plugins_tail_chain_ptr = newplug;
@@ -806,7 +820,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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]