annotate gcc/symtab.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Symbol table.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Jan Hubicka
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "backend.h"
kono
parents:
diff changeset
25 #include "target.h"
kono
parents:
diff changeset
26 #include "rtl.h"
kono
parents:
diff changeset
27 #include "tree.h"
kono
parents:
diff changeset
28 #include "gimple.h"
kono
parents:
diff changeset
29 #include "timevar.h"
kono
parents:
diff changeset
30 #include "cgraph.h"
kono
parents:
diff changeset
31 #include "lto-streamer.h"
kono
parents:
diff changeset
32 #include "print-tree.h"
kono
parents:
diff changeset
33 #include "varasm.h"
kono
parents:
diff changeset
34 #include "langhooks.h"
kono
parents:
diff changeset
35 #include "output.h"
kono
parents:
diff changeset
36 #include "ipa-utils.h"
kono
parents:
diff changeset
37 #include "calls.h"
kono
parents:
diff changeset
38 #include "stringpool.h"
kono
parents:
diff changeset
39 #include "attribs.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
40 #include "builtins.h"
111
kono
parents:
diff changeset
41
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42 static const char *ipa_ref_use_name[] = {"read","write","addr","alias"};
111
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 const char * const ld_plugin_symbol_resolution_names[]=
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 "",
kono
parents:
diff changeset
47 "undef",
kono
parents:
diff changeset
48 "prevailing_def",
kono
parents:
diff changeset
49 "prevailing_def_ironly",
kono
parents:
diff changeset
50 "preempted_reg",
kono
parents:
diff changeset
51 "preempted_ir",
kono
parents:
diff changeset
52 "resolved_ir",
kono
parents:
diff changeset
53 "resolved_exec",
kono
parents:
diff changeset
54 "resolved_dyn",
kono
parents:
diff changeset
55 "prevailing_def_ironly_exp"
kono
parents:
diff changeset
56 };
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at ALIAS
kono
parents:
diff changeset
59 until we find an identifier that is not itself a transparent alias. */
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 static inline tree
kono
parents:
diff changeset
62 ultimate_transparent_alias_target (tree alias)
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 tree target = alias;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 while (IDENTIFIER_TRANSPARENT_ALIAS (target))
kono
parents:
diff changeset
67 {
kono
parents:
diff changeset
68 gcc_checking_assert (TREE_CHAIN (target));
kono
parents:
diff changeset
69 target = TREE_CHAIN (target);
kono
parents:
diff changeset
70 }
kono
parents:
diff changeset
71 gcc_checking_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
kono
parents:
diff changeset
72 && ! TREE_CHAIN (target));
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 return target;
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 /* Hash asmnames ignoring the user specified marks. */
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 hashval_t
kono
parents:
diff changeset
81 symbol_table::decl_assembler_name_hash (const_tree asmname)
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 if (IDENTIFIER_POINTER (asmname)[0] == '*')
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
kono
parents:
diff changeset
86 size_t ulp_len = strlen (user_label_prefix);
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 if (ulp_len == 0)
kono
parents:
diff changeset
89 ;
kono
parents:
diff changeset
90 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
kono
parents:
diff changeset
91 decl_str += ulp_len;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 return htab_hash_string (decl_str);
kono
parents:
diff changeset
94 }
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 return htab_hash_string (IDENTIFIER_POINTER (asmname));
kono
parents:
diff changeset
97 }
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
kono
parents:
diff changeset
100 name. */
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 bool
kono
parents:
diff changeset
103 symbol_table::assembler_names_equal_p (const char *name1, const char *name2)
kono
parents:
diff changeset
104 {
kono
parents:
diff changeset
105 if (name1 != name2)
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 if (name1[0] == '*')
kono
parents:
diff changeset
108 {
kono
parents:
diff changeset
109 size_t ulp_len = strlen (user_label_prefix);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 name1 ++;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 if (ulp_len == 0)
kono
parents:
diff changeset
114 ;
kono
parents:
diff changeset
115 else if (strncmp (name1, user_label_prefix, ulp_len) == 0)
kono
parents:
diff changeset
116 name1 += ulp_len;
kono
parents:
diff changeset
117 else
kono
parents:
diff changeset
118 return false;
kono
parents:
diff changeset
119 }
kono
parents:
diff changeset
120 if (name2[0] == '*')
kono
parents:
diff changeset
121 {
kono
parents:
diff changeset
122 size_t ulp_len = strlen (user_label_prefix);
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 name2 ++;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 if (ulp_len == 0)
kono
parents:
diff changeset
127 ;
kono
parents:
diff changeset
128 else if (strncmp (name2, user_label_prefix, ulp_len) == 0)
kono
parents:
diff changeset
129 name2 += ulp_len;
kono
parents:
diff changeset
130 else
kono
parents:
diff changeset
131 return false;
kono
parents:
diff changeset
132 }
kono
parents:
diff changeset
133 return !strcmp (name1, name2);
kono
parents:
diff changeset
134 }
kono
parents:
diff changeset
135 return true;
kono
parents:
diff changeset
136 }
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 bool
kono
parents:
diff changeset
141 symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
kono
parents:
diff changeset
142 {
kono
parents:
diff changeset
143 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
kono
parents:
diff changeset
144 const char *decl_str;
kono
parents:
diff changeset
145 const char *asmname_str;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 if (decl_asmname == asmname)
kono
parents:
diff changeset
148 return true;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 decl_str = IDENTIFIER_POINTER (decl_asmname);
kono
parents:
diff changeset
151 asmname_str = IDENTIFIER_POINTER (asmname);
kono
parents:
diff changeset
152 return assembler_names_equal_p (decl_str, asmname_str);
kono
parents:
diff changeset
153 }
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* Returns nonzero if P1 and P2 are equal. */
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 /* Insert NODE to assembler name hash. */
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 void
kono
parents:
diff changeset
161 symbol_table::insert_to_assembler_name_hash (symtab_node *node,
kono
parents:
diff changeset
162 bool with_clones)
kono
parents:
diff changeset
163 {
kono
parents:
diff changeset
164 if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
kono
parents:
diff changeset
165 return;
kono
parents:
diff changeset
166 gcc_checking_assert (!node->previous_sharing_asm_name
kono
parents:
diff changeset
167 && !node->next_sharing_asm_name);
kono
parents:
diff changeset
168 if (assembler_name_hash)
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 symtab_node **aslot;
kono
parents:
diff changeset
171 cgraph_node *cnode;
kono
parents:
diff changeset
172 tree decl = node->decl;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 tree name = DECL_ASSEMBLER_NAME (node->decl);
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 /* C++ FE can produce decls without associated assembler name and insert
kono
parents:
diff changeset
177 them to symtab to hold section or TLS information. */
kono
parents:
diff changeset
178 if (!name)
kono
parents:
diff changeset
179 return;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 hashval_t hash = decl_assembler_name_hash (name);
kono
parents:
diff changeset
182 aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
kono
parents:
diff changeset
183 gcc_assert (*aslot != node);
kono
parents:
diff changeset
184 node->next_sharing_asm_name = (symtab_node *)*aslot;
kono
parents:
diff changeset
185 if (*aslot != NULL)
kono
parents:
diff changeset
186 (*aslot)->previous_sharing_asm_name = node;
kono
parents:
diff changeset
187 *aslot = node;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 /* Update also possible inline clones sharing a decl. */
kono
parents:
diff changeset
190 cnode = dyn_cast <cgraph_node *> (node);
kono
parents:
diff changeset
191 if (cnode && cnode->clones && with_clones)
kono
parents:
diff changeset
192 for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
kono
parents:
diff changeset
193 if (cnode->decl == decl)
kono
parents:
diff changeset
194 insert_to_assembler_name_hash (cnode, true);
kono
parents:
diff changeset
195 }
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 }
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 /* Remove NODE from assembler name hash. */
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 void
kono
parents:
diff changeset
202 symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
kono
parents:
diff changeset
203 bool with_clones)
kono
parents:
diff changeset
204 {
kono
parents:
diff changeset
205 if (assembler_name_hash)
kono
parents:
diff changeset
206 {
kono
parents:
diff changeset
207 cgraph_node *cnode;
kono
parents:
diff changeset
208 tree decl = node->decl;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 if (node->next_sharing_asm_name)
kono
parents:
diff changeset
211 node->next_sharing_asm_name->previous_sharing_asm_name
kono
parents:
diff changeset
212 = node->previous_sharing_asm_name;
kono
parents:
diff changeset
213 if (node->previous_sharing_asm_name)
kono
parents:
diff changeset
214 {
kono
parents:
diff changeset
215 node->previous_sharing_asm_name->next_sharing_asm_name
kono
parents:
diff changeset
216 = node->next_sharing_asm_name;
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218 else
kono
parents:
diff changeset
219 {
kono
parents:
diff changeset
220 tree name = DECL_ASSEMBLER_NAME (node->decl);
kono
parents:
diff changeset
221 symtab_node **slot;
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 if (!name)
kono
parents:
diff changeset
224 return;
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 hashval_t hash = decl_assembler_name_hash (name);
kono
parents:
diff changeset
227 slot = assembler_name_hash->find_slot_with_hash (name, hash,
kono
parents:
diff changeset
228 NO_INSERT);
kono
parents:
diff changeset
229 gcc_assert (*slot == node);
kono
parents:
diff changeset
230 if (!node->next_sharing_asm_name)
kono
parents:
diff changeset
231 assembler_name_hash->clear_slot (slot);
kono
parents:
diff changeset
232 else
kono
parents:
diff changeset
233 *slot = node->next_sharing_asm_name;
kono
parents:
diff changeset
234 }
kono
parents:
diff changeset
235 node->next_sharing_asm_name = NULL;
kono
parents:
diff changeset
236 node->previous_sharing_asm_name = NULL;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 /* Update also possible inline clones sharing a decl. */
kono
parents:
diff changeset
239 cnode = dyn_cast <cgraph_node *> (node);
kono
parents:
diff changeset
240 if (cnode && cnode->clones && with_clones)
kono
parents:
diff changeset
241 for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
kono
parents:
diff changeset
242 if (cnode->decl == decl)
kono
parents:
diff changeset
243 unlink_from_assembler_name_hash (cnode, true);
kono
parents:
diff changeset
244 }
kono
parents:
diff changeset
245 }
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 /* Arrange node to be first in its entry of assembler_name_hash. */
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 void
kono
parents:
diff changeset
250 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
kono
parents:
diff changeset
251 {
kono
parents:
diff changeset
252 unlink_from_assembler_name_hash (node, false);
kono
parents:
diff changeset
253 insert_to_assembler_name_hash (node, false);
kono
parents:
diff changeset
254 }
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 /* Initalize asm name hash unless. */
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 void
kono
parents:
diff changeset
259 symbol_table::symtab_initialize_asm_name_hash (void)
kono
parents:
diff changeset
260 {
kono
parents:
diff changeset
261 symtab_node *node;
kono
parents:
diff changeset
262 if (!assembler_name_hash)
kono
parents:
diff changeset
263 {
kono
parents:
diff changeset
264 assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
kono
parents:
diff changeset
265 FOR_EACH_SYMBOL (node)
kono
parents:
diff changeset
266 insert_to_assembler_name_hash (node, false);
kono
parents:
diff changeset
267 }
kono
parents:
diff changeset
268 }
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 void
kono
parents:
diff changeset
273 symbol_table::change_decl_assembler_name (tree decl, tree name)
kono
parents:
diff changeset
274 {
kono
parents:
diff changeset
275 symtab_node *node = NULL;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 /* We can have user ASM names on things, like global register variables, that
kono
parents:
diff changeset
278 are not in the symbol table. */
kono
parents:
diff changeset
279 if ((VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
kono
parents:
diff changeset
280 || TREE_CODE (decl) == FUNCTION_DECL)
kono
parents:
diff changeset
281 node = symtab_node::get (decl);
kono
parents:
diff changeset
282 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
kono
parents:
diff changeset
283 {
kono
parents:
diff changeset
284 SET_DECL_ASSEMBLER_NAME (decl, name);
kono
parents:
diff changeset
285 if (node)
kono
parents:
diff changeset
286 insert_to_assembler_name_hash (node, true);
kono
parents:
diff changeset
287 }
kono
parents:
diff changeset
288 else
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 if (name == DECL_ASSEMBLER_NAME (decl))
kono
parents:
diff changeset
291 return;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
kono
parents:
diff changeset
294 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
kono
parents:
diff changeset
295 : NULL);
kono
parents:
diff changeset
296 if (node)
kono
parents:
diff changeset
297 unlink_from_assembler_name_hash (node, true);
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 const char *old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
kono
parents:
diff changeset
300 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
kono
parents:
diff changeset
301 && DECL_RTL_SET_P (decl))
kono
parents:
diff changeset
302 warning (0, "%qD renamed after being referenced in assembly", decl);
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 SET_DECL_ASSEMBLER_NAME (decl, name);
kono
parents:
diff changeset
305 if (alias)
kono
parents:
diff changeset
306 {
kono
parents:
diff changeset
307 IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
kono
parents:
diff changeset
308 TREE_CHAIN (name) = alias;
kono
parents:
diff changeset
309 }
kono
parents:
diff changeset
310 /* If we change assembler name, also all transparent aliases must
kono
parents:
diff changeset
311 be updated. There are three kinds - those having same assembler name,
kono
parents:
diff changeset
312 those being renamed in varasm.c and weakref being renamed by the
kono
parents:
diff changeset
313 assembler. */
kono
parents:
diff changeset
314 if (node)
kono
parents:
diff changeset
315 {
kono
parents:
diff changeset
316 insert_to_assembler_name_hash (node, true);
kono
parents:
diff changeset
317 ipa_ref *ref;
kono
parents:
diff changeset
318 for (unsigned i = 0; node->iterate_direct_aliases (i, ref); i++)
kono
parents:
diff changeset
319 {
kono
parents:
diff changeset
320 struct symtab_node *alias = ref->referring;
kono
parents:
diff changeset
321 if (alias->transparent_alias && !alias->weakref
kono
parents:
diff changeset
322 && symbol_table::assembler_names_equal_p
kono
parents:
diff changeset
323 (old_name, IDENTIFIER_POINTER (
kono
parents:
diff changeset
324 DECL_ASSEMBLER_NAME (alias->decl))))
kono
parents:
diff changeset
325 change_decl_assembler_name (alias->decl, name);
kono
parents:
diff changeset
326 else if (alias->transparent_alias
kono
parents:
diff changeset
327 && IDENTIFIER_TRANSPARENT_ALIAS (alias->decl))
kono
parents:
diff changeset
328 {
kono
parents:
diff changeset
329 gcc_assert (TREE_CHAIN (DECL_ASSEMBLER_NAME (alias->decl))
kono
parents:
diff changeset
330 && IDENTIFIER_TRANSPARENT_ALIAS
kono
parents:
diff changeset
331 (DECL_ASSEMBLER_NAME (alias->decl)));
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 TREE_CHAIN (DECL_ASSEMBLER_NAME (alias->decl)) =
kono
parents:
diff changeset
334 ultimate_transparent_alias_target
kono
parents:
diff changeset
335 (DECL_ASSEMBLER_NAME (node->decl));
kono
parents:
diff changeset
336 }
kono
parents:
diff changeset
337 #ifdef ASM_OUTPUT_WEAKREF
kono
parents:
diff changeset
338 else gcc_assert (!alias->transparent_alias || alias->weakref);
kono
parents:
diff changeset
339 #else
kono
parents:
diff changeset
340 else gcc_assert (!alias->transparent_alias);
kono
parents:
diff changeset
341 #endif
kono
parents:
diff changeset
342 }
kono
parents:
diff changeset
343 gcc_assert (!node->transparent_alias || !node->definition
kono
parents:
diff changeset
344 || node->weakref
kono
parents:
diff changeset
345 || TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
kono
parents:
diff changeset
346 || symbol_table::assembler_names_equal_p
kono
parents:
diff changeset
347 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
kono
parents:
diff changeset
348 IDENTIFIER_POINTER
kono
parents:
diff changeset
349 (DECL_ASSEMBLER_NAME
kono
parents:
diff changeset
350 (node->get_alias_target ()->decl))));
kono
parents:
diff changeset
351 }
kono
parents:
diff changeset
352 }
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 /* Hash sections by their names. */
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 hashval_t
kono
parents:
diff changeset
358 section_name_hasher::hash (section_hash_entry *n)
kono
parents:
diff changeset
359 {
kono
parents:
diff changeset
360 return htab_hash_string (n->name);
kono
parents:
diff changeset
361 }
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 /* Return true if section P1 name equals to P2. */
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 bool
kono
parents:
diff changeset
366 section_name_hasher::equal (section_hash_entry *n1, const char *name)
kono
parents:
diff changeset
367 {
kono
parents:
diff changeset
368 return n1->name == name || !strcmp (n1->name, name);
kono
parents:
diff changeset
369 }
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 /* Add node into symbol table. This function is not used directly, but via
kono
parents:
diff changeset
372 cgraph/varpool node creation routines. */
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 void
kono
parents:
diff changeset
375 symtab_node::register_symbol (void)
kono
parents:
diff changeset
376 {
kono
parents:
diff changeset
377 symtab->register_symbol (this);
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 if (!decl->decl_with_vis.symtab_node)
kono
parents:
diff changeset
380 decl->decl_with_vis.symtab_node = this;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 ref_list.clear ();
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 /* Be sure to do this last; C++ FE might create new nodes via
kono
parents:
diff changeset
385 DECL_ASSEMBLER_NAME langhook! */
kono
parents:
diff changeset
386 symtab->insert_to_assembler_name_hash (this, false);
kono
parents:
diff changeset
387 }
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 /* Remove NODE from same comdat group. */
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 void
kono
parents:
diff changeset
392 symtab_node::remove_from_same_comdat_group (void)
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 if (same_comdat_group)
kono
parents:
diff changeset
395 {
kono
parents:
diff changeset
396 symtab_node *prev;
kono
parents:
diff changeset
397 for (prev = same_comdat_group;
kono
parents:
diff changeset
398 prev->same_comdat_group != this;
kono
parents:
diff changeset
399 prev = prev->same_comdat_group)
kono
parents:
diff changeset
400 ;
kono
parents:
diff changeset
401 if (same_comdat_group == prev)
kono
parents:
diff changeset
402 prev->same_comdat_group = NULL;
kono
parents:
diff changeset
403 else
kono
parents:
diff changeset
404 prev->same_comdat_group = same_comdat_group;
kono
parents:
diff changeset
405 same_comdat_group = NULL;
kono
parents:
diff changeset
406 set_comdat_group (NULL);
kono
parents:
diff changeset
407 }
kono
parents:
diff changeset
408 }
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 /* Remove node from symbol table. This function is not used directly, but via
kono
parents:
diff changeset
411 cgraph/varpool node removal routines. */
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 void
kono
parents:
diff changeset
414 symtab_node::unregister (void)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 remove_all_references ();
kono
parents:
diff changeset
417 remove_all_referring ();
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 /* Remove reference to section. */
kono
parents:
diff changeset
420 set_section_for_node (NULL);
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 remove_from_same_comdat_group ();
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 symtab->unregister (this);
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 /* During LTO symtab merging we temporarily corrupt decl to symtab node
kono
parents:
diff changeset
427 hash. */
kono
parents:
diff changeset
428 gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
kono
parents:
diff changeset
429 if (decl->decl_with_vis.symtab_node == this)
kono
parents:
diff changeset
430 {
kono
parents:
diff changeset
431 symtab_node *replacement_node = NULL;
kono
parents:
diff changeset
432 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
kono
parents:
diff changeset
433 replacement_node = cnode->find_replacement ();
kono
parents:
diff changeset
434 decl->decl_with_vis.symtab_node = replacement_node;
kono
parents:
diff changeset
435 }
kono
parents:
diff changeset
436 if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
kono
parents:
diff changeset
437 symtab->unlink_from_assembler_name_hash (this, false);
kono
parents:
diff changeset
438 if (in_init_priority_hash)
kono
parents:
diff changeset
439 symtab->init_priority_hash->remove (this);
kono
parents:
diff changeset
440 }
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 /* Remove symbol from symbol table. */
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 void
kono
parents:
diff changeset
446 symtab_node::remove (void)
kono
parents:
diff changeset
447 {
kono
parents:
diff changeset
448 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
kono
parents:
diff changeset
449 cnode->remove ();
kono
parents:
diff changeset
450 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
kono
parents:
diff changeset
451 vnode->remove ();
kono
parents:
diff changeset
452 }
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 /* Add NEW_ to the same comdat group that OLD is in. */
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 void
kono
parents:
diff changeset
457 symtab_node::add_to_same_comdat_group (symtab_node *old_node)
kono
parents:
diff changeset
458 {
kono
parents:
diff changeset
459 gcc_assert (old_node->get_comdat_group ());
kono
parents:
diff changeset
460 gcc_assert (!same_comdat_group);
kono
parents:
diff changeset
461 gcc_assert (this != old_node);
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 set_comdat_group (old_node->get_comdat_group ());
kono
parents:
diff changeset
464 same_comdat_group = old_node;
kono
parents:
diff changeset
465 if (!old_node->same_comdat_group)
kono
parents:
diff changeset
466 old_node->same_comdat_group = this;
kono
parents:
diff changeset
467 else
kono
parents:
diff changeset
468 {
kono
parents:
diff changeset
469 symtab_node *n;
kono
parents:
diff changeset
470 for (n = old_node->same_comdat_group;
kono
parents:
diff changeset
471 n->same_comdat_group != old_node;
kono
parents:
diff changeset
472 n = n->same_comdat_group)
kono
parents:
diff changeset
473 ;
kono
parents:
diff changeset
474 n->same_comdat_group = this;
kono
parents:
diff changeset
475 }
kono
parents:
diff changeset
476 }
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 /* Dissolve the same_comdat_group list in which NODE resides. */
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 void
kono
parents:
diff changeset
481 symtab_node::dissolve_same_comdat_group_list (void)
kono
parents:
diff changeset
482 {
kono
parents:
diff changeset
483 symtab_node *n = this;
kono
parents:
diff changeset
484 symtab_node *next;
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 if (!same_comdat_group)
kono
parents:
diff changeset
487 return;
kono
parents:
diff changeset
488 do
kono
parents:
diff changeset
489 {
kono
parents:
diff changeset
490 next = n->same_comdat_group;
kono
parents:
diff changeset
491 n->same_comdat_group = NULL;
kono
parents:
diff changeset
492 /* Clear comdat_group for comdat locals, since
kono
parents:
diff changeset
493 make_decl_local doesn't. */
kono
parents:
diff changeset
494 if (!TREE_PUBLIC (n->decl))
kono
parents:
diff changeset
495 n->set_comdat_group (NULL);
kono
parents:
diff changeset
496 n = next;
kono
parents:
diff changeset
497 }
kono
parents:
diff changeset
498 while (n != this);
kono
parents:
diff changeset
499 }
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 /* Return printable assembler name of NODE.
kono
parents:
diff changeset
502 This function is used only for debugging. When assembler name
kono
parents:
diff changeset
503 is unknown go with identifier name. */
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 const char *
kono
parents:
diff changeset
506 symtab_node::asm_name () const
kono
parents:
diff changeset
507 {
kono
parents:
diff changeset
508 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
kono
parents:
diff changeset
509 return name ();
kono
parents:
diff changeset
510 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
kono
parents:
diff changeset
511 }
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 /* Return printable identifier name. */
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 const char *
kono
parents:
diff changeset
516 symtab_node::name () const
kono
parents:
diff changeset
517 {
kono
parents:
diff changeset
518 if (!DECL_NAME (decl))
kono
parents:
diff changeset
519 {
kono
parents:
diff changeset
520 if (DECL_ASSEMBLER_NAME_SET_P (decl))
kono
parents:
diff changeset
521 return asm_name ();
kono
parents:
diff changeset
522 else
kono
parents:
diff changeset
523 return "<unnamed>";
kono
parents:
diff changeset
524 }
kono
parents:
diff changeset
525 return lang_hooks.decl_printable_name (decl, 2);
kono
parents:
diff changeset
526 }
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 const char *
kono
parents:
diff changeset
529 symtab_node::get_dump_name (bool asm_name_p) const
kono
parents:
diff changeset
530 {
kono
parents:
diff changeset
531 #define EXTRA 16
kono
parents:
diff changeset
532 const char *fname = asm_name_p ? asm_name () : name ();
kono
parents:
diff changeset
533 unsigned l = strlen (fname);
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 char *s = (char *)ggc_internal_cleared_alloc (l + EXTRA);
kono
parents:
diff changeset
536 snprintf (s, l + EXTRA, "%s/%d", fname, order);
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 return s;
kono
parents:
diff changeset
539 }
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 const char *
kono
parents:
diff changeset
542 symtab_node::dump_name () const
kono
parents:
diff changeset
543 {
kono
parents:
diff changeset
544 return get_dump_name (false);
kono
parents:
diff changeset
545 }
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 const char *
kono
parents:
diff changeset
548 symtab_node::dump_asm_name () const
kono
parents:
diff changeset
549 {
kono
parents:
diff changeset
550 return get_dump_name (true);
kono
parents:
diff changeset
551 }
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 /* Return ipa reference from this symtab_node to
kono
parents:
diff changeset
554 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
kono
parents:
diff changeset
555 of the use. */
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 ipa_ref *
kono
parents:
diff changeset
558 symtab_node::create_reference (symtab_node *referred_node,
kono
parents:
diff changeset
559 enum ipa_ref_use use_type)
kono
parents:
diff changeset
560 {
kono
parents:
diff changeset
561 return create_reference (referred_node, use_type, NULL);
kono
parents:
diff changeset
562 }
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 /* Return ipa reference from this symtab_node to
kono
parents:
diff changeset
566 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
kono
parents:
diff changeset
567 of the use and STMT the statement (if it exists). */
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 ipa_ref *
kono
parents:
diff changeset
570 symtab_node::create_reference (symtab_node *referred_node,
kono
parents:
diff changeset
571 enum ipa_ref_use use_type, gimple *stmt)
kono
parents:
diff changeset
572 {
kono
parents:
diff changeset
573 ipa_ref *ref = NULL, *ref2 = NULL;
kono
parents:
diff changeset
574 ipa_ref_list *list, *list2;
kono
parents:
diff changeset
575 ipa_ref_t *old_references;
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
kono
parents:
diff changeset
578 gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 list = &ref_list;
kono
parents:
diff changeset
581 old_references = vec_safe_address (list->references);
kono
parents:
diff changeset
582 vec_safe_grow (list->references, vec_safe_length (list->references) + 1);
kono
parents:
diff changeset
583 ref = &list->references->last ();
kono
parents:
diff changeset
584
kono
parents:
diff changeset
585 list2 = &referred_node->ref_list;
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
kono
parents:
diff changeset
588 if(use_type == IPA_REF_ALIAS)
kono
parents:
diff changeset
589 {
kono
parents:
diff changeset
590 list2->referring.safe_insert (0, ref);
kono
parents:
diff changeset
591 ref->referred_index = 0;
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 for (unsigned int i = 1; i < list2->referring.length (); i++)
kono
parents:
diff changeset
594 list2->referring[i]->referred_index = i;
kono
parents:
diff changeset
595 }
kono
parents:
diff changeset
596 else
kono
parents:
diff changeset
597 {
kono
parents:
diff changeset
598 list2->referring.safe_push (ref);
kono
parents:
diff changeset
599 ref->referred_index = list2->referring.length () - 1;
kono
parents:
diff changeset
600 }
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 ref->referring = this;
kono
parents:
diff changeset
603 ref->referred = referred_node;
kono
parents:
diff changeset
604 ref->stmt = stmt;
kono
parents:
diff changeset
605 ref->lto_stmt_uid = 0;
kono
parents:
diff changeset
606 ref->use = use_type;
kono
parents:
diff changeset
607 ref->speculative = 0;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 /* If vector was moved in memory, update pointers. */
kono
parents:
diff changeset
610 if (old_references != list->references->address ())
kono
parents:
diff changeset
611 {
kono
parents:
diff changeset
612 int i;
kono
parents:
diff changeset
613 for (i = 0; iterate_reference(i, ref2); i++)
kono
parents:
diff changeset
614 ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
kono
parents:
diff changeset
615 }
kono
parents:
diff changeset
616 return ref;
kono
parents:
diff changeset
617 }
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 ipa_ref *
kono
parents:
diff changeset
620 symtab_node::maybe_create_reference (tree val, gimple *stmt)
kono
parents:
diff changeset
621 {
kono
parents:
diff changeset
622 STRIP_NOPS (val);
kono
parents:
diff changeset
623 ipa_ref_use use_type;
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 switch (TREE_CODE (val))
kono
parents:
diff changeset
626 {
kono
parents:
diff changeset
627 case VAR_DECL:
kono
parents:
diff changeset
628 use_type = IPA_REF_LOAD;
kono
parents:
diff changeset
629 break;
kono
parents:
diff changeset
630 case ADDR_EXPR:
kono
parents:
diff changeset
631 use_type = IPA_REF_ADDR;
kono
parents:
diff changeset
632 break;
kono
parents:
diff changeset
633 default:
kono
parents:
diff changeset
634 gcc_assert (!handled_component_p (val));
kono
parents:
diff changeset
635 return NULL;
kono
parents:
diff changeset
636 }
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 val = get_base_var (val);
kono
parents:
diff changeset
639 if (val && VAR_OR_FUNCTION_DECL_P (val))
kono
parents:
diff changeset
640 {
kono
parents:
diff changeset
641 symtab_node *referred = symtab_node::get (val);
kono
parents:
diff changeset
642 gcc_checking_assert (referred);
kono
parents:
diff changeset
643 return create_reference (referred, use_type, stmt);
kono
parents:
diff changeset
644 }
kono
parents:
diff changeset
645 return NULL;
kono
parents:
diff changeset
646 }
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 /* Clone all references from symtab NODE to this symtab_node. */
kono
parents:
diff changeset
649
kono
parents:
diff changeset
650 void
kono
parents:
diff changeset
651 symtab_node::clone_references (symtab_node *node)
kono
parents:
diff changeset
652 {
kono
parents:
diff changeset
653 ipa_ref *ref = NULL, *ref2 = NULL;
kono
parents:
diff changeset
654 int i;
kono
parents:
diff changeset
655 for (i = 0; node->iterate_reference (i, ref); i++)
kono
parents:
diff changeset
656 {
kono
parents:
diff changeset
657 bool speculative = ref->speculative;
kono
parents:
diff changeset
658 unsigned int stmt_uid = ref->lto_stmt_uid;
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660 ref2 = create_reference (ref->referred, ref->use, ref->stmt);
kono
parents:
diff changeset
661 ref2->speculative = speculative;
kono
parents:
diff changeset
662 ref2->lto_stmt_uid = stmt_uid;
kono
parents:
diff changeset
663 }
kono
parents:
diff changeset
664 }
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 /* Clone all referring from symtab NODE to this symtab_node. */
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 void
kono
parents:
diff changeset
669 symtab_node::clone_referring (symtab_node *node)
kono
parents:
diff changeset
670 {
kono
parents:
diff changeset
671 ipa_ref *ref = NULL, *ref2 = NULL;
kono
parents:
diff changeset
672 int i;
kono
parents:
diff changeset
673 for (i = 0; node->iterate_referring(i, ref); i++)
kono
parents:
diff changeset
674 {
kono
parents:
diff changeset
675 bool speculative = ref->speculative;
kono
parents:
diff changeset
676 unsigned int stmt_uid = ref->lto_stmt_uid;
kono
parents:
diff changeset
677
kono
parents:
diff changeset
678 ref2 = ref->referring->create_reference (this, ref->use, ref->stmt);
kono
parents:
diff changeset
679 ref2->speculative = speculative;
kono
parents:
diff changeset
680 ref2->lto_stmt_uid = stmt_uid;
kono
parents:
diff changeset
681 }
kono
parents:
diff changeset
682 }
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 ipa_ref *
kono
parents:
diff changeset
687 symtab_node::clone_reference (ipa_ref *ref, gimple *stmt)
kono
parents:
diff changeset
688 {
kono
parents:
diff changeset
689 bool speculative = ref->speculative;
kono
parents:
diff changeset
690 unsigned int stmt_uid = ref->lto_stmt_uid;
kono
parents:
diff changeset
691 ipa_ref *ref2;
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 ref2 = create_reference (ref->referred, ref->use, stmt);
kono
parents:
diff changeset
694 ref2->speculative = speculative;
kono
parents:
diff changeset
695 ref2->lto_stmt_uid = stmt_uid;
kono
parents:
diff changeset
696 return ref2;
kono
parents:
diff changeset
697 }
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 /* Find the structure describing a reference to REFERRED_NODE
kono
parents:
diff changeset
700 and associated with statement STMT. */
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 ipa_ref *
kono
parents:
diff changeset
703 symtab_node::find_reference (symtab_node *referred_node,
kono
parents:
diff changeset
704 gimple *stmt, unsigned int lto_stmt_uid)
kono
parents:
diff changeset
705 {
kono
parents:
diff changeset
706 ipa_ref *r = NULL;
kono
parents:
diff changeset
707 int i;
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 for (i = 0; iterate_reference (i, r); i++)
kono
parents:
diff changeset
710 if (r->referred == referred_node
kono
parents:
diff changeset
711 && !r->speculative
kono
parents:
diff changeset
712 && ((stmt && r->stmt == stmt)
kono
parents:
diff changeset
713 || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
kono
parents:
diff changeset
714 || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid)))
kono
parents:
diff changeset
715 return r;
kono
parents:
diff changeset
716 return NULL;
kono
parents:
diff changeset
717 }
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 /* Remove all references that are associated with statement STMT. */
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 void
kono
parents:
diff changeset
722 symtab_node::remove_stmt_references (gimple *stmt)
kono
parents:
diff changeset
723 {
kono
parents:
diff changeset
724 ipa_ref *r = NULL;
kono
parents:
diff changeset
725 int i = 0;
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 while (iterate_reference (i, r))
kono
parents:
diff changeset
728 if (r->stmt == stmt)
kono
parents:
diff changeset
729 r->remove_reference ();
kono
parents:
diff changeset
730 else
kono
parents:
diff changeset
731 i++;
kono
parents:
diff changeset
732 }
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 /* Remove all stmt references in non-speculative references.
kono
parents:
diff changeset
735 Those are not maintained during inlining & clonning.
kono
parents:
diff changeset
736 The exception are speculative references that are updated along
kono
parents:
diff changeset
737 with callgraph edges associated with them. */
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 void
kono
parents:
diff changeset
740 symtab_node::clear_stmts_in_references (void)
kono
parents:
diff changeset
741 {
kono
parents:
diff changeset
742 ipa_ref *r = NULL;
kono
parents:
diff changeset
743 int i;
kono
parents:
diff changeset
744
kono
parents:
diff changeset
745 for (i = 0; iterate_reference (i, r); i++)
kono
parents:
diff changeset
746 if (!r->speculative)
kono
parents:
diff changeset
747 {
kono
parents:
diff changeset
748 r->stmt = NULL;
kono
parents:
diff changeset
749 r->lto_stmt_uid = 0;
kono
parents:
diff changeset
750 }
kono
parents:
diff changeset
751 }
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 /* Remove all references in ref list. */
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 void
kono
parents:
diff changeset
756 symtab_node::remove_all_references (void)
kono
parents:
diff changeset
757 {
kono
parents:
diff changeset
758 while (vec_safe_length (ref_list.references))
kono
parents:
diff changeset
759 ref_list.references->last ().remove_reference ();
kono
parents:
diff changeset
760 vec_free (ref_list.references);
kono
parents:
diff changeset
761 }
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 /* Remove all referring items in ref list. */
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 void
kono
parents:
diff changeset
766 symtab_node::remove_all_referring (void)
kono
parents:
diff changeset
767 {
kono
parents:
diff changeset
768 while (ref_list.referring.length ())
kono
parents:
diff changeset
769 ref_list.referring.last ()->remove_reference ();
kono
parents:
diff changeset
770 ref_list.referring.release ();
kono
parents:
diff changeset
771 }
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 /* Dump references in ref list to FILE. */
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 void
kono
parents:
diff changeset
776 symtab_node::dump_references (FILE *file)
kono
parents:
diff changeset
777 {
kono
parents:
diff changeset
778 ipa_ref *ref = NULL;
kono
parents:
diff changeset
779 int i;
kono
parents:
diff changeset
780 for (i = 0; iterate_reference (i, ref); i++)
kono
parents:
diff changeset
781 {
kono
parents:
diff changeset
782 fprintf (file, "%s (%s)",
kono
parents:
diff changeset
783 ref->referred->dump_asm_name (),
kono
parents:
diff changeset
784 ipa_ref_use_name [ref->use]);
kono
parents:
diff changeset
785 if (ref->speculative)
kono
parents:
diff changeset
786 fprintf (file, " (speculative)");
kono
parents:
diff changeset
787 }
kono
parents:
diff changeset
788 fprintf (file, "\n");
kono
parents:
diff changeset
789 }
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 /* Dump referring in list to FILE. */
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 void
kono
parents:
diff changeset
794 symtab_node::dump_referring (FILE *file)
kono
parents:
diff changeset
795 {
kono
parents:
diff changeset
796 ipa_ref *ref = NULL;
kono
parents:
diff changeset
797 int i;
kono
parents:
diff changeset
798 for (i = 0; iterate_referring(i, ref); i++)
kono
parents:
diff changeset
799 {
kono
parents:
diff changeset
800 fprintf (file, "%s (%s)",
kono
parents:
diff changeset
801 ref->referring->dump_asm_name (),
kono
parents:
diff changeset
802 ipa_ref_use_name [ref->use]);
kono
parents:
diff changeset
803 if (ref->speculative)
kono
parents:
diff changeset
804 fprintf (file, " (speculative)");
kono
parents:
diff changeset
805 }
kono
parents:
diff changeset
806 fprintf (file, "\n");
kono
parents:
diff changeset
807 }
kono
parents:
diff changeset
808
kono
parents:
diff changeset
809 static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
kono
parents:
diff changeset
810
kono
parents:
diff changeset
811 /* Dump base fields of symtab nodes to F. Not to be used directly. */
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 void
kono
parents:
diff changeset
814 symtab_node::dump_base (FILE *f)
kono
parents:
diff changeset
815 {
kono
parents:
diff changeset
816 static const char * const visibility_types[] = {
kono
parents:
diff changeset
817 "default", "protected", "hidden", "internal"
kono
parents:
diff changeset
818 };
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 fprintf (f, "%s (%s)", dump_asm_name (), name ());
kono
parents:
diff changeset
821 dump_addr (f, " @", (void *)this);
kono
parents:
diff changeset
822 fprintf (f, "\n Type: %s", symtab_type_names[type]);
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 if (definition)
kono
parents:
diff changeset
825 fprintf (f, " definition");
kono
parents:
diff changeset
826 if (analyzed)
kono
parents:
diff changeset
827 fprintf (f, " analyzed");
kono
parents:
diff changeset
828 if (alias)
kono
parents:
diff changeset
829 fprintf (f, " alias");
kono
parents:
diff changeset
830 if (transparent_alias)
kono
parents:
diff changeset
831 fprintf (f, " transparent_alias");
kono
parents:
diff changeset
832 if (weakref)
kono
parents:
diff changeset
833 fprintf (f, " weakref");
kono
parents:
diff changeset
834 if (cpp_implicit_alias)
kono
parents:
diff changeset
835 fprintf (f, " cpp_implicit_alias");
kono
parents:
diff changeset
836 if (alias_target)
kono
parents:
diff changeset
837 fprintf (f, " target:%s",
kono
parents:
diff changeset
838 DECL_P (alias_target)
kono
parents:
diff changeset
839 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
kono
parents:
diff changeset
840 (alias_target))
kono
parents:
diff changeset
841 : IDENTIFIER_POINTER (alias_target));
kono
parents:
diff changeset
842 if (body_removed)
kono
parents:
diff changeset
843 fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
kono
parents:
diff changeset
844 fprintf (f, "\n Visibility:");
kono
parents:
diff changeset
845 if (in_other_partition)
kono
parents:
diff changeset
846 fprintf (f, " in_other_partition");
kono
parents:
diff changeset
847 if (used_from_other_partition)
kono
parents:
diff changeset
848 fprintf (f, " used_from_other_partition");
kono
parents:
diff changeset
849 if (force_output)
kono
parents:
diff changeset
850 fprintf (f, " force_output");
kono
parents:
diff changeset
851 if (forced_by_abi)
kono
parents:
diff changeset
852 fprintf (f, " forced_by_abi");
kono
parents:
diff changeset
853 if (externally_visible)
kono
parents:
diff changeset
854 fprintf (f, " externally_visible");
kono
parents:
diff changeset
855 if (no_reorder)
kono
parents:
diff changeset
856 fprintf (f, " no_reorder");
kono
parents:
diff changeset
857 if (resolution != LDPR_UNKNOWN)
kono
parents:
diff changeset
858 fprintf (f, " %s",
kono
parents:
diff changeset
859 ld_plugin_symbol_resolution_names[(int)resolution]);
kono
parents:
diff changeset
860 if (TREE_ASM_WRITTEN (decl))
kono
parents:
diff changeset
861 fprintf (f, " asm_written");
kono
parents:
diff changeset
862 if (DECL_EXTERNAL (decl))
kono
parents:
diff changeset
863 fprintf (f, " external");
kono
parents:
diff changeset
864 if (TREE_PUBLIC (decl))
kono
parents:
diff changeset
865 fprintf (f, " public");
kono
parents:
diff changeset
866 if (DECL_COMMON (decl))
kono
parents:
diff changeset
867 fprintf (f, " common");
kono
parents:
diff changeset
868 if (DECL_WEAK (decl))
kono
parents:
diff changeset
869 fprintf (f, " weak");
kono
parents:
diff changeset
870 if (DECL_DLLIMPORT_P (decl))
kono
parents:
diff changeset
871 fprintf (f, " dll_import");
kono
parents:
diff changeset
872 if (DECL_COMDAT (decl))
kono
parents:
diff changeset
873 fprintf (f, " comdat");
kono
parents:
diff changeset
874 if (get_comdat_group ())
kono
parents:
diff changeset
875 fprintf (f, " comdat_group:%s",
kono
parents:
diff changeset
876 IDENTIFIER_POINTER (get_comdat_group_id ()));
kono
parents:
diff changeset
877 if (DECL_ONE_ONLY (decl))
kono
parents:
diff changeset
878 fprintf (f, " one_only");
kono
parents:
diff changeset
879 if (get_section ())
kono
parents:
diff changeset
880 fprintf (f, " section:%s",
kono
parents:
diff changeset
881 get_section ());
kono
parents:
diff changeset
882 if (implicit_section)
kono
parents:
diff changeset
883 fprintf (f," (implicit_section)");
kono
parents:
diff changeset
884 if (DECL_VISIBILITY_SPECIFIED (decl))
kono
parents:
diff changeset
885 fprintf (f, " visibility_specified");
kono
parents:
diff changeset
886 if (DECL_VISIBILITY (decl))
kono
parents:
diff changeset
887 fprintf (f, " visibility:%s",
kono
parents:
diff changeset
888 visibility_types [DECL_VISIBILITY (decl)]);
kono
parents:
diff changeset
889 if (DECL_VIRTUAL_P (decl))
kono
parents:
diff changeset
890 fprintf (f, " virtual");
kono
parents:
diff changeset
891 if (DECL_ARTIFICIAL (decl))
kono
parents:
diff changeset
892 fprintf (f, " artificial");
kono
parents:
diff changeset
893 if (TREE_CODE (decl) == FUNCTION_DECL)
kono
parents:
diff changeset
894 {
kono
parents:
diff changeset
895 if (DECL_STATIC_CONSTRUCTOR (decl))
kono
parents:
diff changeset
896 fprintf (f, " constructor");
kono
parents:
diff changeset
897 if (DECL_STATIC_DESTRUCTOR (decl))
kono
parents:
diff changeset
898 fprintf (f, " destructor");
kono
parents:
diff changeset
899 }
kono
parents:
diff changeset
900 fprintf (f, "\n");
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 if (same_comdat_group)
kono
parents:
diff changeset
903 fprintf (f, " Same comdat group as: %s\n",
kono
parents:
diff changeset
904 same_comdat_group->dump_asm_name ());
kono
parents:
diff changeset
905 if (next_sharing_asm_name)
kono
parents:
diff changeset
906 fprintf (f, " next sharing asm name: %i\n",
kono
parents:
diff changeset
907 next_sharing_asm_name->order);
kono
parents:
diff changeset
908 if (previous_sharing_asm_name)
kono
parents:
diff changeset
909 fprintf (f, " previous sharing asm name: %i\n",
kono
parents:
diff changeset
910 previous_sharing_asm_name->order);
kono
parents:
diff changeset
911
kono
parents:
diff changeset
912 if (address_taken)
kono
parents:
diff changeset
913 fprintf (f, " Address is taken.\n");
kono
parents:
diff changeset
914 if (aux)
kono
parents:
diff changeset
915 {
kono
parents:
diff changeset
916 fprintf (f, " Aux:");
kono
parents:
diff changeset
917 dump_addr (f, " @", (void *)aux);
kono
parents:
diff changeset
918 fprintf (f, "\n");
kono
parents:
diff changeset
919 }
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 fprintf (f, " References: ");
kono
parents:
diff changeset
922 dump_references (f);
kono
parents:
diff changeset
923 fprintf (f, " Referring: ");
kono
parents:
diff changeset
924 dump_referring (f);
kono
parents:
diff changeset
925 if (lto_file_data)
kono
parents:
diff changeset
926 fprintf (f, " Read from file: %s\n",
kono
parents:
diff changeset
927 lto_file_data->file_name);
kono
parents:
diff changeset
928 }
kono
parents:
diff changeset
929
kono
parents:
diff changeset
930 /* Dump symtab node to F. */
kono
parents:
diff changeset
931
kono
parents:
diff changeset
932 void
kono
parents:
diff changeset
933 symtab_node::dump (FILE *f)
kono
parents:
diff changeset
934 {
kono
parents:
diff changeset
935 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
kono
parents:
diff changeset
936 cnode->dump (f);
kono
parents:
diff changeset
937 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
kono
parents:
diff changeset
938 vnode->dump (f);
kono
parents:
diff changeset
939 }
kono
parents:
diff changeset
940
kono
parents:
diff changeset
941 void
kono
parents:
diff changeset
942 symbol_table::dump (FILE *f)
kono
parents:
diff changeset
943 {
kono
parents:
diff changeset
944 symtab_node *node;
kono
parents:
diff changeset
945 fprintf (f, "Symbol table:\n\n");
kono
parents:
diff changeset
946 FOR_EACH_SYMBOL (node)
kono
parents:
diff changeset
947 node->dump (f);
kono
parents:
diff changeset
948 }
kono
parents:
diff changeset
949
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
950 DEBUG_FUNCTION void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
951 symbol_table::debug (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
952 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
953 dump (stderr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
954 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
955
111
kono
parents:
diff changeset
956 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
kono
parents:
diff changeset
957 Return NULL if there's no such node. */
kono
parents:
diff changeset
958
kono
parents:
diff changeset
959 symtab_node *
kono
parents:
diff changeset
960 symtab_node::get_for_asmname (const_tree asmname)
kono
parents:
diff changeset
961 {
kono
parents:
diff changeset
962 symtab_node *node;
kono
parents:
diff changeset
963
kono
parents:
diff changeset
964 symtab->symtab_initialize_asm_name_hash ();
kono
parents:
diff changeset
965 hashval_t hash = symtab->decl_assembler_name_hash (asmname);
kono
parents:
diff changeset
966 symtab_node **slot
kono
parents:
diff changeset
967 = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
kono
parents:
diff changeset
968 NO_INSERT);
kono
parents:
diff changeset
969
kono
parents:
diff changeset
970 if (slot)
kono
parents:
diff changeset
971 {
kono
parents:
diff changeset
972 node = *slot;
kono
parents:
diff changeset
973 return node;
kono
parents:
diff changeset
974 }
kono
parents:
diff changeset
975 return NULL;
kono
parents:
diff changeset
976 }
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 /* Dump symtab node NODE to stderr. */
kono
parents:
diff changeset
979
kono
parents:
diff changeset
980 DEBUG_FUNCTION void
kono
parents:
diff changeset
981 symtab_node::debug (void)
kono
parents:
diff changeset
982 {
kono
parents:
diff changeset
983 dump (stderr);
kono
parents:
diff changeset
984 }
kono
parents:
diff changeset
985
kono
parents:
diff changeset
986 /* Verify common part of symtab nodes. */
kono
parents:
diff changeset
987
kono
parents:
diff changeset
988 DEBUG_FUNCTION bool
kono
parents:
diff changeset
989 symtab_node::verify_base (void)
kono
parents:
diff changeset
990 {
kono
parents:
diff changeset
991 bool error_found = false;
kono
parents:
diff changeset
992 symtab_node *hashed_node;
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 if (is_a <cgraph_node *> (this))
kono
parents:
diff changeset
995 {
kono
parents:
diff changeset
996 if (TREE_CODE (decl) != FUNCTION_DECL)
kono
parents:
diff changeset
997 {
kono
parents:
diff changeset
998 error ("function symbol is not function");
kono
parents:
diff changeset
999 error_found = true;
kono
parents:
diff changeset
1000 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1001 else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1002 != NULL)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1003 != dyn_cast <cgraph_node *> (this)->ifunc_resolver)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1004 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1005 error ("inconsistent `ifunc' attribute");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1006 error_found = true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1007 }
111
kono
parents:
diff changeset
1008 }
kono
parents:
diff changeset
1009 else if (is_a <varpool_node *> (this))
kono
parents:
diff changeset
1010 {
kono
parents:
diff changeset
1011 if (!VAR_P (decl))
kono
parents:
diff changeset
1012 {
kono
parents:
diff changeset
1013 error ("variable symbol is not variable");
kono
parents:
diff changeset
1014 error_found = true;
kono
parents:
diff changeset
1015 }
kono
parents:
diff changeset
1016 }
kono
parents:
diff changeset
1017 else
kono
parents:
diff changeset
1018 {
kono
parents:
diff changeset
1019 error ("node has unknown type");
kono
parents:
diff changeset
1020 error_found = true;
kono
parents:
diff changeset
1021 }
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 if (symtab->state != LTO_STREAMING)
kono
parents:
diff changeset
1024 {
kono
parents:
diff changeset
1025 hashed_node = symtab_node::get (decl);
kono
parents:
diff changeset
1026 if (!hashed_node)
kono
parents:
diff changeset
1027 {
kono
parents:
diff changeset
1028 error ("node not found node->decl->decl_with_vis.symtab_node");
kono
parents:
diff changeset
1029 error_found = true;
kono
parents:
diff changeset
1030 }
kono
parents:
diff changeset
1031 if (hashed_node != this
kono
parents:
diff changeset
1032 && (!is_a <cgraph_node *> (this)
kono
parents:
diff changeset
1033 || !dyn_cast <cgraph_node *> (this)->clone_of
kono
parents:
diff changeset
1034 || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
kono
parents:
diff changeset
1035 {
kono
parents:
diff changeset
1036 error ("node differs from node->decl->decl_with_vis.symtab_node");
kono
parents:
diff changeset
1037 error_found = true;
kono
parents:
diff changeset
1038 }
kono
parents:
diff changeset
1039 }
kono
parents:
diff changeset
1040 if (symtab->assembler_name_hash)
kono
parents:
diff changeset
1041 {
kono
parents:
diff changeset
1042 hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
kono
parents:
diff changeset
1043 if (hashed_node && hashed_node->previous_sharing_asm_name)
kono
parents:
diff changeset
1044 {
kono
parents:
diff changeset
1045 error ("assembler name hash list corrupted");
kono
parents:
diff changeset
1046 error_found = true;
kono
parents:
diff changeset
1047 }
kono
parents:
diff changeset
1048 while (hashed_node)
kono
parents:
diff changeset
1049 {
kono
parents:
diff changeset
1050 if (hashed_node == this)
kono
parents:
diff changeset
1051 break;
kono
parents:
diff changeset
1052 hashed_node = hashed_node->next_sharing_asm_name;
kono
parents:
diff changeset
1053 }
kono
parents:
diff changeset
1054 if (!hashed_node
kono
parents:
diff changeset
1055 && !(is_a <varpool_node *> (this)
kono
parents:
diff changeset
1056 && DECL_HARD_REGISTER (decl)))
kono
parents:
diff changeset
1057 {
kono
parents:
diff changeset
1058 error ("node not found in symtab assembler name hash");
kono
parents:
diff changeset
1059 error_found = true;
kono
parents:
diff changeset
1060 }
kono
parents:
diff changeset
1061 }
kono
parents:
diff changeset
1062 if (previous_sharing_asm_name
kono
parents:
diff changeset
1063 && previous_sharing_asm_name->next_sharing_asm_name != this)
kono
parents:
diff changeset
1064 {
kono
parents:
diff changeset
1065 error ("double linked list of assembler names corrupted");
kono
parents:
diff changeset
1066 error_found = true;
kono
parents:
diff changeset
1067 }
kono
parents:
diff changeset
1068 if (body_removed && definition)
kono
parents:
diff changeset
1069 {
kono
parents:
diff changeset
1070 error ("node has body_removed but is definition");
kono
parents:
diff changeset
1071 error_found = true;
kono
parents:
diff changeset
1072 }
kono
parents:
diff changeset
1073 if (analyzed && !definition)
kono
parents:
diff changeset
1074 {
kono
parents:
diff changeset
1075 error ("node is analyzed but it is not a definition");
kono
parents:
diff changeset
1076 error_found = true;
kono
parents:
diff changeset
1077 }
kono
parents:
diff changeset
1078 if (cpp_implicit_alias && !alias)
kono
parents:
diff changeset
1079 {
kono
parents:
diff changeset
1080 error ("node is alias but not implicit alias");
kono
parents:
diff changeset
1081 error_found = true;
kono
parents:
diff changeset
1082 }
kono
parents:
diff changeset
1083 if (alias && !definition && !weakref)
kono
parents:
diff changeset
1084 {
kono
parents:
diff changeset
1085 error ("node is alias but not definition");
kono
parents:
diff changeset
1086 error_found = true;
kono
parents:
diff changeset
1087 }
kono
parents:
diff changeset
1088 if (weakref && !transparent_alias)
kono
parents:
diff changeset
1089 {
kono
parents:
diff changeset
1090 error ("node is weakref but not an transparent_alias");
kono
parents:
diff changeset
1091 error_found = true;
kono
parents:
diff changeset
1092 }
kono
parents:
diff changeset
1093 if (transparent_alias && !alias)
kono
parents:
diff changeset
1094 {
kono
parents:
diff changeset
1095 error ("node is transparent_alias but not an alias");
kono
parents:
diff changeset
1096 error_found = true;
kono
parents:
diff changeset
1097 }
kono
parents:
diff changeset
1098 if (same_comdat_group)
kono
parents:
diff changeset
1099 {
kono
parents:
diff changeset
1100 symtab_node *n = same_comdat_group;
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 if (!n->get_comdat_group ())
kono
parents:
diff changeset
1103 {
kono
parents:
diff changeset
1104 error ("node is in same_comdat_group list but has no comdat_group");
kono
parents:
diff changeset
1105 error_found = true;
kono
parents:
diff changeset
1106 }
kono
parents:
diff changeset
1107 if (n->get_comdat_group () != get_comdat_group ())
kono
parents:
diff changeset
1108 {
kono
parents:
diff changeset
1109 error ("same_comdat_group list across different groups");
kono
parents:
diff changeset
1110 error_found = true;
kono
parents:
diff changeset
1111 }
kono
parents:
diff changeset
1112 if (n->type != type)
kono
parents:
diff changeset
1113 {
kono
parents:
diff changeset
1114 error ("mixing different types of symbol in same comdat groups is not supported");
kono
parents:
diff changeset
1115 error_found = true;
kono
parents:
diff changeset
1116 }
kono
parents:
diff changeset
1117 if (n == this)
kono
parents:
diff changeset
1118 {
kono
parents:
diff changeset
1119 error ("node is alone in a comdat group");
kono
parents:
diff changeset
1120 error_found = true;
kono
parents:
diff changeset
1121 }
kono
parents:
diff changeset
1122 do
kono
parents:
diff changeset
1123 {
kono
parents:
diff changeset
1124 if (!n->same_comdat_group)
kono
parents:
diff changeset
1125 {
kono
parents:
diff changeset
1126 error ("same_comdat_group is not a circular list");
kono
parents:
diff changeset
1127 error_found = true;
kono
parents:
diff changeset
1128 break;
kono
parents:
diff changeset
1129 }
kono
parents:
diff changeset
1130 n = n->same_comdat_group;
kono
parents:
diff changeset
1131 }
kono
parents:
diff changeset
1132 while (n != this);
kono
parents:
diff changeset
1133 if (comdat_local_p ())
kono
parents:
diff changeset
1134 {
kono
parents:
diff changeset
1135 ipa_ref *ref = NULL;
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 for (int i = 0; iterate_referring (i, ref); ++i)
kono
parents:
diff changeset
1138 {
kono
parents:
diff changeset
1139 if (!in_same_comdat_group_p (ref->referring))
kono
parents:
diff changeset
1140 {
kono
parents:
diff changeset
1141 error ("comdat-local symbol referred to by %s outside its "
kono
parents:
diff changeset
1142 "comdat",
kono
parents:
diff changeset
1143 identifier_to_locale (ref->referring->name()));
kono
parents:
diff changeset
1144 error_found = true;
kono
parents:
diff changeset
1145 }
kono
parents:
diff changeset
1146 }
kono
parents:
diff changeset
1147 }
kono
parents:
diff changeset
1148 }
kono
parents:
diff changeset
1149 if (implicit_section && !get_section ())
kono
parents:
diff changeset
1150 {
kono
parents:
diff changeset
1151 error ("implicit_section flag is set but section isn't");
kono
parents:
diff changeset
1152 error_found = true;
kono
parents:
diff changeset
1153 }
kono
parents:
diff changeset
1154 if (get_section () && get_comdat_group ()
kono
parents:
diff changeset
1155 && !implicit_section
kono
parents:
diff changeset
1156 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
kono
parents:
diff changeset
1157 {
kono
parents:
diff changeset
1158 error ("Both section and comdat group is set");
kono
parents:
diff changeset
1159 error_found = true;
kono
parents:
diff changeset
1160 }
kono
parents:
diff changeset
1161 /* TODO: Add string table for sections, so we do not keep holding duplicated
kono
parents:
diff changeset
1162 strings. */
kono
parents:
diff changeset
1163 if (alias && definition
kono
parents:
diff changeset
1164 && get_section () != get_alias_target ()->get_section ()
kono
parents:
diff changeset
1165 && (!get_section()
kono
parents:
diff changeset
1166 || !get_alias_target ()->get_section ()
kono
parents:
diff changeset
1167 || strcmp (get_section(),
kono
parents:
diff changeset
1168 get_alias_target ()->get_section ())))
kono
parents:
diff changeset
1169 {
kono
parents:
diff changeset
1170 error ("Alias and target's section differs");
kono
parents:
diff changeset
1171 get_alias_target ()->dump (stderr);
kono
parents:
diff changeset
1172 error_found = true;
kono
parents:
diff changeset
1173 }
kono
parents:
diff changeset
1174 if (alias && definition
kono
parents:
diff changeset
1175 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
kono
parents:
diff changeset
1176 {
kono
parents:
diff changeset
1177 error ("Alias and target's comdat groups differs");
kono
parents:
diff changeset
1178 get_alias_target ()->dump (stderr);
kono
parents:
diff changeset
1179 error_found = true;
kono
parents:
diff changeset
1180 }
kono
parents:
diff changeset
1181 if (transparent_alias && definition && !weakref)
kono
parents:
diff changeset
1182 {
kono
parents:
diff changeset
1183 symtab_node *to = get_alias_target ();
kono
parents:
diff changeset
1184 const char *name1
kono
parents:
diff changeset
1185 = IDENTIFIER_POINTER (
kono
parents:
diff changeset
1186 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl)));
kono
parents:
diff changeset
1187 const char *name2
kono
parents:
diff changeset
1188 = IDENTIFIER_POINTER (
kono
parents:
diff changeset
1189 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to->decl)));
kono
parents:
diff changeset
1190 if (!symbol_table::assembler_names_equal_p (name1, name2))
kono
parents:
diff changeset
1191 {
kono
parents:
diff changeset
1192 error ("Transparent alias and target's assembler names differs");
kono
parents:
diff changeset
1193 get_alias_target ()->dump (stderr);
kono
parents:
diff changeset
1194 error_found = true;
kono
parents:
diff changeset
1195 }
kono
parents:
diff changeset
1196 }
kono
parents:
diff changeset
1197 if (transparent_alias && definition
kono
parents:
diff changeset
1198 && get_alias_target()->transparent_alias && get_alias_target()->analyzed)
kono
parents:
diff changeset
1199 {
kono
parents:
diff changeset
1200 error ("Chained transparent aliases");
kono
parents:
diff changeset
1201 get_alias_target ()->dump (stderr);
kono
parents:
diff changeset
1202 error_found = true;
kono
parents:
diff changeset
1203 }
kono
parents:
diff changeset
1204
kono
parents:
diff changeset
1205 return error_found;
kono
parents:
diff changeset
1206 }
kono
parents:
diff changeset
1207
kono
parents:
diff changeset
1208 /* Verify consistency of NODE. */
kono
parents:
diff changeset
1209
kono
parents:
diff changeset
1210 DEBUG_FUNCTION void
kono
parents:
diff changeset
1211 symtab_node::verify (void)
kono
parents:
diff changeset
1212 {
kono
parents:
diff changeset
1213 if (seen_error ())
kono
parents:
diff changeset
1214 return;
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 timevar_push (TV_CGRAPH_VERIFY);
kono
parents:
diff changeset
1217 if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
kono
parents:
diff changeset
1218 node->verify_node ();
kono
parents:
diff changeset
1219 else
kono
parents:
diff changeset
1220 if (verify_base ())
kono
parents:
diff changeset
1221 {
kono
parents:
diff changeset
1222 debug ();
kono
parents:
diff changeset
1223 internal_error ("symtab_node::verify failed");
kono
parents:
diff changeset
1224 }
kono
parents:
diff changeset
1225 timevar_pop (TV_CGRAPH_VERIFY);
kono
parents:
diff changeset
1226 }
kono
parents:
diff changeset
1227
kono
parents:
diff changeset
1228 /* Verify symbol table for internal consistency. */
kono
parents:
diff changeset
1229
kono
parents:
diff changeset
1230 DEBUG_FUNCTION void
kono
parents:
diff changeset
1231 symtab_node::verify_symtab_nodes (void)
kono
parents:
diff changeset
1232 {
kono
parents:
diff changeset
1233 symtab_node *node;
kono
parents:
diff changeset
1234 hash_map<tree, symtab_node *> comdat_head_map (251);
kono
parents:
diff changeset
1235
kono
parents:
diff changeset
1236 FOR_EACH_SYMBOL (node)
kono
parents:
diff changeset
1237 {
kono
parents:
diff changeset
1238 node->verify ();
kono
parents:
diff changeset
1239 if (node->get_comdat_group ())
kono
parents:
diff changeset
1240 {
kono
parents:
diff changeset
1241 symtab_node **entry, *s;
kono
parents:
diff changeset
1242 bool existed;
kono
parents:
diff changeset
1243
kono
parents:
diff changeset
1244 entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
kono
parents:
diff changeset
1245 &existed);
kono
parents:
diff changeset
1246 if (!existed)
kono
parents:
diff changeset
1247 *entry = node;
kono
parents:
diff changeset
1248 else if (!DECL_EXTERNAL (node->decl))
kono
parents:
diff changeset
1249 {
kono
parents:
diff changeset
1250 for (s = (*entry)->same_comdat_group;
kono
parents:
diff changeset
1251 s != NULL && s != node && s != *entry;
kono
parents:
diff changeset
1252 s = s->same_comdat_group)
kono
parents:
diff changeset
1253 ;
kono
parents:
diff changeset
1254 if (!s || s == *entry)
kono
parents:
diff changeset
1255 {
kono
parents:
diff changeset
1256 error ("Two symbols with same comdat_group are not linked by "
kono
parents:
diff changeset
1257 "the same_comdat_group list.");
kono
parents:
diff changeset
1258 (*entry)->debug ();
kono
parents:
diff changeset
1259 node->debug ();
kono
parents:
diff changeset
1260 internal_error ("symtab_node::verify failed");
kono
parents:
diff changeset
1261 }
kono
parents:
diff changeset
1262 }
kono
parents:
diff changeset
1263 }
kono
parents:
diff changeset
1264 }
kono
parents:
diff changeset
1265 }
kono
parents:
diff changeset
1266
kono
parents:
diff changeset
1267 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
kono
parents:
diff changeset
1268 but other code such as notice_global_symbol generates rtl. */
kono
parents:
diff changeset
1269
kono
parents:
diff changeset
1270 void
kono
parents:
diff changeset
1271 symtab_node::make_decl_local (void)
kono
parents:
diff changeset
1272 {
kono
parents:
diff changeset
1273 rtx rtl, symbol;
kono
parents:
diff changeset
1274
kono
parents:
diff changeset
1275 if (weakref)
kono
parents:
diff changeset
1276 {
kono
parents:
diff changeset
1277 weakref = false;
kono
parents:
diff changeset
1278 IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl)) = 0;
kono
parents:
diff changeset
1279 TREE_CHAIN (DECL_ASSEMBLER_NAME (decl)) = NULL_TREE;
kono
parents:
diff changeset
1280 symtab->change_decl_assembler_name
kono
parents:
diff changeset
1281 (decl, DECL_ASSEMBLER_NAME (get_alias_target ()->decl));
kono
parents:
diff changeset
1282 DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
kono
parents:
diff changeset
1283 DECL_ATTRIBUTES (decl));
kono
parents:
diff changeset
1284 }
kono
parents:
diff changeset
1285 /* Avoid clearing comdat_groups on comdat-local decls. */
kono
parents:
diff changeset
1286 else if (TREE_PUBLIC (decl) == 0)
kono
parents:
diff changeset
1287 return;
kono
parents:
diff changeset
1288
kono
parents:
diff changeset
1289 /* Localizing a symbol also make all its transparent aliases local. */
kono
parents:
diff changeset
1290 ipa_ref *ref;
kono
parents:
diff changeset
1291 for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
kono
parents:
diff changeset
1292 {
kono
parents:
diff changeset
1293 struct symtab_node *alias = ref->referring;
kono
parents:
diff changeset
1294 if (alias->transparent_alias)
kono
parents:
diff changeset
1295 alias->make_decl_local ();
kono
parents:
diff changeset
1296 }
kono
parents:
diff changeset
1297
kono
parents:
diff changeset
1298 if (VAR_P (decl))
kono
parents:
diff changeset
1299 {
kono
parents:
diff changeset
1300 DECL_COMMON (decl) = 0;
kono
parents:
diff changeset
1301 /* ADDRESSABLE flag is not defined for public symbols. */
kono
parents:
diff changeset
1302 TREE_ADDRESSABLE (decl) = 1;
kono
parents:
diff changeset
1303 TREE_STATIC (decl) = 1;
kono
parents:
diff changeset
1304 }
kono
parents:
diff changeset
1305 else
kono
parents:
diff changeset
1306 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
kono
parents:
diff changeset
1307
kono
parents:
diff changeset
1308 DECL_COMDAT (decl) = 0;
kono
parents:
diff changeset
1309 DECL_WEAK (decl) = 0;
kono
parents:
diff changeset
1310 DECL_EXTERNAL (decl) = 0;
kono
parents:
diff changeset
1311 DECL_VISIBILITY_SPECIFIED (decl) = 0;
kono
parents:
diff changeset
1312 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
kono
parents:
diff changeset
1313 TREE_PUBLIC (decl) = 0;
kono
parents:
diff changeset
1314 DECL_DLLIMPORT_P (decl) = 0;
kono
parents:
diff changeset
1315 if (!DECL_RTL_SET_P (decl))
kono
parents:
diff changeset
1316 return;
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 /* Update rtl flags. */
kono
parents:
diff changeset
1319 make_decl_rtl (decl);
kono
parents:
diff changeset
1320
kono
parents:
diff changeset
1321 rtl = DECL_RTL (decl);
kono
parents:
diff changeset
1322 if (!MEM_P (rtl))
kono
parents:
diff changeset
1323 return;
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 symbol = XEXP (rtl, 0);
kono
parents:
diff changeset
1326 if (GET_CODE (symbol) != SYMBOL_REF)
kono
parents:
diff changeset
1327 return;
kono
parents:
diff changeset
1328
kono
parents:
diff changeset
1329 SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
kono
parents:
diff changeset
1330 }
kono
parents:
diff changeset
1331
kono
parents:
diff changeset
1332 /* Copy visibility from N.
kono
parents:
diff changeset
1333 This is useful when THIS becomes a transparent alias of N. */
kono
parents:
diff changeset
1334
kono
parents:
diff changeset
1335 void
kono
parents:
diff changeset
1336 symtab_node::copy_visibility_from (symtab_node *n)
kono
parents:
diff changeset
1337 {
kono
parents:
diff changeset
1338 gcc_checking_assert (n->weakref == weakref);
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 ipa_ref *ref;
kono
parents:
diff changeset
1341 for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
kono
parents:
diff changeset
1342 {
kono
parents:
diff changeset
1343 struct symtab_node *alias = ref->referring;
kono
parents:
diff changeset
1344 if (alias->transparent_alias)
kono
parents:
diff changeset
1345 alias->copy_visibility_from (n);
kono
parents:
diff changeset
1346 }
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 if (VAR_P (decl))
kono
parents:
diff changeset
1349 {
kono
parents:
diff changeset
1350 DECL_COMMON (decl) = DECL_COMMON (n->decl);
kono
parents:
diff changeset
1351 /* ADDRESSABLE flag is not defined for public symbols. */
kono
parents:
diff changeset
1352 if (TREE_PUBLIC (decl) && !TREE_PUBLIC (n->decl))
kono
parents:
diff changeset
1353 TREE_ADDRESSABLE (decl) = 1;
kono
parents:
diff changeset
1354 TREE_STATIC (decl) = TREE_STATIC (n->decl);
kono
parents:
diff changeset
1355 }
kono
parents:
diff changeset
1356 else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
kono
parents:
diff changeset
1357
kono
parents:
diff changeset
1358 DECL_COMDAT (decl) = DECL_COMDAT (n->decl);
kono
parents:
diff changeset
1359 DECL_WEAK (decl) = DECL_WEAK (n->decl);
kono
parents:
diff changeset
1360 DECL_EXTERNAL (decl) = DECL_EXTERNAL (n->decl);
kono
parents:
diff changeset
1361 DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (n->decl);
kono
parents:
diff changeset
1362 DECL_VISIBILITY (decl) = DECL_VISIBILITY (n->decl);
kono
parents:
diff changeset
1363 TREE_PUBLIC (decl) = TREE_PUBLIC (n->decl);
kono
parents:
diff changeset
1364 DECL_DLLIMPORT_P (decl) = DECL_DLLIMPORT_P (n->decl);
kono
parents:
diff changeset
1365 resolution = n->resolution;
kono
parents:
diff changeset
1366 set_comdat_group (n->get_comdat_group ());
kono
parents:
diff changeset
1367 call_for_symbol_and_aliases (symtab_node::set_section,
kono
parents:
diff changeset
1368 const_cast<char *>(n->get_section ()), true);
kono
parents:
diff changeset
1369 externally_visible = n->externally_visible;
kono
parents:
diff changeset
1370 if (!DECL_RTL_SET_P (decl))
kono
parents:
diff changeset
1371 return;
kono
parents:
diff changeset
1372
kono
parents:
diff changeset
1373 /* Update rtl flags. */
kono
parents:
diff changeset
1374 make_decl_rtl (decl);
kono
parents:
diff changeset
1375
kono
parents:
diff changeset
1376 rtx rtl = DECL_RTL (decl);
kono
parents:
diff changeset
1377 if (!MEM_P (rtl))
kono
parents:
diff changeset
1378 return;
kono
parents:
diff changeset
1379
kono
parents:
diff changeset
1380 rtx symbol = XEXP (rtl, 0);
kono
parents:
diff changeset
1381 if (GET_CODE (symbol) != SYMBOL_REF)
kono
parents:
diff changeset
1382 return;
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
kono
parents:
diff changeset
1385 }
kono
parents:
diff changeset
1386
kono
parents:
diff changeset
1387 /* Walk the alias chain to return the symbol NODE is alias of.
kono
parents:
diff changeset
1388 If NODE is not an alias, return NODE.
kono
parents:
diff changeset
1389 Assumes NODE is known to be alias. */
kono
parents:
diff changeset
1390
kono
parents:
diff changeset
1391 symtab_node *
kono
parents:
diff changeset
1392 symtab_node::ultimate_alias_target_1 (enum availability *availability,
kono
parents:
diff changeset
1393 symtab_node *ref)
kono
parents:
diff changeset
1394 {
kono
parents:
diff changeset
1395 bool transparent_p = false;
kono
parents:
diff changeset
1396
kono
parents:
diff changeset
1397 /* To determine visibility of the target, we follow ELF semantic of aliases.
kono
parents:
diff changeset
1398 Here alias is an alternative assembler name of a given definition. Its
kono
parents:
diff changeset
1399 availability prevails the availability of its target (i.e. static alias of
kono
parents:
diff changeset
1400 weak definition is available.
kono
parents:
diff changeset
1401
kono
parents:
diff changeset
1402 Transaparent alias is just alternative anme of a given symbol used within
kono
parents:
diff changeset
1403 one compilation unit and is translated prior hitting the object file. It
kono
parents:
diff changeset
1404 inherits the visibility of its target.
kono
parents:
diff changeset
1405 Weakref is a different animal (and noweak definition is weak).
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 If we ever get into supporting targets with different semantics, a target
kono
parents:
diff changeset
1408 hook will be needed here. */
kono
parents:
diff changeset
1409
kono
parents:
diff changeset
1410 if (availability)
kono
parents:
diff changeset
1411 {
kono
parents:
diff changeset
1412 transparent_p = transparent_alias;
kono
parents:
diff changeset
1413 if (!transparent_p)
kono
parents:
diff changeset
1414 *availability = get_availability (ref);
kono
parents:
diff changeset
1415 else
kono
parents:
diff changeset
1416 *availability = AVAIL_NOT_AVAILABLE;
kono
parents:
diff changeset
1417 }
kono
parents:
diff changeset
1418
kono
parents:
diff changeset
1419 symtab_node *node = this;
kono
parents:
diff changeset
1420 while (node)
kono
parents:
diff changeset
1421 {
kono
parents:
diff changeset
1422 if (node->alias && node->analyzed)
kono
parents:
diff changeset
1423 node = node->get_alias_target ();
kono
parents:
diff changeset
1424 else
kono
parents:
diff changeset
1425 {
kono
parents:
diff changeset
1426 if (!availability || (!transparent_p && node->analyzed))
kono
parents:
diff changeset
1427 ;
kono
parents:
diff changeset
1428 else if (node->analyzed && !node->transparent_alias)
kono
parents:
diff changeset
1429 *availability = node->get_availability (ref);
kono
parents:
diff changeset
1430 else
kono
parents:
diff changeset
1431 *availability = AVAIL_NOT_AVAILABLE;
kono
parents:
diff changeset
1432 return node;
kono
parents:
diff changeset
1433 }
kono
parents:
diff changeset
1434 if (node && availability && transparent_p
kono
parents:
diff changeset
1435 && node->transparent_alias)
kono
parents:
diff changeset
1436 {
kono
parents:
diff changeset
1437 *availability = node->get_availability (ref);
kono
parents:
diff changeset
1438 transparent_p = false;
kono
parents:
diff changeset
1439 }
kono
parents:
diff changeset
1440 }
kono
parents:
diff changeset
1441 if (availability)
kono
parents:
diff changeset
1442 *availability = AVAIL_NOT_AVAILABLE;
kono
parents:
diff changeset
1443 return NULL;
kono
parents:
diff changeset
1444 }
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 /* C++ FE sometimes change linkage flags after producing same body aliases.
kono
parents:
diff changeset
1447
kono
parents:
diff changeset
1448 FIXME: C++ produce implicit aliases for virtual functions and vtables that
kono
parents:
diff changeset
1449 are obviously equivalent. The way it is doing so is however somewhat
kono
parents:
diff changeset
1450 kludgy and interferes with the visibility code. As a result we need to
kono
parents:
diff changeset
1451 copy the visibility from the target to get things right. */
kono
parents:
diff changeset
1452
kono
parents:
diff changeset
1453 void
kono
parents:
diff changeset
1454 symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
kono
parents:
diff changeset
1455 {
kono
parents:
diff changeset
1456 if (is_a <cgraph_node *> (this))
kono
parents:
diff changeset
1457 {
kono
parents:
diff changeset
1458 DECL_DECLARED_INLINE_P (decl)
kono
parents:
diff changeset
1459 = DECL_DECLARED_INLINE_P (target->decl);
kono
parents:
diff changeset
1460 DECL_DISREGARD_INLINE_LIMITS (decl)
kono
parents:
diff changeset
1461 = DECL_DISREGARD_INLINE_LIMITS (target->decl);
kono
parents:
diff changeset
1462 }
kono
parents:
diff changeset
1463 /* FIXME: It is not really clear why those flags should not be copied for
kono
parents:
diff changeset
1464 functions, too. */
kono
parents:
diff changeset
1465 else
kono
parents:
diff changeset
1466 {
kono
parents:
diff changeset
1467 DECL_WEAK (decl) = DECL_WEAK (target->decl);
kono
parents:
diff changeset
1468 DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
kono
parents:
diff changeset
1469 DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
kono
parents:
diff changeset
1470 }
kono
parents:
diff changeset
1471 if (TREE_PUBLIC (decl))
kono
parents:
diff changeset
1472 {
kono
parents:
diff changeset
1473 tree group;
kono
parents:
diff changeset
1474
kono
parents:
diff changeset
1475 DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
kono
parents:
diff changeset
1476 DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
kono
parents:
diff changeset
1477 group = target->get_comdat_group ();
kono
parents:
diff changeset
1478 set_comdat_group (group);
kono
parents:
diff changeset
1479 if (group && !same_comdat_group)
kono
parents:
diff changeset
1480 add_to_same_comdat_group (target);
kono
parents:
diff changeset
1481 }
kono
parents:
diff changeset
1482 externally_visible = target->externally_visible;
kono
parents:
diff changeset
1483 }
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485 /* Set section, do not recurse into aliases.
kono
parents:
diff changeset
1486 When one wants to change section of a symbol and its aliases,
kono
parents:
diff changeset
1487 use set_section. */
kono
parents:
diff changeset
1488
kono
parents:
diff changeset
1489 void
kono
parents:
diff changeset
1490 symtab_node::set_section_for_node (const char *section)
kono
parents:
diff changeset
1491 {
kono
parents:
diff changeset
1492 const char *current = get_section ();
kono
parents:
diff changeset
1493 section_hash_entry **slot;
kono
parents:
diff changeset
1494
kono
parents:
diff changeset
1495 if (current == section
kono
parents:
diff changeset
1496 || (current && section
kono
parents:
diff changeset
1497 && !strcmp (current, section)))
kono
parents:
diff changeset
1498 return;
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 if (current)
kono
parents:
diff changeset
1501 {
kono
parents:
diff changeset
1502 x_section->ref_count--;
kono
parents:
diff changeset
1503 if (!x_section->ref_count)
kono
parents:
diff changeset
1504 {
kono
parents:
diff changeset
1505 hashval_t hash = htab_hash_string (x_section->name);
kono
parents:
diff changeset
1506 slot = symtab->section_hash->find_slot_with_hash (x_section->name,
kono
parents:
diff changeset
1507 hash, INSERT);
kono
parents:
diff changeset
1508 ggc_free (x_section);
kono
parents:
diff changeset
1509 symtab->section_hash->clear_slot (slot);
kono
parents:
diff changeset
1510 }
kono
parents:
diff changeset
1511 x_section = NULL;
kono
parents:
diff changeset
1512 }
kono
parents:
diff changeset
1513 if (!section)
kono
parents:
diff changeset
1514 {
kono
parents:
diff changeset
1515 implicit_section = false;
kono
parents:
diff changeset
1516 return;
kono
parents:
diff changeset
1517 }
kono
parents:
diff changeset
1518 if (!symtab->section_hash)
kono
parents:
diff changeset
1519 symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
kono
parents:
diff changeset
1520 slot = symtab->section_hash->find_slot_with_hash (section,
kono
parents:
diff changeset
1521 htab_hash_string (section),
kono
parents:
diff changeset
1522 INSERT);
kono
parents:
diff changeset
1523 if (*slot)
kono
parents:
diff changeset
1524 x_section = (section_hash_entry *)*slot;
kono
parents:
diff changeset
1525 else
kono
parents:
diff changeset
1526 {
kono
parents:
diff changeset
1527 int len = strlen (section);
kono
parents:
diff changeset
1528 *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
kono
parents:
diff changeset
1529 x_section->name = ggc_vec_alloc<char> (len + 1);
kono
parents:
diff changeset
1530 memcpy (x_section->name, section, len + 1);
kono
parents:
diff changeset
1531 }
kono
parents:
diff changeset
1532 x_section->ref_count++;
kono
parents:
diff changeset
1533 }
kono
parents:
diff changeset
1534
kono
parents:
diff changeset
1535 /* Worker for set_section. */
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 bool
kono
parents:
diff changeset
1538 symtab_node::set_section (symtab_node *n, void *s)
kono
parents:
diff changeset
1539 {
kono
parents:
diff changeset
1540 n->set_section_for_node ((char *)s);
kono
parents:
diff changeset
1541 return false;
kono
parents:
diff changeset
1542 }
kono
parents:
diff changeset
1543
kono
parents:
diff changeset
1544 /* Set section of symbol and its aliases. */
kono
parents:
diff changeset
1545
kono
parents:
diff changeset
1546 void
kono
parents:
diff changeset
1547 symtab_node::set_section (const char *section)
kono
parents:
diff changeset
1548 {
kono
parents:
diff changeset
1549 gcc_assert (!this->alias);
kono
parents:
diff changeset
1550 call_for_symbol_and_aliases
kono
parents:
diff changeset
1551 (symtab_node::set_section, const_cast<char *>(section), true);
kono
parents:
diff changeset
1552 }
kono
parents:
diff changeset
1553
kono
parents:
diff changeset
1554 /* Return the initialization priority. */
kono
parents:
diff changeset
1555
kono
parents:
diff changeset
1556 priority_type
kono
parents:
diff changeset
1557 symtab_node::get_init_priority ()
kono
parents:
diff changeset
1558 {
kono
parents:
diff changeset
1559 if (!this->in_init_priority_hash)
kono
parents:
diff changeset
1560 return DEFAULT_INIT_PRIORITY;
kono
parents:
diff changeset
1561
kono
parents:
diff changeset
1562 symbol_priority_map *h = symtab->init_priority_hash->get (this);
kono
parents:
diff changeset
1563 return h ? h->init : DEFAULT_INIT_PRIORITY;
kono
parents:
diff changeset
1564 }
kono
parents:
diff changeset
1565
kono
parents:
diff changeset
1566 /* Return the finalization priority. */
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 priority_type
kono
parents:
diff changeset
1569 cgraph_node::get_fini_priority ()
kono
parents:
diff changeset
1570 {
kono
parents:
diff changeset
1571 if (!this->in_init_priority_hash)
kono
parents:
diff changeset
1572 return DEFAULT_INIT_PRIORITY;
kono
parents:
diff changeset
1573 symbol_priority_map *h = symtab->init_priority_hash->get (this);
kono
parents:
diff changeset
1574 return h ? h->fini : DEFAULT_INIT_PRIORITY;
kono
parents:
diff changeset
1575 }
kono
parents:
diff changeset
1576
kono
parents:
diff changeset
1577 /* Return the initialization and finalization priority information for
kono
parents:
diff changeset
1578 DECL. If there is no previous priority information, a freshly
kono
parents:
diff changeset
1579 allocated structure is returned. */
kono
parents:
diff changeset
1580
kono
parents:
diff changeset
1581 symbol_priority_map *
kono
parents:
diff changeset
1582 symtab_node::priority_info (void)
kono
parents:
diff changeset
1583 {
kono
parents:
diff changeset
1584 if (!symtab->init_priority_hash)
kono
parents:
diff changeset
1585 symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
kono
parents:
diff changeset
1586
kono
parents:
diff changeset
1587 bool existed;
kono
parents:
diff changeset
1588 symbol_priority_map *h
kono
parents:
diff changeset
1589 = &symtab->init_priority_hash->get_or_insert (this, &existed);
kono
parents:
diff changeset
1590 if (!existed)
kono
parents:
diff changeset
1591 {
kono
parents:
diff changeset
1592 h->init = DEFAULT_INIT_PRIORITY;
kono
parents:
diff changeset
1593 h->fini = DEFAULT_INIT_PRIORITY;
kono
parents:
diff changeset
1594 in_init_priority_hash = true;
kono
parents:
diff changeset
1595 }
kono
parents:
diff changeset
1596
kono
parents:
diff changeset
1597 return h;
kono
parents:
diff changeset
1598 }
kono
parents:
diff changeset
1599
kono
parents:
diff changeset
1600 /* Set initialization priority to PRIORITY. */
kono
parents:
diff changeset
1601
kono
parents:
diff changeset
1602 void
kono
parents:
diff changeset
1603 symtab_node::set_init_priority (priority_type priority)
kono
parents:
diff changeset
1604 {
kono
parents:
diff changeset
1605 symbol_priority_map *h;
kono
parents:
diff changeset
1606
kono
parents:
diff changeset
1607 if (is_a <cgraph_node *> (this))
kono
parents:
diff changeset
1608 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
kono
parents:
diff changeset
1609
kono
parents:
diff changeset
1610 if (priority == DEFAULT_INIT_PRIORITY)
kono
parents:
diff changeset
1611 {
kono
parents:
diff changeset
1612 gcc_assert (get_init_priority() == priority);
kono
parents:
diff changeset
1613 return;
kono
parents:
diff changeset
1614 }
kono
parents:
diff changeset
1615 h = priority_info ();
kono
parents:
diff changeset
1616 h->init = priority;
kono
parents:
diff changeset
1617 }
kono
parents:
diff changeset
1618
kono
parents:
diff changeset
1619 /* Set fialization priority to PRIORITY. */
kono
parents:
diff changeset
1620
kono
parents:
diff changeset
1621 void
kono
parents:
diff changeset
1622 cgraph_node::set_fini_priority (priority_type priority)
kono
parents:
diff changeset
1623 {
kono
parents:
diff changeset
1624 symbol_priority_map *h;
kono
parents:
diff changeset
1625
kono
parents:
diff changeset
1626 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
kono
parents:
diff changeset
1627
kono
parents:
diff changeset
1628 if (priority == DEFAULT_INIT_PRIORITY)
kono
parents:
diff changeset
1629 {
kono
parents:
diff changeset
1630 gcc_assert (get_fini_priority() == priority);
kono
parents:
diff changeset
1631 return;
kono
parents:
diff changeset
1632 }
kono
parents:
diff changeset
1633 h = priority_info ();
kono
parents:
diff changeset
1634 h->fini = priority;
kono
parents:
diff changeset
1635 }
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 /* Worker for symtab_resolve_alias. */
kono
parents:
diff changeset
1638
kono
parents:
diff changeset
1639 bool
kono
parents:
diff changeset
1640 symtab_node::set_implicit_section (symtab_node *n,
kono
parents:
diff changeset
1641 void *data ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
1642 {
kono
parents:
diff changeset
1643 n->implicit_section = true;
kono
parents:
diff changeset
1644 return false;
kono
parents:
diff changeset
1645 }
kono
parents:
diff changeset
1646
kono
parents:
diff changeset
1647 /* Add reference recording that symtab node is alias of TARGET.
kono
parents:
diff changeset
1648 The function can fail in the case of aliasing cycles; in this case
kono
parents:
diff changeset
1649 it returns false. */
kono
parents:
diff changeset
1650
kono
parents:
diff changeset
1651 bool
kono
parents:
diff changeset
1652 symtab_node::resolve_alias (symtab_node *target, bool transparent)
kono
parents:
diff changeset
1653 {
kono
parents:
diff changeset
1654 symtab_node *n;
kono
parents:
diff changeset
1655
kono
parents:
diff changeset
1656 gcc_assert (!analyzed && !vec_safe_length (ref_list.references));
kono
parents:
diff changeset
1657
kono
parents:
diff changeset
1658 /* Never let cycles to creep into the symbol table alias references;
kono
parents:
diff changeset
1659 those will make alias walkers to be infinite. */
kono
parents:
diff changeset
1660 for (n = target; n && n->alias;
kono
parents:
diff changeset
1661 n = n->analyzed ? n->get_alias_target () : NULL)
kono
parents:
diff changeset
1662 if (n == this)
kono
parents:
diff changeset
1663 {
kono
parents:
diff changeset
1664 if (is_a <cgraph_node *> (this))
kono
parents:
diff changeset
1665 error ("function %q+D part of alias cycle", decl);
kono
parents:
diff changeset
1666 else if (is_a <varpool_node *> (this))
kono
parents:
diff changeset
1667 error ("variable %q+D part of alias cycle", decl);
kono
parents:
diff changeset
1668 else
kono
parents:
diff changeset
1669 gcc_unreachable ();
kono
parents:
diff changeset
1670 alias = false;
kono
parents:
diff changeset
1671 return false;
kono
parents:
diff changeset
1672 }
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 /* "analyze" the node - i.e. mark the reference. */
kono
parents:
diff changeset
1675 definition = true;
kono
parents:
diff changeset
1676 alias = true;
kono
parents:
diff changeset
1677 analyzed = true;
kono
parents:
diff changeset
1678 transparent |= transparent_alias;
kono
parents:
diff changeset
1679 transparent_alias = transparent;
kono
parents:
diff changeset
1680 if (transparent)
kono
parents:
diff changeset
1681 while (target->transparent_alias && target->analyzed)
kono
parents:
diff changeset
1682 target = target->get_alias_target ();
kono
parents:
diff changeset
1683 create_reference (target, IPA_REF_ALIAS, NULL);
kono
parents:
diff changeset
1684
kono
parents:
diff changeset
1685 /* Add alias into the comdat group of its target unless it is already there. */
kono
parents:
diff changeset
1686 if (same_comdat_group)
kono
parents:
diff changeset
1687 remove_from_same_comdat_group ();
kono
parents:
diff changeset
1688 set_comdat_group (NULL);
kono
parents:
diff changeset
1689 if (target->get_comdat_group ())
kono
parents:
diff changeset
1690 add_to_same_comdat_group (target);
kono
parents:
diff changeset
1691
kono
parents:
diff changeset
1692 if ((get_section () != target->get_section ()
kono
parents:
diff changeset
1693 || target->get_comdat_group ()) && get_section () && !implicit_section)
kono
parents:
diff changeset
1694 {
kono
parents:
diff changeset
1695 error ("section of alias %q+D must match section of its target", decl);
kono
parents:
diff changeset
1696 }
kono
parents:
diff changeset
1697 call_for_symbol_and_aliases (symtab_node::set_section,
kono
parents:
diff changeset
1698 const_cast<char *>(target->get_section ()), true);
kono
parents:
diff changeset
1699 if (target->implicit_section)
kono
parents:
diff changeset
1700 call_for_symbol_and_aliases (set_implicit_section, NULL, true);
kono
parents:
diff changeset
1701
kono
parents:
diff changeset
1702 /* Alias targets become redundant after alias is resolved into an reference.
kono
parents:
diff changeset
1703 We do not want to keep it around or we would have to mind updating them
kono
parents:
diff changeset
1704 when renaming symbols. */
kono
parents:
diff changeset
1705 alias_target = NULL;
kono
parents:
diff changeset
1706
kono
parents:
diff changeset
1707 if (!transparent && cpp_implicit_alias && symtab->state >= CONSTRUCTION)
kono
parents:
diff changeset
1708 fixup_same_cpp_alias_visibility (target);
kono
parents:
diff changeset
1709
kono
parents:
diff changeset
1710 /* If alias has address taken, so does the target. */
kono
parents:
diff changeset
1711 if (address_taken)
kono
parents:
diff changeset
1712 target->ultimate_alias_target ()->address_taken = true;
kono
parents:
diff changeset
1713
kono
parents:
diff changeset
1714 /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
kono
parents:
diff changeset
1715 If alias is transparent, also all transparent aliases of THIS are now
kono
parents:
diff changeset
1716 aliases of TARGET.
kono
parents:
diff changeset
1717 Also merge same comdat group lists. */
kono
parents:
diff changeset
1718 ipa_ref *ref;
kono
parents:
diff changeset
1719 for (unsigned i = 0; iterate_direct_aliases (i, ref);)
kono
parents:
diff changeset
1720 {
kono
parents:
diff changeset
1721 struct symtab_node *alias_alias = ref->referring;
kono
parents:
diff changeset
1722 if (alias_alias->get_comdat_group ())
kono
parents:
diff changeset
1723 {
kono
parents:
diff changeset
1724 alias_alias->remove_from_same_comdat_group ();
kono
parents:
diff changeset
1725 alias_alias->set_comdat_group (NULL);
kono
parents:
diff changeset
1726 if (target->get_comdat_group ())
kono
parents:
diff changeset
1727 alias_alias->add_to_same_comdat_group (target);
kono
parents:
diff changeset
1728 }
kono
parents:
diff changeset
1729 if (!alias_alias->transparent_alias || transparent)
kono
parents:
diff changeset
1730 {
kono
parents:
diff changeset
1731 alias_alias->remove_all_references ();
kono
parents:
diff changeset
1732 alias_alias->create_reference (target, IPA_REF_ALIAS, NULL);
kono
parents:
diff changeset
1733 }
kono
parents:
diff changeset
1734 else i++;
kono
parents:
diff changeset
1735 }
kono
parents:
diff changeset
1736 return true;
kono
parents:
diff changeset
1737 }
kono
parents:
diff changeset
1738
kono
parents:
diff changeset
1739 /* Worker searching noninterposable alias. */
kono
parents:
diff changeset
1740
kono
parents:
diff changeset
1741 bool
kono
parents:
diff changeset
1742 symtab_node::noninterposable_alias (symtab_node *node, void *data)
kono
parents:
diff changeset
1743 {
kono
parents:
diff changeset
1744 if (!node->transparent_alias && decl_binds_to_current_def_p (node->decl))
kono
parents:
diff changeset
1745 {
kono
parents:
diff changeset
1746 symtab_node *fn = node->ultimate_alias_target ();
kono
parents:
diff changeset
1747
kono
parents:
diff changeset
1748 /* Ensure that the alias is well formed this may not be the case
kono
parents:
diff changeset
1749 of user defined aliases and currently it is not always the case
kono
parents:
diff changeset
1750 of C++ same body aliases (that is a bug). */
kono
parents:
diff changeset
1751 if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
kono
parents:
diff changeset
1752 || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
kono
parents:
diff changeset
1753 || (TREE_CODE (node->decl) == FUNCTION_DECL
kono
parents:
diff changeset
1754 && flags_from_decl_or_type (node->decl)
kono
parents:
diff changeset
1755 != flags_from_decl_or_type (fn->decl))
kono
parents:
diff changeset
1756 || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
kono
parents:
diff changeset
1757 return false;
kono
parents:
diff changeset
1758 *(symtab_node **)data = node;
kono
parents:
diff changeset
1759 return true;
kono
parents:
diff changeset
1760 }
kono
parents:
diff changeset
1761 return false;
kono
parents:
diff changeset
1762 }
kono
parents:
diff changeset
1763
kono
parents:
diff changeset
1764 /* If node can not be overwriten by static or dynamic linker to point to
kono
parents:
diff changeset
1765 different definition, return NODE. Otherwise look for alias with such
kono
parents:
diff changeset
1766 property and if none exists, introduce new one. */
kono
parents:
diff changeset
1767
kono
parents:
diff changeset
1768 symtab_node *
kono
parents:
diff changeset
1769 symtab_node::noninterposable_alias (void)
kono
parents:
diff changeset
1770 {
kono
parents:
diff changeset
1771 tree new_decl;
kono
parents:
diff changeset
1772 symtab_node *new_node = NULL;
kono
parents:
diff changeset
1773
kono
parents:
diff changeset
1774 /* First try to look up existing alias or base object
kono
parents:
diff changeset
1775 (if that is already non-overwritable). */
kono
parents:
diff changeset
1776 symtab_node *node = ultimate_alias_target ();
kono
parents:
diff changeset
1777 gcc_assert (!node->alias && !node->weakref);
kono
parents:
diff changeset
1778 node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
kono
parents:
diff changeset
1779 (void *)&new_node, true);
kono
parents:
diff changeset
1780 if (new_node)
kono
parents:
diff changeset
1781 return new_node;
kono
parents:
diff changeset
1782
kono
parents:
diff changeset
1783 /* If aliases aren't supported by the assembler, fail. */
kono
parents:
diff changeset
1784 if (!TARGET_SUPPORTS_ALIASES)
kono
parents:
diff changeset
1785 return NULL;
kono
parents:
diff changeset
1786
kono
parents:
diff changeset
1787 /* Otherwise create a new one. */
kono
parents:
diff changeset
1788 new_decl = copy_node (node->decl);
kono
parents:
diff changeset
1789 DECL_DLLIMPORT_P (new_decl) = 0;
kono
parents:
diff changeset
1790 DECL_NAME (new_decl) = clone_function_name (node->decl, "localalias");
kono
parents:
diff changeset
1791 if (TREE_CODE (new_decl) == FUNCTION_DECL)
kono
parents:
diff changeset
1792 DECL_STRUCT_FUNCTION (new_decl) = NULL;
kono
parents:
diff changeset
1793 DECL_INITIAL (new_decl) = NULL;
kono
parents:
diff changeset
1794 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
kono
parents:
diff changeset
1795 SET_DECL_RTL (new_decl, NULL);
kono
parents:
diff changeset
1796
kono
parents:
diff changeset
1797 /* Update the properties. */
kono
parents:
diff changeset
1798 DECL_EXTERNAL (new_decl) = 0;
kono
parents:
diff changeset
1799 TREE_PUBLIC (new_decl) = 0;
kono
parents:
diff changeset
1800 DECL_COMDAT (new_decl) = 0;
kono
parents:
diff changeset
1801 DECL_WEAK (new_decl) = 0;
kono
parents:
diff changeset
1802
kono
parents:
diff changeset
1803 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
kono
parents:
diff changeset
1804 DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
kono
parents:
diff changeset
1805 if (TREE_CODE (new_decl) == FUNCTION_DECL)
kono
parents:
diff changeset
1806 {
kono
parents:
diff changeset
1807 DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
kono
parents:
diff changeset
1808 DECL_STATIC_DESTRUCTOR (new_decl) = 0;
kono
parents:
diff changeset
1809 new_node = cgraph_node::create_alias (new_decl, node->decl);
kono
parents:
diff changeset
1810 }
kono
parents:
diff changeset
1811 else
kono
parents:
diff changeset
1812 {
kono
parents:
diff changeset
1813 TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
kono
parents:
diff changeset
1814 DECL_INITIAL (new_decl) = error_mark_node;
kono
parents:
diff changeset
1815 new_node = varpool_node::create_alias (new_decl, node->decl);
kono
parents:
diff changeset
1816 }
kono
parents:
diff changeset
1817 new_node->resolve_alias (node);
kono
parents:
diff changeset
1818 gcc_assert (decl_binds_to_current_def_p (new_decl)
kono
parents:
diff changeset
1819 && targetm.binds_local_p (new_decl));
kono
parents:
diff changeset
1820 return new_node;
kono
parents:
diff changeset
1821 }
kono
parents:
diff changeset
1822
kono
parents:
diff changeset
1823 /* Return true if symtab node and TARGET represents
kono
parents:
diff changeset
1824 semantically equivalent symbols. */
kono
parents:
diff changeset
1825
kono
parents:
diff changeset
1826 bool
kono
parents:
diff changeset
1827 symtab_node::semantically_equivalent_p (symtab_node *target)
kono
parents:
diff changeset
1828 {
kono
parents:
diff changeset
1829 enum availability avail;
kono
parents:
diff changeset
1830 symtab_node *ba;
kono
parents:
diff changeset
1831 symtab_node *bb;
kono
parents:
diff changeset
1832
kono
parents:
diff changeset
1833 /* Equivalent functions are equivalent. */
kono
parents:
diff changeset
1834 if (decl == target->decl)
kono
parents:
diff changeset
1835 return true;
kono
parents:
diff changeset
1836
kono
parents:
diff changeset
1837 /* If symbol is not overwritable by different implementation,
kono
parents:
diff changeset
1838 walk to the base object it defines. */
kono
parents:
diff changeset
1839 ba = ultimate_alias_target (&avail);
kono
parents:
diff changeset
1840 if (avail >= AVAIL_AVAILABLE)
kono
parents:
diff changeset
1841 {
kono
parents:
diff changeset
1842 if (target == ba)
kono
parents:
diff changeset
1843 return true;
kono
parents:
diff changeset
1844 }
kono
parents:
diff changeset
1845 else
kono
parents:
diff changeset
1846 ba = this;
kono
parents:
diff changeset
1847 bb = target->ultimate_alias_target (&avail);
kono
parents:
diff changeset
1848 if (avail >= AVAIL_AVAILABLE)
kono
parents:
diff changeset
1849 {
kono
parents:
diff changeset
1850 if (this == bb)
kono
parents:
diff changeset
1851 return true;
kono
parents:
diff changeset
1852 }
kono
parents:
diff changeset
1853 else
kono
parents:
diff changeset
1854 bb = target;
kono
parents:
diff changeset
1855 return bb == ba;
kono
parents:
diff changeset
1856 }
kono
parents:
diff changeset
1857
kono
parents:
diff changeset
1858 /* Classify symbol symtab node for partitioning. */
kono
parents:
diff changeset
1859
kono
parents:
diff changeset
1860 enum symbol_partitioning_class
kono
parents:
diff changeset
1861 symtab_node::get_partitioning_class (void)
kono
parents:
diff changeset
1862 {
kono
parents:
diff changeset
1863 /* Inline clones are always duplicated.
kono
parents:
diff changeset
1864 This include external delcarations. */
kono
parents:
diff changeset
1865 cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
kono
parents:
diff changeset
1866
kono
parents:
diff changeset
1867 if (DECL_ABSTRACT_P (decl))
kono
parents:
diff changeset
1868 return SYMBOL_EXTERNAL;
kono
parents:
diff changeset
1869
kono
parents:
diff changeset
1870 if (cnode && cnode->global.inlined_to)
kono
parents:
diff changeset
1871 return SYMBOL_DUPLICATE;
kono
parents:
diff changeset
1872
kono
parents:
diff changeset
1873 /* Transparent aliases are always duplicated. */
kono
parents:
diff changeset
1874 if (transparent_alias)
kono
parents:
diff changeset
1875 return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL;
kono
parents:
diff changeset
1876
kono
parents:
diff changeset
1877 /* External declarations are external. */
kono
parents:
diff changeset
1878 if (DECL_EXTERNAL (decl))
kono
parents:
diff changeset
1879 return SYMBOL_EXTERNAL;
kono
parents:
diff changeset
1880
kono
parents:
diff changeset
1881 if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
kono
parents:
diff changeset
1882 {
kono
parents:
diff changeset
1883 if (alias && definition && !ultimate_alias_target ()->definition)
kono
parents:
diff changeset
1884 return SYMBOL_EXTERNAL;
kono
parents:
diff changeset
1885 /* Constant pool references use local symbol names that can not
kono
parents:
diff changeset
1886 be promoted global. We should never put into a constant pool
kono
parents:
diff changeset
1887 objects that can not be duplicated across partitions. */
kono
parents:
diff changeset
1888 if (DECL_IN_CONSTANT_POOL (decl))
kono
parents:
diff changeset
1889 return SYMBOL_DUPLICATE;
kono
parents:
diff changeset
1890 if (DECL_HARD_REGISTER (decl))
kono
parents:
diff changeset
1891 return SYMBOL_DUPLICATE;
kono
parents:
diff changeset
1892 gcc_checking_assert (vnode->definition);
kono
parents:
diff changeset
1893 }
kono
parents:
diff changeset
1894 /* Functions that are cloned may stay in callgraph even if they are unused.
kono
parents:
diff changeset
1895 Handle them as external; compute_ltrans_boundary take care to make
kono
parents:
diff changeset
1896 proper things to happen (i.e. to make them appear in the boundary but
kono
parents:
diff changeset
1897 with body streamed, so clone can me materialized). */
kono
parents:
diff changeset
1898 else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
kono
parents:
diff changeset
1899 return SYMBOL_EXTERNAL;
kono
parents:
diff changeset
1900
kono
parents:
diff changeset
1901 /* Linker discardable symbols are duplicated to every use unless they are
kono
parents:
diff changeset
1902 keyed. */
kono
parents:
diff changeset
1903 if (DECL_ONE_ONLY (decl)
kono
parents:
diff changeset
1904 && !force_output
kono
parents:
diff changeset
1905 && !forced_by_abi
kono
parents:
diff changeset
1906 && !used_from_object_file_p ())
kono
parents:
diff changeset
1907 return SYMBOL_DUPLICATE;
kono
parents:
diff changeset
1908
kono
parents:
diff changeset
1909 return SYMBOL_PARTITION;
kono
parents:
diff changeset
1910 }
kono
parents:
diff changeset
1911
kono
parents:
diff changeset
1912 /* Return true when symbol is known to be non-zero. */
kono
parents:
diff changeset
1913
kono
parents:
diff changeset
1914 bool
kono
parents:
diff changeset
1915 symtab_node::nonzero_address ()
kono
parents:
diff changeset
1916 {
kono
parents:
diff changeset
1917 /* Weakrefs may be NULL when their target is not defined. */
kono
parents:
diff changeset
1918 if (alias && weakref)
kono
parents:
diff changeset
1919 {
kono
parents:
diff changeset
1920 if (analyzed)
kono
parents:
diff changeset
1921 {
kono
parents:
diff changeset
1922 symtab_node *target = ultimate_alias_target ();
kono
parents:
diff changeset
1923
kono
parents:
diff changeset
1924 if (target->alias && target->weakref)
kono
parents:
diff changeset
1925 return false;
kono
parents:
diff changeset
1926 /* We can not recurse to target::nonzero. It is possible that the
kono
parents:
diff changeset
1927 target is used only via the alias.
kono
parents:
diff changeset
1928 We may walk references and look for strong use, but we do not know
kono
parents:
diff changeset
1929 if this strong use will survive to final binary, so be
kono
parents:
diff changeset
1930 conservative here.
kono
parents:
diff changeset
1931 ??? Maybe we could do the lookup during late optimization that
kono
parents:
diff changeset
1932 could be useful to eliminate the NULL pointer checks in LTO
kono
parents:
diff changeset
1933 programs. */
kono
parents:
diff changeset
1934 if (target->definition && !DECL_EXTERNAL (target->decl))
kono
parents:
diff changeset
1935 return true;
kono
parents:
diff changeset
1936 if (target->resolution != LDPR_UNKNOWN
kono
parents:
diff changeset
1937 && target->resolution != LDPR_UNDEF
kono
parents:
diff changeset
1938 && !target->can_be_discarded_p ()
kono
parents:
diff changeset
1939 && flag_delete_null_pointer_checks)
kono
parents:
diff changeset
1940 return true;
kono
parents:
diff changeset
1941 return false;
kono
parents:
diff changeset
1942 }
kono
parents:
diff changeset
1943 else
kono
parents:
diff changeset
1944 return false;
kono
parents:
diff changeset
1945 }
kono
parents:
diff changeset
1946
kono
parents:
diff changeset
1947 /* With !flag_delete_null_pointer_checks we assume that symbols may
kono
parents:
diff changeset
1948 bind to NULL. This is on by default on embedded targets only.
kono
parents:
diff changeset
1949
kono
parents:
diff changeset
1950 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
kono
parents:
diff changeset
1951 linking fails. Important case of WEAK we want to do well are comdats.
kono
parents:
diff changeset
1952 Those are handled by later check for definition.
kono
parents:
diff changeset
1953
kono
parents:
diff changeset
1954 When parsing, beware the cases when WEAK attribute is added later. */
kono
parents:
diff changeset
1955 if (!DECL_WEAK (decl)
kono
parents:
diff changeset
1956 && flag_delete_null_pointer_checks)
kono
parents:
diff changeset
1957 {
kono
parents:
diff changeset
1958 refuse_visibility_changes = true;
kono
parents:
diff changeset
1959 return true;
kono
parents:
diff changeset
1960 }
kono
parents:
diff changeset
1961
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1962 /* If target is defined and either comdat or not extern, we know it will be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1963 output and thus it will bind to non-NULL.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1964 Play safe for flag_delete_null_pointer_checks where weak definition may
111
kono
parents:
diff changeset
1965 be re-defined by NULL. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1966 if (definition && (!DECL_EXTERNAL (decl) || DECL_COMDAT (decl))
111
kono
parents:
diff changeset
1967 && (flag_delete_null_pointer_checks || !DECL_WEAK (decl)))
kono
parents:
diff changeset
1968 {
kono
parents:
diff changeset
1969 if (!DECL_WEAK (decl))
kono
parents:
diff changeset
1970 refuse_visibility_changes = true;
kono
parents:
diff changeset
1971 return true;
kono
parents:
diff changeset
1972 }
kono
parents:
diff changeset
1973
kono
parents:
diff changeset
1974 /* As the last resort, check the resolution info. */
kono
parents:
diff changeset
1975 if (resolution != LDPR_UNKNOWN
kono
parents:
diff changeset
1976 && resolution != LDPR_UNDEF
kono
parents:
diff changeset
1977 && !can_be_discarded_p ()
kono
parents:
diff changeset
1978 && flag_delete_null_pointer_checks)
kono
parents:
diff changeset
1979 return true;
kono
parents:
diff changeset
1980 return false;
kono
parents:
diff changeset
1981 }
kono
parents:
diff changeset
1982
kono
parents:
diff changeset
1983 /* Return 0 if symbol is known to have different address than S2,
kono
parents:
diff changeset
1984 Return 1 if symbol is known to have same address as S2,
kono
parents:
diff changeset
1985 return -1 otherwise.
kono
parents:
diff changeset
1986
kono
parents:
diff changeset
1987 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
kono
parents:
diff changeset
1988 and S2 is going to be accessed. This eliminates the situations when
kono
parents:
diff changeset
1989 either THIS or S2 is NULL and is seful for comparing bases when deciding
kono
parents:
diff changeset
1990 about memory aliasing. */
kono
parents:
diff changeset
1991 int
kono
parents:
diff changeset
1992 symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed)
kono
parents:
diff changeset
1993 {
kono
parents:
diff changeset
1994 enum availability avail1, avail2;
kono
parents:
diff changeset
1995
kono
parents:
diff changeset
1996 /* A Shortcut: equivalent symbols are always equivalent. */
kono
parents:
diff changeset
1997 if (this == s2)
kono
parents:
diff changeset
1998 return 1;
kono
parents:
diff changeset
1999
kono
parents:
diff changeset
2000 /* Unwind transparent aliases first; those are always equal to their
kono
parents:
diff changeset
2001 target. */
kono
parents:
diff changeset
2002 if (this->transparent_alias && this->analyzed)
kono
parents:
diff changeset
2003 return this->get_alias_target ()->equal_address_to (s2);
kono
parents:
diff changeset
2004 while (s2->transparent_alias && s2->analyzed)
kono
parents:
diff changeset
2005 s2 = s2->get_alias_target();
kono
parents:
diff changeset
2006
kono
parents:
diff changeset
2007 if (this == s2)
kono
parents:
diff changeset
2008 return 1;
kono
parents:
diff changeset
2009
kono
parents:
diff changeset
2010 /* For non-interposable aliases, lookup and compare their actual definitions.
kono
parents:
diff changeset
2011 Also check if the symbol needs to bind to given definition. */
kono
parents:
diff changeset
2012 symtab_node *rs1 = ultimate_alias_target (&avail1);
kono
parents:
diff changeset
2013 symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
kono
parents:
diff changeset
2014 bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
kono
parents:
diff changeset
2015 bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
kono
parents:
diff changeset
2016 bool really_binds_local1 = binds_local1;
kono
parents:
diff changeset
2017 bool really_binds_local2 = binds_local2;
kono
parents:
diff changeset
2018
kono
parents:
diff changeset
2019 /* Addresses of vtables and virtual functions can not be used by user
kono
parents:
diff changeset
2020 code and are used only within speculation. In this case we may make
kono
parents:
diff changeset
2021 symbol equivalent to its alias even if interposition may break this
kono
parents:
diff changeset
2022 rule. Doing so will allow us to turn speculative inlining into
kono
parents:
diff changeset
2023 non-speculative more agressively. */
kono
parents:
diff changeset
2024 if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
kono
parents:
diff changeset
2025 binds_local1 = true;
kono
parents:
diff changeset
2026 if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
kono
parents:
diff changeset
2027 binds_local2 = true;
kono
parents:
diff changeset
2028
kono
parents:
diff changeset
2029 /* If both definitions are available we know that even if they are bound
kono
parents:
diff changeset
2030 to other unit they must be defined same way and therefore we can use
kono
parents:
diff changeset
2031 equivalence test. */
kono
parents:
diff changeset
2032 if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
kono
parents:
diff changeset
2033 binds_local1 = binds_local2 = true;
kono
parents:
diff changeset
2034
kono
parents:
diff changeset
2035 if (binds_local1 && binds_local2 && rs1 == rs2)
kono
parents:
diff changeset
2036 {
kono
parents:
diff changeset
2037 /* We made use of the fact that alias is not weak. */
kono
parents:
diff changeset
2038 if (rs1 != this)
kono
parents:
diff changeset
2039 refuse_visibility_changes = true;
kono
parents:
diff changeset
2040 if (rs2 != s2)
kono
parents:
diff changeset
2041 s2->refuse_visibility_changes = true;
kono
parents:
diff changeset
2042 return 1;
kono
parents:
diff changeset
2043 }
kono
parents:
diff changeset
2044
kono
parents:
diff changeset
2045 /* If both symbols may resolve to NULL, we can not really prove them
kono
parents:
diff changeset
2046 different. */
kono
parents:
diff changeset
2047 if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ())
kono
parents:
diff changeset
2048 return -1;
kono
parents:
diff changeset
2049
kono
parents:
diff changeset
2050 /* Except for NULL, functions and variables never overlap. */
kono
parents:
diff changeset
2051 if (TREE_CODE (decl) != TREE_CODE (s2->decl))
kono
parents:
diff changeset
2052 return 0;
kono
parents:
diff changeset
2053
kono
parents:
diff changeset
2054 /* If one of the symbols is unresolved alias, punt. */
kono
parents:
diff changeset
2055 if (rs1->alias || rs2->alias)
kono
parents:
diff changeset
2056 return -1;
kono
parents:
diff changeset
2057
kono
parents:
diff changeset
2058 /* If we have a non-interposale definition of at least one of the symbols
kono
parents:
diff changeset
2059 and the other symbol is different, we know other unit can not interpose
kono
parents:
diff changeset
2060 it to the first symbol; all aliases of the definition needs to be
kono
parents:
diff changeset
2061 present in the current unit. */
kono
parents:
diff changeset
2062 if (((really_binds_local1 || really_binds_local2)
kono
parents:
diff changeset
2063 /* If we have both definitions and they are different, we know they
kono
parents:
diff changeset
2064 will be different even in units they binds to. */
kono
parents:
diff changeset
2065 || (binds_local1 && binds_local2))
kono
parents:
diff changeset
2066 && rs1 != rs2)
kono
parents:
diff changeset
2067 {
kono
parents:
diff changeset
2068 /* We make use of the fact that one symbol is not alias of the other
kono
parents:
diff changeset
2069 and that the definition is non-interposable. */
kono
parents:
diff changeset
2070 refuse_visibility_changes = true;
kono
parents:
diff changeset
2071 s2->refuse_visibility_changes = true;
kono
parents:
diff changeset
2072 rs1->refuse_visibility_changes = true;
kono
parents:
diff changeset
2073 rs2->refuse_visibility_changes = true;
kono
parents:
diff changeset
2074 return 0;
kono
parents:
diff changeset
2075 }
kono
parents:
diff changeset
2076
kono
parents:
diff changeset
2077 /* TODO: Alias oracle basically assume that addresses of global variables
kono
parents:
diff changeset
2078 are different unless they are declared as alias of one to another while
kono
parents:
diff changeset
2079 the code folding comparsions doesn't.
kono
parents:
diff changeset
2080 We probably should be consistent and use this fact here, too, but for
kono
parents:
diff changeset
2081 the moment return false only when we are called from the alias oracle. */
kono
parents:
diff changeset
2082
kono
parents:
diff changeset
2083 return memory_accessed && rs1 != rs2 ? 0 : -1;
kono
parents:
diff changeset
2084 }
kono
parents:
diff changeset
2085
kono
parents:
diff changeset
2086 /* Worker for call_for_symbol_and_aliases. */
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 bool
kono
parents:
diff changeset
2089 symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
kono
parents:
diff changeset
2090 void *),
kono
parents:
diff changeset
2091 void *data,
kono
parents:
diff changeset
2092 bool include_overwritable)
kono
parents:
diff changeset
2093 {
kono
parents:
diff changeset
2094 ipa_ref *ref;
kono
parents:
diff changeset
2095 FOR_EACH_ALIAS (this, ref)
kono
parents:
diff changeset
2096 {
kono
parents:
diff changeset
2097 symtab_node *alias = ref->referring;
kono
parents:
diff changeset
2098 if (include_overwritable
kono
parents:
diff changeset
2099 || alias->get_availability () > AVAIL_INTERPOSABLE)
kono
parents:
diff changeset
2100 if (alias->call_for_symbol_and_aliases (callback, data,
kono
parents:
diff changeset
2101 include_overwritable))
kono
parents:
diff changeset
2102 return true;
kono
parents:
diff changeset
2103 }
kono
parents:
diff changeset
2104 return false;
kono
parents:
diff changeset
2105 }
kono
parents:
diff changeset
2106
kono
parents:
diff changeset
2107 /* Return true if address of N is possibly compared. */
kono
parents:
diff changeset
2108
kono
parents:
diff changeset
2109 static bool
kono
parents:
diff changeset
2110 address_matters_1 (symtab_node *n, void *)
kono
parents:
diff changeset
2111 {
kono
parents:
diff changeset
2112 struct ipa_ref *ref;
kono
parents:
diff changeset
2113
kono
parents:
diff changeset
2114 if (!n->address_can_be_compared_p ())
kono
parents:
diff changeset
2115 return false;
kono
parents:
diff changeset
2116 if (n->externally_visible || n->force_output)
kono
parents:
diff changeset
2117 return true;
kono
parents:
diff changeset
2118
kono
parents:
diff changeset
2119 for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
kono
parents:
diff changeset
2120 if (ref->address_matters_p ())
kono
parents:
diff changeset
2121 return true;
kono
parents:
diff changeset
2122 return false;
kono
parents:
diff changeset
2123 }
kono
parents:
diff changeset
2124
kono
parents:
diff changeset
2125 /* Return true if symbol's address may possibly be compared to other
kono
parents:
diff changeset
2126 symbol's address. */
kono
parents:
diff changeset
2127
kono
parents:
diff changeset
2128 bool
kono
parents:
diff changeset
2129 symtab_node::address_matters_p ()
kono
parents:
diff changeset
2130 {
kono
parents:
diff changeset
2131 gcc_assert (!alias);
kono
parents:
diff changeset
2132 return call_for_symbol_and_aliases (address_matters_1, NULL, true);
kono
parents:
diff changeset
2133 }
kono
parents:
diff changeset
2134
kono
parents:
diff changeset
2135 /* Return true if symbol's alignment may be increased. */
kono
parents:
diff changeset
2136
kono
parents:
diff changeset
2137 bool
kono
parents:
diff changeset
2138 symtab_node::can_increase_alignment_p (void)
kono
parents:
diff changeset
2139 {
kono
parents:
diff changeset
2140 symtab_node *target = ultimate_alias_target ();
kono
parents:
diff changeset
2141
kono
parents:
diff changeset
2142 /* For now support only variables. */
kono
parents:
diff changeset
2143 if (!VAR_P (decl))
kono
parents:
diff changeset
2144 return false;
kono
parents:
diff changeset
2145
kono
parents:
diff changeset
2146 /* With -fno-toplevel-reorder we may have already output the constant. */
kono
parents:
diff changeset
2147 if (TREE_ASM_WRITTEN (target->decl))
kono
parents:
diff changeset
2148 return false;
kono
parents:
diff changeset
2149
kono
parents:
diff changeset
2150 /* If target is already placed in an anchor, we can not touch its
kono
parents:
diff changeset
2151 alignment. */
kono
parents:
diff changeset
2152 if (DECL_RTL_SET_P (target->decl)
kono
parents:
diff changeset
2153 && MEM_P (DECL_RTL (target->decl))
kono
parents:
diff changeset
2154 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
kono
parents:
diff changeset
2155 return false;
kono
parents:
diff changeset
2156
kono
parents:
diff changeset
2157 /* Constant pool entries may be shared. */
kono
parents:
diff changeset
2158 if (DECL_IN_CONSTANT_POOL (target->decl))
kono
parents:
diff changeset
2159 return false;
kono
parents:
diff changeset
2160
kono
parents:
diff changeset
2161 /* We cannot change alignment of symbols that may bind to symbols
kono
parents:
diff changeset
2162 in other translation unit that may contain a definition with lower
kono
parents:
diff changeset
2163 alignment. */
kono
parents:
diff changeset
2164 if (!decl_binds_to_current_def_p (decl))
kono
parents:
diff changeset
2165 return false;
kono
parents:
diff changeset
2166
kono
parents:
diff changeset
2167 /* When compiling partition, be sure the symbol is not output by other
kono
parents:
diff changeset
2168 partition. */
kono
parents:
diff changeset
2169 if (flag_ltrans
kono
parents:
diff changeset
2170 && (target->in_other_partition
kono
parents:
diff changeset
2171 || target->get_partitioning_class () == SYMBOL_DUPLICATE))
kono
parents:
diff changeset
2172 return false;
kono
parents:
diff changeset
2173
kono
parents:
diff changeset
2174 /* Do not override the alignment as specified by the ABI when the used
kono
parents:
diff changeset
2175 attribute is set. */
kono
parents:
diff changeset
2176 if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl))
kono
parents:
diff changeset
2177 return false;
kono
parents:
diff changeset
2178
kono
parents:
diff changeset
2179 /* Do not override explicit alignment set by the user when an explicit
kono
parents:
diff changeset
2180 section name is also used. This is a common idiom used by many
kono
parents:
diff changeset
2181 software projects. */
kono
parents:
diff changeset
2182 if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section)
kono
parents:
diff changeset
2183 return false;
kono
parents:
diff changeset
2184
kono
parents:
diff changeset
2185 return true;
kono
parents:
diff changeset
2186 }
kono
parents:
diff changeset
2187
kono
parents:
diff changeset
2188 /* Worker for symtab_node::increase_alignment. */
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 static bool
kono
parents:
diff changeset
2191 increase_alignment_1 (symtab_node *n, void *v)
kono
parents:
diff changeset
2192 {
kono
parents:
diff changeset
2193 unsigned int align = (size_t)v;
kono
parents:
diff changeset
2194 if (DECL_ALIGN (n->decl) < align
kono
parents:
diff changeset
2195 && n->can_increase_alignment_p ())
kono
parents:
diff changeset
2196 {
kono
parents:
diff changeset
2197 SET_DECL_ALIGN (n->decl, align);
kono
parents:
diff changeset
2198 DECL_USER_ALIGN (n->decl) = 1;
kono
parents:
diff changeset
2199 }
kono
parents:
diff changeset
2200 return false;
kono
parents:
diff changeset
2201 }
kono
parents:
diff changeset
2202
kono
parents:
diff changeset
2203 /* Increase alignment of THIS to ALIGN. */
kono
parents:
diff changeset
2204
kono
parents:
diff changeset
2205 void
kono
parents:
diff changeset
2206 symtab_node::increase_alignment (unsigned int align)
kono
parents:
diff changeset
2207 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2208 gcc_assert (can_increase_alignment_p () && align <= MAX_OFILE_ALIGNMENT);
111
kono
parents:
diff changeset
2209 ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
kono
parents:
diff changeset
2210 (void *)(size_t) align,
kono
parents:
diff changeset
2211 true);
kono
parents:
diff changeset
2212 gcc_assert (DECL_ALIGN (decl) >= align);
kono
parents:
diff changeset
2213 }
kono
parents:
diff changeset
2214
kono
parents:
diff changeset
2215 /* Helper for symtab_node::definition_alignment. */
kono
parents:
diff changeset
2216
kono
parents:
diff changeset
2217 static bool
kono
parents:
diff changeset
2218 get_alignment_1 (symtab_node *n, void *v)
kono
parents:
diff changeset
2219 {
kono
parents:
diff changeset
2220 *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
kono
parents:
diff changeset
2221 return false;
kono
parents:
diff changeset
2222 }
kono
parents:
diff changeset
2223
kono
parents:
diff changeset
2224 /* Return desired alignment of the definition. This is NOT alignment useful
kono
parents:
diff changeset
2225 to access THIS, because THIS may be interposable and DECL_ALIGN should
kono
parents:
diff changeset
2226 be used instead. It however must be guaranteed when output definition
kono
parents:
diff changeset
2227 of THIS. */
kono
parents:
diff changeset
2228
kono
parents:
diff changeset
2229 unsigned int
kono
parents:
diff changeset
2230 symtab_node::definition_alignment ()
kono
parents:
diff changeset
2231 {
kono
parents:
diff changeset
2232 unsigned int align = 0;
kono
parents:
diff changeset
2233 gcc_assert (!alias);
kono
parents:
diff changeset
2234 call_for_symbol_and_aliases (get_alignment_1, &align, true);
kono
parents:
diff changeset
2235 return align;
kono
parents:
diff changeset
2236 }
kono
parents:
diff changeset
2237
kono
parents:
diff changeset
2238 /* Return symbol used to separate symbol name from suffix. */
kono
parents:
diff changeset
2239
kono
parents:
diff changeset
2240 char
kono
parents:
diff changeset
2241 symbol_table::symbol_suffix_separator ()
kono
parents:
diff changeset
2242 {
kono
parents:
diff changeset
2243 #ifndef NO_DOT_IN_LABEL
kono
parents:
diff changeset
2244 return '.';
kono
parents:
diff changeset
2245 #elif !defined NO_DOLLAR_IN_LABEL
kono
parents:
diff changeset
2246 return '$';
kono
parents:
diff changeset
2247 #else
kono
parents:
diff changeset
2248 return '_';
kono
parents:
diff changeset
2249 #endif
kono
parents:
diff changeset
2250 }
kono
parents:
diff changeset
2251
kono
parents:
diff changeset
2252 /* Return true when references to this symbol from REF must bind to current
kono
parents:
diff changeset
2253 definition in final executable. */
kono
parents:
diff changeset
2254
kono
parents:
diff changeset
2255 bool
kono
parents:
diff changeset
2256 symtab_node::binds_to_current_def_p (symtab_node *ref)
kono
parents:
diff changeset
2257 {
kono
parents:
diff changeset
2258 if (!definition)
kono
parents:
diff changeset
2259 return false;
kono
parents:
diff changeset
2260 if (transparent_alias)
kono
parents:
diff changeset
2261 return definition
kono
parents:
diff changeset
2262 && get_alias_target()->binds_to_current_def_p (ref);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2263 cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2264 if (cnode && cnode->ifunc_resolver)
111
kono
parents:
diff changeset
2265 return false;
kono
parents:
diff changeset
2266 if (decl_binds_to_current_def_p (decl))
kono
parents:
diff changeset
2267 return true;
kono
parents:
diff changeset
2268
kono
parents:
diff changeset
2269 /* Inline clones always binds locally. */
kono
parents:
diff changeset
2270 if (cnode && cnode->global.inlined_to)
kono
parents:
diff changeset
2271 return true;
kono
parents:
diff changeset
2272
kono
parents:
diff changeset
2273 if (DECL_EXTERNAL (decl))
kono
parents:
diff changeset
2274 return false;
kono
parents:
diff changeset
2275
kono
parents:
diff changeset
2276 gcc_assert (externally_visible);
kono
parents:
diff changeset
2277
kono
parents:
diff changeset
2278 if (ref)
kono
parents:
diff changeset
2279 {
kono
parents:
diff changeset
2280 cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
kono
parents:
diff changeset
2281 if (cref)
kono
parents:
diff changeset
2282 ref = cref->global.inlined_to;
kono
parents:
diff changeset
2283 }
kono
parents:
diff changeset
2284
kono
parents:
diff changeset
2285 /* If this is a reference from symbol itself and there are no aliases, we
kono
parents:
diff changeset
2286 may be sure that the symbol was not interposed by something else because
kono
parents:
diff changeset
2287 the symbol itself would be unreachable otherwise. This is important
kono
parents:
diff changeset
2288 to optimize recursive functions well.
kono
parents:
diff changeset
2289
kono
parents:
diff changeset
2290 This assumption may be broken by inlining: if symbol is interposable
kono
parents:
diff changeset
2291 but the body is available (i.e. declared inline), inliner may make
kono
parents:
diff changeset
2292 the body reachable even with interposition. */
kono
parents:
diff changeset
2293 if (this == ref && !has_aliases_p ()
kono
parents:
diff changeset
2294 && (!cnode
kono
parents:
diff changeset
2295 || symtab->state >= IPA_SSA_AFTER_INLINING
kono
parents:
diff changeset
2296 || get_availability () >= AVAIL_INTERPOSABLE))
kono
parents:
diff changeset
2297 return true;
kono
parents:
diff changeset
2298
kono
parents:
diff changeset
2299
kono
parents:
diff changeset
2300 /* References within one comdat group are always bound in a group. */
kono
parents:
diff changeset
2301 if (ref
kono
parents:
diff changeset
2302 && symtab->state >= IPA_SSA_AFTER_INLINING
kono
parents:
diff changeset
2303 && get_comdat_group ()
kono
parents:
diff changeset
2304 && get_comdat_group () == ref->get_comdat_group ())
kono
parents:
diff changeset
2305 return true;
kono
parents:
diff changeset
2306
kono
parents:
diff changeset
2307 return false;
kono
parents:
diff changeset
2308 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2309
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2310 /* Return true if symbol should be output to the symbol table. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2311
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2312 bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2313 symtab_node::output_to_lto_symbol_table_p (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2314 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2315 /* Only externally visible symbols matter. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2316 if (!TREE_PUBLIC (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2317 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2318 if (!real_symbol_p ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2319 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2320 /* FIXME: variables probably should not be considered as real symbols at
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2321 first place. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2322 if (VAR_P (decl) && DECL_HARD_REGISTER (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2323 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2324 /* FIXME: Builtins corresponding to real functions probably should have
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2325 symbol table entries. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2326 if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2327 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2328
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2329 /* We have real symbol that should be in symbol table. However try to trim
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2330 down the refernces to libraries bit more because linker will otherwise
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2331 bring unnecesary object files into the final link.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2332 FIXME: The following checks can easily be confused i.e. by self recursive
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2333 function or self-referring variable. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2334
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2335 /* We keep external functions in symtab for sake of inlining
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2336 and devirtualization. We do not want to see them in symbol table as
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2337 references unless they are really used. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2338 cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2339 if (cnode && (!definition || DECL_EXTERNAL (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2340 && cnode->callers)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2341 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2342
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2343 /* Ignore all references from external vars initializers - they are not really
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2344 part of the compilation unit until they are used by folding. Some symbols,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2345 like references to external construction vtables can not be referred to at
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2346 all. We decide this at can_refer_decl_in_current_unit_p. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2347 if (!definition || DECL_EXTERNAL (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2348 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2349 int i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2350 struct ipa_ref *ref;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2351 for (i = 0; iterate_referring (i, ref); i++)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2352 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2353 if (ref->use == IPA_REF_ALIAS)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2354 continue;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2355 if (is_a <cgraph_node *> (ref->referring))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2356 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2357 if (!DECL_EXTERNAL (ref->referring->decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2358 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2359 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2360 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2361 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2362 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2363 }