Home | History | Annotate | Download | only in gcc

Lines Matching refs:plugin

1 /* Support for GCC plugin mechanism.
20 /* This file contains the support for GCC plugin mechanism based on the
21 APIs described in doc/plugin.texi. */
31 #include "plugin.h"
34 #include "plugin-version.h"
54 # include "plugin.def"
101 /* List node for keeping track of plugin-registered callback. */
104 const char *plugin_name; /* Name of plugin that registers the callback. */
106 void *user_data; /* plugin-specified data. */
114 /* For invoke_plugin_callbacks(), see plugin.h. */
118 /* Each plugin should define an initialization function with exactly
122 /* Each plugin should define this symbol to assert that it is
133 const struct plugin_name_args *plugin = (const struct plugin_name_args *) p;
134 return htab_hash_string (plugin->base_name);
143 const struct plugin_name_args *plugin = (const struct plugin_name_args *) s1;
144 return !strcmp (plugin->base_name, (const char *) s2);
148 /* Given a plugin's full-path name FULL_NAME, e.g. /pass/to/NAME.so,
164 /* Create a plugin_name_args object for the given plugin and insert it
171 struct plugin_name_args *plugin;
195 option). A GCC plugin is therefore probably a Mac OS plugin but their
212 "inaccessible plugin file %s expanded from short plugin name %s: %m",
227 /* If the same plugin (name) has been specified earlier, either emit an
232 plugin = (struct plugin_name_args *) *slot;
233 if (strcmp (plugin->full_name, plugin_name))
234 error ("plugin %qs was specified with different paths: %qs and %qs",
235 plugin->base_name, plugin->full_name, plugin_name);
239 plugin = XCNEW (struct plugin_name_args);
240 plugin->base_name = base_name;
241 plugin->full_name = plugin_name;
243 *slot = plugin;
267 the plugin name is 'foo' and the key is 'bar-primary-key'. */
310 /* Check if the named plugin has already been specified earlier in the
317 struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
332 If there are already arguments for this plugin, we will need to
336 if (plugin->argc > 0)
339 plugin->argc + 1);
340 memcpy (args, plugin->argv,
341 sizeof (struct plugin_argument) * plugin->argc);
342 XDELETEVEC (plugin->argv);
343 plugin->argv = args;
344 ++plugin->argc;
348 gcc_assert (plugin->argv == NULL);
349 plugin->argv = XNEWVEC (struct plugin_argument, 1);
350 plugin->argc = 1;
353 plugin->argv[plugin->argc - 1].key = key;
354 plugin->argv[plugin->argc - 1].value = value;
357 error ("plugin %s should be specified before %<-fplugin-arg-%s%> "
360 /* We don't need the plugin's name anymore. Just release it. */
364 /* Register additional plugin information. NAME is the name passed to
372 struct plugin_name_args *plugin;
376 error ("unable to register info for plugin %qs - plugin name not found",
380 plugin = (struct plugin_name_args *) *slot;
381 plugin->version = info->version;
382 plugin->help = info->help;
440 /* Called from the plugin's initialization code. Register a single callback.
443 PLUGIN_NAME - display name for this plugin
446 USER_DATA - plugin-provided data */
472 error ("unknown callback event registered by plugin %s",
505 error ("plugin %s registered a null callback function "
520 /* Remove a callback for EVENT which has been registered with for a plugin
541 /* Invoke all plugin callbacks registered with the specified event,
605 /* Try to initialize PLUGIN. Return true if successful. */
630 try_init_one_plugin (struct plugin_name_args *plugin)
635 dl_handle = LoadLibrary (plugin->full_name);
639 error ("cannot load plugin %s\n%s", plugin->full_name, err);
644 /* Check the plugin license. Unlike the name suggests, GetProcAddress()
650 "plugin %s is not licensed under a GPL-compatible license\n"
651 "%s", plugin->full_name, err);
663 error ("cannot find %s in plugin %s\n%s", str_plugin_init_func_name,
664 plugin->full_name, err);
669 /* Call the plugin-provided initialization routine with the arguments. */
670 if ((*plugin_init) (plugin, &gcc_version))
673 error ("fail to initialize plugin %s", plugin->full_name);
676 /* Leak dl_handle on purpose to ensure the plugin is loaded for the
692 try_init_one_plugin (struct plugin_name_args *plugin)
700 between the API expected by the plugin and the GCC API; we use
703 dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);
706 error ("cannot load plugin %s: %s", plugin->full_name, dlerror ());
713 /* Check the plugin license. */
716 "plugin %s is not licensed under a GPL-compatible license"
717 " %s", plugin->full_name, dlerror ());
726 error ("cannot find %s in plugin %s: %s", str_plugin_init_func_name,
727 plugin->full_name, err);
731 /* Call the plugin-provided initialization routine with the arguments. */
732 if ((*plugin_init) (plugin, &gcc_version))
735 error ("failed to initialize plugin %s", plugin->full_name);
738 /* leak dl_handle on purpose to ensure the plugin is loaded for the
744 /* Routine to dlopen and initialize one plugin. This function is passed to
755 struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
756 bool ok = try_init_one_plugin (plugin);
759 htab_remove_elt_with_hash (plugin_name_args_tab, plugin->base_name,
760 htab_hash_string (plugin->base_name));
761 XDELETE (plugin);
768 /* Main plugin initialization function. Called from compile_file() in
774 /* If no plugin was specified in the command-line, simply return. */
781 /* Traverse and initialize each plugin specified in the command-line. */
788 /* Release memory used by one plugin. */
793 struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
794 XDELETE (plugin);
798 /* Free memory allocated by the plugin system. */
809 the plugin code. */
826 /* Print the version of one plugin. */
832 struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
833 const char *version = plugin->version ? plugin->version : "Unknown version.";
835 fprintf (opt->file, " %s%s: %s\n", opt->indent, plugin->base_name, version);
839 /* Print the version of each plugin. */
854 /* Print help for one plugin. SLOT is the hash table slot. DATA is the
861 struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
862 const char *help = plugin->help ? plugin->help : "No help available .";
866 fprintf (opt->file, " %s%s:\n", opt->indent, plugin->base_name);
883 /* Print help for each plugin. The output goes to FILE and every line starts
1001 /* Retrieve the default plugin directory. The gcc driver should have passed
1003 -print-file-name=plugin option to gcc. */