aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Klose <doko@gcc.gnu.org>2010-04-12 23:58:18 +0000
committerMatthias Klose <doko@gcc.gnu.org>2010-04-12 23:58:18 +0000
commit4adbd5dd3cf5801e622fcfff3149a27940d34089 (patch)
tree03b93cac03234238b2a22c3947bc8bcd44f3d7fb
parente0db9cc648242cbbea38cc3c559663acb501aee8 (diff)
downloadgcc-4adbd5dd3cf5801e622fcfff3149a27940d34089.zip
gcc-4adbd5dd3cf5801e622fcfff3149a27940d34089.tar.gz
gcc-4adbd5dd3cf5801e622fcfff3149a27940d34089.tar.bz2
gcc.c (cc1_options): Handle -iplugindir before processing the cc1 spec.
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
-rw-r--r--gcc/ChangeLog33
-rw-r--r--gcc/Makefile.in4
-rw-r--r--gcc/common.opt4
-rw-r--r--gcc/doc/invoke.texi11
-rw-r--r--gcc/doc/plugins.texi8
-rw-r--r--gcc/gcc-plugin.h6
-rw-r--r--gcc/gcc.c20
-rw-r--r--gcc/plugin.c48
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/plugindir1.c4
-rw-r--r--gcc/testsuite/gcc.dg/plugindir2.c4
-rw-r--r--gcc/testsuite/gcc.dg/plugindir3.c4
-rw-r--r--gcc/testsuite/gcc.dg/plugindir4.c4
13 files changed, 149 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7c2a25d..3e197ab 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index c1cec39..3fada58 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -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; \
diff --git a/gcc/common.opt b/gcc/common.opt
index d5f00a0..6e9e696 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -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>
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ad7d097..1c52a3a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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
diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi
index a938e02..77000fe 100644
--- a/gcc/doc/plugins.texi
+++ b/gcc/doc/plugins.texi
@@ -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
diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
index 275be1d9..948c439 100644
--- a/gcc/gcc-plugin.h
+++ b/gcc/gcc-plugin.h
@@ -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 */
diff --git a/gcc/gcc.c b/gcc/gcc.c
index cee4bf7..d219053 100644
--- 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. */
diff --git a/gcc/plugin.c b/gcc/plugin.c
index 25e5b95..9e1b5f4 100644
--- a/gcc/plugin.c
+++ b/gcc/plugin.c
@@ -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;
+}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 68e4aa9..d267f5c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..a973ec0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugindir1.c
@@ -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
index 0000000..58c1505
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugindir2.c
@@ -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
index 0000000..4103753
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugindir3.c
@@ -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
index 0000000..27b2f24
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugindir4.c
@@ -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.*" } */