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?


Joseph S. Myers wrote:

This patch does not appear to use make_relative_prefix to adjust the path if the compiler is run from some location other than the configured prefix, so would break relocatability.



Thanks Joseph for the review & the suggestion. I am attaching an improved version of the patch, against trunk rev148688


gcc/ChangeLog:
2009-06-19 Basile Starynkevitch <basile@starynkevitch.net>
* doc/plugins.texi (Loading Plugins): Mention how -fplugin=foobar searchs in the plugins/ directory.
* Makefile.in (plugin.o): Passes -DPLUGIN_DEFAULT_DIR -DSTANDARD_PREFIX -DSTANDARD_EXEC_PREFIX flags.
* plugin.c (try_init_one_plugin): With -fplugin=foobar, search foobar.so in the plugins/ directory.


I do think that it is better to have a default plugin directory, but I am not sure yet of how it should be called (perhaps gcc-plugins/ is a better name than plugins/). Perhaps we should also mention how to figure out it (e.g. mentioning a -print-file-name=plugins in the documentation).

So comments are welcome.

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/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi	(revision 148688)
+++ gcc/doc/plugins.texi	(working copy)
@@ -22,6 +22,10 @@ The plugin arguments are parsed by GCC and passed
 plugins as key-value pairs. Multiple plugins can be invoked by
 specifying multiple @option{-fplugin} arguments.
 
+For convenience, a plugin given as a simple @var{NAME} (starting with
+a letter or digit) is loaded from a well defined @file{plugins/}
+directory.  So @option{-fplugin=foobar} loads the plugin in
+@file{@var{libexecsubdir}/plugins/foobar.so} if it exists.
 
 @section Plugin API
 
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 148688)
+++ gcc/plugin.c	(working copy)
@@ -590,6 +590,45 @@ 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 */
+  if (!dl_handle && ISALNUM(plugin->full_name[0]))
+    {
+      char* pluginpath = 0;
+      static const char *relocated_prefix;
+      /* If this path starts with the configure-time prefix, but the
+	 compiler has been relocated, replace it with the run-time
+	 prefix.  Both PLUGIN_DEFAULT_DIR & PLUGIN_PREFIX are passed
+	 in our compilation command in Makefile.in. */
+      if (!relocated_prefix)
+	{
+	  char *dummy;
+	  /* Make relative prefix expects the first argument
+	     to be a program, not a directory.  */
+	  dummy = concat (STANDARD_EXEC_PREFIX, "dummy", NULL);
+	  relocated_prefix 
+	    = make_relative_prefix (dummy,
+				    PLUGIN_DEFAULT_DIR,
+				    STANDARD_PREFIX);
+	}
+      /* construct the plugin path, possibly adding a .so suffix if it
+	 does not appear in the full name */
+      if (relocated_prefix)
+	pluginpath
+	  = concat (relocated_prefix,
+		    "/", /* maybe use DIR_SEPARATOR */
+		    plugin->full_name,
+		    strstr(plugin->full_name, ".so") ? "" : ".so",
+		    NULL);
+      if (pluginpath)
+	{
+	  dl_handle = dlopen (pluginpath, RTLD_NOW);
+	  free(pluginpath);
+	}
+    }
+
   if (!dl_handle)
     {
       error ("Cannot load plugin %s\n%s", plugin->full_name, dlerror ());
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 148688)
+++ 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).
@@ -2517,7 +2519,13 @@ 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_DIR=\"$(plugins_default_dir)\" \
+         -DSTANDARD_PREFIX=\"$(prefix)\" \
+         -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
+         -c $(srcdir)/plugin.c $(OUTPUT_OPTION)
 
+
 main.o : main.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H)
 
 host-default.o : host-default.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \

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