Commit 4adbd5dd by Matthias Klose

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
parent e0db9cc6
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> 2010-04-12 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (any_rotate): New code iterator. * config/i386/i386.md (any_rotate): New code iterator.
......
...@@ -4233,7 +4233,7 @@ distclean: clean lang.distclean ...@@ -4233,7 +4233,7 @@ distclean: clean lang.distclean
-rm -f gcov.pod -rm -f gcov.pod
# Delete po/*.gmo only if we are not building in the source directory. # Delete po/*.gmo only if we are not building in the source directory.
-if [ ! -f po/exgettext ]; then rm -f po/*.gmo; fi -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'. # 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. # Most of these files ARE PRESENT in the GCC distribution.
...@@ -4690,6 +4690,7 @@ $(TESTSUITEDIR)/site.exp: site.exp ...@@ -4690,6 +4690,7 @@ $(TESTSUITEDIR)/site.exp: site.exp
# This is only used for check-% targets that aren't parallelized. # This is only used for check-% targets that aren't parallelized.
$(filter-out $(lang_checks_parallelized),$(lang_checks)): check-% : site.exp $(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)
test -d $(TESTSUITEDIR)/$* || mkdir $(TESTSUITEDIR)/$* test -d $(TESTSUITEDIR)/$* || mkdir $(TESTSUITEDIR)/$*
-(rootme=`${PWD_COMMAND}`; export rootme; \ -(rootme=`${PWD_COMMAND}`; export rootme; \
...@@ -4777,6 +4778,7 @@ $(patsubst %,%-subtargets,$(lang_checks_parallelized)): check-%-subtargets: ...@@ -4777,6 +4778,7 @@ $(patsubst %,%-subtargets,$(lang_checks_parallelized)): check-%-subtargets:
# Otherwise check-$lang isn't parallelized and runtest is invoked just with # Otherwise check-$lang isn't parallelized and runtest is invoked just with
# the $(RUNTESTFLAGS) arguments. # the $(RUNTESTFLAGS) arguments.
check-parallel-% : site.exp check-parallel-% : site.exp
-test -d plugin || mkdir plugin
-test -d $(TESTSUITEDIR) || mkdir $(TESTSUITEDIR) -test -d $(TESTSUITEDIR) || mkdir $(TESTSUITEDIR)
test -d $(TESTSUITEDIR)/$(check_p_subdir) || mkdir $(TESTSUITEDIR)/$(check_p_subdir) test -d $(TESTSUITEDIR)/$(check_p_subdir) || mkdir $(TESTSUITEDIR)/$(check_p_subdir)
-(rootme=`${PWD_COMMAND}`; export rootme; \ -(rootme=`${PWD_COMMAND}`; export rootme; \
......
...@@ -1539,6 +1539,10 @@ gxcoff+ ...@@ -1539,6 +1539,10 @@ gxcoff+
Common JoinedOrMissing Negative(gcoff) Common JoinedOrMissing Negative(gcoff)
Generate debug information in extended XCOFF format 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 o
Common Joined Separate Common Joined Separate
-o <file> Place output into <file> -o <file> Place output into <file>
......
...@@ -425,8 +425,9 @@ Objective-C and Objective-C++ Dialects}. ...@@ -425,8 +425,9 @@ Objective-C and Objective-C++ Dialects}.
@item Directory Options @item Directory Options
@xref{Directory Options,,Options for Directory Search}. @xref{Directory Options,,Options for Directory Search}.
@gccoptlist{-B@var{prefix} -I@var{dir} -iquote@var{dir} -L@var{dir} @gccoptlist{-B@var{prefix} -I@var{dir} -iplugindir=@var{dir}}
-specs=@var{file} -I- --sysroot=@var{dir}} -iquote@var{dir} -L@var{dir} -specs=@var{file} -I-
--sysroot=@var{dir}
@item Machine Dependent Options @item Machine Dependent Options
@xref{Submodel Options,,Hardware Models and Configurations}. @xref{Submodel Options,,Hardware Models and Configurations}.
...@@ -8892,6 +8893,12 @@ the ordering for the include_next directive are not inadvertently changed. ...@@ -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, If you really need to change the search order for system directories,
use the @option{-nostdinc} and/or @option{-isystem} options. 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} @item -iquote@var{dir}
@opindex iquote @opindex iquote
Add the directory @var{dir} to the head of the list of directories to Add the directory @var{dir} to the head of the list of directories to
......
...@@ -22,6 +22,11 @@ The plugin arguments are parsed by GCC and passed to respective ...@@ -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 plugins as key-value pairs. Multiple plugins can be invoked by
specifying multiple @option{-fplugin} arguments. 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 @section Plugin API
...@@ -407,6 +412,9 @@ On most systems, you can query this @code{plugin} directory by ...@@ -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 invoking @command{gcc -print-file-name=plugin} (replace if needed
@command{gcc} with the appropriate program path). @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: The following GNU Makefile excerpt shows how to build a simple plugin:
@smallexample @smallexample
......
...@@ -141,4 +141,10 @@ extern void register_callback (const char *plugin_name, ...@@ -141,4 +141,10 @@ extern void register_callback (const char *plugin_name,
extern int unregister_callback (const char *plugin_name, int event); 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 */ #endif /* GCC_PLUGIN_H */
...@@ -403,6 +403,7 @@ static const char *if_exists_else_spec_function (int, const char **); ...@@ -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 *replace_outfile_spec_function (int, const char **);
static const char *version_compare_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 *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 *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_dump_opt_spec_function (int, const char **);
static const char *compare_debug_self_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 = ...@@ -872,6 +873,7 @@ static const char *cpp_unique_options =
%{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
%{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
%{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\ %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\
%{!iplugindir*:%{fplugin*:-iplugindir=%:find-file(plugin)}}\
%{H} %C %{D*&U*&A*} %{i*} %Z %i\ %{H} %C %{D*&U*&A*} %{i*} %Z %i\
%{fmudflap:-D_MUDFLAP -include mf-runtime.h}\ %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\
%{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\ %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\
...@@ -894,6 +896,7 @@ static const char *cpp_debug_options = "%{d*}"; ...@@ -894,6 +896,7 @@ static const char *cpp_debug_options = "%{d*}";
/* NB: This is shared amongst all front-ends, except for Ada. */ /* NB: This is shared amongst all front-ends, except for Ada. */
static const char *cc1_options = static const char *cc1_options =
"%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ "%{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*}\ %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{a*}\
%{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \ %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
%{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %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[] = ...@@ -1726,6 +1729,7 @@ static const struct spec_function static_spec_functions[] =
{ "replace-outfile", replace_outfile_spec_function }, { "replace-outfile", replace_outfile_spec_function },
{ "version-compare", version_compare_spec_function }, { "version-compare", version_compare_spec_function },
{ "include", include_spec_function }, { "include", include_spec_function },
{ "find-file", find_file_spec_function },
{ "print-asm-header", print_asm_header_spec_function }, { "print-asm-header", print_asm_header_spec_function },
{ "compare-debug-dump-opt", compare_debug_dump_opt_spec_function }, { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function },
{ "compare-debug-self-opt", compare_debug_self_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) ...@@ -8710,6 +8714,22 @@ include_spec_function (int argc, const char **argv)
return NULL; 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 /* %:print-asm-header spec function. Print a banner to say that the
following output is from the assembler. */ following output is from the assembler. */
......
/* Support for GCC plugin mechanism. /* 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. This file is part of GCC.
...@@ -124,16 +124,41 @@ get_plugin_base_name (const char *full_name) ...@@ -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 /* Create a plugin_name_args object for the given plugin and insert it
the hash table. This function is called when -fplugin=/path/to/NAME.so to the hash table. This function is called when
option is processed. */ -fplugin=/path/to/NAME.so or -fplugin=NAME option is processed. */
void void
add_new_plugin (const char* plugin_name) add_new_plugin (const char* plugin_name)
{ {
struct plugin_name_args *plugin; struct plugin_name_args *plugin;
void **slot; 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 /* If this is the first -fplugin= option we encounter, create
'plugin_name_args_tab' hash table. */ 'plugin_name_args_tab' hash table. */
...@@ -809,6 +834,7 @@ plugin_default_version_check (struct plugin_gcc_version *gcc_version, ...@@ -809,6 +834,7 @@ plugin_default_version_check (struct plugin_gcc_version *gcc_version,
return true; return true;
} }
/* Return the current value of event_last, so that plugins which provide /* Return the current value of event_last, so that plugins which provide
additional functionality for events for the benefit of high-level plugins additional functionality for events for the benefit of high-level plugins
know how many valid entries plugin_event_name holds. */ know how many valid entries plugin_event_name holds. */
...@@ -818,3 +844,15 @@ get_event_last (void) ...@@ -818,3 +844,15 @@ get_event_last (void)
{ {
return event_last; 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;
}
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> 2010-04-12 Uros Bizjak <ubizjak@gmail.com>
* gcc.target/i386/rotate-2.c: New test. * gcc.target/i386/rotate-2.c: New test.
......
/* { dg-do compile } */
/* { dg-options "-c -fplugin=foo" } */
/* { dg-prune-output ".*inacessible plugin file.*foo\.so expanded from short plugin name.*" } */
/* { dg-do compile } */
/* { dg-options "-save-temps -c -fplugin=foo" } */
/* { dg-prune-output ".*inacessible plugin file.*foo\.so expanded from short plugin name.*" } */
/* { dg-do preprocess } */
/* { dg-options "-fplugin=foo" } */
/* { dg-prune-output ".*inacessible plugin file.*foo\.so expanded from short plugin name.*" } */
/* { 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.*" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment