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: Automatic lto plugin handling


On 2012.10.07 at 10:37 +0200, Markus Trippelsdorf wrote:
> On 2012.10.04 at 09:53 -0700, H.J. Lu wrote:
> > I would prefer to add automatic plugin support to binutils:
> > 
> > 1. Figure out gcc driver name and the plugin DSO name at configure time.
> > 2. If --plugin is used without DSO name, call
> > 
> > popen ($gcc-driver -print-prog-name=$DSO)
> > 
> > to get plugin DSO path.
> 
> Picking up an idea from Jan Hubicka¹, this could be fully automated if
> all compilers would drop their lto-plugin into a default plugin
> directory.
> Then ar/nm/ranlib could load these plugins one after the other, until
> one of them claims the file in question.
> If the linker later encounters files that are claimed by different
> plugins, just error out (for the moment).

It turned out that LLVM already supports automatic loading of the plugin
without an explicit --plugin argument. See:
http://llvm.org/docs/GoldPlugin.html

It relies on the gold plugin being present in ../lib/bfd-plugins.
See bfd/plugin.c:
 235   plugin_dir = concat (BINDIR, "/../lib/bfd-plugins", NULL);

(This is /usr/x86_64-pc-linux-gnu/binutils-bin/lib/bfd-plugins on my
system.)

If one places gcc's liblto_plugin into this directory instead, it isn't
loaded automatically unfortunately. The attached patch fixes that.

(If both plugins are present, only liblto_plugin.so is loaded for now,
because it comes first alphabetically.)

diff --git a/binutils/ar.c b/binutils/ar.c
index aceb9d1..c2d2c74 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -140,7 +140,11 @@ static int show_version = 0;
 
 static int show_help = 0;
 
+#if BFD_SUPPORTS_PLUGINS
+static const char *plugin_target = "plugin";
+#else
 static const char *plugin_target = NULL;
+#endif
 
 static const char *target = NULL;
 
@@ -555,7 +559,6 @@ decode_options (int argc, char **argv)
           break;
 	case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
-	  plugin_target = "plugin";
 	  bfd_plugin_set_plugin (optarg);
 #else
 	  fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
@@ -616,7 +619,6 @@ ranlib_main (int argc, char **argv)
 	  /* PR binutils/13493: Support plugins.  */
 	case OPTION_PLUGIN:
 #if BFD_SUPPORTS_PLUGINS
-	  plugin_target = "plugin";
 	  bfd_plugin_set_plugin (optarg);
 #else
 	  fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
diff --git a/binutils/nm.c b/binutils/nm.c
index ad38e27..84627bc 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -177,7 +177,11 @@ static char other_format[] = "%02x";
 static char desc_format[] = "%04x";
 
 static char *target = NULL;
-static char *plugin_target = NULL;
+#if BFD_SUPPORTS_PLUGINS
+static const char *plugin_target = "plugin";
+#else
+static const char *plugin_target = NULL;
+#endif
 
 /* Used to cache the line numbers for a BFD.  */
 static bfd *lineno_cache_bfd;
@@ -1647,7 +1651,6 @@ main (int argc, char **argv)
 
 	case OPTION_PLUGIN:	/* --plugin */
 #if BFD_SUPPORTS_PLUGINS
-	  plugin_target = "plugin";
 	  bfd_plugin_set_plugin (optarg);
 #else
 	  fatal (_("sorry - this program has been built without plugin support\n"));

-- 
Markus


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