annotate gcc/vtable-verify.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Copyright (C) 2013-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 This file is part of GCC.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
6 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
7 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
8 version.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
13 for more details.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
16 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
17 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 /* Virtual Table Pointer Security. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #ifndef VTABLE_VERIFY_H
kono
parents:
diff changeset
22 #define VTABLE_VERIFY_H
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "sbitmap.h"
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 /* The function decl used to create calls to __VLTVtableVerify. It must
kono
parents:
diff changeset
27 be global because it needs to be initialized in the C++ front end, but
kono
parents:
diff changeset
28 used in the middle end (in the vtable verification pass). */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 extern tree verify_vtbl_ptr_fndecl;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 /* Global variable keeping track of how many vtable map variables we
kono
parents:
diff changeset
33 have created. */
kono
parents:
diff changeset
34 extern unsigned num_vtable_map_nodes;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 /* Keep track of how many virtual calls we are actually verifying. */
kono
parents:
diff changeset
37 extern int total_num_virtual_calls;
kono
parents:
diff changeset
38 extern int total_num_verified_vcalls;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 /* Each vtable map variable corresponds to a virtual class. Each
kono
parents:
diff changeset
41 vtable map variable has a hash table associated with it, that keeps
kono
parents:
diff changeset
42 track of the vtable pointers for which we have generated a call to
kono
parents:
diff changeset
43 __VLTRegisterPair (with the current vtable map variable). This is
kono
parents:
diff changeset
44 the hash table node that is used for each entry in this hash table
kono
parents:
diff changeset
45 of vtable pointers.
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 Sometimes there are multiple valid vtable pointer entries that use
kono
parents:
diff changeset
48 the same vtable pointer decl with different offsets. Therefore,
kono
parents:
diff changeset
49 for each vtable pointer in the hash table, there is also an array
kono
parents:
diff changeset
50 of offsets used with that vtable. */
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 struct vtable_registration
kono
parents:
diff changeset
53 {
kono
parents:
diff changeset
54 tree vtable_decl; /* The var decl of the vtable. */
kono
parents:
diff changeset
55 vec<unsigned> offsets; /* The offsets array. */
kono
parents:
diff changeset
56 };
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 struct registration_hasher : nofree_ptr_hash <struct vtable_registration>
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 static inline hashval_t hash (const vtable_registration *);
kono
parents:
diff changeset
61 static inline bool equal (const vtable_registration *,
kono
parents:
diff changeset
62 const vtable_registration *);
kono
parents:
diff changeset
63 };
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 typedef hash_table<registration_hasher> register_table_type;
kono
parents:
diff changeset
66 typedef register_table_type::iterator registration_iterator_type;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* This struct is used to represent the class hierarchy information
kono
parents:
diff changeset
69 that we need. Each vtable map variable has an associated class
kono
parents:
diff changeset
70 hierarchy node (struct vtv_graph_node). Note: In this struct,
kono
parents:
diff changeset
71 'children' means immediate descendants in the class hierarchy;
kono
parents:
diff changeset
72 'descendant' means any descendant however many levels deep. */
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 struct vtv_graph_node {
kono
parents:
diff changeset
75 tree class_type; /* The record_type of the class. */
kono
parents:
diff changeset
76 unsigned class_uid; /* A unique, monotonically
kono
parents:
diff changeset
77 ascending id for class node.
kono
parents:
diff changeset
78 Each vtable map node also has
kono
parents:
diff changeset
79 an id. The class uid is the
kono
parents:
diff changeset
80 same as the vtable map node id
kono
parents:
diff changeset
81 for nodes corresponding to the
kono
parents:
diff changeset
82 same class. */
kono
parents:
diff changeset
83 unsigned num_processed_children; /* # of children for whom we have
kono
parents:
diff changeset
84 computed the class hierarchy
kono
parents:
diff changeset
85 transitive closure. */
kono
parents:
diff changeset
86 vec<struct vtv_graph_node *> parents; /* Vector of parents in the graph. */
kono
parents:
diff changeset
87 vec<struct vtv_graph_node *> children; /* Vector of children in the graph.*/
kono
parents:
diff changeset
88 sbitmap descendants; /* Bitmap representing all this node's
kono
parents:
diff changeset
89 descendants in the graph. */
kono
parents:
diff changeset
90 };
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* This is the node used for our hashtable of vtable map variable
kono
parents:
diff changeset
93 information. When we create a vtable map variable (var decl) we
kono
parents:
diff changeset
94 put it into one of these nodes; create a corresponding
kono
parents:
diff changeset
95 vtv_graph_node for our class hierarchy info and store that in this
kono
parents:
diff changeset
96 node; generate a unique (monotonically ascending) id for both the
kono
parents:
diff changeset
97 vtbl_map_node and the vtv_graph_node; and insert the node into two
kono
parents:
diff changeset
98 data structures (to make it easy to find in several different
kono
parents:
diff changeset
99 ways): 1). A hash table ("vtbl_map_hash" in vtable-verify.c).
kono
parents:
diff changeset
100 This gives us an easy way to check to see if we already have a node
kono
parents:
diff changeset
101 for the vtable map variable or not; and 2). An array (vector) of
kono
parents:
diff changeset
102 vtbl_map_nodes, where the array index corresponds to the unique id
kono
parents:
diff changeset
103 of the vtbl_map_node, which gives us an easy way to use bitmaps to
kono
parents:
diff changeset
104 represent and find the vtable map nodes. */
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 struct vtbl_map_node {
kono
parents:
diff changeset
107 tree vtbl_map_decl; /* The var decl for the vtable map
kono
parents:
diff changeset
108 variable. */
kono
parents:
diff changeset
109 tree class_name; /* The DECL_ASSEMBLER_NAME of the
kono
parents:
diff changeset
110 class. */
kono
parents:
diff changeset
111 struct vtv_graph_node *class_info; /* Our class hierarchy info for the
kono
parents:
diff changeset
112 class. */
kono
parents:
diff changeset
113 unsigned uid; /* The unique id for the vtable map
kono
parents:
diff changeset
114 variable. */
kono
parents:
diff changeset
115 struct vtbl_map_node *next, *prev; /* Pointers for the linked list
kono
parents:
diff changeset
116 structure. */
kono
parents:
diff changeset
117 register_table_type *registered; /* Hashtable of vtable pointers for which
kono
parents:
diff changeset
118 we have generated a _VLTRegisterPair
kono
parents:
diff changeset
119 call with this vtable map variable. */
kono
parents:
diff changeset
120 bool is_used; /* Boolean indicating if we used this vtable map
kono
parents:
diff changeset
121 variable in a call to __VLTVerifyVtablePointer. */
kono
parents:
diff changeset
122 };
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 /* Controls debugging for vtable verification. */
kono
parents:
diff changeset
125 extern bool vtv_debug;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 /* The global vector of vtbl_map_nodes. */
kono
parents:
diff changeset
128 extern vec<struct vtbl_map_node *> vtbl_map_nodes_vec;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* The global vectors for mangled class names for anonymous classes. */
kono
parents:
diff changeset
131 extern GTY(()) vec<tree, va_gc> *vtbl_mangled_name_types;
kono
parents:
diff changeset
132 extern GTY(()) vec<tree, va_gc> *vtbl_mangled_name_ids;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 extern void vtbl_register_mangled_name (tree, tree);
kono
parents:
diff changeset
135 extern struct vtbl_map_node *vtbl_map_get_node (tree);
kono
parents:
diff changeset
136 extern struct vtbl_map_node *find_or_create_vtbl_map_node (tree);
kono
parents:
diff changeset
137 extern void vtbl_map_node_class_insert (struct vtbl_map_node *, unsigned);
kono
parents:
diff changeset
138 extern bool vtbl_map_node_registration_find (struct vtbl_map_node *,
kono
parents:
diff changeset
139 tree, unsigned);
kono
parents:
diff changeset
140 extern bool vtbl_map_node_registration_insert (struct vtbl_map_node *,
kono
parents:
diff changeset
141 tree, unsigned);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 #endif /* VTABLE_VERIFY_H */