public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH GCC5.0: conditionally skip gcc_version in gcc-plugin.h
@ 2014-11-12 13:07 Basile Starynkevitch
  2014-11-12 13:14 ` Jakub Jelinek
  0 siblings, 1 reply; 8+ messages in thread
From: Basile Starynkevitch @ 2014-11-12 13:07 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1495 bytes --]

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  <basile@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

[-- Attachment #2: gcc5-r217404-gccpluginversion-skip.diff --]
[-- Type: text/x-diff, Size: 1984 bytes --]

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:
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-11-13  6:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-12 13:07 PATCH GCC5.0: conditionally skip gcc_version in gcc-plugin.h Basile Starynkevitch
2014-11-12 13:14 ` Jakub Jelinek
2014-11-12 13:20   ` PATCH GCC5.0: conditionally skip gcc_version in plugin-version.h Basile Starynkevitch
2014-11-12 13:29     ` Jakub Jelinek
2014-11-12 13:38       ` Basile Starynkevitch
2014-11-13  6:53         ` Basile Starynkevitch
2014-11-12 14:37   ` PATCH GCC5.0: conditionally skip gcc_version in gcc-plugin.h Richard Biener
2014-11-12 14:38     ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).