summaryrefslogtreecommitdiffstats
path: root/scripts/gcc-plugins/gcc-common.h
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2017-01-10 19:48:03 -0500
committerKees Cook <keescook@chromium.org>2017-01-10 19:50:57 -0500
commit8d4973a1c01d4b38871fbc6631e1fdd20e6c9e90 (patch)
tree61cf46a09d1cfbb9e8354037196173b0b84ab7f0 /scripts/gcc-plugins/gcc-common.h
parent81d873a87114b05dbb74d1fbf0c4322ba4bfdee4 (diff)
gcc-plugins: add PASS_INFO and build_const_char_string()
This updates the GCC plugins gcc-common.h from PaX Team to include more helpers and header files, specifically adds the PASS_INFO() macro to make plugin declarations nicer and a helper for proper const string building. Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'scripts/gcc-plugins/gcc-common.h')
-rw-r--r--scripts/gcc-plugins/gcc-common.h55
1 files changed, 44 insertions, 11 deletions
diff --git a/scripts/gcc-plugins/gcc-common.h b/scripts/gcc-plugins/gcc-common.h
index 12262c0cc691..b232ab15624c 100644
--- a/scripts/gcc-plugins/gcc-common.h
+++ b/scripts/gcc-plugins/gcc-common.h
@@ -26,6 +26,9 @@
26#include "except.h" 26#include "except.h"
27#include "function.h" 27#include "function.h"
28#include "toplev.h" 28#include "toplev.h"
29#if BUILDING_GCC_VERSION >= 5000
30#include "expr.h"
31#endif
29#include "basic-block.h" 32#include "basic-block.h"
30#include "intl.h" 33#include "intl.h"
31#include "ggc.h" 34#include "ggc.h"
@@ -80,6 +83,9 @@
80#include "diagnostic.h" 83#include "diagnostic.h"
81#include "tree-dump.h" 84#include "tree-dump.h"
82#include "tree-pass.h" 85#include "tree-pass.h"
86#if BUILDING_GCC_VERSION >= 4009
87#include "pass_manager.h"
88#endif
83#include "predict.h" 89#include "predict.h"
84#include "ipa-utils.h" 90#include "ipa-utils.h"
85 91
@@ -119,20 +125,17 @@
119#include "builtins.h" 125#include "builtins.h"
120#endif 126#endif
121 127
122/* #include "expr.h" where are you... */
123extern rtx emit_move_insn(rtx x, rtx y);
124
125/* missing from basic_block.h... */ 128/* missing from basic_block.h... */
126extern void debug_dominance_info(enum cdi_direction dir); 129void debug_dominance_info(enum cdi_direction dir);
127extern void debug_dominance_tree(enum cdi_direction dir, basic_block root); 130void debug_dominance_tree(enum cdi_direction dir, basic_block root);
128 131
129#if BUILDING_GCC_VERSION == 4006 132#if BUILDING_GCC_VERSION == 4006
130extern void debug_gimple_stmt(gimple); 133void debug_gimple_stmt(gimple);
131extern void debug_gimple_seq(gimple_seq); 134void debug_gimple_seq(gimple_seq);
132extern void print_gimple_seq(FILE *, gimple_seq, int, int); 135void print_gimple_seq(FILE *, gimple_seq, int, int);
133extern void print_gimple_stmt(FILE *, gimple, int, int); 136void print_gimple_stmt(FILE *, gimple, int, int);
134extern void print_gimple_expr(FILE *, gimple, int, int); 137void print_gimple_expr(FILE *, gimple, int, int);
135extern void dump_gimple_stmt(pretty_printer *, gimple, int, int); 138void dump_gimple_stmt(pretty_printer *, gimple, int, int);
136#endif 139#endif
137 140
138#define __unused __attribute__((__unused__)) 141#define __unused __attribute__((__unused__))
@@ -146,6 +149,29 @@ extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
146/* should come from c-tree.h if only it were installed for gcc 4.5... */ 149/* should come from c-tree.h if only it were installed for gcc 4.5... */
147#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE) 150#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
148 151
152static inline tree build_const_char_string(int len, const char *str)
153{
154 tree cstr, elem, index, type;
155
156 cstr = build_string(len, str);
157 elem = build_type_variant(char_type_node, 1, 0);
158 index = build_index_type(size_int(len - 1));
159 type = build_array_type(elem, index);
160 TREE_TYPE(cstr) = type;
161 TREE_CONSTANT(cstr) = 1;
162 TREE_READONLY(cstr) = 1;
163 TREE_STATIC(cstr) = 1;
164 return cstr;
165}
166
167#define PASS_INFO(NAME, REF, ID, POS) \
168struct register_pass_info NAME##_pass_info = { \
169 .pass = make_##NAME##_pass(), \
170 .reference_pass_name = REF, \
171 .ref_pass_instance_number = ID, \
172 .pos_op = POS, \
173}
174
149#if BUILDING_GCC_VERSION == 4005 175#if BUILDING_GCC_VERSION == 4005
150#define FOR_EACH_LOCAL_DECL(FUN, I, D) \ 176#define FOR_EACH_LOCAL_DECL(FUN, I, D) \
151 for (tree vars = (FUN)->local_decls, (I) = 0; \ 177 for (tree vars = (FUN)->local_decls, (I) = 0; \
@@ -527,6 +553,8 @@ static inline const greturn *as_a_const_greturn(const_gimple stmt)
527#define section_name_prefix LTO_SECTION_NAME_PREFIX 553#define section_name_prefix LTO_SECTION_NAME_PREFIX
528#define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__) 554#define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)
529 555
556rtx emit_move_insn(rtx x, rtx y);
557
530typedef struct rtx_def rtx_insn; 558typedef struct rtx_def rtx_insn;
531 559
532static inline const char *get_decl_section_name(const_tree decl) 560static inline const char *get_decl_section_name(const_tree decl)
@@ -643,6 +671,11 @@ static inline const greturn *as_a_const_greturn(const_gimple stmt)
643#define NODE_DECL(node) (node)->decl 671#define NODE_DECL(node) (node)->decl
644#define cgraph_node_name(node) (node)->name() 672#define cgraph_node_name(node) (node)->name()
645#define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias 673#define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
674
675static inline opt_pass *get_pass_for_id(int id)
676{
677 return g->get_passes()->get_pass_for_id(id);
678}
646#endif 679#endif
647 680
648#if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000 681#if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000