Branch data Line data Source code
1 : : /* Symbol table.
2 : : Copyright (C) 2012-2025 Free Software Foundation, Inc.
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 "backend.h"
25 : : #include "target.h"
26 : : #include "rtl.h"
27 : : #include "tree.h"
28 : : #include "gimple.h"
29 : : #include "timevar.h"
30 : : #include "cgraph.h"
31 : : #include "lto-streamer.h"
32 : : #include "print-tree.h"
33 : : #include "varasm.h"
34 : : #include "langhooks.h"
35 : : #include "output.h"
36 : : #include "ipa-utils.h"
37 : : #include "calls.h"
38 : : #include "stringpool.h"
39 : : #include "attribs.h"
40 : : #include "builtins.h"
41 : : #include "fold-const.h"
42 : :
43 : : static const char *ipa_ref_use_name[] = {"read","write","addr","alias"};
44 : :
45 : : const char * const ld_plugin_symbol_resolution_names[]=
46 : : {
47 : : "",
48 : : "undef",
49 : : "prevailing_def",
50 : : "prevailing_def_ironly",
51 : : "preempted_reg",
52 : : "preempted_ir",
53 : : "resolved_ir",
54 : : "resolved_exec",
55 : : "resolved_dyn",
56 : : "prevailing_def_ironly_exp"
57 : : };
58 : :
59 : : /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at ALIAS
60 : : until we find an identifier that is not itself a transparent alias. */
61 : :
62 : : static inline tree
63 : 186 : ultimate_transparent_alias_target (tree alias)
64 : : {
65 : 186 : tree target = alias;
66 : :
67 : 186 : while (IDENTIFIER_TRANSPARENT_ALIAS (target))
68 : : {
69 : 0 : gcc_checking_assert (TREE_CHAIN (target));
70 : 0 : target = TREE_CHAIN (target);
71 : : }
72 : 186 : gcc_checking_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
73 : : && ! TREE_CHAIN (target));
74 : :
75 : 186 : return target;
76 : : }
77 : :
78 : :
79 : : /* Hash asmnames ignoring the user specified marks. */
80 : :
81 : : hashval_t
82 : 561821928 : symbol_table::decl_assembler_name_hash (const_tree asmname)
83 : : {
84 : 561821928 : if (IDENTIFIER_POINTER (asmname)[0] == '*')
85 : : {
86 : 2931251 : const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
87 : 2931251 : size_t ulp_len = strlen (user_label_prefix);
88 : :
89 : 2931251 : if (ulp_len == 0)
90 : : ;
91 : 85 : else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
92 : 85 : decl_str += ulp_len;
93 : :
94 : 2931251 : return htab_hash_string (decl_str);
95 : : }
96 : :
97 : 558890677 : return htab_hash_string (IDENTIFIER_POINTER (asmname));
98 : : }
99 : :
100 : : /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
101 : : name. */
102 : :
103 : : bool
104 : 486447680 : symbol_table::assembler_names_equal_p (const char *name1, const char *name2)
105 : : {
106 : 486447680 : if (name1 != name2)
107 : : {
108 : 486447581 : if (name1[0] == '*')
109 : : {
110 : 2472823 : size_t ulp_len = strlen (user_label_prefix);
111 : :
112 : 2472823 : name1 ++;
113 : :
114 : 2472823 : if (ulp_len == 0)
115 : : ;
116 : 30 : else if (strncmp (name1, user_label_prefix, ulp_len) == 0)
117 : 30 : name1 += ulp_len;
118 : : else
119 : : return false;
120 : : }
121 : 486447581 : if (name2[0] == '*')
122 : : {
123 : 2308712 : size_t ulp_len = strlen (user_label_prefix);
124 : :
125 : 2308712 : name2 ++;
126 : :
127 : 2308712 : if (ulp_len == 0)
128 : : ;
129 : 18 : else if (strncmp (name2, user_label_prefix, ulp_len) == 0)
130 : 18 : name2 += ulp_len;
131 : : else
132 : : return false;
133 : : }
134 : 486447581 : return !strcmp (name1, name2);
135 : : }
136 : : return true;
137 : : }
138 : :
139 : : /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
140 : :
141 : : bool
142 : 583767335 : symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
143 : : {
144 : 583767335 : tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
145 : 583767335 : const char *decl_str;
146 : 583767335 : const char *asmname_str;
147 : :
148 : 583767335 : if (decl_asmname == asmname)
149 : : return true;
150 : :
151 : 486447581 : decl_str = IDENTIFIER_POINTER (decl_asmname);
152 : 486447581 : asmname_str = IDENTIFIER_POINTER (asmname);
153 : 486447581 : return assembler_names_equal_p (decl_str, asmname_str);
154 : : }
155 : :
156 : :
157 : : /* Returns nonzero if P1 and P2 are equal. */
158 : :
159 : : /* Insert NODE to assembler name hash. */
160 : :
161 : : void
162 : 131001429 : symbol_table::insert_to_assembler_name_hash (symtab_node *node,
163 : : bool with_clones)
164 : : {
165 : 157934407 : if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
166 : : return;
167 : 131001220 : gcc_checking_assert (!node->previous_sharing_asm_name
168 : : && !node->next_sharing_asm_name);
169 : 131001220 : if (assembler_name_hash)
170 : : {
171 : 12026953 : symtab_node **aslot;
172 : 12026953 : cgraph_node *cnode;
173 : 12026953 : tree decl = node->decl;
174 : :
175 : 12026953 : tree name = DECL_ASSEMBLER_NAME (node->decl);
176 : :
177 : : /* C++ FE can produce decls without associated assembler name and insert
178 : : them to symtab to hold section or TLS information. */
179 : 12026953 : if (!name)
180 : 0 : return;
181 : :
182 : 12026953 : hashval_t hash = decl_assembler_name_hash (name);
183 : 12026953 : aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
184 : 12026953 : gcc_assert (*aslot != node);
185 : 12026953 : node->next_sharing_asm_name = (symtab_node *)*aslot;
186 : 12026953 : if (*aslot != NULL)
187 : 3249857 : (*aslot)->previous_sharing_asm_name = node;
188 : 12026953 : *aslot = node;
189 : :
190 : : /* Update also possible inline clones sharing a decl. */
191 : 24053906 : cnode = dyn_cast <cgraph_node *> (node);
192 : 8664306 : if (cnode && cnode->clones && with_clones)
193 : 16 : for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
194 : 10 : if (cnode->decl == decl)
195 : 2 : insert_to_assembler_name_hash (cnode, true);
196 : : }
197 : :
198 : : }
199 : :
200 : : /* Remove NODE from assembler name hash. */
201 : :
202 : : void
203 : 115253281 : symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
204 : : bool with_clones)
205 : : {
206 : 115253281 : if (assembler_name_hash)
207 : : {
208 : 5212635 : cgraph_node *cnode;
209 : 5212635 : tree decl = node->decl;
210 : :
211 : 5212635 : if (node->next_sharing_asm_name)
212 : 2817769 : node->next_sharing_asm_name->previous_sharing_asm_name
213 : 2817769 : = node->previous_sharing_asm_name;
214 : 5212635 : if (node->previous_sharing_asm_name)
215 : : {
216 : 1050899 : node->previous_sharing_asm_name->next_sharing_asm_name
217 : 1050899 : = node->next_sharing_asm_name;
218 : : }
219 : : else
220 : : {
221 : 4161736 : tree name = DECL_ASSEMBLER_NAME (node->decl);
222 : 4161736 : symtab_node **slot;
223 : :
224 : 4161736 : if (!name)
225 : 0 : return;
226 : :
227 : 4161736 : hashval_t hash = decl_assembler_name_hash (name);
228 : 4161736 : slot = assembler_name_hash->find_slot_with_hash (name, hash,
229 : : NO_INSERT);
230 : 4161736 : gcc_assert (*slot == node);
231 : 4161736 : if (!node->next_sharing_asm_name)
232 : 2140741 : assembler_name_hash->clear_slot (slot);
233 : : else
234 : 2020995 : *slot = node->next_sharing_asm_name;
235 : : }
236 : 5212635 : node->next_sharing_asm_name = NULL;
237 : 5212635 : node->previous_sharing_asm_name = NULL;
238 : :
239 : : /* Update also possible inline clones sharing a decl. */
240 : 5212635 : cnode = dyn_cast <cgraph_node *> (node);
241 : 5107274 : if (cnode && cnode->clones && with_clones)
242 : 16 : for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
243 : 10 : if (cnode->decl == decl)
244 : 2 : unlink_from_assembler_name_hash (cnode, true);
245 : : }
246 : : }
247 : :
248 : : /* Arrange node to be first in its entry of assembler_name_hash. */
249 : :
250 : : void
251 : 2052 : symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
252 : : {
253 : 2052 : unlink_from_assembler_name_hash (node, false);
254 : 2052 : insert_to_assembler_name_hash (node, false);
255 : 2052 : }
256 : :
257 : : /* Initialize asm name hash unless. */
258 : :
259 : : void
260 : 84786896 : symbol_table::symtab_initialize_asm_name_hash (void)
261 : : {
262 : 84786896 : symtab_node *node;
263 : 84786896 : if (!assembler_name_hash)
264 : : {
265 : 242500 : assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
266 : 8872680 : FOR_EACH_SYMBOL (node)
267 : 8630180 : insert_to_assembler_name_hash (node, false);
268 : : }
269 : 84786896 : }
270 : :
271 : : /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
272 : :
273 : : void
274 : 2857985 : symbol_table::change_decl_assembler_name (tree decl, tree name)
275 : : {
276 : 2857985 : symtab_node *node = NULL;
277 : :
278 : : /* We can have user ASM names on things, like global register variables, that
279 : : are not in the symbol table. */
280 : 13498 : if ((VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
281 : 2859072 : || TREE_CODE (decl) == FUNCTION_DECL)
282 : 2856898 : node = symtab_node::get (decl);
283 : 2857985 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
284 : : {
285 : 1856955 : SET_DECL_ASSEMBLER_NAME (decl, name);
286 : 1856955 : if (node)
287 : 11 : insert_to_assembler_name_hash (node, true);
288 : : }
289 : : else
290 : : {
291 : 1001030 : if (name == DECL_ASSEMBLER_NAME (decl))
292 : : return;
293 : :
294 : 158228 : tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
295 : 158228 : ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
296 : 0 : : NULL);
297 : 158228 : if (node)
298 : 7563 : unlink_from_assembler_name_hash (node, true);
299 : :
300 : 158228 : const char *old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
301 : 158228 : if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
302 : 158228 : && DECL_RTL_SET_P (decl))
303 : 0 : warning (0, "%qD renamed after being referenced in assembly", decl);
304 : :
305 : 158228 : SET_DECL_ASSEMBLER_NAME (decl, name);
306 : 158228 : if (DECL_RTL_SET_P (decl))
307 : : {
308 : 1 : SET_DECL_RTL (decl, NULL);
309 : 1 : make_decl_rtl (decl);
310 : : }
311 : 158228 : if (alias)
312 : : {
313 : 0 : gcc_assert (!IDENTIFIER_INTERNAL_P (name));
314 : 0 : IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
315 : 0 : TREE_CHAIN (name) = alias;
316 : : }
317 : : /* If we change assembler name, also all transparent aliases must
318 : : be updated. There are three kinds - those having same assembler name,
319 : : those being renamed in varasm.cc and weakref being renamed by the
320 : : assembler. */
321 : 158228 : if (node)
322 : : {
323 : 7563 : insert_to_assembler_name_hash (node, true);
324 : 7563 : ipa_ref *ref;
325 : 7585 : for (unsigned i = 0; node->iterate_direct_aliases (i, ref); i++)
326 : : {
327 : 22 : struct symtab_node *alias = ref->referring;
328 : 0 : if (alias->transparent_alias && !alias->weakref
329 : 22 : && symbol_table::assembler_names_equal_p
330 : 0 : (old_name, IDENTIFIER_POINTER (
331 : : DECL_ASSEMBLER_NAME (alias->decl))))
332 : 0 : change_decl_assembler_name (alias->decl, name);
333 : 22 : else if (alias->transparent_alias
334 : 22 : && IDENTIFIER_TRANSPARENT_ALIAS (alias->decl))
335 : : {
336 : 0 : gcc_assert (TREE_CHAIN (DECL_ASSEMBLER_NAME (alias->decl))
337 : : && IDENTIFIER_TRANSPARENT_ALIAS
338 : : (DECL_ASSEMBLER_NAME (alias->decl)));
339 : :
340 : 0 : TREE_CHAIN (DECL_ASSEMBLER_NAME (alias->decl)) =
341 : : ultimate_transparent_alias_target
342 : 0 : (DECL_ASSEMBLER_NAME (node->decl));
343 : : }
344 : : #ifdef ASM_OUTPUT_WEAKREF
345 : 22 : else gcc_assert (!alias->transparent_alias || alias->weakref);
346 : : #else
347 : : else gcc_assert (!alias->transparent_alias);
348 : : #endif
349 : : }
350 : 7563 : gcc_assert (!node->transparent_alias || !node->definition
351 : : || node->weakref
352 : : || TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
353 : : || symbol_table::assembler_names_equal_p
354 : : (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
355 : : IDENTIFIER_POINTER
356 : : (DECL_ASSEMBLER_NAME
357 : : (node->get_alias_target ()->decl))));
358 : : }
359 : : }
360 : : }
361 : :
362 : : /* Hash sections by their names. */
363 : :
364 : : hashval_t
365 : 12416806 : section_name_hasher::hash (section_hash_entry *n)
366 : : {
367 : 12416806 : return htab_hash_string (n->name);
368 : : }
369 : :
370 : : /* Return true if section P1 name equals to P2. */
371 : :
372 : : bool
373 : 12352027 : section_name_hasher::equal (section_hash_entry *n1, const char *name)
374 : : {
375 : 12352027 : return n1->name == name || !strcmp (n1->name, name);
376 : : }
377 : :
378 : : /* Bump the reference count on ENTRY so that it is retained. */
379 : :
380 : : static section_hash_entry *
381 : 48383 : retain_section_hash_entry (section_hash_entry *entry)
382 : : {
383 : 48383 : entry->ref_count++;
384 : 48383 : return entry;
385 : : }
386 : :
387 : : /* Drop the reference count on ENTRY and remove it if the reference
388 : : count drops to zero. */
389 : :
390 : : static void
391 : 1891535 : release_section_hash_entry (section_hash_entry *entry)
392 : : {
393 : 1891535 : if (entry)
394 : : {
395 : 27796 : entry->ref_count--;
396 : 27796 : if (!entry->ref_count)
397 : : {
398 : 24226 : hashval_t hash = htab_hash_string (entry->name);
399 : 24226 : section_hash_entry **slot
400 : 24226 : = symtab->section_hash->find_slot_with_hash (entry->name,
401 : : hash, INSERT);
402 : 24226 : ggc_free (entry);
403 : 24226 : symtab->section_hash->clear_slot (slot);
404 : : }
405 : : }
406 : 1891535 : }
407 : :
408 : : /* Add node into symbol table. This function is not used directly, but via
409 : : cgraph/varpool node creation routines. */
410 : :
411 : : void
412 : 122361621 : symtab_node::register_symbol (void)
413 : : {
414 : 122361621 : symtab->register_symbol (this);
415 : :
416 : 122361621 : if (!decl->decl_with_vis.symtab_node)
417 : 119240050 : decl->decl_with_vis.symtab_node = this;
418 : :
419 : 122361621 : ref_list.clear ();
420 : :
421 : : /* Be sure to do this last; C++ FE might create new nodes via
422 : : DECL_ASSEMBLER_NAME langhook! */
423 : 122361621 : symtab->insert_to_assembler_name_hash (this, false);
424 : 122361621 : }
425 : :
426 : : /* Remove NODE from same comdat group. */
427 : :
428 : : void
429 : 125703415 : symtab_node::remove_from_same_comdat_group (void)
430 : : {
431 : 125703415 : if (same_comdat_group)
432 : : {
433 : : symtab_node *prev;
434 : : for (prev = same_comdat_group;
435 : 14144366 : prev->same_comdat_group != this;
436 : : prev = prev->same_comdat_group)
437 : : ;
438 : 13504615 : if (same_comdat_group == prev)
439 : 13104271 : prev->same_comdat_group = NULL;
440 : : else
441 : 400344 : prev->same_comdat_group = same_comdat_group;
442 : 13504615 : same_comdat_group = NULL;
443 : 13504615 : set_comdat_group (NULL);
444 : : }
445 : 125703415 : }
446 : :
447 : : /* Remove node from symbol table. This function is not used directly, but via
448 : : cgraph/varpool node removal routines.
449 : : INFO is a clone info to attach to new root of clone tree (if any). */
450 : :
451 : : void
452 : 115243665 : symtab_node::unregister (clone_info *info)
453 : : {
454 : 115243665 : remove_all_references ();
455 : 115243665 : remove_all_referring ();
456 : :
457 : : /* Remove reference to section. */
458 : 115243665 : set_section_for_node (NULL);
459 : :
460 : 115243665 : remove_from_same_comdat_group ();
461 : :
462 : 115243665 : symtab->unregister (this);
463 : :
464 : : /* During LTO symtab merging we temporarily corrupt decl to symtab node
465 : : hash. */
466 : 115243665 : gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
467 : 115243665 : if (decl->decl_with_vis.symtab_node == this)
468 : : {
469 : 112632195 : symtab_node *replacement_node = NULL;
470 : 112632195 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
471 : 92376954 : replacement_node = cnode->find_replacement (info);
472 : 112632195 : decl->decl_with_vis.symtab_node = replacement_node;
473 : : }
474 : 115243665 : if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
475 : 115243664 : symtab->unlink_from_assembler_name_hash (this, false);
476 : 115243665 : if (in_init_priority_hash)
477 : 107 : symtab->init_priority_hash->remove (this);
478 : 115243665 : }
479 : :
480 : :
481 : : /* Remove symbol from symbol table. */
482 : :
483 : : void
484 : 110037178 : symtab_node::remove (void)
485 : : {
486 : 110037178 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
487 : 89883778 : cnode->remove ();
488 : 20153400 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
489 : 20153400 : vnode->remove ();
490 : 110037178 : }
491 : :
492 : : /* Add NEW_ to the same comdat group that OLD is in. */
493 : :
494 : : void
495 : 13581341 : symtab_node::add_to_same_comdat_group (symtab_node *old_node)
496 : : {
497 : 13581341 : gcc_assert (old_node->get_comdat_group ());
498 : 13581341 : gcc_assert (!same_comdat_group);
499 : 13581341 : gcc_assert (this != old_node);
500 : :
501 : 13581341 : set_comdat_group (old_node->get_comdat_group ());
502 : 13581341 : same_comdat_group = old_node;
503 : 13581341 : if (!old_node->same_comdat_group)
504 : 13162005 : old_node->same_comdat_group = this;
505 : : else
506 : : {
507 : : symtab_node *n;
508 : : for (n = old_node->same_comdat_group;
509 : 765574 : n->same_comdat_group != old_node;
510 : : n = n->same_comdat_group)
511 : : ;
512 : 419336 : n->same_comdat_group = this;
513 : : }
514 : :
515 : 13581341 : cgraph_node *n;
516 : 13595176 : if (comdat_local_p ()
517 : 13595169 : && (n = dyn_cast <cgraph_node *> (this)) != NULL)
518 : : {
519 : 29898 : for (cgraph_edge *e = n->callers; e; e = e->next_caller)
520 : 16070 : if (e->caller->inlined_to)
521 : 3545 : e->caller->inlined_to->calls_comdat_local = true;
522 : : else
523 : 12525 : e->caller->calls_comdat_local = true;
524 : : }
525 : 13581341 : }
526 : :
527 : : /* Dissolve the same_comdat_group list in which NODE resides. */
528 : :
529 : : void
530 : 1978 : symtab_node::dissolve_same_comdat_group_list (void)
531 : : {
532 : 1978 : symtab_node *n = this;
533 : 1978 : symtab_node *next;
534 : :
535 : 1978 : if (!same_comdat_group)
536 : : return;
537 : 3895 : do
538 : : {
539 : 3895 : next = n->same_comdat_group;
540 : 3895 : n->same_comdat_group = NULL;
541 : 3895 : if (dyn_cast <cgraph_node *> (n))
542 : 3625 : dyn_cast <cgraph_node *> (n)->calls_comdat_local = false;
543 : : /* Clear comdat_group for comdat locals, since
544 : : make_decl_local doesn't. */
545 : 3895 : if (!TREE_PUBLIC (n->decl))
546 : 2088 : n->set_comdat_group (NULL);
547 : 3895 : n = next;
548 : : }
549 : 3895 : while (n != this);
550 : : }
551 : :
552 : : /* Return printable assembler name of NODE.
553 : : This function is used only for debugging. When assembler name
554 : : is unknown go with identifier name. */
555 : :
556 : : const char *
557 : 44024 : symtab_node::asm_name () const
558 : : {
559 : 44024 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
560 : 195 : return name ();
561 : 43829 : return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
562 : : }
563 : :
564 : : /* Return printable identifier name. */
565 : :
566 : : const char *
567 : 43149 : symtab_node::name () const
568 : : {
569 : 43149 : if (!DECL_NAME (decl))
570 : : {
571 : 0 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
572 : 0 : return asm_name ();
573 : : else
574 : : return "<unnamed>";
575 : : }
576 : 43149 : return lang_hooks.decl_printable_name (decl, 2);
577 : : }
578 : :
579 : : const char *
580 : 78245 : symtab_node::get_dump_name (bool asm_name_p) const
581 : : {
582 : : #define EXTRA 16
583 : 78245 : const char *fname = asm_name_p ? asm_name () : name ();
584 : 78245 : unsigned l = strlen (fname);
585 : :
586 : 78245 : char *s = (char *)ggc_internal_cleared_alloc (l + EXTRA);
587 : 78245 : snprintf (s, l + EXTRA, "%s/%d", fname, m_uid);
588 : :
589 : 78245 : return s;
590 : : }
591 : :
592 : : const char *
593 : 34530 : symtab_node::dump_name () const
594 : : {
595 : 34530 : return get_dump_name (false);
596 : : }
597 : :
598 : : const char *
599 : 43715 : symtab_node::dump_asm_name () const
600 : : {
601 : 43715 : return get_dump_name (true);
602 : : }
603 : :
604 : : /* Return ipa reference from this symtab_node to
605 : : REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
606 : : of the use. */
607 : :
608 : : ipa_ref *
609 : 6798587 : symtab_node::create_reference (symtab_node *referred_node,
610 : : enum ipa_ref_use use_type)
611 : : {
612 : 6798587 : return create_reference (referred_node, use_type, NULL);
613 : : }
614 : :
615 : :
616 : : /* Return ipa reference from this symtab_node to
617 : : REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
618 : : of the use and STMT the statement (if it exists). */
619 : :
620 : : ipa_ref *
621 : 40567985 : symtab_node::create_reference (symtab_node *referred_node,
622 : : enum ipa_ref_use use_type, gimple *stmt)
623 : : {
624 : 40567985 : ipa_ref *ref = NULL, *ref2 = NULL;
625 : 40567985 : ipa_ref_list *list, *list2;
626 : 40567985 : ipa_ref_t *old_references;
627 : :
628 : 40567985 : gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
629 : 40567985 : gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
630 : :
631 : 40567985 : list = &ref_list;
632 : 40567985 : old_references = list->references.address ();
633 : 68006515 : list->references.safe_grow (list->references.length () + 1, false);
634 : 40567985 : ref = &list->references.last ();
635 : :
636 : 40567985 : list2 = &referred_node->ref_list;
637 : :
638 : : /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
639 : 40567985 : if(use_type == IPA_REF_ALIAS)
640 : : {
641 : 6951732 : list2->referring.safe_insert (0, ref);
642 : 6951732 : ref->referred_index = 0;
643 : :
644 : 7093989 : for (unsigned int i = 1; i < list2->referring.length (); i++)
645 : 142257 : list2->referring[i]->referred_index = i;
646 : : }
647 : : else
648 : : {
649 : 33616253 : list2->referring.safe_push (ref);
650 : 67232506 : ref->referred_index = list2->referring.length () - 1;
651 : : }
652 : :
653 : 40567985 : ref->referring = this;
654 : 40567985 : ref->referred = referred_node;
655 : 40567985 : ref->stmt = stmt;
656 : 40567985 : ref->lto_stmt_uid = 0;
657 : 40567985 : ref->speculative_id = 0;
658 : 40567985 : ref->use = use_type;
659 : 40567985 : ref->speculative = 0;
660 : :
661 : : /* If vector was moved in memory, update pointers. */
662 : 81135970 : if (old_references != list->references.address ())
663 : : {
664 : : int i;
665 : 50679536 : for (i = 0; iterate_reference(i, ref2); i++)
666 : 36219255 : ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
667 : : }
668 : 40567985 : return ref;
669 : : }
670 : :
671 : : ipa_ref *
672 : 52687 : symtab_node::maybe_create_reference (tree val, gimple *stmt)
673 : : {
674 : 52687 : STRIP_NOPS (val);
675 : 52687 : ipa_ref_use use_type;
676 : :
677 : 52687 : switch (TREE_CODE (val))
678 : : {
679 : : case VAR_DECL:
680 : : use_type = IPA_REF_LOAD;
681 : : break;
682 : 8146 : case ADDR_EXPR:
683 : 8146 : use_type = IPA_REF_ADDR;
684 : 8146 : break;
685 : 44161 : default:
686 : 44161 : gcc_assert (!handled_component_p (val));
687 : : return NULL;
688 : : }
689 : :
690 : 8526 : val = get_base_var (val);
691 : 8526 : if (val && VAR_OR_FUNCTION_DECL_P (val))
692 : : {
693 : 4869 : symtab_node *referred = symtab_node::get (val);
694 : 4869 : gcc_checking_assert (referred);
695 : 4869 : return create_reference (referred, use_type, stmt);
696 : : }
697 : : return NULL;
698 : : }
699 : :
700 : : /* Clone all references from symtab NODE to this symtab_node. */
701 : :
702 : : void
703 : 3252302 : symtab_node::clone_references (symtab_node *node)
704 : : {
705 : 3252302 : ipa_ref *ref = NULL, *ref2 = NULL;
706 : 3252302 : int i;
707 : 4061877 : for (i = 0; node->iterate_reference (i, ref); i++)
708 : : {
709 : 809575 : bool speculative = ref->speculative;
710 : 809575 : unsigned int stmt_uid = ref->lto_stmt_uid;
711 : 809575 : unsigned int spec_id = ref->speculative_id;
712 : :
713 : 809575 : ref2 = create_reference (ref->referred, ref->use, ref->stmt);
714 : 809575 : ref2->speculative = speculative;
715 : 809575 : ref2->lto_stmt_uid = stmt_uid;
716 : 809575 : ref2->speculative_id = spec_id;
717 : : }
718 : 3252302 : }
719 : :
720 : : /* Clone all referring from symtab NODE to this symtab_node. */
721 : :
722 : : void
723 : 2650 : symtab_node::clone_referring (symtab_node *node)
724 : : {
725 : 2650 : ipa_ref *ref = NULL, *ref2 = NULL;
726 : 2650 : int i;
727 : 4569 : for (i = 0; node->iterate_referring(i, ref); i++)
728 : : {
729 : 1919 : bool speculative = ref->speculative;
730 : 1919 : unsigned int stmt_uid = ref->lto_stmt_uid;
731 : 1919 : unsigned int spec_id = ref->speculative_id;
732 : :
733 : 1919 : ref2 = ref->referring->create_reference (this, ref->use, ref->stmt);
734 : 1919 : ref2->speculative = speculative;
735 : 1919 : ref2->lto_stmt_uid = stmt_uid;
736 : 1919 : ref2->speculative_id = spec_id;
737 : : }
738 : 2650 : }
739 : :
740 : : /* Clone reference REF to this symtab_node and set its stmt to STMT. */
741 : :
742 : : ipa_ref *
743 : 12297 : symtab_node::clone_reference (ipa_ref *ref, gimple *stmt)
744 : : {
745 : 12297 : bool speculative = ref->speculative;
746 : 12297 : unsigned int stmt_uid = ref->lto_stmt_uid;
747 : 12297 : unsigned int spec_id = ref->speculative_id;
748 : 12297 : ipa_ref *ref2;
749 : :
750 : 12297 : ref2 = create_reference (ref->referred, ref->use, stmt);
751 : 12297 : ref2->speculative = speculative;
752 : 12297 : ref2->lto_stmt_uid = stmt_uid;
753 : 12297 : ref2->speculative_id = spec_id;
754 : 12297 : return ref2;
755 : : }
756 : :
757 : : /* Find the structure describing a reference to REFERRED_NODE of USE_TYPE and
758 : : associated with statement STMT or LTO_STMT_UID. */
759 : :
760 : : ipa_ref *
761 : 10394 : symtab_node::find_reference (symtab_node *referred_node,
762 : : gimple *stmt, unsigned int lto_stmt_uid,
763 : : enum ipa_ref_use use_type)
764 : : {
765 : 10394 : ipa_ref *r = NULL;
766 : 10394 : int i;
767 : :
768 : 55375 : for (i = 0; iterate_reference (i, r); i++)
769 : 55372 : if (r->referred == referred_node
770 : 16906 : && !r->speculative
771 : 16906 : && r->use == use_type
772 : 13995 : && ((stmt && r->stmt == stmt)
773 : 4225 : || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
774 : 4061 : || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid)))
775 : : return r;
776 : : return NULL;
777 : : }
778 : :
779 : : /* Remove all references that are associated with statement STMT. */
780 : :
781 : : void
782 : 73488 : symtab_node::remove_stmt_references (gimple *stmt)
783 : : {
784 : 73488 : ipa_ref *r = NULL;
785 : 73488 : int i = 0;
786 : :
787 : 74572 : while (iterate_reference (i, r))
788 : 1084 : if (r->stmt == stmt)
789 : 0 : r->remove_reference ();
790 : : else
791 : 1084 : i++;
792 : 73488 : }
793 : :
794 : : /* Remove all stmt references in non-speculative references in THIS
795 : : and all clones.
796 : : Those are not maintained during inlining & cloning.
797 : : The exception are speculative references that are updated along
798 : : with callgraph edges associated with them. */
799 : :
800 : : void
801 : 2168664 : symtab_node::clear_stmts_in_references (void)
802 : : {
803 : 2168664 : ipa_ref *r = NULL;
804 : 2168664 : int i;
805 : :
806 : 8635899 : for (i = 0; iterate_reference (i, r); i++)
807 : 6467235 : if (!r->speculative)
808 : : {
809 : 6462549 : r->stmt = NULL;
810 : 6462549 : r->lto_stmt_uid = 0;
811 : 6462549 : r->speculative_id = 0;
812 : : }
813 : 2168664 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
814 : 2168664 : if (cnode)
815 : : {
816 : 2168664 : if (cnode->clones)
817 : 678026 : for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
818 : 563227 : cnode->clear_stmts_in_references ();
819 : : }
820 : 2168664 : }
821 : :
822 : : /* Remove all references in ref list. */
823 : :
824 : : void
825 : 239651513 : symtab_node::remove_all_references (void)
826 : : {
827 : 275963114 : while (ref_list.references.length ())
828 : 36311601 : ref_list.references.last ().remove_reference ();
829 : 239651513 : ref_list.references.release ();
830 : 239651513 : }
831 : :
832 : : /* Remove all referring items in ref list. */
833 : :
834 : : void
835 : 115243665 : symtab_node::remove_all_referring (void)
836 : : {
837 : 115345952 : while (ref_list.referring.length ())
838 : 102287 : ref_list.referring.last ()->remove_reference ();
839 : 115243665 : ref_list.referring.release ();
840 : 115243665 : }
841 : :
842 : : /* Dump references in ref list to FILE. */
843 : :
844 : : void
845 : 8220 : symtab_node::dump_references (FILE *file)
846 : : {
847 : 8220 : ipa_ref *ref = NULL;
848 : 8220 : int i;
849 : 15279 : for (i = 0; iterate_reference (i, ref); i++)
850 : : {
851 : 7059 : fprintf (file, "%s (%s) ", ref->referred->dump_asm_name (),
852 : 7059 : ipa_ref_use_name[ref->use]);
853 : 7059 : if (ref->speculative)
854 : 47 : fprintf (file, "(speculative) ");
855 : : }
856 : 8220 : fprintf (file, "\n");
857 : 8220 : }
858 : :
859 : : /* Dump referring in list to FILE. */
860 : :
861 : : void
862 : 8220 : symtab_node::dump_referring (FILE *file)
863 : : {
864 : 8220 : ipa_ref *ref = NULL;
865 : 8220 : int i;
866 : 13228 : for (i = 0; iterate_referring(i, ref); i++)
867 : : {
868 : 5008 : fprintf (file, "%s (%s) ", ref->referring->dump_asm_name (),
869 : 5008 : ipa_ref_use_name[ref->use]);
870 : 5008 : if (ref->speculative)
871 : 47 : fprintf (file, "(speculative) ");
872 : : }
873 : 8220 : fprintf (file, "\n");
874 : 8220 : }
875 : :
876 : : static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
877 : :
878 : : /* Dump the visibility of the symbol. */
879 : :
880 : : const char *
881 : 0 : symtab_node::get_visibility_string () const
882 : : {
883 : 0 : static const char * const visibility_types[]
884 : : = { "default", "protected", "hidden", "internal" };
885 : 0 : return visibility_types[DECL_VISIBILITY (decl)];
886 : : }
887 : :
888 : : /* Dump the type_name of the symbol. */
889 : : const char *
890 : 0 : symtab_node::get_symtab_type_string () const
891 : : {
892 : 0 : return symtab_type_names[type];
893 : : }
894 : :
895 : : /* Dump base fields of symtab nodes to F. Not to be used directly. */
896 : :
897 : : void
898 : 8220 : symtab_node::dump_base (FILE *f)
899 : : {
900 : 8220 : static const char * const visibility_types[] = {
901 : : "default", "protected", "hidden", "internal"
902 : : };
903 : :
904 : 8220 : fprintf (f, "%s (%s)", dump_asm_name (), name ());
905 : 8220 : if (dump_flags & TDF_ADDRESS)
906 : 103 : dump_addr (f, " @", (void *)this);
907 : 8220 : fprintf (f, "\n Type: %s", symtab_type_names[type]);
908 : :
909 : 8220 : if (definition)
910 : 6281 : fprintf (f, " definition");
911 : 8220 : if (analyzed)
912 : 6278 : fprintf (f, " analyzed");
913 : 8220 : if (alias)
914 : 100 : fprintf (f, " alias");
915 : 8220 : if (transparent_alias)
916 : 0 : fprintf (f, " transparent_alias");
917 : 8220 : if (weakref)
918 : 0 : fprintf (f, " weakref");
919 : 8220 : if (symver)
920 : 0 : fprintf (f, " symver");
921 : 8220 : if (cpp_implicit_alias)
922 : 81 : fprintf (f, " cpp_implicit_alias");
923 : 8220 : if (alias_target)
924 : 0 : fprintf (f, " target:%s",
925 : 0 : DECL_P (alias_target)
926 : 0 : ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
927 : : (alias_target))
928 : 0 : : IDENTIFIER_POINTER (alias_target));
929 : 8220 : if (body_removed)
930 : 631 : fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
931 : 8220 : fprintf (f, "\n Visibility:");
932 : 8220 : if (in_other_partition)
933 : 0 : fprintf (f, " in_other_partition");
934 : 8220 : if (used_from_other_partition)
935 : 0 : fprintf (f, " used_from_other_partition");
936 : 8220 : if (force_output)
937 : 640 : fprintf (f, " force_output");
938 : 8220 : if (forced_by_abi)
939 : 540 : fprintf (f, " forced_by_abi");
940 : 8220 : if (externally_visible)
941 : 3872 : fprintf (f, " externally_visible");
942 : 8220 : if (semantic_interposition)
943 : 7796 : fprintf (f, " semantic_interposition");
944 : 8220 : if (no_reorder)
945 : 555 : fprintf (f, " no_reorder");
946 : 8220 : if (resolution != LDPR_UNKNOWN)
947 : 1066 : fprintf (f, " %s",
948 : 1066 : ld_plugin_symbol_resolution_names[(int)resolution]);
949 : 8220 : if (TREE_ASM_WRITTEN (decl))
950 : 194 : fprintf (f, " asm_written");
951 : 8220 : if (DECL_EXTERNAL (decl))
952 : 1684 : fprintf (f, " external");
953 : 8220 : if (TREE_PUBLIC (decl))
954 : 6387 : fprintf (f, " public");
955 : 8220 : if (DECL_COMMON (decl))
956 : 22 : fprintf (f, " common");
957 : 8220 : if (DECL_WEAK (decl))
958 : 1482 : fprintf (f, " weak");
959 : 8220 : if (DECL_DLLIMPORT_P (decl))
960 : 0 : fprintf (f, " dll_import");
961 : 8220 : if (DECL_COMDAT (decl))
962 : 1452 : fprintf (f, " comdat");
963 : 8220 : if (get_comdat_group ())
964 : 2710 : fprintf (f, " comdat_group:%s",
965 : 1355 : IDENTIFIER_POINTER (get_comdat_group_id ()));
966 : 8220 : if (DECL_ONE_ONLY (decl))
967 : 1401 : fprintf (f, " one_only");
968 : 8220 : if (get_section ())
969 : 38 : fprintf (f, " section:%s",
970 : : get_section ());
971 : 8220 : if (implicit_section)
972 : 36 : fprintf (f," (implicit_section)");
973 : 8220 : if (DECL_VISIBILITY_SPECIFIED (decl))
974 : 577 : fprintf (f, " visibility_specified");
975 : 8220 : if (DECL_VISIBILITY (decl))
976 : 40 : fprintf (f, " visibility:%s",
977 : 20 : visibility_types [DECL_VISIBILITY (decl)]);
978 : 8220 : if (DECL_VIRTUAL_P (decl))
979 : 1270 : fprintf (f, " virtual");
980 : 8220 : if (DECL_ARTIFICIAL (decl))
981 : 2296 : fprintf (f, " artificial");
982 : 8220 : if (TREE_CODE (decl) == FUNCTION_DECL)
983 : : {
984 : 5760 : if (DECL_STATIC_CONSTRUCTOR (decl))
985 : 48 : fprintf (f, " constructor");
986 : 5760 : if (DECL_STATIC_DESTRUCTOR (decl))
987 : 7 : fprintf (f, " destructor");
988 : : }
989 : 8220 : if (ifunc_resolver)
990 : 3 : fprintf (f, " ifunc_resolver");
991 : 8220 : fprintf (f, "\n");
992 : :
993 : 8220 : if (same_comdat_group)
994 : 158 : fprintf (f, " Same comdat group as: %s\n",
995 : : same_comdat_group->dump_asm_name ());
996 : 8220 : if (next_sharing_asm_name)
997 : 350 : fprintf (f, " next sharing asm name: %i\n",
998 : 350 : next_sharing_asm_name->get_uid ());
999 : 8220 : if (previous_sharing_asm_name)
1000 : 317 : fprintf (f, " previous sharing asm name: %i\n",
1001 : 317 : previous_sharing_asm_name->get_uid ());
1002 : :
1003 : 8220 : if (address_taken)
1004 : 865 : fprintf (f, " Address is taken.\n");
1005 : 8220 : if (aux)
1006 : : {
1007 : 511 : fprintf (f, " Aux:");
1008 : 511 : dump_addr (f, " @", (void *)aux);
1009 : 511 : fprintf (f, "\n");
1010 : : }
1011 : :
1012 : 8220 : fprintf (f, " References: ");
1013 : 8220 : dump_references (f);
1014 : 8220 : fprintf (f, " Referring: ");
1015 : 8220 : dump_referring (f);
1016 : 8220 : if (lto_file_data)
1017 : 189 : fprintf (f, " Read from file: %s\n",
1018 : : lto_file_data->file_name);
1019 : 8220 : }
1020 : :
1021 : : /* Dump symtab node to F. */
1022 : :
1023 : : void
1024 : 7377 : symtab_node::dump (FILE *f)
1025 : : {
1026 : 7377 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
1027 : 4917 : cnode->dump (f);
1028 : 2460 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
1029 : 2460 : vnode->dump (f);
1030 : 7377 : }
1031 : :
1032 : : void
1033 : 0 : symtab_node::dump_graphviz (FILE *f)
1034 : : {
1035 : 0 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
1036 : 0 : cnode->dump_graphviz (f);
1037 : 0 : }
1038 : :
1039 : : void
1040 : 1248 : symbol_table::dump (FILE *f)
1041 : : {
1042 : 1248 : symtab_node *node;
1043 : 1248 : fprintf (f, "Symbol table:\n\n");
1044 : 8622 : FOR_EACH_SYMBOL (node)
1045 : 7374 : node->dump (f);
1046 : 1248 : }
1047 : :
1048 : : void
1049 : 0 : symbol_table::dump_graphviz (FILE *f)
1050 : : {
1051 : 0 : symtab_node *node;
1052 : 0 : fprintf (f, "digraph symtab {\n");
1053 : 0 : FOR_EACH_SYMBOL (node)
1054 : 0 : node->dump_graphviz (f);
1055 : 0 : fprintf (f, "}\n");
1056 : 0 : }
1057 : :
1058 : : DEBUG_FUNCTION void
1059 : 0 : symbol_table::debug (void)
1060 : : {
1061 : 0 : dump (stderr);
1062 : 0 : }
1063 : :
1064 : : /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1065 : : Return NULL if there's no such node. */
1066 : :
1067 : : symtab_node *
1068 : 84301950 : symtab_node::get_for_asmname (const_tree asmname)
1069 : : {
1070 : 84301950 : symtab_node *node;
1071 : :
1072 : 84301950 : symtab->symtab_initialize_asm_name_hash ();
1073 : 84301950 : hashval_t hash = symtab->decl_assembler_name_hash (asmname);
1074 : 84301950 : symtab_node **slot
1075 : 84301950 : = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
1076 : : NO_INSERT);
1077 : :
1078 : 84301950 : if (slot)
1079 : : {
1080 : 84299075 : node = *slot;
1081 : 84299075 : return node;
1082 : : }
1083 : : return NULL;
1084 : : }
1085 : :
1086 : : /* Dump symtab node NODE to stderr. */
1087 : :
1088 : : DEBUG_FUNCTION void
1089 : 0 : symtab_node::debug (void)
1090 : : {
1091 : 0 : dump (stderr);
1092 : 0 : }
1093 : :
1094 : : /* Verify common part of symtab nodes. */
1095 : :
1096 : : #if __GNUC__ >= 10
1097 : : /* Disable warnings about missing quoting in GCC diagnostics for
1098 : : the verification errors. Their format strings don't follow GCC
1099 : : diagnostic conventions and the calls are ultimately followed by
1100 : : one to internal_error. */
1101 : : # pragma GCC diagnostic push
1102 : : # pragma GCC diagnostic ignored "-Wformat-diag"
1103 : : #endif
1104 : :
1105 : : DEBUG_FUNCTION bool
1106 : 84800724 : symtab_node::verify_base (void)
1107 : : {
1108 : 84800724 : bool error_found = false;
1109 : 84800724 : symtab_node *hashed_node;
1110 : :
1111 : 84800724 : if (is_a <cgraph_node *> (this))
1112 : : {
1113 : 52976230 : if (TREE_CODE (decl) != FUNCTION_DECL)
1114 : : {
1115 : 0 : error ("function symbol is not function");
1116 : 0 : error_found = true;
1117 : : }
1118 : 52976230 : else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))
1119 : 52976230 : != NULL)
1120 : 52976230 : != dyn_cast <cgraph_node *> (this)->ifunc_resolver)
1121 : : {
1122 : 0 : error ("inconsistent %<ifunc%> attribute");
1123 : 0 : error_found = true;
1124 : : }
1125 : : }
1126 : 31824494 : else if (is_a <varpool_node *> (this))
1127 : : {
1128 : 31824494 : if (!VAR_P (decl))
1129 : : {
1130 : 0 : error ("variable symbol is not variable");
1131 : 0 : error_found = true;
1132 : : }
1133 : : }
1134 : : else
1135 : : {
1136 : 0 : error ("node has unknown type");
1137 : 0 : error_found = true;
1138 : : }
1139 : 84800724 : if (order < 0 || order >= symtab->order)
1140 : : {
1141 : 0 : error ("node has invalid order %i", order);
1142 : 0 : error_found = true;
1143 : : }
1144 : :
1145 : 84800724 : if (symtab->state != LTO_STREAMING)
1146 : : {
1147 : 84647692 : hashed_node = symtab_node::get (decl);
1148 : 84647692 : if (!hashed_node)
1149 : : {
1150 : 0 : error ("node not found node->decl->decl_with_vis.symtab_node");
1151 : 0 : error_found = true;
1152 : : }
1153 : 84647692 : if (hashed_node != this
1154 : 90347417 : && (!is_a <cgraph_node *> (this)
1155 : 5699725 : || !dyn_cast <cgraph_node *> (this)->clone_of
1156 : 5699725 : || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
1157 : : {
1158 : 0 : error ("node differs from node->decl->decl_with_vis.symtab_node");
1159 : 0 : error_found = true;
1160 : : }
1161 : : }
1162 : 84800724 : if (symtab->assembler_name_hash)
1163 : : {
1164 : 84221828 : hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
1165 : 84221828 : if (hashed_node)
1166 : : {
1167 : 84221023 : if (hashed_node->previous_sharing_asm_name)
1168 : : {
1169 : 0 : error ("assembler name hash list corrupted");
1170 : 0 : error_found = true;
1171 : : }
1172 : 84221023 : else if (previous_sharing_asm_name == NULL)
1173 : : {
1174 : 78603806 : if (hashed_node != this)
1175 : : {
1176 : 0 : error ("assembler name hash list corrupted");
1177 : 0 : error_found = true;
1178 : : }
1179 : : }
1180 : 5617217 : else if (!(is_a <varpool_node *> (this) && DECL_HARD_REGISTER (decl)))
1181 : : {
1182 : 5617217 : if (!asmname_hasher::equal (previous_sharing_asm_name,
1183 : 5617217 : DECL_ASSEMBLER_NAME (decl)))
1184 : : {
1185 : 0 : error ("node not found in symtab assembler name hash");
1186 : 0 : error_found = true;
1187 : : }
1188 : : }
1189 : : }
1190 : : }
1191 : 84800724 : if (previous_sharing_asm_name
1192 : 5617217 : && previous_sharing_asm_name->next_sharing_asm_name != this)
1193 : : {
1194 : 0 : error ("double linked list of assembler names corrupted");
1195 : 0 : error_found = true;
1196 : : }
1197 : 84800724 : if (body_removed && definition)
1198 : : {
1199 : 0 : error ("node has body_removed but is definition");
1200 : 0 : error_found = true;
1201 : : }
1202 : 84800724 : if (analyzed && !definition)
1203 : : {
1204 : 0 : error ("node is analyzed but it is not a definition");
1205 : 0 : error_found = true;
1206 : : }
1207 : 84800724 : if (cpp_implicit_alias && !alias)
1208 : : {
1209 : 0 : error ("node is alias but not implicit alias");
1210 : 0 : error_found = true;
1211 : : }
1212 : 84800724 : if (alias && !definition && !weakref)
1213 : : {
1214 : 0 : error ("node is alias but not definition");
1215 : 0 : error_found = true;
1216 : : }
1217 : 84800724 : if (weakref && !transparent_alias)
1218 : : {
1219 : 0 : error ("node is weakref but not an transparent_alias");
1220 : 0 : error_found = true;
1221 : : }
1222 : 84800724 : if (transparent_alias && !alias)
1223 : : {
1224 : 0 : error ("node is transparent_alias but not an alias");
1225 : 0 : error_found = true;
1226 : : }
1227 : 84800724 : if (symver && !alias)
1228 : : {
1229 : 0 : error ("node is symver but not alias");
1230 : 0 : error_found = true;
1231 : : }
1232 : : /* Limitation of gas requires us to output targets of symver aliases as
1233 : : global symbols. This is binutils PR 25295. */
1234 : 84800724 : if (symver
1235 : 84800724 : && (!TREE_PUBLIC (get_alias_target ()->decl)
1236 : 16 : || DECL_VISIBILITY (get_alias_target ()->decl) != VISIBILITY_DEFAULT))
1237 : : {
1238 : 0 : error ("symver target is not exported with default visibility");
1239 : 0 : error_found = true;
1240 : : }
1241 : 84800724 : if (symver
1242 : 84800724 : && (!TREE_PUBLIC (decl)
1243 : 16 : || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT))
1244 : : {
1245 : 0 : error ("symver is not exported with default visibility");
1246 : 0 : error_found = true;
1247 : : }
1248 : 84800724 : if (same_comdat_group)
1249 : : {
1250 : 3381473 : symtab_node *n = same_comdat_group;
1251 : :
1252 : 3381473 : if (!n->get_comdat_group ())
1253 : : {
1254 : 0 : error ("node is in same_comdat_group list but has no comdat_group");
1255 : 0 : error_found = true;
1256 : : }
1257 : 3381473 : if (n->get_comdat_group () != get_comdat_group ())
1258 : : {
1259 : 0 : error ("same_comdat_group list across different groups");
1260 : 0 : error_found = true;
1261 : : }
1262 : 3381473 : if (n->type != type)
1263 : : {
1264 : 0 : error ("mixing different types of symbol in same comdat groups is not supported");
1265 : 0 : error_found = true;
1266 : : }
1267 : 3381473 : if (n == this)
1268 : : {
1269 : 0 : error ("node is alone in a comdat group");
1270 : 0 : error_found = true;
1271 : : }
1272 : 5945888 : do
1273 : : {
1274 : 5945888 : if (!n->same_comdat_group)
1275 : : {
1276 : 0 : error ("same_comdat_group is not a circular list");
1277 : 0 : error_found = true;
1278 : 0 : break;
1279 : : }
1280 : 5945888 : n = n->same_comdat_group;
1281 : : }
1282 : 5945888 : while (n != this);
1283 : 3381473 : if (comdat_local_p ())
1284 : : {
1285 : 57159 : ipa_ref *ref = NULL;
1286 : :
1287 : 58672 : for (int i = 0; iterate_referring (i, ref); ++i)
1288 : : {
1289 : 1513 : if (!in_same_comdat_group_p (ref->referring))
1290 : : {
1291 : 0 : error ("comdat-local symbol referred to by %s outside its "
1292 : : "comdat",
1293 : : identifier_to_locale (ref->referring->name()));
1294 : 0 : error_found = true;
1295 : : }
1296 : : }
1297 : : }
1298 : : }
1299 : 100186343 : if (implicit_section && !get_section ())
1300 : : {
1301 : 0 : error ("implicit_section flag is set but section isn%'t");
1302 : 0 : error_found = true;
1303 : : }
1304 : 100190510 : if (get_section () && get_comdat_group ()
1305 : 2849702 : && !implicit_section
1306 : 15389996 : && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
1307 : : {
1308 : 0 : error ("Both section and comdat group is set");
1309 : 0 : error_found = true;
1310 : : }
1311 : : /* TODO: Add string table for sections, so we do not keep holding duplicated
1312 : : strings. */
1313 : 1556519 : if (alias && definition
1314 : 1616570 : && get_section () != get_alias_target ()->get_section ()
1315 : 84800724 : && (!get_section()
1316 : 0 : || !get_alias_target ()->get_section ()
1317 : 0 : || strcmp (get_section(),
1318 : : get_alias_target ()->get_section ())))
1319 : : {
1320 : 0 : error ("Alias and target%'s section differs");
1321 : 0 : get_alias_target ()->dump (stderr);
1322 : 0 : error_found = true;
1323 : : }
1324 : 1556519 : if (alias && definition
1325 : 86355993 : && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1326 : : {
1327 : 0 : error ("Alias and target%'s comdat groups differs");
1328 : 0 : get_alias_target ()->dump (stderr);
1329 : 0 : error_found = true;
1330 : : }
1331 : 84800724 : if (transparent_alias && definition && !weakref)
1332 : : {
1333 : 93 : symtab_node *to = get_alias_target ();
1334 : 93 : const char *name1
1335 : 93 : = IDENTIFIER_POINTER (
1336 : : ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl)));
1337 : 93 : const char *name2
1338 : 93 : = IDENTIFIER_POINTER (
1339 : : ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to->decl)));
1340 : 93 : if (!symbol_table::assembler_names_equal_p (name1, name2))
1341 : : {
1342 : 0 : error ("Transparent alias and target%'s assembler names differs");
1343 : 0 : get_alias_target ()->dump (stderr);
1344 : 0 : error_found = true;
1345 : : }
1346 : : }
1347 : 1442 : if (transparent_alias && definition
1348 : 84800916 : && get_alias_target()->transparent_alias && get_alias_target()->analyzed)
1349 : : {
1350 : 0 : error ("Chained transparent aliases");
1351 : 0 : get_alias_target ()->dump (stderr);
1352 : 0 : error_found = true;
1353 : : }
1354 : :
1355 : 84800724 : return error_found;
1356 : : }
1357 : :
1358 : : /* Verify consistency of NODE. */
1359 : :
1360 : : DEBUG_FUNCTION void
1361 : 84803076 : symtab_node::verify (void)
1362 : : {
1363 : 84803076 : if (seen_error ())
1364 : : return;
1365 : :
1366 : 84800724 : timevar_push (TV_CGRAPH_VERIFY);
1367 : 84800724 : if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
1368 : 52976230 : node->verify_node ();
1369 : : else
1370 : 31824494 : if (verify_base ())
1371 : : {
1372 : 0 : debug ();
1373 : 0 : internal_error ("symtab_node::verify failed");
1374 : : }
1375 : 84800724 : timevar_pop (TV_CGRAPH_VERIFY);
1376 : : }
1377 : :
1378 : : /* Return true and set *DATA to true if NODE is an ifunc resolver. */
1379 : :
1380 : : static bool
1381 : 5699420 : check_ifunc_resolver (cgraph_node *node, void *data)
1382 : : {
1383 : 5699420 : if (node->ifunc_resolver)
1384 : : {
1385 : 432 : bool *is_ifunc_resolver = (bool *) data;
1386 : 432 : *is_ifunc_resolver = true;
1387 : 432 : return true;
1388 : : }
1389 : : return false;
1390 : : }
1391 : :
1392 : : static bitmap ifunc_ref_map;
1393 : :
1394 : : /* Return true if any caller of NODE is an ifunc resolver. */
1395 : :
1396 : : static bool
1397 : 5310026 : is_caller_ifunc_resolver (cgraph_node *node)
1398 : : {
1399 : 5310026 : bool is_ifunc_resolver = false;
1400 : :
1401 : 15607090 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
1402 : : {
1403 : : /* Return true if caller is known to be an IFUNC resolver. */
1404 : 10297378 : if (e->caller->called_by_ifunc_resolver)
1405 : : return true;
1406 : :
1407 : : /* Check for recursive call. */
1408 : 10297211 : if (e->caller == node)
1409 : 11488 : continue;
1410 : :
1411 : : /* Skip if it has been visited. */
1412 : 10285723 : unsigned int uid = e->caller->get_uid ();
1413 : 10285723 : if (!bitmap_set_bit (ifunc_ref_map, uid))
1414 : 8314353 : continue;
1415 : :
1416 : 1971370 : if (is_caller_ifunc_resolver (e->caller))
1417 : : {
1418 : : /* Return true if caller is an IFUNC resolver. */
1419 : 22 : e->caller->called_by_ifunc_resolver = true;
1420 : 22 : return true;
1421 : : }
1422 : :
1423 : : /* Check if caller's alias is an IFUNC resolver. */
1424 : 1971348 : e->caller->call_for_symbol_and_aliases (check_ifunc_resolver,
1425 : : &is_ifunc_resolver,
1426 : : true);
1427 : 1971348 : if (is_ifunc_resolver)
1428 : : {
1429 : : /* Return true if caller's alias is an IFUNC resolver. */
1430 : 125 : e->caller->called_by_ifunc_resolver = true;
1431 : 125 : return true;
1432 : : }
1433 : : }
1434 : :
1435 : : return false;
1436 : : }
1437 : :
1438 : : /* Check symbol table for callees of IFUNC resolvers. */
1439 : :
1440 : : void
1441 : 242830 : symtab_node::check_ifunc_callee_symtab_nodes (void)
1442 : : {
1443 : 242830 : symtab_node *node;
1444 : :
1445 : 242830 : bitmap_obstack_initialize (NULL);
1446 : 242830 : ifunc_ref_map = BITMAP_ALLOC (NULL);
1447 : :
1448 : 8873397 : FOR_EACH_SYMBOL (node)
1449 : : {
1450 : 8630567 : cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1451 : 8630567 : if (!cnode)
1452 : 5291604 : continue;
1453 : :
1454 : 5310333 : unsigned int uid = cnode->get_uid ();
1455 : 5310333 : if (bitmap_bit_p (ifunc_ref_map, uid))
1456 : 1971370 : continue;
1457 : 3338963 : bitmap_set_bit (ifunc_ref_map, uid);
1458 : :
1459 : 3338963 : bool is_ifunc_resolver = false;
1460 : 3338963 : cnode->call_for_symbol_and_aliases (check_ifunc_resolver,
1461 : : &is_ifunc_resolver, true);
1462 : 3338963 : if (is_ifunc_resolver || is_caller_ifunc_resolver (cnode))
1463 : 599 : cnode->called_by_ifunc_resolver = true;
1464 : : }
1465 : :
1466 : 242830 : BITMAP_FREE (ifunc_ref_map);
1467 : 242830 : bitmap_obstack_release (NULL);
1468 : 242830 : }
1469 : :
1470 : : /* Verify symbol table for internal consistency. */
1471 : :
1472 : : DEBUG_FUNCTION void
1473 : 2169192 : symtab_node::verify_symtab_nodes (void)
1474 : : {
1475 : 2169192 : symtab_node *node;
1476 : 2169192 : hash_map<tree, symtab_node *> comdat_head_map (251);
1477 : 2169192 : asm_node *anode;
1478 : :
1479 : 2293888 : for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
1480 : 124696 : if (anode->order < 0 || anode->order >= symtab->order)
1481 : : {
1482 : 0 : error ("invalid order in asm node %i", anode->order);
1483 : 0 : internal_error ("symtab_node::verify failed");
1484 : : }
1485 : :
1486 : 75966209 : FOR_EACH_SYMBOL (node)
1487 : : {
1488 : 73797017 : node->verify ();
1489 : 73797017 : if (node->get_comdat_group ())
1490 : : {
1491 : 10875787 : symtab_node **entry, *s;
1492 : 10875787 : bool existed;
1493 : :
1494 : 10875787 : entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
1495 : : &existed);
1496 : 10875787 : if (!existed)
1497 : 9496709 : *entry = node;
1498 : 1379078 : else if (!DECL_EXTERNAL (node->decl))
1499 : : {
1500 : 1378933 : for (s = (*entry)->same_comdat_group;
1501 : 2527748 : s != NULL && s != node && s != *entry;
1502 : 1148815 : s = s->same_comdat_group)
1503 : : ;
1504 : 1378933 : if (!s || s == *entry)
1505 : : {
1506 : 0 : error ("Two symbols with same comdat_group are not linked by "
1507 : : "the same_comdat_group list.");
1508 : 0 : (*entry)->debug ();
1509 : 0 : node->debug ();
1510 : 0 : internal_error ("symtab_node::verify failed");
1511 : : }
1512 : : }
1513 : : }
1514 : : }
1515 : 2169192 : }
1516 : :
1517 : : #if __GNUC__ >= 10
1518 : : # pragma GCC diagnostic pop
1519 : : #endif
1520 : :
1521 : : /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1522 : : but other code such as notice_global_symbol generates rtl. */
1523 : :
1524 : : void
1525 : 3653070 : symtab_node::make_decl_local (void)
1526 : : {
1527 : 3653070 : rtx rtl, symbol;
1528 : :
1529 : 3653070 : if (weakref)
1530 : : {
1531 : 0 : weakref = false;
1532 : 0 : IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl)) = 0;
1533 : 0 : TREE_CHAIN (DECL_ASSEMBLER_NAME (decl)) = NULL_TREE;
1534 : 0 : symtab->change_decl_assembler_name
1535 : 0 : (decl, DECL_ASSEMBLER_NAME (get_alias_target ()->decl));
1536 : 0 : DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
1537 : 0 : DECL_ATTRIBUTES (decl));
1538 : : }
1539 : : /* Avoid clearing comdat_groups on comdat-local decls. */
1540 : 3653070 : else if (TREE_PUBLIC (decl) == 0)
1541 : 3653056 : return;
1542 : :
1543 : : /* Localizing a symbol also make all its transparent aliases local. */
1544 : : ipa_ref *ref;
1545 : 104949 : for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
1546 : : {
1547 : 1831 : struct symtab_node *alias = ref->referring;
1548 : 1831 : if (alias->transparent_alias)
1549 : 5 : alias->make_decl_local ();
1550 : : }
1551 : :
1552 : 103118 : if (VAR_P (decl))
1553 : : {
1554 : 12247 : DECL_COMMON (decl) = 0;
1555 : : /* ADDRESSABLE flag is not defined for public symbols. */
1556 : 12247 : TREE_ADDRESSABLE (decl) = 1;
1557 : 12247 : TREE_STATIC (decl) = 1;
1558 : : }
1559 : : else
1560 : 90871 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1561 : :
1562 : 103118 : DECL_COMDAT (decl) = 0;
1563 : 103118 : DECL_WEAK (decl) = 0;
1564 : 103118 : DECL_EXTERNAL (decl) = 0;
1565 : 103118 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
1566 : 103118 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1567 : 103118 : TREE_PUBLIC (decl) = 0;
1568 : 103118 : DECL_DLLIMPORT_P (decl) = 0;
1569 : 103118 : if (!DECL_RTL_SET_P (decl))
1570 : : return;
1571 : :
1572 : : /* Update rtl flags. */
1573 : 14 : make_decl_rtl (decl);
1574 : :
1575 : 14 : rtl = DECL_RTL (decl);
1576 : 14 : if (!MEM_P (rtl))
1577 : : return;
1578 : :
1579 : 14 : symbol = XEXP (rtl, 0);
1580 : 14 : if (GET_CODE (symbol) != SYMBOL_REF)
1581 : : return;
1582 : :
1583 : 14 : SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
1584 : : }
1585 : :
1586 : : /* Copy visibility from N.
1587 : : This is useful when THIS becomes a transparent alias of N. */
1588 : :
1589 : : void
1590 : 0 : symtab_node::copy_visibility_from (symtab_node *n)
1591 : : {
1592 : 0 : gcc_checking_assert (n->weakref == weakref);
1593 : :
1594 : : ipa_ref *ref;
1595 : 0 : for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
1596 : : {
1597 : 0 : struct symtab_node *alias = ref->referring;
1598 : 0 : if (alias->transparent_alias)
1599 : 0 : alias->copy_visibility_from (n);
1600 : : }
1601 : :
1602 : 0 : if (VAR_P (decl))
1603 : : {
1604 : 0 : DECL_COMMON (decl) = DECL_COMMON (n->decl);
1605 : : /* ADDRESSABLE flag is not defined for public symbols. */
1606 : 0 : if (TREE_PUBLIC (decl) && !TREE_PUBLIC (n->decl))
1607 : 0 : TREE_ADDRESSABLE (decl) = 1;
1608 : 0 : TREE_STATIC (decl) = TREE_STATIC (n->decl);
1609 : : }
1610 : 0 : else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1611 : :
1612 : 0 : DECL_COMDAT (decl) = DECL_COMDAT (n->decl);
1613 : 0 : DECL_WEAK (decl) = DECL_WEAK (n->decl);
1614 : 0 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (n->decl);
1615 : 0 : DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (n->decl);
1616 : 0 : DECL_VISIBILITY (decl) = DECL_VISIBILITY (n->decl);
1617 : 0 : TREE_PUBLIC (decl) = TREE_PUBLIC (n->decl);
1618 : 0 : DECL_DLLIMPORT_P (decl) = DECL_DLLIMPORT_P (n->decl);
1619 : 0 : resolution = n->resolution;
1620 : 0 : set_comdat_group (n->get_comdat_group ());
1621 : 0 : set_section (*n);
1622 : 0 : externally_visible = n->externally_visible;
1623 : 0 : if (!DECL_RTL_SET_P (decl))
1624 : 0 : return;
1625 : :
1626 : : /* Update rtl flags. */
1627 : 0 : make_decl_rtl (decl);
1628 : :
1629 : 0 : rtx rtl = DECL_RTL (decl);
1630 : 0 : if (!MEM_P (rtl))
1631 : : return;
1632 : :
1633 : 0 : rtx symbol = XEXP (rtl, 0);
1634 : 0 : if (GET_CODE (symbol) != SYMBOL_REF)
1635 : : return;
1636 : :
1637 : 0 : SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
1638 : : }
1639 : :
1640 : : /* Walk the alias chain to return the symbol NODE is alias of.
1641 : : If NODE is not an alias, return NODE.
1642 : : Assumes NODE is known to be alias. */
1643 : :
1644 : : symtab_node *
1645 : 38218169 : symtab_node::ultimate_alias_target_1 (enum availability *availability,
1646 : : symtab_node *ref)
1647 : : {
1648 : 38218169 : bool transparent_p = false;
1649 : :
1650 : : /* To determine visibility of the target, we follow ELF semantic of aliases.
1651 : : Here alias is an alternative assembler name of a given definition. Its
1652 : : availability prevails the availability of its target (i.e. static alias of
1653 : : weak definition is available.
1654 : :
1655 : : Transparent alias is just alternative name of a given symbol used within
1656 : : one compilation unit and is translated prior hitting the object file. It
1657 : : inherits the visibility of its target.
1658 : : Weakref is a different animal (and noweak definition is weak).
1659 : :
1660 : : If we ever get into supporting targets with different semantics, a target
1661 : : hook will be needed here. */
1662 : :
1663 : 38218169 : if (availability)
1664 : : {
1665 : 11890430 : transparent_p = transparent_alias;
1666 : 11890430 : if (!transparent_p)
1667 : 11884644 : *availability = get_availability (ref);
1668 : : else
1669 : 5786 : *availability = AVAIL_NOT_AVAILABLE;
1670 : : }
1671 : :
1672 : : symtab_node *node = this;
1673 : 76427619 : while (node)
1674 : : {
1675 : 76427619 : if (node->alias && node->analyzed)
1676 : 38209450 : node = node->get_alias_target ();
1677 : : else
1678 : : {
1679 : 38218169 : if (!availability || (!transparent_p && node->analyzed))
1680 : : ;
1681 : 43796 : else if (node->analyzed && !node->transparent_alias)
1682 : 307 : *availability = node->get_availability (ref);
1683 : : else
1684 : 43489 : *availability = AVAIL_NOT_AVAILABLE;
1685 : 38218169 : return node;
1686 : : }
1687 : 38209450 : if (node && availability && transparent_p
1688 : 443 : && node->transparent_alias)
1689 : : {
1690 : 22 : *availability = node->get_availability (ref);
1691 : 22 : transparent_p = false;
1692 : : }
1693 : : }
1694 : 0 : if (availability)
1695 : 0 : *availability = AVAIL_NOT_AVAILABLE;
1696 : : return NULL;
1697 : : }
1698 : :
1699 : : /* C++ FE sometimes change linkage flags after producing same body aliases.
1700 : :
1701 : : FIXME: C++ produce implicit aliases for virtual functions and vtables that
1702 : : are obviously equivalent. The way it is doing so is however somewhat
1703 : : kludgy and interferes with the visibility code. As a result we need to
1704 : : copy the visibility from the target to get things right. */
1705 : :
1706 : : void
1707 : 7285466 : symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
1708 : : {
1709 : 7285466 : if (is_a <cgraph_node *> (this))
1710 : : {
1711 : 21856251 : DECL_DECLARED_INLINE_P (decl)
1712 : 7285417 : = DECL_DECLARED_INLINE_P (target->decl);
1713 : 21856251 : DECL_DISREGARD_INLINE_LIMITS (decl)
1714 : 7285417 : = DECL_DISREGARD_INLINE_LIMITS (target->decl);
1715 : : }
1716 : : /* FIXME: It is not really clear why those flags should not be copied for
1717 : : functions, too. */
1718 : : else
1719 : : {
1720 : 49 : DECL_WEAK (decl) = DECL_WEAK (target->decl);
1721 : 49 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1722 : 49 : DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
1723 : : }
1724 : 7285466 : if (TREE_PUBLIC (decl))
1725 : : {
1726 : 7260423 : tree group;
1727 : :
1728 : 7260423 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1729 : 7260423 : DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
1730 : 7260423 : group = target->get_comdat_group ();
1731 : 7260423 : set_comdat_group (group);
1732 : 7260423 : if (group && !same_comdat_group)
1733 : 0 : add_to_same_comdat_group (target);
1734 : : }
1735 : 7285466 : externally_visible = target->externally_visible;
1736 : 7285466 : }
1737 : :
1738 : : /* Set section, do not recurse into aliases.
1739 : : When one wants to change section of a symbol and its aliases,
1740 : : use set_section. */
1741 : :
1742 : : void
1743 : 117109993 : symtab_node::set_section_for_node (const char *section)
1744 : : {
1745 : 117109993 : const char *current = get_section ();
1746 : :
1747 : 117109993 : if (current == section
1748 : 1884667 : || (current && section
1749 : 0 : && !strcmp (current, section)))
1750 : : return;
1751 : :
1752 : 1884667 : release_section_hash_entry (x_section);
1753 : 1884667 : if (!section)
1754 : : {
1755 : 27172 : x_section = NULL;
1756 : 27172 : implicit_section = false;
1757 : 27172 : return;
1758 : : }
1759 : 1857495 : if (!symtab->section_hash)
1760 : 36310 : symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
1761 : 1857495 : section_hash_entry **slot = symtab->section_hash->find_slot_with_hash
1762 : 1857495 : (section, htab_hash_string (section), INSERT);
1763 : 1857495 : if (*slot)
1764 : 41523 : x_section = retain_section_hash_entry (*slot);
1765 : : else
1766 : : {
1767 : 1815972 : int len = strlen (section);
1768 : 1815972 : *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
1769 : 1815972 : x_section->ref_count = 1;
1770 : 1815972 : x_section->name = ggc_vec_alloc<char> (len + 1);
1771 : 1815972 : memcpy (x_section->name, section, len + 1);
1772 : : }
1773 : : }
1774 : :
1775 : : /* Set the section of node THIS to be the same as the section
1776 : : of node OTHER. Keep reference counts of the sections
1777 : : up-to-date as needed. */
1778 : :
1779 : : void
1780 : 21235011 : symtab_node::set_section_for_node (const symtab_node &other)
1781 : : {
1782 : 21235011 : if (x_section == other.x_section)
1783 : : return;
1784 : 7484 : if (get_section () && other.get_section ())
1785 : 616 : gcc_checking_assert (strcmp (get_section (), other.get_section ()) != 0);
1786 : 6868 : release_section_hash_entry (x_section);
1787 : 6868 : if (other.x_section)
1788 : 6860 : x_section = retain_section_hash_entry (other.x_section);
1789 : : else
1790 : : {
1791 : 8 : x_section = NULL;
1792 : 8 : implicit_section = false;
1793 : : }
1794 : : }
1795 : :
1796 : : /* Workers for set_section. */
1797 : :
1798 : : bool
1799 : 1863826 : symtab_node::set_section_from_string (symtab_node *n, void *s)
1800 : : {
1801 : 1863826 : n->set_section_for_node ((char *)s);
1802 : 1863826 : return false;
1803 : : }
1804 : :
1805 : : /* Set the section of node N to be the same as the section
1806 : : of node O. */
1807 : :
1808 : : bool
1809 : 21235011 : symtab_node::set_section_from_node (symtab_node *n, void *o)
1810 : : {
1811 : 21235011 : const symtab_node &other = *static_cast<const symtab_node *> (o);
1812 : 21235011 : n->set_section_for_node (other);
1813 : 21235011 : return false;
1814 : : }
1815 : :
1816 : : /* Set section of symbol and its aliases. */
1817 : :
1818 : : void
1819 : 1820817 : symtab_node::set_section (const char *section)
1820 : : {
1821 : 1820817 : gcc_assert (!this->alias || !this->analyzed);
1822 : 1820817 : call_for_symbol_and_aliases
1823 : 1820817 : (symtab_node::set_section_from_string, const_cast<char *>(section), true);
1824 : 1820817 : }
1825 : :
1826 : : void
1827 : 21234764 : symtab_node::set_section (const symtab_node &other)
1828 : : {
1829 : 21234764 : call_for_symbol_and_aliases
1830 : 21234764 : (symtab_node::set_section_from_node, const_cast<symtab_node *>(&other), true);
1831 : 21234764 : }
1832 : :
1833 : : /* Return the initialization priority. */
1834 : :
1835 : : priority_type
1836 : 46189 : symtab_node::get_init_priority ()
1837 : : {
1838 : 46189 : if (!this->in_init_priority_hash)
1839 : : return DEFAULT_INIT_PRIORITY;
1840 : :
1841 : 3755 : symbol_priority_map *h = symtab->init_priority_hash->get (this);
1842 : 3755 : return h ? h->init : DEFAULT_INIT_PRIORITY;
1843 : : }
1844 : :
1845 : : /* Return the finalization priority. */
1846 : :
1847 : : priority_type
1848 : 1897 : cgraph_node::get_fini_priority ()
1849 : : {
1850 : 1897 : if (!this->in_init_priority_hash)
1851 : : return DEFAULT_INIT_PRIORITY;
1852 : 1819 : symbol_priority_map *h = symtab->init_priority_hash->get (this);
1853 : 1819 : return h ? h->fini : DEFAULT_INIT_PRIORITY;
1854 : : }
1855 : :
1856 : : /* Return the initialization and finalization priority information for
1857 : : DECL. If there is no previous priority information, a freshly
1858 : : allocated structure is returned. */
1859 : :
1860 : : symbol_priority_map *
1861 : 5169 : symtab_node::priority_info (void)
1862 : : {
1863 : 5169 : if (!symtab->init_priority_hash)
1864 : 3403 : symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
1865 : :
1866 : 5169 : bool existed;
1867 : 5169 : symbol_priority_map *h
1868 : 5169 : = &symtab->init_priority_hash->get_or_insert (this, &existed);
1869 : 5169 : if (!existed)
1870 : : {
1871 : 5149 : h->init = DEFAULT_INIT_PRIORITY;
1872 : 5149 : h->fini = DEFAULT_INIT_PRIORITY;
1873 : 5149 : in_init_priority_hash = true;
1874 : : }
1875 : :
1876 : 5169 : return h;
1877 : : }
1878 : :
1879 : : /* Set initialization priority to PRIORITY. */
1880 : :
1881 : : void
1882 : 25196 : symtab_node::set_init_priority (priority_type priority)
1883 : : {
1884 : 25196 : symbol_priority_map *h;
1885 : :
1886 : 25196 : if (is_a <cgraph_node *> (this))
1887 : 25151 : gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
1888 : :
1889 : 25196 : if (priority == DEFAULT_INIT_PRIORITY)
1890 : : {
1891 : 21640 : gcc_assert (get_init_priority() == priority);
1892 : : return;
1893 : : }
1894 : 3556 : h = priority_info ();
1895 : 3556 : h->init = priority;
1896 : : }
1897 : :
1898 : : /* Set finalization priority to PRIORITY. */
1899 : :
1900 : : void
1901 : 1626 : cgraph_node::set_fini_priority (priority_type priority)
1902 : : {
1903 : 1626 : symbol_priority_map *h;
1904 : :
1905 : 1626 : gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
1906 : :
1907 : 1626 : if (priority == DEFAULT_INIT_PRIORITY)
1908 : : {
1909 : 13 : gcc_assert (get_fini_priority() == priority);
1910 : : return;
1911 : : }
1912 : 1613 : h = priority_info ();
1913 : 1613 : h->fini = priority;
1914 : : }
1915 : :
1916 : : /* Worker for symtab_resolve_alias. */
1917 : :
1918 : : bool
1919 : 3153 : symtab_node::set_implicit_section (symtab_node *n,
1920 : : void *data ATTRIBUTE_UNUSED)
1921 : : {
1922 : 3153 : n->implicit_section = true;
1923 : 3153 : return false;
1924 : : }
1925 : :
1926 : : /* Add reference recording that symtab node is alias of TARGET.
1927 : : The function can fail in the case of aliasing cycles; in this case
1928 : : it returns false. */
1929 : :
1930 : : bool
1931 : 6939229 : symtab_node::resolve_alias (symtab_node *target, bool transparent)
1932 : : {
1933 : 6939229 : symtab_node *n;
1934 : :
1935 : 6939229 : gcc_assert (!analyzed && !ref_list.references.length ());
1936 : :
1937 : : /* Never let cycles to creep into the symbol table alias references;
1938 : : those will make alias walkers to be infinite. */
1939 : 6941647 : for (n = target; n && n->alias;
1940 : 2632 : n = n->analyzed ? n->get_alias_target () : NULL)
1941 : 2634 : if (n == this)
1942 : : {
1943 : 2 : if (is_a <cgraph_node *> (this))
1944 : 2 : error ("function %q+D part of alias cycle", decl);
1945 : 0 : else if (is_a <varpool_node *> (this))
1946 : 0 : error ("variable %q+D part of alias cycle", decl);
1947 : : else
1948 : 0 : gcc_unreachable ();
1949 : 2 : alias = false;
1950 : 2 : return false;
1951 : : }
1952 : :
1953 : : /* "analyze" the node - i.e. mark the reference. */
1954 : 6939227 : definition = true;
1955 : 6939227 : alias = true;
1956 : 6939227 : analyzed = true;
1957 : 6939227 : transparent |= transparent_alias;
1958 : 6939227 : transparent_alias = transparent;
1959 : 6939227 : if (transparent)
1960 : 54 : while (target->transparent_alias && target->analyzed)
1961 : 0 : target = target->get_alias_target ();
1962 : 6939227 : create_reference (target, IPA_REF_ALIAS, NULL);
1963 : :
1964 : : /* Add alias into the comdat group of its target unless it is already there. */
1965 : 6939227 : if (same_comdat_group)
1966 : 3249748 : remove_from_same_comdat_group ();
1967 : 6939227 : set_comdat_group (NULL);
1968 : 6939227 : if (target->get_comdat_group ())
1969 : 6649912 : add_to_same_comdat_group (target);
1970 : :
1971 : 6939240 : if ((get_section () != target->get_section ()
1972 : 6939232 : || target->get_comdat_group ()) && get_section () && !implicit_section)
1973 : : {
1974 : 2 : error ("section of alias %q+D must match section of its target", decl);
1975 : : }
1976 : 6939227 : set_section (*target);
1977 : 6939227 : if (target->implicit_section)
1978 : 2967 : call_for_symbol_and_aliases (set_implicit_section, NULL, true);
1979 : :
1980 : : /* Alias targets become redundant after alias is resolved into an reference.
1981 : : We do not want to keep it around or we would have to mind updating them
1982 : : when renaming symbols. */
1983 : 6939227 : alias_target = NULL;
1984 : :
1985 : 6939227 : if (!transparent && cpp_implicit_alias && symtab->state >= CONSTRUCTION)
1986 : 8436 : fixup_same_cpp_alias_visibility (target);
1987 : :
1988 : : /* If alias has address taken, so does the target. */
1989 : 6939227 : if (address_taken)
1990 : 982 : target->ultimate_alias_target ()->address_taken = true;
1991 : :
1992 : : /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
1993 : : If alias is transparent, also all transparent aliases of THIS are now
1994 : : aliases of TARGET.
1995 : : Also merge same comdat group lists. */
1996 : : ipa_ref *ref;
1997 : 6939474 : for (unsigned i = 0; iterate_direct_aliases (i, ref);)
1998 : : {
1999 : 247 : struct symtab_node *alias_alias = ref->referring;
2000 : 247 : if (alias_alias->get_comdat_group ())
2001 : : {
2002 : 184 : alias_alias->remove_from_same_comdat_group ();
2003 : 184 : alias_alias->set_comdat_group (NULL);
2004 : 184 : if (target->get_comdat_group ())
2005 : 184 : alias_alias->add_to_same_comdat_group (target);
2006 : : }
2007 : 247 : if ((!alias_alias->transparent_alias
2008 : 235 : && !alias_alias->symver)
2009 : 12 : || transparent)
2010 : : {
2011 : 247 : alias_alias->remove_all_references ();
2012 : 247 : alias_alias->create_reference (target, IPA_REF_ALIAS, NULL);
2013 : : }
2014 : 0 : else i++;
2015 : : }
2016 : : return true;
2017 : : }
2018 : :
2019 : : /* Worker searching noninterposable alias. */
2020 : :
2021 : : bool
2022 : 59435 : symtab_node::noninterposable_alias (symtab_node *node, void *data)
2023 : : {
2024 : 59435 : if (!node->transparent_alias && decl_binds_to_current_def_p (node->decl))
2025 : : {
2026 : 57187 : symtab_node *fn = node->ultimate_alias_target ();
2027 : :
2028 : : /* Ensure that the alias is well formed this may not be the case
2029 : : of user defined aliases and currently it is not always the case
2030 : : of C++ same body aliases (that is a bug). */
2031 : 57187 : if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
2032 : 57187 : || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
2033 : 57187 : || (TREE_CODE (node->decl) == FUNCTION_DECL
2034 : 114374 : && flags_from_decl_or_type (node->decl)
2035 : 57187 : != flags_from_decl_or_type (fn->decl))
2036 : 114356 : || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
2037 : 20 : return false;
2038 : 57167 : *(symtab_node **)data = node;
2039 : 57167 : return true;
2040 : : }
2041 : : return false;
2042 : : }
2043 : :
2044 : : /* If node cannot be overwriten by static or dynamic linker to point to
2045 : : different definition, return NODE. Otherwise look for alias with such
2046 : : property and if none exists, introduce new one. */
2047 : :
2048 : : symtab_node *
2049 : 58140 : symtab_node::noninterposable_alias (void)
2050 : : {
2051 : 58140 : tree new_decl;
2052 : 58140 : symtab_node *new_node = NULL;
2053 : :
2054 : : /* First try to look up existing alias or base object
2055 : : (if that is already non-overwritable). */
2056 : 58140 : symtab_node *node = ultimate_alias_target ();
2057 : 58140 : gcc_assert (!node->alias && !node->weakref);
2058 : 58140 : node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
2059 : : (void *)&new_node, true);
2060 : 58140 : if (new_node)
2061 : : return new_node;
2062 : :
2063 : : /* If aliases aren't supported by the assembler, fail. */
2064 : 973 : if (!TARGET_SUPPORTS_ALIASES)
2065 : : return NULL;
2066 : 973 : else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)))
2067 : : return NULL;
2068 : :
2069 : : /* Otherwise create a new one. */
2070 : 972 : new_decl = copy_node (node->decl);
2071 : 972 : DECL_DLLIMPORT_P (new_decl) = 0;
2072 : 972 : tree name = clone_function_name (node->decl, "localalias");
2073 : 972 : if (!flag_wpa)
2074 : : {
2075 : : unsigned long num = 0;
2076 : : /* In the rare case we already have a localalias, but the above
2077 : : node->call_for_symbol_and_aliases call didn't find any suitable,
2078 : : iterate until we find one not used yet. */
2079 : 966 : while (symtab_node::get_for_asmname (name))
2080 : 0 : name = clone_function_name (node->decl, "localalias", num++);
2081 : : }
2082 : 972 : DECL_NAME (new_decl) = name;
2083 : 972 : if (TREE_CODE (new_decl) == FUNCTION_DECL)
2084 : 970 : DECL_STRUCT_FUNCTION (new_decl) = NULL;
2085 : 972 : DECL_INITIAL (new_decl) = NULL;
2086 : 972 : SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
2087 : 972 : SET_DECL_RTL (new_decl, NULL);
2088 : :
2089 : : /* Update the properties. */
2090 : 972 : DECL_EXTERNAL (new_decl) = 0;
2091 : 972 : TREE_PUBLIC (new_decl) = 0;
2092 : 972 : DECL_COMDAT (new_decl) = 0;
2093 : 972 : DECL_WEAK (new_decl) = 0;
2094 : :
2095 : : /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
2096 : 972 : DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
2097 : 972 : if (TREE_CODE (new_decl) == FUNCTION_DECL)
2098 : : {
2099 : 970 : DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
2100 : 970 : DECL_STATIC_DESTRUCTOR (new_decl) = 0;
2101 : 970 : new_node = cgraph_node::create_alias (new_decl, node->decl);
2102 : :
2103 : 1940 : cgraph_node *new_cnode = dyn_cast <cgraph_node *> (new_node),
2104 : 970 : *cnode = dyn_cast <cgraph_node *> (node);
2105 : :
2106 : 970 : new_cnode->unit_id = cnode->unit_id;
2107 : 970 : new_cnode->merged_comdat = cnode->merged_comdat;
2108 : 970 : new_cnode->merged_extern_inline = cnode->merged_extern_inline;
2109 : : }
2110 : : else
2111 : : {
2112 : 2 : TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
2113 : 2 : DECL_INITIAL (new_decl) = error_mark_node;
2114 : 2 : new_node = varpool_node::create_alias (new_decl, node->decl);
2115 : : }
2116 : 972 : new_node->resolve_alias (node);
2117 : 972 : gcc_assert (decl_binds_to_current_def_p (new_decl)
2118 : : && targetm.binds_local_p (new_decl));
2119 : 972 : return new_node;
2120 : : }
2121 : :
2122 : : /* Return true if symtab node and TARGET represents
2123 : : semantically equivalent symbols. */
2124 : :
2125 : : bool
2126 : 343266 : symtab_node::semantically_equivalent_p (symtab_node *target)
2127 : : {
2128 : 343266 : enum availability avail;
2129 : 343266 : symtab_node *ba;
2130 : 343266 : symtab_node *bb;
2131 : :
2132 : : /* Equivalent functions are equivalent. */
2133 : 343266 : if (decl == target->decl)
2134 : : return true;
2135 : :
2136 : : /* If symbol is not overwritable by different implementation,
2137 : : walk to the base object it defines. */
2138 : 261450 : ba = ultimate_alias_target (&avail);
2139 : 261450 : if (avail >= AVAIL_AVAILABLE)
2140 : : {
2141 : 48059 : if (target == ba)
2142 : : return true;
2143 : : }
2144 : : else
2145 : : ba = this;
2146 : 261426 : bb = target->ultimate_alias_target (&avail);
2147 : 261426 : if (avail >= AVAIL_AVAILABLE)
2148 : : {
2149 : 47667 : if (this == bb)
2150 : : return true;
2151 : : }
2152 : : else
2153 : : bb = target;
2154 : 261367 : return bb == ba;
2155 : : }
2156 : :
2157 : : /* Classify symbol symtab node for partitioning. */
2158 : :
2159 : : enum symbol_partitioning_class
2160 : 2279316 : symtab_node::get_partitioning_class (void)
2161 : : {
2162 : : /* Inline clones are always duplicated.
2163 : : This include external declarations. */
2164 : 2279316 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2165 : :
2166 : 2279316 : if (DECL_ABSTRACT_P (decl))
2167 : : return SYMBOL_EXTERNAL;
2168 : :
2169 : 2279316 : if (cnode && cnode->inlined_to)
2170 : : return SYMBOL_DUPLICATE;
2171 : :
2172 : : /* Transparent aliases are always duplicated. */
2173 : 2196168 : if (transparent_alias)
2174 : 66 : return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL;
2175 : :
2176 : : /* External declarations are external. */
2177 : 2196102 : if (DECL_EXTERNAL (decl))
2178 : : return SYMBOL_EXTERNAL;
2179 : :
2180 : : /* Even static aliases of external functions as external. Those can happen
2181 : : when COMDAT got resolved to non-IL implementation. */
2182 : 2045309 : if (alias && DECL_EXTERNAL (ultimate_alias_target ()->decl))
2183 : : return SYMBOL_EXTERNAL;
2184 : :
2185 : 2045309 : if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
2186 : : {
2187 : 925866 : if (alias && definition && !ultimate_alias_target ()->definition)
2188 : : return SYMBOL_EXTERNAL;
2189 : : /* Constant pool references use local symbol names that cannot
2190 : : be promoted global. We should never put into a constant pool
2191 : : objects that cannot be duplicated across partitions. */
2192 : 925866 : if (DECL_IN_CONSTANT_POOL (decl))
2193 : : return SYMBOL_DUPLICATE;
2194 : 925676 : if (DECL_HARD_REGISTER (decl))
2195 : : return SYMBOL_DUPLICATE;
2196 : 925580 : gcc_checking_assert (vnode->definition);
2197 : : }
2198 : : /* Functions that are cloned may stay in callgraph even if they are unused.
2199 : : Handle them as external; compute_ltrans_boundary take care to make
2200 : : proper things to happen (i.e. to make them appear in the boundary but
2201 : : with body streamed, so clone can me materialized). */
2202 : 1119443 : else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
2203 : : return SYMBOL_EXTERNAL;
2204 : :
2205 : : /* Linker discardable symbols are duplicated to every use unless they are
2206 : : keyed. */
2207 : 2055554 : if (DECL_ONE_ONLY (decl)
2208 : 13681 : && !force_output
2209 : 13637 : && !forced_by_abi
2210 : 2053935 : && !used_from_object_file_p ())
2211 : : return SYMBOL_DUPLICATE;
2212 : :
2213 : : return SYMBOL_PARTITION;
2214 : : }
2215 : :
2216 : : /* Return true when symbol is known to be non-zero, assume that
2217 : : flag_delete_null_pointer_checks is equal to delete_null_pointer_checks. */
2218 : :
2219 : : bool
2220 : 13962615 : symtab_node::nonzero_address (bool delete_null_pointer_checks)
2221 : : {
2222 : : /* Weakrefs may be NULL when their target is not defined. */
2223 : 13962615 : if (alias && weakref)
2224 : : {
2225 : 2749 : if (analyzed)
2226 : : {
2227 : 188 : symtab_node *target = ultimate_alias_target ();
2228 : :
2229 : 188 : if (target->alias && target->weakref)
2230 : : return false;
2231 : : /* We cannot recurse to target::nonzero. It is possible that the
2232 : : target is used only via the alias.
2233 : : We may walk references and look for strong use, but we do not know
2234 : : if this strong use will survive to final binary, so be
2235 : : conservative here.
2236 : : ??? Maybe we could do the lookup during late optimization that
2237 : : could be useful to eliminate the NULL pointer checks in LTO
2238 : : programs. */
2239 : 0 : if (target->definition && !DECL_EXTERNAL (target->decl))
2240 : : return true;
2241 : 0 : if (target->resolution != LDPR_UNKNOWN
2242 : : && target->resolution != LDPR_UNDEF
2243 : 0 : && !target->can_be_discarded_p ()
2244 : 0 : && delete_null_pointer_checks)
2245 : : return true;
2246 : 0 : return false;
2247 : : }
2248 : : else
2249 : : return false;
2250 : : }
2251 : :
2252 : : /* With !flag_delete_null_pointer_checks we assume that symbols may
2253 : : bind to NULL. This is on by default on embedded targets only.
2254 : :
2255 : : Otherwise all non-WEAK symbols must be defined and thus non-NULL or
2256 : : linking fails. Important case of WEAK we want to do well are comdats,
2257 : : which also must be defined somewhere.
2258 : :
2259 : : When parsing, beware the cases when WEAK attribute is added later. */
2260 : 17566642 : if ((!DECL_WEAK (decl) || DECL_COMDAT (decl))
2261 : 14823557 : && delete_null_pointer_checks)
2262 : : {
2263 : 11206167 : refuse_visibility_changes = true;
2264 : 11206167 : return true;
2265 : : }
2266 : :
2267 : : /* If target is defined and not extern, we know it will be
2268 : : output and thus it will bind to non-NULL.
2269 : : Play safe for flag_delete_null_pointer_checks where weak definition may
2270 : : be re-defined by NULL. */
2271 : 2729622 : if (definition && !DECL_EXTERNAL (decl)
2272 : 5483320 : && (delete_null_pointer_checks || !DECL_WEAK (decl)))
2273 : : {
2274 : 2728921 : if (!DECL_WEAK (decl))
2275 : 9064 : refuse_visibility_changes = true;
2276 : 2728921 : return true;
2277 : : }
2278 : :
2279 : : /* As the last resort, check the resolution info. */
2280 : 24778 : if (resolution != LDPR_UNKNOWN
2281 : : && resolution != LDPR_UNDEF
2282 : 0 : && !can_be_discarded_p ()
2283 : 24778 : && delete_null_pointer_checks)
2284 : : return true;
2285 : : return false;
2286 : : }
2287 : :
2288 : : /* Return true when symbol is known to be non-zero. */
2289 : :
2290 : : bool
2291 : 13961958 : symtab_node::nonzero_address ()
2292 : : {
2293 : 13961958 : return nonzero_address (flag_delete_null_pointer_checks);
2294 : : }
2295 : :
2296 : : /* Return 0 if symbol is known to have different address than S2,
2297 : : Return 1 if symbol is known to have same address as S2,
2298 : : return -1 otherwise.
2299 : :
2300 : : If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
2301 : : and S2 is going to be accessed. This eliminates the situations when
2302 : : either THIS or S2 is NULL and is useful for comparing bases when deciding
2303 : : about memory aliasing. */
2304 : : int
2305 : 85216439 : symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed)
2306 : : {
2307 : 85216439 : enum availability avail1, avail2;
2308 : :
2309 : : /* A Shortcut: equivalent symbols are always equivalent. */
2310 : 85216439 : if (this == s2)
2311 : : return 1;
2312 : :
2313 : : /* Unwind transparent aliases first; those are always equal to their
2314 : : target. */
2315 : 84693819 : if (this->transparent_alias && this->analyzed)
2316 : 0 : return this->get_alias_target ()->equal_address_to (s2);
2317 : 84693819 : while (s2->transparent_alias && s2->analyzed)
2318 : 0 : s2 = s2->get_alias_target();
2319 : :
2320 : 84693819 : if (this == s2)
2321 : : return 1;
2322 : :
2323 : : /* For non-interposable aliases, lookup and compare their actual definitions.
2324 : : Also check if the symbol needs to bind to given definition. */
2325 : 84693819 : symtab_node *rs1 = ultimate_alias_target (&avail1);
2326 : 84693819 : symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
2327 : 84693819 : bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
2328 : 84693819 : bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
2329 : 84693819 : bool really_binds_local1 = binds_local1;
2330 : 84693819 : bool really_binds_local2 = binds_local2;
2331 : :
2332 : : /* Addresses of vtables and virtual functions cannot be used by user
2333 : : code and are used only within speculation. In this case we may make
2334 : : symbol equivalent to its alias even if interposition may break this
2335 : : rule. Doing so will allow us to turn speculative inlining into
2336 : : non-speculative more aggressively. */
2337 : 84693819 : if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
2338 : : binds_local1 = true;
2339 : 84693819 : if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
2340 : 84693819 : binds_local2 = true;
2341 : :
2342 : : /* If both definitions are available we know that even if they are bound
2343 : : to other unit they must be defined same way and therefore we can use
2344 : : equivalence test. */
2345 : 84693819 : if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
2346 : : binds_local1 = binds_local2 = true;
2347 : :
2348 : 84693819 : if (binds_local1 && binds_local2 && rs1 == rs2)
2349 : : {
2350 : : /* We made use of the fact that alias is not weak. */
2351 : 358 : if (rs1 != this)
2352 : 232 : refuse_visibility_changes = true;
2353 : 358 : if (rs2 != s2)
2354 : 126 : s2->refuse_visibility_changes = true;
2355 : 358 : return 1;
2356 : : }
2357 : :
2358 : : /* If both symbols may resolve to NULL, we cannot really prove them
2359 : : different. */
2360 : 84693461 : if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ())
2361 : : return -1;
2362 : :
2363 : : /* Except for NULL, functions and variables never overlap. */
2364 : 84693402 : if (TREE_CODE (decl) != TREE_CODE (s2->decl))
2365 : : return 0;
2366 : :
2367 : : /* If one of the symbols is unresolved alias, punt. */
2368 : 84538825 : if (rs1->alias || rs2->alias)
2369 : : return -1;
2370 : :
2371 : : /* If we have a non-interposable definition of at least one of the symbols
2372 : : and the other symbol is different, we know other unit cannot interpose
2373 : : it to the first symbol; all aliases of the definition needs to be
2374 : : present in the current unit. */
2375 : 84538817 : if (((really_binds_local1 || really_binds_local2)
2376 : : /* If we have both definitions and they are different, we know they
2377 : : will be different even in units they binds to. */
2378 : 11518843 : || (binds_local1 && binds_local2))
2379 : 73105350 : && rs1 != rs2)
2380 : : {
2381 : : /* We make use of the fact that one symbol is not alias of the other
2382 : : and that the definition is non-interposable. */
2383 : 73105257 : refuse_visibility_changes = true;
2384 : 73105257 : s2->refuse_visibility_changes = true;
2385 : 73105257 : rs1->refuse_visibility_changes = true;
2386 : 73105257 : rs2->refuse_visibility_changes = true;
2387 : 73105257 : return 0;
2388 : : }
2389 : :
2390 : 11433560 : if (rs1 == rs2)
2391 : : return -1;
2392 : :
2393 : : /* If the FE tells us at least one of the decls will never be aliased nor
2394 : : overlapping with other vars in some other way, return 0. */
2395 : 11433460 : if (VAR_P (decl)
2396 : 11433460 : && (lookup_attribute ("non overlapping", DECL_ATTRIBUTES (decl))
2397 : 11430430 : || lookup_attribute ("non overlapping", DECL_ATTRIBUTES (s2->decl))))
2398 : 3002 : return 0;
2399 : :
2400 : : /* TODO: Alias oracle basically assume that addresses of global variables
2401 : : are different unless they are declared as alias of one to another while
2402 : : the code folding comparisons doesn't.
2403 : : We probably should be consistent and use this fact here, too, but for
2404 : : the moment return false only when we are called from the alias oracle.
2405 : : Return 0 in C constant initializers and C++ manifestly constant
2406 : : expressions, the likelyhood that different vars will be aliases is
2407 : : small and returning -1 lets us reject too many initializers. */
2408 : 11430458 : if (memory_accessed || folding_initializer)
2409 : : return 0;
2410 : :
2411 : : return -1;
2412 : : }
2413 : :
2414 : : /* Worker for call_for_symbol_and_aliases. */
2415 : :
2416 : : bool
2417 : 148408 : symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
2418 : : void *),
2419 : : void *data,
2420 : : bool include_overwritable)
2421 : : {
2422 : 148408 : ipa_ref *ref;
2423 : 316205 : FOR_EACH_ALIAS (this, ref)
2424 : : {
2425 : 169072 : symtab_node *alias = ref->referring;
2426 : 169072 : if (include_overwritable
2427 : 169072 : || alias->get_availability () > AVAIL_INTERPOSABLE)
2428 : 169072 : if (alias->call_for_symbol_and_aliases (callback, data,
2429 : : include_overwritable))
2430 : : return true;
2431 : : }
2432 : : return false;
2433 : : }
2434 : :
2435 : : /* Return true if address of N is possibly compared. */
2436 : :
2437 : : static bool
2438 : 608622 : address_matters_1 (symtab_node *n, void *)
2439 : : {
2440 : 608622 : struct ipa_ref *ref;
2441 : :
2442 : 608622 : if (!n->address_can_be_compared_p ())
2443 : : return false;
2444 : 595900 : if (n->externally_visible || n->force_output)
2445 : : return true;
2446 : :
2447 : 496158 : for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
2448 : 442520 : if (ref->address_matters_p ())
2449 : : return true;
2450 : : return false;
2451 : : }
2452 : :
2453 : : /* Return true if symbol's address may possibly be compared to other
2454 : : symbol's address. */
2455 : :
2456 : : bool
2457 : 586425 : symtab_node::address_matters_p ()
2458 : : {
2459 : 586425 : gcc_assert (!alias);
2460 : 586425 : return call_for_symbol_and_aliases (address_matters_1, NULL, true);
2461 : : }
2462 : :
2463 : : /* Return true if symbol's alignment may be increased. */
2464 : :
2465 : : bool
2466 : 29219 : symtab_node::can_increase_alignment_p (void)
2467 : : {
2468 : 29219 : symtab_node *target = ultimate_alias_target ();
2469 : :
2470 : : /* For now support only variables. */
2471 : 29219 : if (!VAR_P (decl))
2472 : : return false;
2473 : :
2474 : : /* With -fno-toplevel-reorder we may have already output the constant. */
2475 : 29219 : if (TREE_ASM_WRITTEN (target->decl))
2476 : : return false;
2477 : :
2478 : : /* If target is already placed in an anchor, we cannot touch its
2479 : : alignment. */
2480 : 28532 : if (DECL_RTL_SET_P (target->decl)
2481 : 13711 : && MEM_P (DECL_RTL (target->decl))
2482 : 42243 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
2483 : : return false;
2484 : :
2485 : : /* Constant pool entries may be shared. */
2486 : 28532 : if (DECL_IN_CONSTANT_POOL (target->decl))
2487 : : return false;
2488 : :
2489 : : /* We cannot change alignment of symbols that may bind to symbols
2490 : : in other translation unit that may contain a definition with lower
2491 : : alignment. */
2492 : 26410 : if (!decl_binds_to_current_def_p (decl))
2493 : : return false;
2494 : :
2495 : : /* When compiling partition, be sure the symbol is not output by other
2496 : : partition. */
2497 : 17437 : if (flag_ltrans
2498 : 17437 : && (target->in_other_partition
2499 : 321 : || target->get_partitioning_class () == SYMBOL_DUPLICATE))
2500 : 0 : return false;
2501 : :
2502 : : /* Do not override the alignment as specified by the ABI when the used
2503 : : attribute is set. */
2504 : 17437 : if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl))
2505 : : return false;
2506 : :
2507 : : /* Do not override explicit alignment set by the user when an explicit
2508 : : section name is also used. This is a common idiom used by many
2509 : : software projects. */
2510 : 17437 : if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section)
2511 : : return false;
2512 : :
2513 : : return true;
2514 : : }
2515 : :
2516 : : /* Worker for symtab_node::increase_alignment. */
2517 : :
2518 : : static bool
2519 : 4823 : increase_alignment_1 (symtab_node *n, void *v)
2520 : : {
2521 : 4823 : unsigned int align = (size_t)v;
2522 : 4823 : if (DECL_ALIGN (n->decl) < align
2523 : 4823 : && n->can_increase_alignment_p ())
2524 : : {
2525 : 3854 : SET_DECL_ALIGN (n->decl, align);
2526 : 3854 : DECL_USER_ALIGN (n->decl) = 1;
2527 : : }
2528 : 4823 : return false;
2529 : : }
2530 : :
2531 : : /* Increase alignment of THIS to ALIGN. */
2532 : :
2533 : : void
2534 : 4651 : symtab_node::increase_alignment (unsigned int align)
2535 : : {
2536 : 4651 : gcc_assert (can_increase_alignment_p () && align <= MAX_OFILE_ALIGNMENT);
2537 : 4651 : ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
2538 : 4651 : (void *)(size_t) align,
2539 : : true);
2540 : 4651 : gcc_assert (DECL_ALIGN (decl) >= align);
2541 : 4651 : }
2542 : :
2543 : : /* Helper for symtab_node::definition_alignment. */
2544 : :
2545 : : static bool
2546 : 1700124 : get_alignment_1 (symtab_node *n, void *v)
2547 : : {
2548 : 1700124 : *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
2549 : 1700124 : return false;
2550 : : }
2551 : :
2552 : : /* Return desired alignment of the definition. This is NOT alignment useful
2553 : : to access THIS, because THIS may be interposable and DECL_ALIGN should
2554 : : be used instead. It however must be guaranteed when output definition
2555 : : of THIS. */
2556 : :
2557 : : unsigned int
2558 : 1639490 : symtab_node::definition_alignment ()
2559 : : {
2560 : 1639490 : unsigned int align = 0;
2561 : 1639490 : gcc_assert (!alias);
2562 : 1639490 : call_for_symbol_and_aliases (get_alignment_1, &align, true);
2563 : 1639490 : return align;
2564 : : }
2565 : :
2566 : : /* Return symbol used to separate symbol name from suffix. */
2567 : :
2568 : : char
2569 : 309978 : symbol_table::symbol_suffix_separator ()
2570 : : {
2571 : : #ifndef NO_DOT_IN_LABEL
2572 : 309978 : return '.';
2573 : : #elif !defined NO_DOLLAR_IN_LABEL
2574 : : return '$';
2575 : : #else
2576 : : return '_';
2577 : : #endif
2578 : : }
2579 : :
2580 : : /* Return true when references to this symbol from REF must bind to current
2581 : : definition in final executable. */
2582 : :
2583 : : bool
2584 : 95126428 : symtab_node::binds_to_current_def_p (symtab_node *ref)
2585 : : {
2586 : 95126428 : if (!definition && !in_other_partition)
2587 : : return false;
2588 : 46514547 : if (transparent_alias)
2589 : 13 : return definition
2590 : 13 : && get_alias_target()->binds_to_current_def_p (ref);
2591 : 46514534 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2592 : 46514534 : if (cnode && cnode->ifunc_resolver)
2593 : : return false;
2594 : 46514439 : if (decl_binds_to_current_def_p (decl))
2595 : : return true;
2596 : :
2597 : : /* Inline clones always binds locally. */
2598 : 22349390 : if (cnode && cnode->inlined_to)
2599 : : return true;
2600 : :
2601 : 22323512 : if (DECL_EXTERNAL (decl))
2602 : : return false;
2603 : :
2604 : 19020794 : gcc_assert (externally_visible);
2605 : :
2606 : 19020794 : if (ref)
2607 : : {
2608 : 166667 : cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
2609 : 166667 : if (cref)
2610 : 166667 : ref = cref->inlined_to;
2611 : : }
2612 : :
2613 : : /* If this is a reference from symbol itself and there are no aliases, we
2614 : : may be sure that the symbol was not interposed by something else because
2615 : : the symbol itself would be unreachable otherwise. This is important
2616 : : to optimize recursive functions well.
2617 : :
2618 : : This assumption may be broken by inlining: if symbol is interposable
2619 : : but the body is available (i.e. declared inline), inliner may make
2620 : : the body reachable even with interposition. */
2621 : 4344 : if (this == ref && !has_aliases_p ()
2622 : 170952 : && (!cnode
2623 : 4285 : || symtab->state >= IPA_SSA_AFTER_INLINING
2624 : 0 : || get_availability () >= AVAIL_INTERPOSABLE))
2625 : 4285 : return true;
2626 : :
2627 : :
2628 : : /* References within one comdat group are always bound in a group. */
2629 : 19016509 : if (ref
2630 : 89723 : && symtab->state >= IPA_SSA_AFTER_INLINING
2631 : 89723 : && get_comdat_group ()
2632 : 19106228 : && get_comdat_group () == ref->get_comdat_group ())
2633 : : return true;
2634 : :
2635 : : return false;
2636 : : }
2637 : :
2638 : : /* Return true if symbol should be output to the symbol table. */
2639 : :
2640 : : bool
2641 : 1190634 : symtab_node::output_to_lto_symbol_table_p (void)
2642 : : {
2643 : : /* Only externally visible symbols matter. */
2644 : 1190634 : if (!TREE_PUBLIC (decl))
2645 : : return false;
2646 : 1120976 : if (!real_symbol_p ())
2647 : : return false;
2648 : : /* FIXME: variables probably should not be considered as real symbols at
2649 : : first place. */
2650 : 1120976 : if (VAR_P (decl) && DECL_HARD_REGISTER (decl))
2651 : : return false;
2652 : 654852 : if (TREE_CODE (decl) == FUNCTION_DECL && !definition
2653 : 1584598 : && fndecl_built_in_p (decl))
2654 : : {
2655 : : /* Builtins like those for most math functions have actual implementations
2656 : : in libraries so make sure to output references into the symbol table to
2657 : : make those libraries referenced. Note this is incomplete handling for
2658 : : now and only covers math functions. */
2659 : 40436 : return builtin_with_linkage_p (decl);
2660 : : }
2661 : :
2662 : : /* We have real symbol that should be in symbol table. However try to trim
2663 : : down the references to libraries bit more because linker will otherwise
2664 : : bring unnecessary object files into the final link.
2665 : : FIXME: The following checks can easily be confused i.e. by self recursive
2666 : : function or self-referring variable. */
2667 : :
2668 : : /* We keep external functions in symtab for sake of inlining
2669 : : and devirtualization. We do not want to see them in symbol table as
2670 : : references unless they are really used. */
2671 : 1080516 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2672 : 614416 : if (cnode && (!definition || DECL_EXTERNAL (decl))
2673 : 423514 : && cnode->callers)
2674 : : return true;
2675 : :
2676 : : /* Ignore all references from external vars initializers - they are not really
2677 : : part of the compilation unit until they are used by folding. Some symbols,
2678 : : like references to external construction vtables cannot be referred to at
2679 : : all. We decide this at can_refer_decl_in_current_unit_p. */
2680 : 1058894 : if (!definition || DECL_EXTERNAL (decl))
2681 : : {
2682 : : int i;
2683 : : struct ipa_ref *ref;
2684 : 408392 : for (i = 0; iterate_referring (i, ref); i++)
2685 : : {
2686 : 408344 : if (ref->use == IPA_REF_ALIAS)
2687 : 48 : continue;
2688 : 816640 : if (is_a <cgraph_node *> (ref->referring))
2689 : : return true;
2690 : 403070 : if (!DECL_EXTERNAL (ref->referring->decl))
2691 : : return true;
2692 : : }
2693 : : return false;
2694 : : }
2695 : : return true;
2696 : : }
|