+2009-04-17 Rafael Avila de Espindola <espindola@google.com>
+
+ * Makefile.in (REVISION_s): Always include quotes. Change ifdef to use
+ REVISION_c.
+ (OBJS-common): Add plugin-version.o.
+ (plugin-version.o): New.
+ * gcc-plugin.h (plugin_gcc_version): New.
+ (plugin_default_version_check): New.
+ (plugin_init_func, plugin_init): Add version argument.
+ * plugin-version.c: New.
+ * plugin.c (str_plugin_gcc_version_name): New.
+ (try_init_one_plugin): Read plugin_gcc_version from the plugin and
+ pass it to the init function.
+ (plugin_default_version_check): New.
+
2009-04-17 Richard Guenther <rguenther@suse.de>
* tree-ssa-alias.c (refs_may_alias_p_1): Do not use TBAA
ifdef REVISION_c
REVISION_s := "\"$(if $(DEVPHASE_c), $(REVISION_c))\""
else
-REVISION_s :=
+REVISION_s := "\"\""
endif
# Shorthand variables for dependency lists.
params.o \
passes.o \
plugin.o \
+ plugin-version.o \
pointer-set.o \
postreload-gcse.o \
postreload.o \
dumpvers: dumpvers.c
-ifdef REVISION_s
+ifdef REVISION_c
version.o: version.c version.h $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
else
version.o: version.c version.h $(DATESTAMP) $(BASEVER) $(DEVPHASE)
plugin.o : plugin.c $(PLUGIN_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h \
errors.h $(TOPLEV_H) $(TREE_H) $(TREE_PASS_H) intl.h
+plugin-version.o : plugin-version.c $(SYSTEM_H) gcc-plugin.h configargs.h
+ $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
+ -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
+ -DREVISION=$(REVISION_s) -DDEVPHASE=$(DEVPHASE_s) -c \
+ -DPLUGIN $(srcdir)/plugin-version.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 \
const char *help;
};
+/* Represents the gcc version. Used to avoid using an incompatible plugin. */
+
+struct plugin_gcc_version
+{
+ const char *basever;
+ const char *datestamp;
+ const char *devphase;
+ const char *revision;
+ const char *configuration_arguments;
+};
+
+extern struct plugin_gcc_version plugin_gcc_version;
+
+/* The default version check. Compares every field in VERSION. */
+
+extern bool plugin_default_version_check(struct plugin_gcc_version *version);
+
/* Function type for the plugin initialization routine. Each plugin module
should define this as an externally-visible function with name
"plugin_init."
PLUGIN_NAME - name of the plugin (useful for error reporting)
+ VERSION - the plugin_gcc_version symbol of the plugin itself.
ARGC - the size of the ARGV array
ARGV - an array of key-value argument pair
Returns 0 if initialization finishes successfully. */
typedef int (*plugin_init_func) (const char *plugin_name,
+ struct plugin_gcc_version *version,
int argc, struct plugin_argument *argv);
/* Declaration for "plugin_init" function so that it doesn't need to be
duplicated in every plugin. */
-extern int plugin_init (const char *, int, struct plugin_argument *);
+extern int plugin_init (const char *, struct plugin_gcc_version *version,
+ int, struct plugin_argument *);
/* Function type for a plugin callback routine.
--- /dev/null
+/* Version information for plugins.
+ Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "system.h"
+#include "gcc-plugin.h"
+#include "configargs.h"
+
+static char basever[] = BASEVER;
+static char datestamp[] = DATESTAMP;
+static char devphase[] = DEVPHASE;
+static char revision[] = REVISION;
+
+/* FIXME plugins: We should make the version information more precise.
+ One way to do is to add a checksum. */
+
+struct plugin_gcc_version plugin_gcc_version = {basever, datestamp, devphase,
+ revision,
+ configuration_arguments};
/* Each plugin should define an initialization function with exactly
this name. */
static const char *str_plugin_init_func_name = "plugin_init";
+static const char *str_plugin_gcc_version_name = "plugin_gcc_version";
#endif
/* Helper function for the hash table that compares the base_name of the
{
void *dl_handle;
plugin_init_func plugin_init;
+ struct plugin_gcc_version *version;
char *err;
PTR_UNION_TYPE (plugin_init_func) plugin_init_union;
+ PTR_UNION_TYPE (struct plugin_gcc_version*) version_union;
dl_handle = dlopen (plugin->full_name, RTLD_NOW);
if (!dl_handle)
return false;
}
+ PTR_UNION_AS_VOID_PTR (version_union) =
+ dlsym (dl_handle, str_plugin_gcc_version_name);
+ version = PTR_UNION_AS_CAST_PTR (version_union);
+
/* Call the plugin-provided initialization routine with the arguments. */
- if ((*plugin_init) (plugin->base_name, plugin->argc, plugin->argv))
+ if ((*plugin_init) (plugin->base_name, version, plugin->argc, plugin->argv))
{
error ("Fail to initialize plugin %s", plugin->full_name);
return false;
{
dump_active_plugins (stderr);
}
+
+/* The default version check. Compares every field in VERSION. */
+
+bool
+plugin_default_version_check(struct plugin_gcc_version *version)
+{
+ /* version is NULL if the plugin was not linked with plugin-version.o */
+ if (!version)
+ return false;
+
+ if (strcmp (version->basever, plugin_gcc_version.basever))
+ return false;
+ if (strcmp (version->datestamp, plugin_gcc_version.datestamp))
+ return false;
+ if (strcmp (version->devphase, plugin_gcc_version.devphase))
+ return false;
+ if (strcmp (version->revision, plugin_gcc_version.revision))
+ return false;
+ if (strcmp (version->configuration_arguments,
+ plugin_gcc_version.configuration_arguments))
+ return false;
+ return true;
+}