]>
Commit | Line | Data |
---|---|---|
2aae7680 | 1 | /* Symbol table. |
d1e082c2 | 2 | Copyright (C) 2012-2013 Free Software Foundation, Inc. |
2aae7680 JH |
3 | Contributed by Jan Hubicka |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 3, or (at your option) any later | |
10 | version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING3. If not see | |
19 | <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | #include "tm.h" | |
25 | #include "tree.h" | |
26 | #include "tree-inline.h" | |
8f940ee6 | 27 | #include "langhooks.h" |
2aae7680 | 28 | #include "hashtab.h" |
1ab24192 | 29 | #include "ggc.h" |
2aae7680 | 30 | #include "cgraph.h" |
1ab24192 | 31 | #include "diagnostic.h" |
474ffc72 | 32 | #include "timevar.h" |
65d630d4 JH |
33 | #include "lto-streamer.h" |
34 | #include "rtl.h" | |
35 | ||
36 | const char * const ld_plugin_symbol_resolution_names[]= | |
37 | { | |
38 | "", | |
39 | "undef", | |
40 | "prevailing_def", | |
41 | "prevailing_def_ironly", | |
42 | "preempted_reg", | |
43 | "preempted_ir", | |
44 | "resolved_ir", | |
45 | "resolved_exec", | |
46 | "resolved_dyn", | |
47 | "prevailing_def_ironly_exp" | |
48 | }; | |
1ab24192 JH |
49 | |
50 | /* Hash table used to convert declarations into nodes. */ | |
51 | static GTY((param_is (union symtab_node_def))) htab_t symtab_hash; | |
52 | /* Hash table used to convert assembler names into nodes. */ | |
53 | static GTY((param_is (union symtab_node_def))) htab_t assembler_name_hash; | |
2aae7680 JH |
54 | |
55 | /* Linked list of symbol table nodes. */ | |
56 | symtab_node symtab_nodes; | |
57 | ||
58 | /* The order index of the next symtab node to be created. This is | |
59 | used so that we can sort the cgraph nodes in order by when we saw | |
60 | them, to support -fno-toplevel-reorder. */ | |
61 | int symtab_order; | |
62 | ||
1ab24192 JH |
63 | /* Returns a hash code for P. */ |
64 | ||
65 | static hashval_t | |
66 | hash_node (const void *p) | |
67 | { | |
68 | const_symtab_node n = (const_symtab_node ) p; | |
69 | return (hashval_t) DECL_UID (n->symbol.decl); | |
70 | } | |
71 | ||
72 | ||
73 | /* Returns nonzero if P1 and P2 are equal. */ | |
74 | ||
75 | static int | |
76 | eq_node (const void *p1, const void *p2) | |
77 | { | |
78 | const_symtab_node n1 = (const_symtab_node) p1; | |
79 | const_symtab_node n2 = (const_symtab_node) p2; | |
80 | return DECL_UID (n1->symbol.decl) == DECL_UID (n2->symbol.decl); | |
81 | } | |
82 | ||
83 | /* Returns a hash code for P. */ | |
84 | ||
85 | static hashval_t | |
86 | hash_node_by_assembler_name (const void *p) | |
87 | { | |
88 | const_symtab_node n = (const_symtab_node) p; | |
89 | return (hashval_t) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n->symbol.decl)); | |
90 | } | |
91 | ||
92 | /* Returns nonzero if P1 and P2 are equal. */ | |
93 | ||
94 | static int | |
95 | eq_assembler_name (const void *p1, const void *p2) | |
96 | { | |
97 | const_symtab_node n1 = (const_symtab_node) p1; | |
98 | const_tree name = (const_tree)p2; | |
99 | return (decl_assembler_name_equal (n1->symbol.decl, name)); | |
100 | } | |
101 | ||
102 | /* Insert NODE to assembler name hash. */ | |
103 | ||
104 | static void | |
c3167b00 | 105 | insert_to_assembler_name_hash (symtab_node node, bool with_clones) |
1ab24192 | 106 | { |
5d59b5e1 | 107 | if (is_a <varpool_node> (node) && DECL_HARD_REGISTER (node->symbol.decl)) |
b5493fb2 | 108 | return; |
1ab24192 JH |
109 | gcc_checking_assert (!node->symbol.previous_sharing_asm_name |
110 | && !node->symbol.next_sharing_asm_name); | |
111 | if (assembler_name_hash) | |
112 | { | |
113 | void **aslot; | |
c3167b00 JH |
114 | struct cgraph_node *cnode; |
115 | tree decl = node->symbol.decl; | |
116 | ||
1ab24192 JH |
117 | tree name = DECL_ASSEMBLER_NAME (node->symbol.decl); |
118 | ||
119 | aslot = htab_find_slot_with_hash (assembler_name_hash, name, | |
120 | decl_assembler_name_hash (name), | |
121 | INSERT); | |
122 | gcc_assert (*aslot != node); | |
123 | node->symbol.next_sharing_asm_name = (symtab_node)*aslot; | |
124 | if (*aslot != NULL) | |
125 | ((symtab_node)*aslot)->symbol.previous_sharing_asm_name = node; | |
126 | *aslot = node; | |
c3167b00 JH |
127 | |
128 | /* Update also possible inline clones sharing a decl. */ | |
129 | cnode = dyn_cast <cgraph_node> (node); | |
130 | if (cnode && cnode->clones && with_clones) | |
131 | for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone) | |
132 | if (cnode->symbol.decl == decl) | |
133 | insert_to_assembler_name_hash ((symtab_node) cnode, true); | |
1ab24192 JH |
134 | } |
135 | ||
136 | } | |
137 | ||
138 | /* Remove NODE from assembler name hash. */ | |
139 | ||
140 | static void | |
c3167b00 | 141 | unlink_from_assembler_name_hash (symtab_node node, bool with_clones) |
1ab24192 JH |
142 | { |
143 | if (assembler_name_hash) | |
144 | { | |
c3167b00 JH |
145 | struct cgraph_node *cnode; |
146 | tree decl = node->symbol.decl; | |
147 | ||
1ab24192 JH |
148 | if (node->symbol.next_sharing_asm_name) |
149 | node->symbol.next_sharing_asm_name->symbol.previous_sharing_asm_name | |
150 | = node->symbol.previous_sharing_asm_name; | |
151 | if (node->symbol.previous_sharing_asm_name) | |
152 | { | |
153 | node->symbol.previous_sharing_asm_name->symbol.next_sharing_asm_name | |
154 | = node->symbol.next_sharing_asm_name; | |
155 | } | |
156 | else | |
157 | { | |
158 | tree name = DECL_ASSEMBLER_NAME (node->symbol.decl); | |
159 | void **slot; | |
160 | slot = htab_find_slot_with_hash (assembler_name_hash, name, | |
161 | decl_assembler_name_hash (name), | |
162 | NO_INSERT); | |
163 | gcc_assert (*slot == node); | |
164 | if (!node->symbol.next_sharing_asm_name) | |
165 | htab_clear_slot (assembler_name_hash, slot); | |
166 | else | |
167 | *slot = node->symbol.next_sharing_asm_name; | |
168 | } | |
b5493fb2 JH |
169 | node->symbol.next_sharing_asm_name = NULL; |
170 | node->symbol.previous_sharing_asm_name = NULL; | |
c3167b00 JH |
171 | |
172 | /* Update also possible inline clones sharing a decl. */ | |
173 | cnode = dyn_cast <cgraph_node> (node); | |
174 | if (cnode && cnode->clones && with_clones) | |
175 | for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone) | |
176 | if (cnode->symbol.decl == decl) | |
177 | unlink_from_assembler_name_hash ((symtab_node) cnode, true); | |
1ab24192 JH |
178 | } |
179 | } | |
180 | ||
b5493fb2 JH |
181 | /* Arrange node to be first in its entry of assembler_name_hash. */ |
182 | ||
183 | void | |
184 | symtab_prevail_in_asm_name_hash (symtab_node node) | |
185 | { | |
c3167b00 JH |
186 | unlink_from_assembler_name_hash (node, false); |
187 | insert_to_assembler_name_hash (node, false); | |
b5493fb2 JH |
188 | } |
189 | ||
1ab24192 | 190 | |
2aae7680 JH |
191 | /* Add node into symbol table. This function is not used directly, but via |
192 | cgraph/varpool node creation routines. */ | |
193 | ||
194 | void | |
195 | symtab_register_node (symtab_node node) | |
196 | { | |
1ab24192 JH |
197 | struct symtab_node_base key; |
198 | symtab_node *slot; | |
199 | ||
2aae7680 JH |
200 | node->symbol.next = symtab_nodes; |
201 | node->symbol.previous = NULL; | |
202 | if (symtab_nodes) | |
203 | symtab_nodes->symbol.previous = node; | |
204 | symtab_nodes = node; | |
205 | ||
1ab24192 JH |
206 | if (!symtab_hash) |
207 | symtab_hash = htab_create_ggc (10, hash_node, eq_node, NULL); | |
208 | key.decl = node->symbol.decl; | |
209 | slot = (symtab_node *) htab_find_slot (symtab_hash, &key, INSERT); | |
210 | if (*slot == NULL) | |
211 | *slot = node; | |
212 | ||
66379195 | 213 | ipa_empty_ref_list (&node->symbol.ref_list); |
1ab24192 | 214 | |
2aae7680 JH |
215 | node->symbol.order = symtab_order++; |
216 | ||
66379195 JH |
217 | /* Be sure to do this last; C++ FE might create new nodes via |
218 | DECL_ASSEMBLER_NAME langhook! */ | |
c3167b00 | 219 | insert_to_assembler_name_hash (node, false); |
2aae7680 JH |
220 | } |
221 | ||
1ab24192 JH |
222 | /* Make NODE to be the one symtab hash is pointing to. Used when reshaping tree |
223 | of inline clones. */ | |
224 | ||
225 | void | |
226 | symtab_insert_node_to_hashtable (symtab_node node) | |
227 | { | |
228 | struct symtab_node_base key; | |
229 | symtab_node *slot; | |
230 | ||
231 | if (!symtab_hash) | |
232 | symtab_hash = htab_create_ggc (10, hash_node, eq_node, NULL); | |
233 | key.decl = node->symbol.decl; | |
234 | slot = (symtab_node *) htab_find_slot (symtab_hash, &key, INSERT); | |
235 | *slot = node; | |
236 | } | |
237 | ||
2aae7680 JH |
238 | /* Remove node from symbol table. This function is not used directly, but via |
239 | cgraph/varpool node removal routines. */ | |
240 | ||
241 | void | |
242 | symtab_unregister_node (symtab_node node) | |
243 | { | |
1ab24192 | 244 | void **slot; |
2aae7680 | 245 | ipa_remove_all_references (&node->symbol.ref_list); |
5932a4d4 | 246 | ipa_remove_all_referring (&node->symbol.ref_list); |
2aae7680 JH |
247 | |
248 | if (node->symbol.same_comdat_group) | |
249 | { | |
250 | symtab_node prev; | |
251 | for (prev = node->symbol.same_comdat_group; | |
252 | prev->symbol.same_comdat_group != node; | |
253 | prev = prev->symbol.same_comdat_group) | |
254 | ; | |
255 | if (node->symbol.same_comdat_group == prev) | |
256 | prev->symbol.same_comdat_group = NULL; | |
257 | else | |
258 | prev->symbol.same_comdat_group = node->symbol.same_comdat_group; | |
259 | node->symbol.same_comdat_group = NULL; | |
260 | } | |
261 | ||
262 | if (node->symbol.previous) | |
263 | node->symbol.previous->symbol.next = node->symbol.next; | |
264 | else | |
265 | symtab_nodes = node->symbol.next; | |
266 | if (node->symbol.next) | |
267 | node->symbol.next->symbol.previous = node->symbol.previous; | |
268 | node->symbol.next = NULL; | |
269 | node->symbol.previous = NULL; | |
1ab24192 JH |
270 | |
271 | slot = htab_find_slot (symtab_hash, node, NO_INSERT); | |
272 | if (*slot == node) | |
273 | { | |
274 | symtab_node replacement_node = NULL; | |
5d59b5e1 LC |
275 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
276 | replacement_node = (symtab_node)cgraph_find_replacement_node (cnode); | |
1ab24192 JH |
277 | if (!replacement_node) |
278 | htab_clear_slot (symtab_hash, slot); | |
279 | else | |
280 | *slot = replacement_node; | |
281 | } | |
c3167b00 | 282 | unlink_from_assembler_name_hash (node, false); |
1ab24192 JH |
283 | } |
284 | ||
285 | /* Return symbol table node associated with DECL, if any, | |
286 | and NULL otherwise. */ | |
287 | ||
288 | symtab_node | |
289 | symtab_get_node (const_tree decl) | |
290 | { | |
291 | symtab_node *slot; | |
292 | struct symtab_node_base key; | |
293 | ||
294 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL | |
295 | || (TREE_CODE (decl) == VAR_DECL | |
296 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
297 | || in_lto_p))); | |
298 | ||
299 | if (!symtab_hash) | |
300 | return NULL; | |
301 | ||
302 | key.decl = CONST_CAST2 (tree, const_tree, decl); | |
303 | ||
304 | slot = (symtab_node *) htab_find_slot (symtab_hash, &key, | |
305 | NO_INSERT); | |
306 | ||
307 | if (slot) | |
308 | return *slot; | |
309 | return NULL; | |
2aae7680 JH |
310 | } |
311 | ||
312 | /* Remove symtab NODE from the symbol table. */ | |
313 | ||
314 | void | |
315 | symtab_remove_node (symtab_node node) | |
316 | { | |
5d59b5e1 LC |
317 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
318 | cgraph_remove_node (cnode); | |
319 | else if (varpool_node *vnode = dyn_cast <varpool_node> (node)) | |
320 | varpool_remove_node (vnode); | |
2aae7680 | 321 | } |
1ab24192 | 322 | |
b5493fb2 | 323 | /* Initalize asm name hash unless. */ |
1ab24192 | 324 | |
b5493fb2 JH |
325 | void |
326 | symtab_initialize_asm_name_hash (void) | |
1ab24192 JH |
327 | { |
328 | symtab_node node; | |
1ab24192 JH |
329 | if (!assembler_name_hash) |
330 | { | |
331 | assembler_name_hash = | |
332 | htab_create_ggc (10, hash_node_by_assembler_name, eq_assembler_name, | |
333 | NULL); | |
334 | FOR_EACH_SYMBOL (node) | |
c3167b00 | 335 | insert_to_assembler_name_hash (node, false); |
1ab24192 | 336 | } |
b5493fb2 | 337 | } |
1ab24192 | 338 | |
b5493fb2 JH |
339 | /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. |
340 | Return NULL if there's no such node. */ | |
341 | ||
342 | symtab_node | |
343 | symtab_node_for_asm (const_tree asmname) | |
344 | { | |
345 | symtab_node node; | |
346 | void **slot; | |
347 | ||
348 | symtab_initialize_asm_name_hash (); | |
1ab24192 JH |
349 | slot = htab_find_slot_with_hash (assembler_name_hash, asmname, |
350 | decl_assembler_name_hash (asmname), | |
351 | NO_INSERT); | |
352 | ||
353 | if (slot) | |
354 | { | |
355 | node = (symtab_node) *slot; | |
356 | return node; | |
357 | } | |
358 | return NULL; | |
359 | } | |
360 | ||
361 | /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */ | |
362 | ||
363 | void | |
364 | change_decl_assembler_name (tree decl, tree name) | |
365 | { | |
366 | symtab_node node = NULL; | |
367 | ||
368 | /* We can have user ASM names on things, like global register variables, that | |
369 | are not in the symbol table. */ | |
370 | if ((TREE_CODE (decl) == VAR_DECL | |
371 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) | |
372 | || TREE_CODE (decl) == FUNCTION_DECL) | |
373 | node = symtab_get_node (decl); | |
374 | if (!DECL_ASSEMBLER_NAME_SET_P (decl)) | |
375 | { | |
376 | SET_DECL_ASSEMBLER_NAME (decl, name); | |
377 | if (node) | |
c3167b00 | 378 | insert_to_assembler_name_hash (node, true); |
1ab24192 JH |
379 | } |
380 | else | |
381 | { | |
382 | if (name == DECL_ASSEMBLER_NAME (decl)) | |
383 | return; | |
384 | ||
385 | if (node) | |
c3167b00 | 386 | unlink_from_assembler_name_hash (node, true); |
1ab24192 JH |
387 | if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) |
388 | && DECL_RTL_SET_P (decl)) | |
389 | warning (0, "%D renamed after being referenced in assembly", decl); | |
390 | ||
391 | SET_DECL_ASSEMBLER_NAME (decl, name); | |
392 | if (node) | |
c3167b00 | 393 | insert_to_assembler_name_hash (node, true); |
1ab24192 JH |
394 | } |
395 | } | |
396 | ||
65d630d4 JH |
397 | /* Add NEW_ to the same comdat group that OLD is in. */ |
398 | ||
399 | void | |
400 | symtab_add_to_same_comdat_group (symtab_node new_node, | |
401 | symtab_node old_node) | |
402 | { | |
403 | gcc_assert (DECL_ONE_ONLY (old_node->symbol.decl)); | |
404 | gcc_assert (!new_node->symbol.same_comdat_group); | |
405 | gcc_assert (new_node != old_node); | |
406 | ||
407 | DECL_COMDAT_GROUP (new_node->symbol.decl) = DECL_COMDAT_GROUP (old_node->symbol.decl); | |
408 | new_node->symbol.same_comdat_group = old_node; | |
409 | if (!old_node->symbol.same_comdat_group) | |
410 | old_node->symbol.same_comdat_group = new_node; | |
411 | else | |
412 | { | |
413 | symtab_node n; | |
414 | for (n = old_node->symbol.same_comdat_group; | |
415 | n->symbol.same_comdat_group != old_node; | |
416 | n = n->symbol.same_comdat_group) | |
417 | ; | |
418 | n->symbol.same_comdat_group = new_node; | |
419 | } | |
420 | } | |
421 | ||
422 | /* Dissolve the same_comdat_group list in which NODE resides. */ | |
423 | ||
424 | void | |
425 | symtab_dissolve_same_comdat_group_list (symtab_node node) | |
426 | { | |
427 | symtab_node n = node, next; | |
428 | ||
429 | if (!node->symbol.same_comdat_group) | |
430 | return; | |
431 | do | |
432 | { | |
433 | next = n->symbol.same_comdat_group; | |
434 | n->symbol.same_comdat_group = NULL; | |
435 | n = next; | |
436 | } | |
437 | while (n != node); | |
438 | } | |
439 | ||
8f940ee6 JH |
440 | /* Return printable assembler name of NODE. |
441 | This function is used only for debugging. When assembler name | |
442 | is unknown go with identifier name. */ | |
443 | ||
444 | const char * | |
445 | symtab_node_asm_name (symtab_node node) | |
446 | { | |
447 | if (!DECL_ASSEMBLER_NAME_SET_P (node->symbol.decl)) | |
448 | return lang_hooks.decl_printable_name (node->symbol.decl, 2); | |
449 | return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->symbol.decl)); | |
450 | } | |
451 | ||
452 | /* Return printable identifier name. */ | |
453 | ||
454 | const char * | |
455 | symtab_node_name (symtab_node node) | |
456 | { | |
457 | return lang_hooks.decl_printable_name (node->symbol.decl, 2); | |
458 | } | |
459 | ||
460 | static const char * const symtab_type_names[] = {"symbol", "function", "variable"}; | |
461 | ||
462 | /* Dump base fields of symtab nodes. Not to be used directly. */ | |
463 | ||
464 | void | |
465 | dump_symtab_base (FILE *f, symtab_node node) | |
466 | { | |
467 | static const char * const visibility_types[] = { | |
468 | "default", "protected", "hidden", "internal" | |
469 | }; | |
470 | ||
471 | fprintf (f, "%s/%i (%s)", | |
472 | symtab_node_asm_name (node), | |
473 | node->symbol.order, | |
474 | symtab_node_name (node)); | |
475 | dump_addr (f, " @", (void *)node); | |
e70670cf JH |
476 | fprintf (f, "\n Type: %s", symtab_type_names[node->symbol.type]); |
477 | ||
478 | if (node->symbol.definition) | |
479 | fprintf (f, " definition"); | |
480 | if (node->symbol.analyzed) | |
481 | fprintf (f, " analyzed"); | |
482 | if (node->symbol.alias) | |
483 | fprintf (f, " alias"); | |
484 | fprintf (f, "\n Visibility:"); | |
8f940ee6 JH |
485 | if (node->symbol.in_other_partition) |
486 | fprintf (f, " in_other_partition"); | |
487 | if (node->symbol.used_from_other_partition) | |
488 | fprintf (f, " used_from_other_partition"); | |
ead84f73 JH |
489 | if (node->symbol.force_output) |
490 | fprintf (f, " force_output"); | |
8f940ee6 JH |
491 | if (node->symbol.resolution != LDPR_UNKNOWN) |
492 | fprintf (f, " %s", | |
493 | ld_plugin_symbol_resolution_names[(int)node->symbol.resolution]); | |
494 | if (TREE_ASM_WRITTEN (node->symbol.decl)) | |
495 | fprintf (f, " asm_written"); | |
496 | if (DECL_EXTERNAL (node->symbol.decl)) | |
497 | fprintf (f, " external"); | |
498 | if (TREE_PUBLIC (node->symbol.decl)) | |
499 | fprintf (f, " public"); | |
500 | if (DECL_COMMON (node->symbol.decl)) | |
501 | fprintf (f, " common"); | |
502 | if (DECL_WEAK (node->symbol.decl)) | |
503 | fprintf (f, " weak"); | |
504 | if (DECL_DLLIMPORT_P (node->symbol.decl)) | |
505 | fprintf (f, " dll_import"); | |
506 | if (DECL_COMDAT (node->symbol.decl)) | |
507 | fprintf (f, " comdat"); | |
508 | if (DECL_COMDAT_GROUP (node->symbol.decl)) | |
509 | fprintf (f, " comdat_group:%s", | |
510 | IDENTIFIER_POINTER (DECL_COMDAT_GROUP (node->symbol.decl))); | |
511 | if (DECL_ONE_ONLY (node->symbol.decl)) | |
512 | fprintf (f, " one_only"); | |
513 | if (DECL_SECTION_NAME (node->symbol.decl)) | |
514 | fprintf (f, " section_name:%s", | |
f68c0487 | 515 | TREE_STRING_POINTER (DECL_SECTION_NAME (node->symbol.decl))); |
8f940ee6 JH |
516 | if (DECL_VISIBILITY_SPECIFIED (node->symbol.decl)) |
517 | fprintf (f, " visibility_specified"); | |
518 | if (DECL_VISIBILITY (node->symbol.decl)) | |
519 | fprintf (f, " visibility:%s", | |
520 | visibility_types [DECL_VISIBILITY (node->symbol.decl)]); | |
521 | if (DECL_VIRTUAL_P (node->symbol.decl)) | |
522 | fprintf (f, " virtual"); | |
523 | if (DECL_ARTIFICIAL (node->symbol.decl)) | |
524 | fprintf (f, " artificial"); | |
838ff415 JH |
525 | if (TREE_CODE (node->symbol.decl) == FUNCTION_DECL) |
526 | { | |
527 | if (DECL_STATIC_CONSTRUCTOR (node->symbol.decl)) | |
528 | fprintf (f, " constructor"); | |
529 | if (DECL_STATIC_DESTRUCTOR (node->symbol.decl)) | |
530 | fprintf (f, " destructor"); | |
531 | } | |
8f940ee6 JH |
532 | fprintf (f, "\n"); |
533 | ||
534 | if (node->symbol.same_comdat_group) | |
535 | fprintf (f, " Same comdat group as: %s/%i\n", | |
536 | symtab_node_asm_name (node->symbol.same_comdat_group), | |
537 | node->symbol.same_comdat_group->symbol.order); | |
538 | if (node->symbol.next_sharing_asm_name) | |
539 | fprintf (f, " next sharing asm name: %i\n", | |
fe0bd630 | 540 | node->symbol.next_sharing_asm_name->symbol.order); |
8f940ee6 JH |
541 | if (node->symbol.previous_sharing_asm_name) |
542 | fprintf (f, " previous sharing asm name: %i\n", | |
fe0bd630 | 543 | node->symbol.previous_sharing_asm_name->symbol.order); |
8f940ee6 JH |
544 | |
545 | if (node->symbol.address_taken) | |
fe0bd630 | 546 | fprintf (f, " Address is taken.\n"); |
66058468 JH |
547 | if (node->symbol.aux) |
548 | { | |
549 | fprintf (f, " Aux:"); | |
550 | dump_addr (f, " @", (void *)node->symbol.aux); | |
551 | } | |
8f940ee6 JH |
552 | |
553 | fprintf (f, " References: "); | |
554 | ipa_dump_references (f, &node->symbol.ref_list); | |
5932a4d4 JH |
555 | fprintf (f, " Referring: "); |
556 | ipa_dump_referring (f, &node->symbol.ref_list); | |
b5493fb2 JH |
557 | if (node->symbol.lto_file_data) |
558 | fprintf (f, " Read from file: %s\n", | |
559 | node->symbol.lto_file_data->file_name); | |
8f940ee6 JH |
560 | } |
561 | ||
562 | /* Dump symtab node. */ | |
563 | ||
564 | void | |
565 | dump_symtab_node (FILE *f, symtab_node node) | |
566 | { | |
5d59b5e1 LC |
567 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
568 | dump_cgraph_node (f, cnode); | |
569 | else if (varpool_node *vnode = dyn_cast <varpool_node> (node)) | |
570 | dump_varpool_node (f, vnode); | |
8f940ee6 JH |
571 | } |
572 | ||
573 | /* Dump symbol table. */ | |
574 | ||
575 | void | |
576 | dump_symtab (FILE *f) | |
577 | { | |
578 | symtab_node node; | |
579 | fprintf (f, "Symbol table:\n\n"); | |
580 | FOR_EACH_SYMBOL (node) | |
581 | dump_symtab_node (f, node); | |
582 | } | |
583 | ||
584 | /* Dump symtab node NODE to stderr. */ | |
585 | ||
586 | DEBUG_FUNCTION void | |
587 | debug_symtab_node (symtab_node node) | |
588 | { | |
589 | dump_symtab_node (stderr, node); | |
590 | } | |
591 | ||
592 | /* Dump symbol table to stderr. */ | |
593 | ||
594 | DEBUG_FUNCTION void | |
595 | debug_symtab (void) | |
596 | { | |
597 | dump_symtab (stderr); | |
598 | } | |
599 | ||
474ffc72 JH |
600 | /* Verify common part of symtab nodes. */ |
601 | ||
602 | DEBUG_FUNCTION bool | |
603 | verify_symtab_base (symtab_node node) | |
604 | { | |
605 | bool error_found = false; | |
606 | symtab_node hashed_node; | |
607 | ||
5d59b5e1 | 608 | if (is_a <cgraph_node> (node)) |
474ffc72 JH |
609 | { |
610 | if (TREE_CODE (node->symbol.decl) != FUNCTION_DECL) | |
611 | { | |
612 | error ("function symbol is not function"); | |
613 | error_found = true; | |
614 | } | |
615 | } | |
5d59b5e1 | 616 | else if (is_a <varpool_node> (node)) |
474ffc72 JH |
617 | { |
618 | if (TREE_CODE (node->symbol.decl) != VAR_DECL) | |
619 | { | |
620 | error ("variable symbol is not variable"); | |
621 | error_found = true; | |
622 | } | |
623 | } | |
624 | else | |
625 | { | |
626 | error ("node has unknown type"); | |
627 | error_found = true; | |
628 | } | |
629 | ||
630 | hashed_node = symtab_get_node (node->symbol.decl); | |
631 | if (!hashed_node) | |
632 | { | |
633 | error ("node not found in symtab decl hashtable"); | |
634 | error_found = true; | |
635 | } | |
636 | if (assembler_name_hash) | |
637 | { | |
638 | hashed_node = symtab_node_for_asm (DECL_ASSEMBLER_NAME (node->symbol.decl)); | |
639 | if (hashed_node && hashed_node->symbol.previous_sharing_asm_name) | |
640 | { | |
641 | error ("assembler name hash list corrupted"); | |
642 | error_found = true; | |
643 | } | |
644 | while (hashed_node) | |
645 | { | |
646 | if (hashed_node == node) | |
647 | break; | |
648 | hashed_node = hashed_node->symbol.next_sharing_asm_name; | |
649 | } | |
b5493fb2 | 650 | if (!hashed_node |
5d59b5e1 LC |
651 | && !(is_a <varpool_node> (node) |
652 | || DECL_HARD_REGISTER (node->symbol.decl))) | |
474ffc72 JH |
653 | { |
654 | error ("node not found in symtab assembler name hash"); | |
655 | error_found = true; | |
656 | } | |
657 | } | |
658 | if (node->symbol.previous_sharing_asm_name | |
659 | && node->symbol.previous_sharing_asm_name->symbol.next_sharing_asm_name != node) | |
660 | { | |
661 | error ("double linked list of assembler names corrupted"); | |
e70670cf JH |
662 | error_found = true; |
663 | } | |
664 | if (node->symbol.analyzed && !node->symbol.definition) | |
665 | { | |
666 | error ("node is analyzed byt it is not a definition"); | |
667 | error_found = true; | |
474ffc72 JH |
668 | } |
669 | if (node->symbol.same_comdat_group) | |
670 | { | |
671 | symtab_node n = node->symbol.same_comdat_group; | |
672 | ||
673 | if (!DECL_ONE_ONLY (n->symbol.decl)) | |
674 | { | |
675 | error ("non-DECL_ONE_ONLY node in a same_comdat_group list"); | |
676 | error_found = true; | |
677 | } | |
678 | if (n->symbol.type != node->symbol.type) | |
679 | { | |
680 | error ("mixing different types of symbol in same comdat groups is not supported"); | |
681 | error_found = true; | |
682 | } | |
683 | if (n == node) | |
684 | { | |
685 | error ("node is alone in a comdat group"); | |
686 | error_found = true; | |
687 | } | |
688 | do | |
689 | { | |
690 | if (!n->symbol.same_comdat_group) | |
691 | { | |
692 | error ("same_comdat_group is not a circular list"); | |
693 | error_found = true; | |
694 | break; | |
695 | } | |
696 | n = n->symbol.same_comdat_group; | |
697 | } | |
698 | while (n != node); | |
699 | } | |
700 | return error_found; | |
701 | } | |
702 | ||
703 | /* Verify consistency of NODE. */ | |
704 | ||
705 | DEBUG_FUNCTION void | |
706 | verify_symtab_node (symtab_node node) | |
707 | { | |
708 | if (seen_error ()) | |
709 | return; | |
710 | ||
711 | timevar_push (TV_CGRAPH_VERIFY); | |
5d59b5e1 LC |
712 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
713 | verify_cgraph_node (cnode); | |
474ffc72 JH |
714 | else |
715 | if (verify_symtab_base (node)) | |
716 | { | |
717 | dump_symtab_node (stderr, node); | |
718 | internal_error ("verify_symtab_node failed"); | |
719 | } | |
720 | timevar_pop (TV_CGRAPH_VERIFY); | |
721 | } | |
722 | ||
723 | /* Verify symbol table for internal consistency. */ | |
724 | ||
725 | DEBUG_FUNCTION void | |
726 | verify_symtab (void) | |
727 | { | |
728 | symtab_node node; | |
729 | FOR_EACH_SYMBOL (node) | |
730 | verify_symtab_node (node); | |
731 | } | |
732 | ||
65d630d4 JH |
733 | /* Return true when RESOLUTION indicate that linker will use |
734 | the symbol from non-LTO object files. */ | |
735 | ||
736 | bool | |
737 | resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution) | |
738 | { | |
739 | return (resolution == LDPR_PREVAILING_DEF | |
740 | || resolution == LDPR_PREEMPTED_REG | |
741 | || resolution == LDPR_RESOLVED_EXEC | |
742 | || resolution == LDPR_RESOLVED_DYN); | |
743 | } | |
744 | ||
745 | /* Return true when NODE is known to be used from other (non-LTO) object file. | |
746 | Known only when doing LTO via linker plugin. */ | |
747 | ||
748 | bool | |
749 | symtab_used_from_object_file_p (symtab_node node) | |
750 | { | |
751 | if (!TREE_PUBLIC (node->symbol.decl) || DECL_EXTERNAL (node->symbol.decl)) | |
752 | return false; | |
753 | if (resolution_used_from_other_file_p (node->symbol.resolution)) | |
754 | return true; | |
755 | return false; | |
756 | } | |
757 | ||
758 | /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early, | |
759 | but other code such as notice_global_symbol generates rtl. */ | |
760 | void | |
761 | symtab_make_decl_local (tree decl) | |
762 | { | |
763 | rtx rtl, symbol; | |
764 | ||
765 | if (TREE_CODE (decl) == VAR_DECL) | |
766 | DECL_COMMON (decl) = 0; | |
767 | else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
768 | ||
769 | if (DECL_ONE_ONLY (decl) || DECL_COMDAT (decl)) | |
770 | { | |
65d630d4 JH |
771 | DECL_SECTION_NAME (decl) = 0; |
772 | DECL_COMDAT (decl) = 0; | |
773 | } | |
774 | DECL_COMDAT_GROUP (decl) = 0; | |
775 | DECL_WEAK (decl) = 0; | |
776 | DECL_EXTERNAL (decl) = 0; | |
b5493fb2 JH |
777 | DECL_VISIBILITY_SPECIFIED (decl) = 0; |
778 | DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; | |
65d630d4 | 779 | TREE_PUBLIC (decl) = 0; |
1cdbb3f9 JH |
780 | DECL_VISIBILITY_SPECIFIED (decl) = 0; |
781 | DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; | |
65d630d4 JH |
782 | if (!DECL_RTL_SET_P (decl)) |
783 | return; | |
784 | ||
785 | /* Update rtl flags. */ | |
786 | make_decl_rtl (decl); | |
787 | ||
788 | rtl = DECL_RTL (decl); | |
789 | if (!MEM_P (rtl)) | |
790 | return; | |
791 | ||
792 | symbol = XEXP (rtl, 0); | |
793 | if (GET_CODE (symbol) != SYMBOL_REF) | |
794 | return; | |
795 | ||
796 | SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl); | |
797 | } | |
e70670cf JH |
798 | |
799 | /* Given NODE, walk the alias chain to return the symbol NODE is alias of. | |
800 | If NODE is not an alias, return NODE. | |
801 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ | |
802 | ||
803 | symtab_node | |
804 | symtab_alias_ultimate_target (symtab_node node, enum availability *availability) | |
805 | { | |
806 | if (availability) | |
807 | { | |
808 | if (is_a <cgraph_node> (node)) | |
809 | *availability = cgraph_function_body_availability (cgraph (node)); | |
810 | else | |
811 | *availability = cgraph_variable_initializer_availability (varpool (node)); | |
812 | } | |
813 | while (node) | |
814 | { | |
815 | if (node->symbol.alias && node->symbol.analyzed) | |
816 | node = symtab_alias_target (node); | |
817 | else | |
818 | return node; | |
819 | if (node && availability) | |
820 | { | |
821 | enum availability a; | |
822 | if (is_a <cgraph_node> (node)) | |
823 | a = cgraph_function_body_availability (cgraph (node)); | |
824 | else | |
825 | a = cgraph_variable_initializer_availability (varpool (node)); | |
826 | if (a < *availability) | |
827 | *availability = a; | |
828 | } | |
829 | } | |
830 | if (availability) | |
831 | *availability = AVAIL_NOT_AVAILABLE; | |
832 | return NULL; | |
833 | } | |
1ab24192 | 834 | #include "gt-symtab.h" |