Hello All,

Some plugins (including MELT, see http://gcc-melt.org/ for more)
are made of several C++ source files which all include "plugin-version.h"
because they have some C++ code which depends upon the particular version 
of GCC.

So they typically code

  #if GCCPLUGIN_VERSION >= 4009
     /* code for GCC 4.9 or newer. */
  #else 
     /* code for GCC 4.8 */
  #endif /*GCCPLUGIN_VERSION*/

after including "plugin-version.h"; however that file also defines static
data, notably `gcc_version`. That data symbol may be useless in most of 
the plugin files -except the one initializing the plugin. Having several
useless data symbols may disturb the debugger (since the static symbol
`gcc_version` is no longer unique) and may consume some tiny useless data
(at least when the plugin is compiled with -O0).

The attached small patch (for trunk svn rev. 217404) disables the definition 
of `gcc_version` when the preprocessor symbol GCCPLUGIN_SKIP_VERSION_DATA 
is defined as 1 before #include "plugin-version.h"

### gcc/ChangeLog entry:

2014-11-12  Basile Starynkevitch  <bas...@starynkevitch.net>

        * configure.ac (plugin-version.h): Don't define version data 
        when GCCPLUGIN_SKIP_VERSION_DATA was #define-d as 1.

        * doc/plugins.texi: (Plugins building): Document 
        GCCPLUGIN_SKIP_VERSION_DATA. Put it with GCCPLUGIN_VERSION* names
        in the function index.

###################

Ok for trunk? Comments are welcome.

Regards

-- 
Basile Starynkevitch     http://starynkevitch.net/Basile
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 217404)
+++ gcc/configure.ac	(working copy)
@@ -1664,6 +1664,10 @@
 #define GCCPLUGIN_VERSION_PATCHLEVEL   `echo $gcc_BASEVER | sed -e 's/^[0-9]*\.[0-9]*\.\([0-9]*\)$/\1/'`
 #define GCCPLUGIN_VERSION  (GCCPLUGIN_VERSION_MAJOR*1000 + GCCPLUGIN_VERSION_MINOR)
 
+/* Some plugins might not want the data below, they would define
+   GCCPLUGIN_SKIP_VERSION_DATA as 1 before including this.  */
+
+#if !GCCPLUGIN_SKIP_VERSION_DATA
 static char basever[] = "$gcc_BASEVER";
 static char datestamp[] = "$gcc_DATESTAMP";
 static char devphase[] = "$gcc_DEVPHASE";
@@ -1675,6 +1679,7 @@
 static struct plugin_gcc_version gcc_version = {basever, datestamp,
 						devphase, revision,
 						configuration_arguments};
+#endif /* GCCPLUGIN_SKIP_VERSION_DATA */
 EOF
 changequote([,])dnl
 
Index: gcc/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi	(revision 217404)
+++ gcc/doc/plugins.texi	(working copy)
@@ -157,6 +157,16 @@
 
 but you can also check the individual fields if you want a less strict check.
 
+A plugin might want to include in some of its source files the
+@file{plugin-version.h} header for preprocessor constants
+@code{GCCPLUGIN_VERSION} without defining the static symbol
+@code{gcc_version}. In that case it should define the preprocessor
+symbol @code{GCCPLUGIN_SKIP_VERSION_DATA} to @code{1} before including
+that header.
+@findex GCCPLUGIN_VERSION
+@findex GCCPLUGIN_SKIP_VERSION_DATA
+@findex gcc_version
+
 @subsection Plugin callbacks
 
 Callback functions have the following prototype:
@@ -488,6 +498,10 @@
 #error this GCC plugin is for GCC 4.7
 #endif
 @end smallexample
+@findex GCCPLUGIN_VERSION_MAJOR 
+@findex GCCPLUGIN_VERSION_MINOR
+@findex GCCPLUGIN_VERSION_PATCHLEVEL
+@findex GCCPLUGIN_VERSION
 
 The following GNU Makefile excerpt shows how to build a simple plugin:
 

Reply via email to