Skip to content

Commit

Permalink
Work-in-progress support for gcc 4.9
Browse files Browse the repository at this point in the history
This patch is a work-in-progress that makes the plugin closer to compilable
against what will become gcc 4.9 (currently gcc trunk; specifically r205593
patched to install various missing headers).

This is mostly:
  (A) tracking down where declarations have landed in the new layout
  (B) adding new headers to the list of those to be installed
  (C) some porting due to "real" changes e.g. passes becoming C++ classes.
  (D) adding -fno-rtti when building against 4.9 or later
  • Loading branch information
davidmalcolm committed Dec 3, 2013
1 parent 92ed26c commit 903202a
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -60,7 +60,7 @@ PLUGIN_OBJECT_GENERATED_FILES:= $(patsubst %.c,%.o,$(PLUGIN_GENERATED_SOURCE_FIL
PLUGIN_OBJECT_FILES:= $(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES)
GCCPLUGINS_DIR:= $(shell $(CC) --print-file-name=plugin)

GENERATOR_DEPS=cpybuilder.py wrapperbuilder.py
GENERATOR_DEPS=cpybuilder.py wrapperbuilder.py print-gcc-version

# The plugin supports both Python 2 and Python 3
#
Expand Down Expand Up @@ -154,7 +154,7 @@ $(PLUGIN_OBJECT_GENERATED_FILES): CPPFLAGS+= $(if $(srcdir),-I$(srcdir))
$(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES): %.o: $(srcdir)%.c autogenerated-config.h $(srcdir)gcc-python.h $(LIBGCC_C_API_SO) autogenerated-EXTRA_CFLAGS.txt
$(COMPILE.c) $(shell cat autogenerated-EXTRA_CFLAGS.txt) $(OUTPUT_OPTION) $<

print-gcc-version: print-gcc-version.c
print-gcc-version: print-gcc-version.c autogenerated-EXTRA_CFLAGS.txt
$(CC) \
$(CPPFLAGS) $(CFLAGS) \
$(shell cat autogenerated-EXTRA_CFLAGS.txt) \
Expand Down
5 changes: 3 additions & 2 deletions configbuilder.py
Expand Up @@ -136,8 +136,9 @@ def compile(self, test, src, extraargs):
outpath = os.path.join(dirpath, 'feature-test.o')
args= [os.environ.get('CC', 'gcc'),
'-c', # don't run the linker (no main)
'-o', outpath,
srcpath] + extraargs
'-o', outpath]
args += extraargs
args += [srcpath]
p = Popen(args, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
c = p.wait()
Expand Down
1 change: 1 addition & 0 deletions docs/versions.rst
Expand Up @@ -81,4 +81,5 @@ On my machine, running this currently gives::
4.6 4006
4.7 4007
4.8 4008
4.9 4009
=========== ========================
20 changes: 18 additions & 2 deletions gcc-c-api/gcc-callgraph.c
Expand Up @@ -18,6 +18,7 @@
*/

#include "gcc-callgraph.h"
#include "tree.h"
#include "cgraph.h"
#include "ggc.h"

Expand All @@ -34,7 +35,14 @@ gcc_private_make_cgraph_node (struct cgraph_node *inner)

GCC_PUBLIC_API (void) gcc_cgraph_node_mark_in_use (gcc_cgraph_node node)
{
/* As of gcc 4.9, a cgraph_node inherits from symtab node and uses that
struct's marking routine.
*/
#if (GCC_VERSION >= 4009)
gt_ggc_mx_symtab_node (node.inner);
#else
gt_ggc_mx_cgraph_node (node.inner);
#endif
}

GCC_PUBLIC_API (gcc_function_decl)
Expand All @@ -44,13 +52,21 @@ gcc_cgraph_node_get_decl (gcc_cgraph_node node)
tree decl;
field of cgraph_node in favor of
struct symtab_node_base symbol;
gcc 4.9 made cgraph_node inherit from symtab_node_base, renaming
the latter to symtab_node.
*/
tree decl;

#if (GCC_VERSION >= 4008)
decl = node.inner->symbol.decl;
#if (GCC_VERSION >= 4009)
/* Access decl field of parent class, symtab_node */
decl = node.inner->decl;
#else
# if (GCC_VERSION >= 4008)
decl = node.inner->symbol.decl;
# else
decl = node.inner->decl;
# endif
#endif

return gcc_private_make_function_decl (decl);
Expand Down
18 changes: 16 additions & 2 deletions gcc-c-api/gcc-cfg.c
Expand Up @@ -20,16 +20,30 @@
#include "gcc-cfg.h"

#include "tree.h"
#include "function.h"
#include "basic-block.h"

#if (GCC_VERSION >= 4009)
#include "tree-ssa-alias.h" /* needed by gimple.h in 4.9 */
#include "internal-fn.h" /* needed by gimple.h in 4.9 */
#include "is-a.h" /* needed by gimple.h in 4.9 */
#include "predict.h" /* needed by gimple.h in 4.9 */
#include "gimple-expr.h" /* needed by gimple.h in 4.9 */
#endif
#include "gimple.h"

/* gcc 4.9 moved gimple_stmt_iterator into this header */
#if (GCC_VERSION >= 4009)
#include "gimple-iterator.h"
#endif

#include "params.h"
#include "cp/name-lookup.h" /* for global_namespace */
#include "tree.h"
#include "function.h"
#include "diagnostic.h"
#include "cgraph.h"
#include "opts.h"
#include "c-family/c-pragma.h" /* for parse_in */
#include "basic-block.h"
#include "rtl.h"

#include "gcc-private-compat.h"
Expand Down
1 change: 0 additions & 1 deletion gcc-c-api/gcc-function.c
Expand Up @@ -22,7 +22,6 @@

/* TODO: rationalize these headers */
#include "tree.h"
#include "gimple.h"
#include "params.h"
#include "cp/name-lookup.h" /* for global_namespace */
#include "tree.h"
Expand Down
21 changes: 18 additions & 3 deletions gcc-c-api/gcc-gimple.c
Expand Up @@ -21,18 +21,27 @@
#include "gcc-tree.h"
#include "gcc-internal.h"

//#include "tree.h"
#include "tree.h"
#include "function.h"
#include "basic-block.h"
#if (GCC_VERSION >= 4009)
//#include "alias.h" /* needed by tree-ssa-alias.h in 4.9 */
#include "tree-ssa-alias.h" /* needed by gimple.h in 4.9 */
#include "internal-fn.h" /* needed by gimple.h in 4.9 */
#include "is-a.h" /* needed by gimple.h in 4.9 */
#include "predict.h" /* needed by gimple.h in 4.9 */
#include "gimple-expr.h" /* needed by gimple.h in 4.9 */
#endif
#include "gimple.h"

#if 0
#include "params.h"
#include "cp/name-lookup.h" /* for global_namespace */
#include "tree.h"
#include "function.h"
#include "diagnostic.h"
#include "cgraph.h"
#include "opts.h"
#include "c-family/c-pragma.h" /* for parse_in */
#include "basic-block.h"
#include "rtl.h"
#endif

Expand All @@ -41,7 +50,13 @@
GCC_IMPLEMENT_PUBLIC_API (void) gcc_gimple_mark_in_use (gcc_gimple stmt)
{
/* Mark the underlying object (recursing into its fields): */

/* GCC 4.9 converted gimple to a class hierarchy */
#if (GCC_VERSION >= 4009)
gt_ggc_mx_gimple_statement_base (stmt.inner);
#else
gt_ggc_mx_gimple_statement_d (stmt.inner);
#endif
}

GCC_IMPLEMENT_PRIVATE_API (struct gcc_gimple_phi)
Expand Down
25 changes: 20 additions & 5 deletions gcc-c-api/gcc-variable.c
Expand Up @@ -19,6 +19,7 @@

#include "gcc-variable.h"
#include "ggc.h"
#include "tree.h"
#include "cgraph.h" /* for varpool_nodes */

/***********************************************************
Expand All @@ -36,11 +37,17 @@ GCC_IMPLEMENT_PUBLIC_API (void) gcc_variable_mark_in_use (gcc_variable var)
{
/* Mark the underlying object (recursing into its fields): */

/* In GCC 4.8, struct varpool_node became part of union symtab_node_def */
#if (GCC_VERSION >= 4008)
gt_ggc_mx_symtab_node_def (var.inner);
/* In GCC 4.8, struct varpool_node became part of union symtab_node_def, and
In GCC 4.9, union symtab_node_def became class symtab_node.
*/
#if (GCC_VERSION >= 4009)
gt_ggc_mx_symtab_node (var.inner);
#else
# if (GCC_VERSION >= 4008)
gt_ggc_mx_symtab_node_def (var.inner);
# else
gt_ggc_mx_varpool_node (var.inner);
# endif
#endif
}

Expand All @@ -50,13 +57,21 @@ GCC_IMPLEMENT_PUBLIC_API (gcc_tree) gcc_variable_get_decl (gcc_variable var)
tree decl;
field of varpool_node in favor of
struct symtab_node_base symbol;
gcc 4.9 made varpool_node be a derived class of symtab_node_base,
renaming it to symtab_node.
*/
tree decl;

#if (GCC_VERSION >= 4008)
decl = var.inner->symbol.decl;
#if (GCC_VERSION >= 4009)
/* Get from base class */
decl = var.inner->decl;
#else
# if (GCC_VERSION >= 4008)
decl = var.inner->symbol.decl;
# else
decl = var.inner->decl;
# endif
#endif

return gcc_private_make_tree (decl);
Expand Down
5 changes: 5 additions & 0 deletions gcc-python-attribute.c
Expand Up @@ -25,6 +25,11 @@
#include "diagnostic.h"
#include "plugin.h"

#if (GCC_VERSION >= 4009)
/* GCC 4.9 moved debug_tree here: */
#include "print-tree.h"
#endif

/*
Attribute handling
*/
Expand Down
12 changes: 12 additions & 0 deletions gcc-python-gimple.c
Expand Up @@ -23,8 +23,13 @@
#include "gcc-python-compat.h"
#include "gcc-python-closure.h"
#include "gimple.h"

/* gimple_phi_arg_def etc were in tree-flow-inline.h prior to 4.9, when they
moved to gimple.h */
#if (GCC_VERSION < 4009)
#include "tree-flow.h"
#include "tree-flow-inline.h"
#endif

/*
Needed for pp_gimple_stmt_1 for gcc 4.8+;
Expand All @@ -36,6 +41,13 @@

#include "gcc-c-api/gcc-gimple.h"

/* GCC 4.9 moved struct walk_stmt_info into the new header gimple-walk.h,
which in turn needs the new header gimple-iterator.h: */
#if (GCC_VERSION >= 4009)
#include "gimple-iterator.h"
#include "gimple-walk.h"
#endif

gcc_gimple_asm
PyGccGimple_as_gcc_gimple_asm(struct PyGccGimple *self)
{
Expand Down

0 comments on commit 903202a

Please sign in to comment.