1
# DP: Backport of plugins to the 4.4 branch
3
svn diff svn://gcc.gnu.org/svn/gcc/branches/gcc-4_4-branch@157307 svn://gcc.gnu.org/svn/gcc/branches/gcc-4_4-plugins \
4
| sed -r 's,^--- (\S+)\t(\S+)(.*)$,--- a/src/\1\t\2,;s,^\+\+\+ (\S+)\t(\S+)(.*)$,+++ b/src/\1\t\2,'
6
Index: gcc/doc/sourcebuild.texi
7
===================================================================
8
--- a/src/gcc/doc/sourcebuild.texi (.../gcc-4_4-branch)
9
+++ b/src/gcc/doc/sourcebuild.texi (.../gcc-4_4-plugins)
12
Install man pages for the front end. This target should ignore
15
+Install headers needed for plugins.
17
Copies its dependencies into the source directory. This generally should
18
be used for generated files such as Bison output files which are not
19
Index: gcc/doc/plugins.texi
20
===================================================================
21
--- a/src/gcc/doc/plugins.texi (.../gcc-4_4-branch)
22
+++ b/src/gcc/doc/plugins.texi (.../gcc-4_4-plugins)
24
+@c Copyright (c) 2009 Free Software Foundation, Inc.
25
+@c Free Software Foundation, Inc.
26
+@c This is part of the GCC manual.
27
+@c For copying conditions, see the file gcc.texi.
33
+@section Loading Plugins
35
+Plugins are supported on platforms that support @option{-ldl
36
+-rdynamic}. They are loaded by the compiler using @code{dlopen}
37
+and invoked at pre-determined locations in the compilation
40
+Plugins are loaded with
42
+@option{-fplugin=/path/to/NAME.so} @option{-fplugin-arg-NAME-<key1>[=<value1>]}
44
+The plugin arguments are parsed by GCC and passed to respective
45
+plugins as key-value pairs. Multiple plugins can be invoked by
46
+specifying multiple @option{-fplugin} arguments.
51
+Plugins are activated by the compiler at specific events as defined in
52
+@file{gcc-plugin.h}. For each event of interest, the plugin should
53
+call @code{register_callback} specifying the name of the event and
54
+address of the callback function that will handle that event.
56
+The header @file{gcc-plugin.h} must be the first gcc header to be included.
58
+@subsection Plugin initialization
60
+Every plugin should export a function called @code{plugin_init} that
61
+is called right after the plugin is loaded. This function is
62
+responsible for registering all the callbacks required by the plugin
63
+and do any other required initialization.
65
+This function is called from @code{compile_file} right before invoking
66
+the parser. The arguments to @code{plugin_init} are:
69
+@item @code{plugin_info}: Plugin invocation information.
70
+@item @code{version}: GCC version.
73
+The @code{plugin_info} struct is defined as follows:
76
+struct plugin_name_args
78
+ char *base_name; /* Short name of the plugin
79
+ (filename without .so suffix). */
80
+ const char *full_name; /* Path to the plugin as specified with
82
+ int argc; /* Number of arguments specified with
83
+ -fplugin-arg-.... */
84
+ struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
85
+ const char *version; /* Version string provided by plugin. */
86
+ const char *help; /* Help string provided by plugin. */
90
+If initialization fails, @code{plugin_init} must return a non-zero
91
+value. Otherwise, it should return 0.
93
+The version of the GCC compiler loading the plugin is described by the
97
+struct plugin_gcc_version
99
+ const char *basever;
100
+ const char *datestamp;
101
+ const char *devphase;
102
+ const char *revision;
103
+ const char *configuration_arguments;
107
+The function @code{plugin_default_version_check} takes two pointers to
108
+such structure and compare them field by field. It can be used by the
109
+plugin's @code{plugin_init} function.
112
+@subsection Plugin callbacks
114
+Callback functions have the following prototype:
117
+/* The prototype for a plugin callback function.
118
+ gcc_data - event-specific data provided by GCC
119
+ user_data - plugin-specific data provided by the plug-in. */
120
+typedef void (*plugin_callback_func)(void *gcc_data, void *user_data);
123
+Callbacks can be invoked at the following pre-determined events:
129
+ PLUGIN_PASS_MANAGER_SETUP, /* To hook into pass manager. */
130
+ PLUGIN_FINISH_TYPE, /* After finishing parsing a type. */
131
+ PLUGIN_FINISH_UNIT, /* Useful for summary processing. */
132
+ PLUGIN_CXX_CP_PRE_GENERICIZE, /* Allows to see low level AST in C++ FE. */
133
+ PLUGIN_FINISH, /* Called before GCC exits. */
134
+ PLUGIN_INFO, /* Information about the plugin. */
135
+ PLUGIN_GGC_START, /* Called at start of GCC Garbage Collection. */
136
+ PLUGIN_GGC_MARKING, /* Extend the GGC marking. */
137
+ PLUGIN_GGC_END, /* Called at end of GGC. */
138
+ PLUGIN_REGISTER_GGC_ROOTS, /* Register an extra GGC root table. */
139
+ PLUGIN_ATTRIBUTES, /* Called during attribute registration */
140
+ PLUGIN_START_UNIT, /* Called before processing a translation unit. */
141
+ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback
147
+To register a callback, the plugin calls @code{register_callback} with
151
+@item @code{char *name}: Plugin name.
152
+@item @code{enum plugin_event event}: The event code.
153
+@item @code{plugin_callback_func callback}: The function that handles @code{event}.
154
+@item @code{void *user_data}: Pointer to plugin-specific data.
157
+For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, and
158
+PLUGIN_REGISTER_GGC_ROOTS pseudo-events the @code{callback} should be
159
+null, and the @code{user_data} is specific.
161
+@section Interacting with the pass manager
163
+There needs to be a way to add/reorder/remove passes dynamically. This
164
+is useful for both analysis plugins (plugging in after a certain pass
165
+such as CFG or an IPA pass) and optimization plugins.
167
+Basic support for inserting new passes or replacing existing passes is
168
+provided. A plugin registers a new pass with GCC by calling
169
+@code{register_callback} with the @code{PLUGIN_PASS_MANAGER_SETUP}
170
+event and a pointer to a @code{struct plugin_pass} object defined as follows
173
+enum pass_positioning_ops
175
+ PASS_POS_INSERT_AFTER, // Insert after the reference pass.
176
+ PASS_POS_INSERT_BEFORE, // Insert before the reference pass.
177
+ PASS_POS_REPLACE // Replace the reference pass.
182
+ struct opt_pass *pass; /* New pass provided by the plugin. */
183
+ const char *reference_pass_name; /* Name of the reference pass for hooking
184
+ up the new pass. */
185
+ int ref_pass_instance_number; /* Insert the pass at the specified
186
+ instance number of the reference pass. */
187
+ /* Do it for every instance if it is 0. */
188
+ enum pass_positioning_ops pos_op; /* how to insert the new pass. */
192
+/* Sample plugin code that registers a new pass. */
194
+plugin_init (struct plugin_name_args *plugin_info,
195
+ struct plugin_gcc_version *version)
197
+ struct plugin_pass pass_info;
201
+ /* Code to fill in the pass_info object with new pass information. */
205
+ /* Register the new pass. */
206
+ register_callback (plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
213
+@section Interacting with the GCC Garbage Collector
215
+Some plugins may want to be informed when GGC (the GCC Garbage
216
+Collector) is running. They can register callbacks for the
217
+@code{PLUGIN_GGC_START} and @code{PLUGIN_GGC_END} events (for which
218
+the callback is called with a null @code{gcc_data}) to be notified of
219
+the start or end of the GCC garbage collection.
221
+Some plugins may need to have GGC mark additional data. This can be
222
+done by registering a callback (called with a null @code{gcc_data})
223
+for the @code{PLUGIN_GGC_MARKING} event. Such callbacks can call the
224
+@code{ggc_set_mark} routine, preferably thru the @code{ggc_mark} macro
225
+(and conversely, these routines should usually not be used in plugins
226
+outside of the @code{PLUGIN_GGC_MARKING} event).
228
+Some plugins may need to add extra GGC root tables, e.g. to handle
229
+their own @code{GTY}-ed data. This can be done with the
230
+@code{PLUGIN_REGISTER_GGC_ROOTS} pseudo-event with a null callback and
231
+the extra root table as @code{user_data}. Running the @code{gengtype
232
+-p @var{source-dir} @var{file-list} @var{plugin*.c} ...} utility
233
+generates this extra root table.
235
+You should understand the details of memory management inside GCC
236
+before using @code{PLUGIN_GGC_MARKING} or
237
+@code{PLUGIN_REGISTER_GGC_ROOTS}.
240
+@section Giving information about a plugin
242
+A plugin should give some information to the user about itself. This
243
+uses the following structure:
248
+ const char *version;
253
+Such a structure is passed as the @code{user_data} by the plugin's
254
+init routine using @code{register_callback} with the
255
+@code{PLUGIN_INFO} pseudo-event and a null callback.
257
+@section Registering custom attributes
259
+For analysis purposes it is useful to be able to add custom attributes.
261
+The @code{PLUGIN_ATTRIBUTES} callback is called during attribute
262
+registration. Use the @code{register_attribute} function to register
266
+/* Attribute handler callback */
268
+handle_user_attribute (tree *node, tree name, tree args,
269
+ int flags, bool *no_add_attrs)
274
+/* Attribute definition */
275
+static struct attribute_spec user_attr =
276
+ @{ "user", 1, 1, false, false, false, handle_user_attribute @};
278
+/* Plugin callback called during attribute registration.
279
+Registered with register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL)
282
+register_attributes (void *event_data, void *data)
284
+ warning (0, G_("Callback to register attributes"));
285
+ register_attribute (&user_attr);
291
+@section Building GCC plugins
293
+If plugins are enabled, GCC installs the headers needed to build a
294
+plugin (somehwere in the installation tree, e.g. under
295
+@file{/usr/local}). In particular a @file{plugin/include} directory
296
+is installed, containing all the header files needed to build plugins.
298
+On most systems, you can query this @code{plugin} directory by
299
+invoking @command{gcc -print-file-name=plugin} (replace if needed
300
+@command{gcc} with the appropriate program path).
302
+The following GNU Makefile excerpt shows how to build a simple plugin:
306
+PLUGIN_SOURCE_FILES= plugin1.c plugin2.c
307
+PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
308
+GCCPLUGINS_DIR:= $(shell $(GCC) -print-file-name=plugin)
309
+CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -O2
311
+plugin.so: $(PLUGIN_OBJECT_FILES)
312
+ $(GCC) -shared $^ -o $@
315
+A single source file plugin may be built with @code{gcc -I`gcc
316
+-print-file-name=plugin`/include -fPIC -shared -O2 plugin.c -o
317
+plugin.so}, using backquote shell syntax to query the @file{plugin}
320
+Plugins needing to use @command{gengtype} require a GCC build
321
+directory for the same version of GCC that they will be linked
323
Index: gcc/doc/gccint.texi
324
===================================================================
325
--- a/src/gcc/doc/gccint.texi (.../gcc-4_4-branch)
326
+++ b/src/gcc/doc/gccint.texi (.../gcc-4_4-plugins)
328
* Collect2:: How @code{collect2} works; how it finds @code{ld}.
329
* Header Dirs:: Understanding the standard header file directories.
330
* Type Information:: GCC's memory management; generating type information.
331
+* Plugins:: Extending the compiler with plugins.
333
* Funding:: How to help assure funding for free software.
334
* GNU Project:: The GNU Project and GNU/Linux.
336
@include collect2.texi
337
@include headerdirs.texi
339
+@include plugins.texi
341
@include funding.texi
343
Index: gcc/doc/invoke.texi
344
===================================================================
345
--- a/src/gcc/doc/invoke.texi (.../gcc-4_4-branch)
346
+++ b/src/gcc/doc/invoke.texi (.../gcc-4_4-plugins)
348
@xref{Overall Options,,Options Controlling the Kind of Output}.
349
@gccoptlist{-c -S -E -o @var{file} -combine -pipe -pass-exit-codes @gol
350
-x @var{language} -v -### --help@r{[}=@var{class}@r{[},@dots{}@r{]]} --target-help @gol
351
---version -wrapper@@@var{file}}
352
+--version -wrapper@@@var{file} -fplugin=@var{file} -fplugin-arg-@var{name}=@var{arg}}
354
@item C Language Options
355
@xref{C Dialect Options,,Options Controlling C Dialect}.
356
@@ -1297,6 +1297,19 @@
357
This will invoke all subprograms of gcc under "gdb --args",
358
thus cc1 invocation will be "gdb --args cc1 ...".
360
+@item -fplugin=@var{name}.so
361
+Load the plugin code in file @var{name}.so, assumed to be a
362
+shared object to be dlopen'd by the compiler. The base name of
363
+the shared object file is used to identify the plugin for the
364
+purposes of argument parsing (See
365
+@option{-fplugin-arg-@var{name}-@var{key}=@var{value}} below).
366
+Each plugin should define the callback functions specified in the
369
+@item -fplugin-arg-@var{name}-@var{key}=@var{value}
370
+Define an argument called @var{key} with a value of @var{value}
371
+for the plugin called @var{name}.
373
@include @value{srcdir}/../libiberty/at-file.texi
376
Index: gcc/doc/gty.texi
377
===================================================================
378
--- a/src/gcc/doc/gty.texi (.../gcc-4_4-branch)
379
+++ b/src/gcc/doc/gty.texi (.../gcc-4_4-plugins)
381
somewhere. It will be called @file{gtype-@var{lang}.h}, where
382
@var{lang} is the name of the subdirectory the language is contained in.
384
+Plugins can add additional root tables. Run the @code{gengtype}
385
+utility in plugin mode as @code{gengtype -p @var{source-dir}
386
+@var{file-list} @var{plugin*.c}} with your plugin files
387
+@var{plugin*.c} using @code{GTY} to generate the corresponding
388
+@var{gt-plugin*.h} files. The GCC build tree is needed to be present in
392
@node Invoking the garbage collector
393
@section How to invoke the garbage collector
394
@cindex garbage collector, invocation
395
Index: gcc/doc/install.texi
396
===================================================================
397
--- a/src/gcc/doc/install.texi (.../gcc-4_4-branch)
398
+++ b/src/gcc/doc/install.texi (.../gcc-4_4-plugins)
399
@@ -1740,6 +1740,9 @@
400
@item --enable-aot-compile-rpm
401
Adds aot-compile-rpm to the list of installed scripts.
403
+@item --enable-browser-plugin
404
+Build the gcjwebplugin web browser plugin.
408
Use the single-byte @code{char} and the Win32 A functions natively,