This is the mail archive of the 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]

default plugin directory?

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
instead of the full path

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

Comments are welcome.


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
+ */
+  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 
+		  "/", /* maybe use DIR_SEPARATOR */
+		  plugin->full_name, 
+		  strstr(plugin->full_name, ".so") ? "" : ".so",
+		  NULL);
+      dl_handle = dlopen (pluginpath, RTLD_NOW);
+      free(pluginpath);
+    }
   if (!dl_handle)
       error ("Cannot load plugin %s\n%s", plugin->full_name, dlerror ());
Index: gcc/
--- gcc/	(revision 148653)
+++ gcc/	(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 \
+	-DPLUGIN_DEFAULT_DIRECTORY=\"$(plugins_default_dir)\" \
+	-c $(srcdir)/toplev.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]