This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: default plugin directory?


Basile STARYNKEVITCH wrote:
Hello All,

I would believe that in the future many linux (or other) distributions might have some well known sets of GCC plugins.

So the intuition would be that most plugins would be installed at some "standard" place, eg $(libexecsubdir)/plugins

In that case, it would probably be much more easy for users of these plugins to avoid typing the full path of the plugin.

Concretely, I am suggesting that some users would pass just
 -fplugin=treehydra
instead of the full path
 -fplugin=/usr/lib/gcc/x86_64-linux-gnu/4.5.1/plugins/treehydra.so

The attached patch is an [untested, but compiled] proof of concept of my idea, just to start discussion.
gcc/ChangeLog:
2009-06-18 Basile Starynkevitch <basile@starynkevitch.net>
* plugin.c (try_init_one_plugin): use the PLUGIN_DEFAULT_DIRECTORY for -fplugin=foo.
* Makefile.in (plugins_default_dir): Added new variable.
(plugin.o): explicitly defines PLUGIN_DEFAULT_DIRECTORY.



Sorry the patch did not compile because of a stupid typo of mine in gcc/Makefile.in (I thought that once prev-gcc/xgcc appears in the make output, some compilation succeeded). I am attaching a better version, which bootstraped. Of course I did not test it yet.

The MELT branch actually has some more complex variant of this.

Of course, we need to agree on the idea, on the plugin default directory location (should it be separately configurable?), add some documentation, ...
Sp I am waiting for comments!


Regards.



--
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 148653)
+++ gcc/plugin.c	(working copy)
@@ -586,6 +586,25 @@ try_init_one_plugin (struct plugin_name_args *plug
   PTR_UNION_TYPE (plugin_init_func) plugin_init_union;
 
   dl_handle = dlopen (plugin->full_name, RTLD_NOW);
+
+  /* if we cannot find the plugin by its full name, try to get it in
+     the default directory: if passing -fplugin=foo, look there for
+     foo.so */
+#ifdef PLUGIN_DEFAULT_DIRECTORY
+  if (!dl_handle && ISALNUM(plugin->full_name[0]))
+    {
+      /* construct the plugin path, possibly adding a .so suffix if it
+	 does not appear in the full name */
+      char* pluginpath 
+	= concat (PLUGIN_DEFAULT_DIRECTORY, 
+		  "/", /* maybe use DIR_SEPARATOR */
+		  plugin->full_name, 
+		  strstr(plugin->full_name, ".so") ? "" : ".so",
+		  NULL);
+      dl_handle = dlopen (pluginpath, RTLD_NOW);
+      free(pluginpath);
+    }
+#endif
   if (!dl_handle)
     {
       error ("Cannot load plugin %s\n%s", plugin->full_name, dlerror ());
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 148653)
+++ gcc/Makefile.in	(working copy)
@@ -492,6 +492,8 @@ libsubdir = $(libdir)/gcc/$(target_noncanonical)/$
 libexecsubdir = $(libexecdir)/gcc/$(target_noncanonical)/$(version)
 # Directory in which plugin headers are installed
 plugin_includedir = $(libsubdir)/plugin/include
+# Directory holding default dynamic plugins 
+plugins_default_dir = $(libexecsubdir)/plugins
 # Used to produce a relative $(gcc_tooldir) in gcc.o
 unlibsubdir = ../../..
 # $(prefix), expressed as a path relative to $(libsubdir).
@@ -2518,6 +2520,9 @@ passes.o : passes.c $(CONFIG_H) $(SYSTEM_H) corety
 
 plugin.o : plugin.c $(PLUGIN_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h \
    $(TOPLEV_H) $(TREE_H) $(TREE_PASS_H) intl.h $(PLUGIN_VERSION_H) $(GGC_H)
+	$(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS)  \
+	-DPLUGIN_DEFAULT_DIRECTORY=\"$(plugins_default_dir)\" \
+	-c $(srcdir)/plugin.c $(OUTPUT_OPTION)
 
 main.o : main.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H)
 

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