gcc.c (cc1_options): Handle -iplugindir before processing the cc1 spec.
authorMatthias Klose <doko@gcc.gnu.org>
Mon, 12 Apr 2010 23:58:18 +0000 (23:58 +0000)
committerMatthias Klose <doko@gcc.gnu.org>
Mon, 12 Apr 2010 23:58:18 +0000 (23:58 +0000)
gcc/

2010-04-13  Matthias Klose  <doko@ubuntu.com>

* gcc.c (cc1_options): Handle -iplugindir before processing
the cc1 spec. Only add -iplugindir once.
(cpp_unique_options): Add -iplugindir option if -fplugin* options
found.
* common.opt (iplugindir): Remove `Separate' property, initialize.
* plugin.c (default_plugin_dir_name): Error with missing -iplugindir
option.
* Makefile.in (check-%, check-parallel-%): Create plugin dir.
(distclean): Remove plugin dir.

2010-04-13  Basile Starynkevitch  <basile@starynkevitch.net>

* doc/plugins.texi (Loading Plugins): Document short
-fplugin=foo option.
(Plugin API): Mention default_plugin_dir_name function.

* gcc.c (find_file_spec_function): Add new declaration.
(static_spec_func): Use it for "find-file".
(find_file_spec_function): Add new function.
(cc1_options): Add -iplugindir option if -fplugin* options found.

* gcc-plugin.h (default_plugin_dir_name): Added new declaration.

* plugin.c (add_new_plugin): Updated comment, and handle short
plugin name.
(default_plugin_dir_name): Added new function.

* common.opt (iplugindir): New option to set the plugin
directory.

gcc/testsuite/

2010-04-13  Matthias Klose  <doko@ubuntu.com>

* gcc.dg/plugindir1.c: New testcase.
* gcc.dg/plugindir2.c: New testcase.
* gcc.dg/plugindir3.c: New testcase.
* gcc.dg/plugindir4.c: New testcase.

From-SVN: r158247

13 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/common.opt
gcc/doc/invoke.texi
gcc/doc/plugins.texi
gcc/gcc-plugin.h
gcc/gcc.c
gcc/plugin.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/plugindir1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugindir2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugindir3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugindir4.c [new file with mode: 0644]

index 7c2a25d7afd7aaff684bbe5073ecc80e1daece31..3e197ab5ecd4548c5f7f60ef038c3de3f1d72cac 100644 (file)
@@ -1,3 +1,36 @@
+2010-04-13  Matthias Klose  <doko@ubuntu.com>
+
+       * gcc.c (cc1_options): Handle -iplugindir before processing
+       the cc1 spec. Only add -iplugindir once.
+       (cpp_unique_options): Add -iplugindir option if -fplugin* options
+       found.
+       * common.opt (iplugindir): Remove `Separate' property, initialize.
+       * plugin.c (default_plugin_dir_name): Error with missing -iplugindir
+       option.
+       * Makefile.in (check-%, check-parallel-%): Create plugin dir.
+       (distclean): Remove plugin dir.
+       * doc/invoke.texi: Document -iplugindir.
+
+2010-04-13  Basile Starynkevitch  <basile@starynkevitch.net>
+
+       * doc/plugins.texi (Loading Plugins): Document short
+       -fplugin=foo option.
+       (Plugin API): Mention default_plugin_dir_name function.
+
+       * gcc.c (find_file_spec_function): Add new declaration.
+       (static_spec_func): Use it for "find-file".
+       (find_file_spec_function): Add new function.
+       (cc1_options): Add -iplugindir option if -fplugin* options found.
+
+       * gcc-plugin.h (default_plugin_dir_name): Added new declaration.
+
+       * plugin.c (add_new_plugin): Updated comment, and handle short
+       plugin name.
+       (default_plugin_dir_name): Added new function.
+
+       * common.opt (iplugindir): New option to set the plugin
+       directory.
+
 2010-04-12  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.md (any_rotate): New code iterator.
index c1cec39725311fa7ecab725c90866008ff7caed5..3fada585d950b5fb4d93acbfc74562cf294716ce 100644 (file)
@@ -4233,7 +4233,7 @@ distclean: clean lang.distclean
        -rm -f gcov.pod
 # Delete po/*.gmo only if we are not building in the source directory.
        -if [ ! -f po/exgettext ]; then rm -f po/*.gmo; fi
-       -rmdir ada cp f java objc intl po testsuite 2>/dev/null
+       -rmdir ada cp f java objc intl po testsuite plugin 2>/dev/null
 
 # Get rid of every file that's generated from some other file, except for `configure'.
 # Most of these files ARE PRESENT in the GCC distribution.
@@ -4690,6 +4690,7 @@ $(TESTSUITEDIR)/site.exp: site.exp
 
 # This is only used for check-% targets that aren't parallelized.
 $(filter-out $(lang_checks_parallelized),$(lang_checks)): check-% : site.exp
+       -test -d plugin || mkdir plugin
        -test -d $(TESTSUITEDIR) || mkdir $(TESTSUITEDIR)
        test -d $(TESTSUITEDIR)/$* || mkdir $(TESTSUITEDIR)/$*
        -(rootme=`${PWD_COMMAND}`; export rootme; \
@@ -4777,6 +4778,7 @@ $(patsubst %,%-subtargets,$(lang_checks_parallelized)): check-%-subtargets:
 # Otherwise check-$lang isn't parallelized and runtest is invoked just with
 # the $(RUNTESTFLAGS) arguments.
 check-parallel-% : site.exp
+       -test -d plugin || mkdir plugin
        -test -d $(TESTSUITEDIR) || mkdir $(TESTSUITEDIR)
        test -d $(TESTSUITEDIR)/$(check_p_subdir) || mkdir $(TESTSUITEDIR)/$(check_p_subdir)
        -(rootme=`${PWD_COMMAND}`; export rootme; \
index d5f00a0bd9ad6b81291be0d418b234a6016a7696..6e9e6965f2220ca38e7966d7be1ed036b0251a3c 100644 (file)
@@ -1539,6 +1539,10 @@ gxcoff+
 Common JoinedOrMissing Negative(gcoff)
 Generate debug information in extended XCOFF format
 
+iplugindir=
+Common Joined Var(plugindir_string) Init(0)
+-iplugindir=<dir>      Set <dir> to be the default plugin directory
+
 o
 Common Joined Separate
 -o <file>      Place output into <file>
index ad7d097990fde7cebe36dd6284c0b17c6f3ba533..1c52a3a54648e0eb61ec2172cab0f1f409a85413 100644 (file)
@@ -425,8 +425,9 @@ Objective-C and Objective-C++ Dialects}.
 
 @item Directory Options
 @xref{Directory Options,,Options for Directory Search}.
-@gccoptlist{-B@var{prefix}  -I@var{dir}  -iquote@var{dir}  -L@var{dir}
--specs=@var{file}  -I- --sysroot=@var{dir}}
+@gccoptlist{-B@var{prefix} -I@var{dir} -iplugindir=@var{dir}}
+-iquote@var{dir} -L@var{dir} -specs=@var{file} -I-
+--sysroot=@var{dir}
 
 @item Machine Dependent Options
 @xref{Submodel Options,,Hardware Models and Configurations}.
@@ -8892,6 +8893,12 @@ the ordering for the include_next directive are not inadvertently changed.
 If you really need to change the search order for system directories,
 use the @option{-nostdinc} and/or @option{-isystem} options.
 
+@item -iplugindir=@var{dir}
+Set the directory to search for plugins which are passed
+by @option{-fplugin=@var{name}} instead of
+@option{-fplugin=@var{path}/@var{name}.so}.  This option is not meant
+to be used by the user, but only passed by the driver.
+
 @item -iquote@var{dir}
 @opindex iquote
 Add the directory @var{dir} to the head of the list of directories to
index a938e02bb617ed18479269c00bd7f67a820a735c..77000fee646f7bc2243bfc38685463dbdf405ee6 100644 (file)
@@ -22,6 +22,11 @@ The plugin arguments are parsed by GCC and passed to respective
 plugins as key-value pairs. Multiple plugins can be invoked by
 specifying multiple @option{-fplugin} arguments.
 
+A plugin can be simply given by its short name (no dots or
+slashes). When simply passing @option{-fplugin=NAME}, the plugin is
+loaded from the @file{plugin} directory, so @option{-fplugin=NAME} is
+the same as @option{-fplugin=`gcc -print-file-name=plugin`/NAME.so},
+using backquote shell syntax to query the @file{plugin} directory.
 
 @section Plugin API
 
@@ -407,6 +412,9 @@ On most systems, you can query this @code{plugin} directory by
 invoking @command{gcc -print-file-name=plugin} (replace if needed
 @command{gcc} with the appropriate program path).
 
+Inside plugins, this @code{plugin} directory name can be queried by
+calling @code{default_plugin_dir_name ()}.
+
 The following GNU Makefile excerpt shows how to build a simple plugin:
 
 @smallexample
index 275be1d980a7ff3add5a86224739943922c9c883..948c4397570c65a51bfda95ff97fb186aba62603 100644 (file)
@@ -141,4 +141,10 @@ extern void register_callback (const char *plugin_name,
 
 extern int unregister_callback (const char *plugin_name, int event);
 
+
+/* Retrieve the plugin directory name, as returned by the
+   -fprint-file-name=plugin argument to the gcc program, which is the
+   -iplugindir program argument to cc1.  */
+extern const char* default_plugin_dir_name (void);
+
 #endif /* GCC_PLUGIN_H */
index cee4bf7767be9d87d9cc846dec45558ba1e63dae..d2190533796fae58263454c54e246633c4adeb91 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -403,6 +403,7 @@ static const char *if_exists_else_spec_function (int, const char **);
 static const char *replace_outfile_spec_function (int, const char **);
 static const char *version_compare_spec_function (int, const char **);
 static const char *include_spec_function (int, const char **);
+static const char *find_file_spec_function (int, const char **);
 static const char *print_asm_header_spec_function (int, const char **);
 static const char *compare_debug_dump_opt_spec_function (int, const char **);
 static const char *compare_debug_self_opt_spec_function (int, const char **);
@@ -872,6 +873,7 @@ static const char *cpp_unique_options =
  %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
  %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
  %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\
+ %{!iplugindir*:%{fplugin*:-iplugindir=%:find-file(plugin)}}\
  %{H} %C %{D*&U*&A*} %{i*} %Z %i\
  %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\
  %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\
@@ -894,6 +896,7 @@ static const char *cpp_debug_options = "%{d*}";
 /* NB: This is shared amongst all front-ends, except for Ada.  */
 static const char *cc1_options =
 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
+ %{!iplugindir*:%{fplugin*:-iplugindir=%:find-file(plugin)}}\
  %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{a*}\
  %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
  %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
@@ -1726,6 +1729,7 @@ static const struct spec_function static_spec_functions[] =
   { "replace-outfile",         replace_outfile_spec_function },
   { "version-compare",         version_compare_spec_function },
   { "include",                 include_spec_function },
+  { "find-file",               find_file_spec_function },
   { "print-asm-header",                print_asm_header_spec_function },
   { "compare-debug-dump-opt",  compare_debug_dump_opt_spec_function },
   { "compare-debug-self-opt",  compare_debug_self_opt_spec_function },
@@ -8710,6 +8714,22 @@ include_spec_function (int argc, const char **argv)
   return NULL;
 }
 
+/* %:find-file spec function.  This function replace its argument by
+    the file found thru find_file, that is the -print-file-name gcc
+    program option. */
+static const char *
+find_file_spec_function (int argc, const char**argv)
+{
+  const char *file;
+
+  if (argc != 1)
+    abort ();
+
+  file = find_file (argv[0]);
+  return file;
+}
+
+
 /* %:print-asm-header spec function.  Print a banner to say that the
    following output is from the assembler.  */
 
index 25e5b95be8fe923097cdf7bffacdee07c3787346..9e1b5f4ada157b0544095b77939e6e1c29fd85f8 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for GCC plugin mechanism.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -124,16 +124,41 @@ get_plugin_base_name (const char *full_name)
 }
 
 
-/* Create a plugin_name_args object for the give plugin and insert it to
-   the hash table. This function is called when -fplugin=/path/to/NAME.so
-   option is processed.  */
+/* Create a plugin_name_args object for the given plugin and insert it
+   to the hash table. This function is called when
+   -fplugin=/path/to/NAME.so or -fplugin=NAME option is processed.  */
 
 void
 add_new_plugin (const char* plugin_name)
 {
   struct plugin_name_args *plugin;
   void **slot;
-  char *base_name = get_plugin_base_name (plugin_name);
+  char *base_name;
+  bool name_is_short;
+  const char *pc;
+
+  /* Replace short names by their full path when relevant.  */
+  name_is_short  = !IS_ABSOLUTE_PATH (plugin_name);
+  for (pc = plugin_name; name_is_short && *pc; pc++)
+    if (*pc == '.' || IS_DIR_SEPARATOR (*pc))
+      name_is_short = false;
+
+  if (name_is_short)
+    {
+      base_name = CONST_CAST (char*, plugin_name);
+      /* FIXME: the ".so" suffix is currently builtin, since plugins
+        only work on ELF host systems like e.g. Linux or Solaris.
+        When plugins shall be available on non ELF systems such as
+        Windows or MacOS, this code has to be greatly improved.  */
+      plugin_name = concat (default_plugin_dir_name (), "/",
+                           plugin_name, ".so", NULL);
+      if (access (plugin_name, R_OK))
+       fatal_error
+         ("inacessible plugin file %s expanded from short plugin name %s: %m",
+          plugin_name, base_name);
+    }
+  else
+    base_name = get_plugin_base_name (plugin_name);
 
   /* If this is the first -fplugin= option we encounter, create
      'plugin_name_args_tab' hash table.  */
@@ -809,6 +834,7 @@ plugin_default_version_check (struct plugin_gcc_version *gcc_version,
   return true;
 }
 
+
 /* Return the current value of event_last, so that plugins which provide
    additional functionality for events for the benefit of high-level plugins
    know how many valid entries plugin_event_name holds.  */
@@ -818,3 +844,15 @@ get_event_last (void)
 {
   return event_last;
 }
+
+
+/* Retrieve the default plugin directory.  The gcc driver should have passed
+   it as -iplugindir <dir> to the cc1 program, and it is queriable thru the
+   -print-file-name=plugin option to gcc.  */
+const char*
+default_plugin_dir_name (void)
+{
+  if (!plugindir_string)
+    fatal_error ("-iplugindir <dir> option not passed from the gcc driver");
+  return plugindir_string;
+}
index 68e4aa9e452a6451f5a6a26ad5a4a3ee1b7f7b88..d267f5caa5ff289209c1d38c1447bae594cc2de4 100644 (file)
@@ -1,3 +1,10 @@
+2010-04-13  Matthias Klose  <doko@ubuntu.com>
+
+       * gcc.dg/plugindir1.c: New testcase.
+       * gcc.dg/plugindir2.c: New testcase.
+       * gcc.dg/plugindir3.c: New testcase.
+       * gcc.dg/plugindir4.c: New testcase.
+
 2010-04-12  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/rotate-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/plugindir1.c b/gcc/testsuite/gcc.dg/plugindir1.c
new file mode 100644 (file)
index 0000000..a973ec0
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-c -fplugin=foo" } */
+
+/* { dg-prune-output ".*inacessible plugin file.*foo\.so expanded from short plugin name.*" } */
diff --git a/gcc/testsuite/gcc.dg/plugindir2.c b/gcc/testsuite/gcc.dg/plugindir2.c
new file mode 100644 (file)
index 0000000..58c1505
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-save-temps -c -fplugin=foo" } */
+
+/* { dg-prune-output ".*inacessible plugin file.*foo\.so expanded from short plugin name.*" } */
diff --git a/gcc/testsuite/gcc.dg/plugindir3.c b/gcc/testsuite/gcc.dg/plugindir3.c
new file mode 100644 (file)
index 0000000..4103753
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do preprocess } */
+/* { dg-options "-fplugin=foo" } */
+
+/* { dg-prune-output ".*inacessible plugin file.*foo\.so expanded from short plugin name.*" } */
diff --git a/gcc/testsuite/gcc.dg/plugindir4.c b/gcc/testsuite/gcc.dg/plugindir4.c
new file mode 100644 (file)
index 0000000..27b2f24
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do preprocess } */
+/* { dg-options "-iplugindir=my-plugindir -fplugin=foo" } */
+
+/* { dg-prune-output ".*inacessible plugin file.*my-plugindir/foo\.so expanded from short plugin name.*" } */