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 : 556653654 : symbol_table::decl_assembler_name_hash (const_tree asmname)
83 : : {
84 : 556653654 : if (IDENTIFIER_POINTER (asmname)[0] == '*')
85 : : {
86 : 2931782 : const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
87 : 2931782 : size_t ulp_len = strlen (user_label_prefix);
88 : :
89 : 2931782 : 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 : 2931782 : return htab_hash_string (decl_str);
95 : : }
96 : :
97 : 553721872 : 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 : 481801201 : symbol_table::assembler_names_equal_p (const char *name1, const char *name2)
105 : : {
106 : 481801201 : if (name1 != name2)
107 : : {
108 : 481801102 : if (name1[0] == '*')
109 : : {
110 : 2473710 : size_t ulp_len = strlen (user_label_prefix);
111 : :
112 : 2473710 : name1 ++;
113 : :
114 : 2473710 : 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 : 481801102 : if (name2[0] == '*')
122 : : {
123 : 2307853 : size_t ulp_len = strlen (user_label_prefix);
124 : :
125 : 2307853 : name2 ++;
126 : :
127 : 2307853 : 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 : 481801102 : return !strcmp (name1, name2);
135 : : }
136 : : return true;
137 : : }
138 : :
139 : : /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
140 : :
141 : : bool
142 : 578023533 : symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
143 : : {
144 : 578023533 : tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
145 : 578023533 : const char *decl_str;
146 : 578023533 : const char *asmname_str;
147 : :
148 : 578023533 : if (decl_asmname == asmname)
149 : : return true;
150 : :
151 : 481801102 : decl_str = IDENTIFIER_POINTER (decl_asmname);
152 : 481801102 : asmname_str = IDENTIFIER_POINTER (asmname);
153 : 481801102 : 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 : 130144177 : symbol_table::insert_to_assembler_name_hash (symtab_node *node,
163 : : bool with_clones)
164 : : {
165 : 157100528 : if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
166 : : return;
167 : 130143968 : gcc_checking_assert (!node->previous_sharing_asm_name
168 : : && !node->next_sharing_asm_name);
169 : 130143968 : if (assembler_name_hash)
170 : : {
171 : 11860156 : symtab_node **aslot;
172 : 11860156 : cgraph_node *cnode;
173 : 11860156 : tree decl = node->decl;
174 : :
175 : 11860156 : 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 : 11860156 : if (!name)
180 : 0 : return;
181 : :
182 : 11860156 : hashval_t hash = decl_assembler_name_hash (name);
183 : 11860156 : aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
184 : 11860156 : gcc_assert (*aslot != node);
185 : 11860156 : node->next_sharing_asm_name = (symtab_node *)*aslot;
186 : 11860156 : if (*aslot != NULL)
187 : 3168811 : (*aslot)->previous_sharing_asm_name = node;
188 : 11860156 : *aslot = node;
189 : :
190 : : /* Update also possible inline clones sharing a decl. */
191 : 23720312 : cnode = dyn_cast <cgraph_node *> (node);
192 : 8501478 : 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 : 114525140 : symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
204 : : bool with_clones)
205 : : {
206 : 114525140 : if (assembler_name_hash)
207 : : {
208 : 5077492 : cgraph_node *cnode;
209 : 5077492 : tree decl = node->decl;
210 : :
211 : 5077492 : if (node->next_sharing_asm_name)
212 : 2736931 : node->next_sharing_asm_name->previous_sharing_asm_name
213 : 2736931 : = node->previous_sharing_asm_name;
214 : 5077492 : if (node->previous_sharing_asm_name)
215 : : {
216 : 1021781 : node->previous_sharing_asm_name->next_sharing_asm_name
217 : 1021781 : = node->next_sharing_asm_name;
218 : : }
219 : : else
220 : : {
221 : 4055711 : tree name = DECL_ASSEMBLER_NAME (node->decl);
222 : 4055711 : symtab_node **slot;
223 : :
224 : 4055711 : if (!name)
225 : 0 : return;
226 : :
227 : 4055711 : hashval_t hash = decl_assembler_name_hash (name);
228 : 4055711 : slot = assembler_name_hash->find_slot_with_hash (name, hash,
229 : : NO_INSERT);
230 : 4055711 : gcc_assert (*slot == node);
231 : 4055711 : if (!node->next_sharing_asm_name)
232 : 2087458 : assembler_name_hash->clear_slot (slot);
233 : : else
234 : 1968253 : *slot = node->next_sharing_asm_name;
235 : : }
236 : 5077492 : node->next_sharing_asm_name = NULL;
237 : 5077492 : node->previous_sharing_asm_name = NULL;
238 : :
239 : : /* Update also possible inline clones sharing a decl. */
240 : 5077492 : cnode = dyn_cast <cgraph_node *> (node);
241 : 4973757 : 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 : 84016803 : symbol_table::symtab_initialize_asm_name_hash (void)
261 : : {
262 : 84016803 : symtab_node *node;
263 : 84016803 : if (!assembler_name_hash)
264 : : {
265 : 244557 : assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
266 : 8793469 : FOR_EACH_SYMBOL (node)
267 : 8548912 : insert_to_assembler_name_hash (node, false);
268 : : }
269 : 84016803 : }
270 : :
271 : : /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
272 : :
273 : : void
274 : 2829039 : symbol_table::change_decl_assembler_name (tree decl, tree name)
275 : : {
276 : 2829039 : 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 : 2830126 : || TREE_CODE (decl) == FUNCTION_DECL)
282 : 2827952 : node = symtab_node::get (decl);
283 : 2829039 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
284 : : {
285 : 1829638 : SET_DECL_ASSEMBLER_NAME (decl, name);
286 : 1829638 : if (node)
287 : 11 : insert_to_assembler_name_hash (node, true);
288 : : }
289 : : else
290 : : {
291 : 999401 : if (name == DECL_ASSEMBLER_NAME (decl))
292 : : return;
293 : :
294 : 156253 : tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
295 : 156253 : ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
296 : 0 : : NULL);
297 : 156253 : if (node)
298 : 7916 : unlink_from_assembler_name_hash (node, true);
299 : :
300 : 156253 : const char *old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
301 : 156253 : if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
302 : 156253 : && DECL_RTL_SET_P (decl))
303 : 0 : warning (0, "%qD renamed after being referenced in assembly", decl);
304 : :
305 : 156253 : SET_DECL_ASSEMBLER_NAME (decl, name);
306 : 156253 : if (DECL_RTL_SET_P (decl))
307 : : {
308 : 1 : SET_DECL_RTL (decl, NULL);
309 : 1 : make_decl_rtl (decl);
310 : : }
311 : 156253 : 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 : 156253 : if (node)
322 : : {
323 : 7916 : insert_to_assembler_name_hash (node, true);
324 : 7916 : ipa_ref *ref;
325 : 7942 : for (unsigned i = 0; node->iterate_direct_aliases (i, ref); i++)
326 : : {
327 : 26 : struct symtab_node *alias = ref->referring;
328 : 0 : if (alias->transparent_alias && !alias->weakref
329 : 26 : && 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 : 26 : else if (alias->transparent_alias
334 : 26 : && 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 : 26 : else gcc_assert (!alias->transparent_alias || alias->weakref);
346 : : #else
347 : : else gcc_assert (!alias->transparent_alias);
348 : : #endif
349 : : }
350 : 7916 : 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 : 12349765 : section_name_hasher::hash (section_hash_entry *n)
366 : : {
367 : 12349765 : return htab_hash_string (n->name);
368 : : }
369 : :
370 : : /* Return true if section P1 name equals to P2. */
371 : :
372 : : bool
373 : 12289145 : section_name_hasher::equal (section_hash_entry *n1, const char *name)
374 : : {
375 : 12289145 : 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 : 47079 : retain_section_hash_entry (section_hash_entry *entry)
382 : : {
383 : 47079 : entry->ref_count++;
384 : 47079 : 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 : 1879577 : release_section_hash_entry (section_hash_entry *entry)
392 : : {
393 : 1879577 : if (entry)
394 : : {
395 : 27781 : entry->ref_count--;
396 : 27781 : if (!entry->ref_count)
397 : : {
398 : 24223 : hashval_t hash = htab_hash_string (entry->name);
399 : 24223 : section_hash_entry **slot
400 : 24223 : = symtab->section_hash->find_slot_with_hash (entry->name,
401 : : hash, INSERT);
402 : 24223 : ggc_free (entry);
403 : 24223 : symtab->section_hash->clear_slot (slot);
404 : : }
405 : : }
406 : 1879577 : }
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 : 121585284 : symtab_node::register_symbol (void)
413 : : {
414 : 121585284 : symtab->register_symbol (this);
415 : :
416 : 121585284 : if (!decl->decl_with_vis.symtab_node)
417 : 118544285 : decl->decl_with_vis.symtab_node = this;
418 : :
419 : 121585284 : ref_list.clear ();
420 : :
421 : : /* Be sure to do this last; C++ FE might create new nodes via
422 : : DECL_ASSEMBLER_NAME langhook! */
423 : 121585284 : symtab->insert_to_assembler_name_hash (this, false);
424 : 121585284 : }
425 : :
426 : : /* Remove NODE from same comdat group. */
427 : :
428 : : void
429 : 124842136 : symtab_node::remove_from_same_comdat_group (void)
430 : : {
431 : 124842136 : if (same_comdat_group)
432 : : {
433 : : symtab_node *prev;
434 : : for (prev = same_comdat_group;
435 : 13961386 : prev->same_comdat_group != this;
436 : : prev = prev->same_comdat_group)
437 : : ;
438 : 13325352 : if (same_comdat_group == prev)
439 : 12928767 : prev->same_comdat_group = NULL;
440 : : else
441 : 396585 : prev->same_comdat_group = same_comdat_group;
442 : 13325352 : same_comdat_group = NULL;
443 : 13325352 : set_comdat_group (NULL);
444 : : }
445 : 124842136 : }
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 : 114515171 : symtab_node::unregister (clone_info *info)
453 : : {
454 : 114515171 : remove_all_references ();
455 : 114515171 : remove_all_referring ();
456 : :
457 : : /* Remove reference to section. */
458 : 114515171 : set_section_for_node (NULL);
459 : :
460 : 114515171 : remove_from_same_comdat_group ();
461 : :
462 : 114515171 : symtab->unregister (this);
463 : :
464 : : /* During LTO symtab merging we temporarily corrupt decl to symtab node
465 : : hash. */
466 : 114515171 : gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
467 : 114515171 : if (decl->decl_with_vis.symtab_node == this)
468 : : {
469 : 111971705 : symtab_node *replacement_node = NULL;
470 : 111971705 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
471 : 91681739 : replacement_node = cnode->find_replacement (info);
472 : 111971705 : decl->decl_with_vis.symtab_node = replacement_node;
473 : : }
474 : 114515171 : if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
475 : 114515170 : symtab->unlink_from_assembler_name_hash (this, false);
476 : 114515171 : if (in_init_priority_hash)
477 : 107 : symtab->init_priority_hash->remove (this);
478 : 114515171 : }
479 : :
480 : :
481 : : /* Remove symbol from symbol table. */
482 : :
483 : : void
484 : 109443406 : symtab_node::remove (void)
485 : : {
486 : 109443406 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
487 : 89253654 : cnode->remove ();
488 : 20189752 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
489 : 20189752 : vnode->remove ();
490 : 109443406 : }
491 : :
492 : : /* Add NEW_ to the same comdat group that OLD is in. */
493 : :
494 : : void
495 : 13399070 : symtab_node::add_to_same_comdat_group (symtab_node *old_node)
496 : : {
497 : 13399070 : gcc_assert (old_node->get_comdat_group ());
498 : 13399070 : gcc_assert (!same_comdat_group);
499 : 13399070 : gcc_assert (this != old_node);
500 : :
501 : 13399070 : set_comdat_group (old_node->get_comdat_group ());
502 : 13399070 : same_comdat_group = old_node;
503 : 13399070 : if (!old_node->same_comdat_group)
504 : 12984152 : old_node->same_comdat_group = this;
505 : : else
506 : : {
507 : : symtab_node *n;
508 : : for (n = old_node->same_comdat_group;
509 : 760348 : n->same_comdat_group != old_node;
510 : : n = n->same_comdat_group)
511 : : ;
512 : 414918 : n->same_comdat_group = this;
513 : : }
514 : :
515 : 13399070 : cgraph_node *n;
516 : 13411503 : if (comdat_local_p ()
517 : 13411496 : && (n = dyn_cast <cgraph_node *> (this)) != NULL)
518 : : {
519 : 27038 : for (cgraph_edge *e = n->callers; e; e = e->next_caller)
520 : 14612 : if (e->caller->inlined_to)
521 : 3548 : e->caller->inlined_to->calls_comdat_local = true;
522 : : else
523 : 11064 : e->caller->calls_comdat_local = true;
524 : : }
525 : 13399070 : }
526 : :
527 : : /* Dissolve the same_comdat_group list in which NODE resides. */
528 : :
529 : : void
530 : 1980 : symtab_node::dissolve_same_comdat_group_list (void)
531 : : {
532 : 1980 : symtab_node *n = this;
533 : 1980 : symtab_node *next;
534 : :
535 : 1980 : if (!same_comdat_group)
536 : : return;
537 : 3899 : do
538 : : {
539 : 3899 : next = n->same_comdat_group;
540 : 3899 : n->same_comdat_group = NULL;
541 : 3899 : if (dyn_cast <cgraph_node *> (n))
542 : 3629 : dyn_cast <cgraph_node *> (n)->calls_comdat_local = false;
543 : : /* Clear comdat_group for comdat locals, since
544 : : make_decl_local doesn't. */
545 : 3899 : if (!TREE_PUBLIC (n->decl))
546 : 2090 : n->set_comdat_group (NULL);
547 : 3899 : n = next;
548 : : }
549 : 3899 : 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 : 44405 : symtab_node::asm_name () const
558 : : {
559 : 44405 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
560 : 195 : return name ();
561 : 44210 : return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
562 : : }
563 : :
564 : : /* Return printable identifier name. */
565 : :
566 : : const char *
567 : 44681 : symtab_node::name () const
568 : : {
569 : 44681 : 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 : 44681 : return lang_hooks.decl_printable_name (decl, 2);
577 : : }
578 : :
579 : : const char *
580 : 80083 : symtab_node::get_dump_name (bool asm_name_p) const
581 : : {
582 : : #define EXTRA 16
583 : 80083 : const char *fname = asm_name_p ? asm_name () : name ();
584 : 80083 : unsigned l = strlen (fname);
585 : :
586 : 80083 : char *s = (char *)ggc_internal_cleared_alloc (l + EXTRA);
587 : 80083 : snprintf (s, l + EXTRA, "%s/%d", fname, m_uid);
588 : :
589 : 80083 : return s;
590 : : }
591 : :
592 : : const char *
593 : 35987 : symtab_node::dump_name () const
594 : : {
595 : 35987 : return get_dump_name (false);
596 : : }
597 : :
598 : : const char *
599 : 44096 : symtab_node::dump_asm_name () const
600 : : {
601 : 44096 : 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 : 6736866 : symtab_node::create_reference (symtab_node *referred_node,
610 : : enum ipa_ref_use use_type)
611 : : {
612 : 6736866 : 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 : 40370454 : symtab_node::create_reference (symtab_node *referred_node,
622 : : enum ipa_ref_use use_type, gimple *stmt)
623 : : {
624 : 40370454 : ipa_ref *ref = NULL, *ref2 = NULL;
625 : 40370454 : ipa_ref_list *list, *list2;
626 : 40370454 : ipa_ref_t *old_references;
627 : :
628 : 40370454 : gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
629 : 40370454 : gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
630 : :
631 : 40370454 : list = &ref_list;
632 : 40370454 : old_references = list->references.address ();
633 : 67775359 : list->references.safe_grow (list->references.length () + 1, false);
634 : 40370454 : ref = &list->references.last ();
635 : :
636 : 40370454 : list2 = &referred_node->ref_list;
637 : :
638 : : /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
639 : 40370454 : if(use_type == IPA_REF_ALIAS)
640 : : {
641 : 6854278 : list2->referring.safe_insert (0, ref);
642 : 6854278 : ref->referred_index = 0;
643 : :
644 : 6996617 : for (unsigned int i = 1; i < list2->referring.length (); i++)
645 : 142339 : list2->referring[i]->referred_index = i;
646 : : }
647 : : else
648 : : {
649 : 33516176 : list2->referring.safe_push (ref);
650 : 67032352 : ref->referred_index = list2->referring.length () - 1;
651 : : }
652 : :
653 : 40370454 : ref->referring = this;
654 : 40370454 : ref->referred = referred_node;
655 : 40370454 : ref->stmt = stmt;
656 : 40370454 : ref->lto_stmt_uid = 0;
657 : 40370454 : ref->speculative_id = 0;
658 : 40370454 : ref->use = use_type;
659 : 40370454 : ref->speculative = 0;
660 : :
661 : : /* If vector was moved in memory, update pointers. */
662 : 80740908 : if (old_references != list->references.address ())
663 : : {
664 : : int i;
665 : 50369545 : for (i = 0; iterate_reference(i, ref2); i++)
666 : 36077624 : ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
667 : : }
668 : 40370454 : return ref;
669 : : }
670 : :
671 : : ipa_ref *
672 : 52732 : symtab_node::maybe_create_reference (tree val, gimple *stmt)
673 : : {
674 : 52732 : STRIP_NOPS (val);
675 : 52732 : ipa_ref_use use_type;
676 : :
677 : 52732 : switch (TREE_CODE (val))
678 : : {
679 : : case VAR_DECL:
680 : : use_type = IPA_REF_LOAD;
681 : : break;
682 : 8183 : case ADDR_EXPR:
683 : 8183 : use_type = IPA_REF_ADDR;
684 : 8183 : break;
685 : 44161 : default:
686 : 44161 : gcc_assert (!handled_component_p (val));
687 : : return NULL;
688 : : }
689 : :
690 : 8571 : val = get_base_var (val);
691 : 8571 : if (val && VAR_OR_FUNCTION_DECL_P (val))
692 : : {
693 : 4914 : symtab_node *referred = symtab_node::get (val);
694 : 4914 : gcc_checking_assert (referred);
695 : 4914 : 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 : 3167762 : symtab_node::clone_references (symtab_node *node)
704 : : {
705 : 3167762 : ipa_ref *ref = NULL, *ref2 = NULL;
706 : 3167762 : int i;
707 : 3976446 : for (i = 0; node->iterate_reference (i, ref); i++)
708 : : {
709 : 808684 : bool speculative = ref->speculative;
710 : 808684 : unsigned int stmt_uid = ref->lto_stmt_uid;
711 : 808684 : unsigned int spec_id = ref->speculative_id;
712 : :
713 : 808684 : ref2 = create_reference (ref->referred, ref->use, ref->stmt);
714 : 808684 : ref2->speculative = speculative;
715 : 808684 : ref2->lto_stmt_uid = stmt_uid;
716 : 808684 : ref2->speculative_id = spec_id;
717 : : }
718 : 3167762 : }
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 : 25923 : symtab_node::clone_reference (ipa_ref *ref, gimple *stmt)
744 : : {
745 : 25923 : bool speculative = ref->speculative;
746 : 25923 : unsigned int stmt_uid = ref->lto_stmt_uid;
747 : 25923 : unsigned int spec_id = ref->speculative_id;
748 : 25923 : ipa_ref *ref2;
749 : :
750 : 25923 : ref2 = create_reference (ref->referred, ref->use, stmt);
751 : 25923 : ref2->speculative = speculative;
752 : 25923 : ref2->lto_stmt_uid = stmt_uid;
753 : 25923 : ref2->speculative_id = spec_id;
754 : 25923 : 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 : 10329 : 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 : 10329 : ipa_ref *r = NULL;
766 : 10329 : int i;
767 : :
768 : 55821 : for (i = 0; iterate_reference (i, r); i++)
769 : 55818 : if (r->referred == referred_node
770 : 17058 : && !r->speculative
771 : 17058 : && r->use == use_type
772 : 13946 : && ((stmt && r->stmt == stmt)
773 : 4240 : || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
774 : 4076 : || (!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 : 73737 : symtab_node::remove_stmt_references (gimple *stmt)
783 : : {
784 : 73737 : ipa_ref *r = NULL;
785 : 73737 : int i = 0;
786 : :
787 : 76181 : while (iterate_reference (i, r))
788 : 2444 : if (r->stmt == stmt)
789 : 0 : r->remove_reference ();
790 : : else
791 : 2444 : i++;
792 : 73737 : }
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 : 2139616 : symtab_node::clear_stmts_in_references (void)
802 : : {
803 : 2139616 : ipa_ref *r = NULL;
804 : 2139616 : int i;
805 : :
806 : 8606188 : for (i = 0; iterate_reference (i, r); i++)
807 : 6466572 : if (!r->speculative)
808 : : {
809 : 6453196 : r->stmt = NULL;
810 : 6453196 : r->lto_stmt_uid = 0;
811 : 6453196 : r->speculative_id = 0;
812 : : }
813 : 2139616 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
814 : 2139616 : if (cnode)
815 : : {
816 : 2139616 : if (cnode->clones)
817 : 669053 : for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
818 : 551218 : cnode->clear_stmts_in_references ();
819 : : }
820 : 2139616 : }
821 : :
822 : : /* Remove all references in ref list. */
823 : :
824 : : void
825 : 237849988 : symtab_node::remove_all_references (void)
826 : : {
827 : 273959864 : while (ref_list.references.length ())
828 : 36109876 : ref_list.references.last ().remove_reference ();
829 : 237849988 : ref_list.references.release ();
830 : 237849988 : }
831 : :
832 : : /* Remove all referring items in ref list. */
833 : :
834 : : void
835 : 114515171 : symtab_node::remove_all_referring (void)
836 : : {
837 : 114614768 : while (ref_list.referring.length ())
838 : 99597 : ref_list.referring.last ()->remove_reference ();
839 : 114515171 : ref_list.referring.release ();
840 : 114515171 : }
841 : :
842 : : /* Dump references in ref list to FILE. */
843 : :
844 : : void
845 : 8295 : symtab_node::dump_references (FILE *file)
846 : : {
847 : 8295 : ipa_ref *ref = NULL;
848 : 8295 : int i;
849 : 15414 : for (i = 0; iterate_reference (i, ref); i++)
850 : : {
851 : 7119 : fprintf (file, "%s (%s) ", ref->referred->dump_asm_name (),
852 : 7119 : ipa_ref_use_name[ref->use]);
853 : 7119 : if (ref->speculative)
854 : 107 : fprintf (file, "(speculative) ");
855 : : }
856 : 8295 : fprintf (file, "\n");
857 : 8295 : }
858 : :
859 : : /* Dump referring in list to FILE. */
860 : :
861 : : void
862 : 8295 : symtab_node::dump_referring (FILE *file)
863 : : {
864 : 8295 : ipa_ref *ref = NULL;
865 : 8295 : int i;
866 : 13345 : for (i = 0; iterate_referring(i, ref); i++)
867 : : {
868 : 5050 : fprintf (file, "%s (%s) ", ref->referring->dump_asm_name (),
869 : 5050 : ipa_ref_use_name[ref->use]);
870 : 5050 : if (ref->speculative)
871 : 101 : fprintf (file, "(speculative) ");
872 : : }
873 : 8295 : fprintf (file, "\n");
874 : 8295 : }
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 : 8295 : symtab_node::dump_base (FILE *f)
899 : : {
900 : 8295 : static const char * const visibility_types[] = {
901 : : "default", "protected", "hidden", "internal"
902 : : };
903 : :
904 : 8295 : fprintf (f, "%s (%s)", dump_asm_name (), name ());
905 : 8295 : if (dump_flags & TDF_ADDRESS)
906 : 103 : dump_addr (f, " @", (void *)this);
907 : 8295 : fprintf (f, "\n Type: %s", symtab_type_names[type]);
908 : :
909 : 8295 : if (definition)
910 : 6362 : fprintf (f, " definition");
911 : 8295 : if (analyzed)
912 : 6359 : fprintf (f, " analyzed");
913 : 8295 : if (alias)
914 : 100 : fprintf (f, " alias");
915 : 8295 : if (transparent_alias)
916 : 0 : fprintf (f, " transparent_alias");
917 : 8295 : if (weakref)
918 : 0 : fprintf (f, " weakref");
919 : 8295 : if (symver)
920 : 0 : fprintf (f, " symver");
921 : 8295 : if (cpp_implicit_alias)
922 : 81 : fprintf (f, " cpp_implicit_alias");
923 : 8295 : 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 : 8295 : if (body_removed)
930 : 625 : fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
931 : 8295 : fprintf (f, "\n Visibility:");
932 : 8295 : if (in_other_partition)
933 : 0 : fprintf (f, " in_other_partition");
934 : 8295 : if (used_from_other_partition)
935 : 0 : fprintf (f, " used_from_other_partition");
936 : 8295 : if (force_output)
937 : 640 : fprintf (f, " force_output");
938 : 8295 : if (forced_by_abi)
939 : 540 : fprintf (f, " forced_by_abi");
940 : 8295 : if (externally_visible)
941 : 3878 : fprintf (f, " externally_visible");
942 : 8295 : if (semantic_interposition)
943 : 7862 : fprintf (f, " semantic_interposition");
944 : 8295 : if (no_reorder)
945 : 555 : fprintf (f, " no_reorder");
946 : 8295 : if (resolution != LDPR_UNKNOWN)
947 : 1066 : fprintf (f, " %s",
948 : 1066 : ld_plugin_symbol_resolution_names[(int)resolution]);
949 : 8295 : if (TREE_ASM_WRITTEN (decl))
950 : 194 : fprintf (f, " asm_written");
951 : 8295 : if (DECL_EXTERNAL (decl))
952 : 1684 : fprintf (f, " external");
953 : 8295 : if (TREE_PUBLIC (decl))
954 : 6447 : fprintf (f, " public");
955 : 8295 : if (DECL_COMMON (decl))
956 : 22 : fprintf (f, " common");
957 : 8295 : if (DECL_WEAK (decl))
958 : 1494 : fprintf (f, " weak");
959 : 8295 : if (DECL_DLLIMPORT_P (decl))
960 : 0 : fprintf (f, " dll_import");
961 : 8295 : if (DECL_COMDAT (decl))
962 : 1458 : fprintf (f, " comdat");
963 : 8295 : if (get_comdat_group ())
964 : 2710 : fprintf (f, " comdat_group:%s",
965 : 1355 : IDENTIFIER_POINTER (get_comdat_group_id ()));
966 : 8295 : if (DECL_ONE_ONLY (decl))
967 : 1407 : fprintf (f, " one_only");
968 : 8295 : if (get_section ())
969 : 38 : fprintf (f, " section:%s",
970 : : get_section ());
971 : 8295 : if (implicit_section)
972 : 36 : fprintf (f," (implicit_section)");
973 : 8295 : if (DECL_VISIBILITY_SPECIFIED (decl))
974 : 577 : fprintf (f, " visibility_specified");
975 : 8295 : if (DECL_VISIBILITY (decl))
976 : 40 : fprintf (f, " visibility:%s",
977 : 20 : visibility_types [DECL_VISIBILITY (decl)]);
978 : 8295 : if (DECL_VIRTUAL_P (decl))
979 : 1330 : fprintf (f, " virtual");
980 : 8295 : if (DECL_ARTIFICIAL (decl))
981 : 2302 : fprintf (f, " artificial");
982 : 8295 : if (TREE_CODE (decl) == FUNCTION_DECL)
983 : : {
984 : 5835 : if (DECL_STATIC_CONSTRUCTOR (decl))
985 : 48 : fprintf (f, " constructor");
986 : 5835 : if (DECL_STATIC_DESTRUCTOR (decl))
987 : 7 : fprintf (f, " destructor");
988 : : }
989 : 8295 : if (ifunc_resolver)
990 : 3 : fprintf (f, " ifunc_resolver");
991 : 8295 : fprintf (f, "\n");
992 : :
993 : 8295 : if (same_comdat_group)
994 : 158 : fprintf (f, " Same comdat group as: %s\n",
995 : : same_comdat_group->dump_asm_name ());
996 : 8295 : if (next_sharing_asm_name)
997 : 410 : fprintf (f, " next sharing asm name: %i\n",
998 : 410 : next_sharing_asm_name->get_uid ());
999 : 8295 : if (previous_sharing_asm_name)
1000 : 374 : fprintf (f, " previous sharing asm name: %i\n",
1001 : 374 : previous_sharing_asm_name->get_uid ());
1002 : :
1003 : 8295 : if (address_taken)
1004 : 871 : fprintf (f, " Address is taken.\n");
1005 : 8295 : if (aux)
1006 : : {
1007 : 511 : fprintf (f, " Aux:");
1008 : 511 : dump_addr (f, " @", (void *)aux);
1009 : 511 : fprintf (f, "\n");
1010 : : }
1011 : :
1012 : 8295 : fprintf (f, " References: ");
1013 : 8295 : dump_references (f);
1014 : 8295 : fprintf (f, " Referring: ");
1015 : 8295 : dump_referring (f);
1016 : 8295 : if (lto_file_data)
1017 : 189 : fprintf (f, " Read from file: %s\n",
1018 : : lto_file_data->file_name);
1019 : 8295 : }
1020 : :
1021 : : /* Dump symtab node to F. */
1022 : :
1023 : : void
1024 : 7440 : symtab_node::dump (FILE *f)
1025 : : {
1026 : 7440 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
1027 : 4980 : cnode->dump (f);
1028 : 2460 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
1029 : 2460 : vnode->dump (f);
1030 : 7440 : }
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 : 8685 : FOR_EACH_SYMBOL (node)
1045 : 7437 : 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 : 83527743 : symtab_node::get_for_asmname (const_tree asmname)
1069 : : {
1070 : 83527743 : symtab_node *node;
1071 : :
1072 : 83527743 : symtab->symtab_initialize_asm_name_hash ();
1073 : 83527743 : hashval_t hash = symtab->decl_assembler_name_hash (asmname);
1074 : 83527743 : symtab_node **slot
1075 : 83527743 : = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
1076 : : NO_INSERT);
1077 : :
1078 : 83527743 : if (slot)
1079 : : {
1080 : 83523980 : node = *slot;
1081 : 83523980 : 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 : 84036125 : symtab_node::verify_base (void)
1107 : : {
1108 : 84036125 : bool error_found = false;
1109 : 84036125 : symtab_node *hashed_node;
1110 : :
1111 : 84036125 : if (is_a <cgraph_node *> (this))
1112 : : {
1113 : 52238114 : if (TREE_CODE (decl) != FUNCTION_DECL)
1114 : : {
1115 : 0 : error ("function symbol is not function");
1116 : 0 : error_found = true;
1117 : : }
1118 : 52238114 : else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))
1119 : 52238114 : != NULL)
1120 : 52238114 : != dyn_cast <cgraph_node *> (this)->ifunc_resolver)
1121 : : {
1122 : 0 : error ("inconsistent %<ifunc%> attribute");
1123 : 0 : error_found = true;
1124 : : }
1125 : : }
1126 : 31798011 : else if (is_a <varpool_node *> (this))
1127 : : {
1128 : 31798011 : 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 : 84036125 : if (order < 0 || order >= symtab->order)
1140 : : {
1141 : 0 : error ("node has invalid order %i", order);
1142 : 0 : error_found = true;
1143 : : }
1144 : :
1145 : 84036125 : if (symtab->state != LTO_STREAMING)
1146 : : {
1147 : 83881398 : hashed_node = symtab_node::get (decl);
1148 : 83881398 : if (!hashed_node)
1149 : : {
1150 : 0 : error ("node not found node->decl->decl_with_vis.symtab_node");
1151 : 0 : error_found = true;
1152 : : }
1153 : 83881398 : if (hashed_node != this
1154 : 89404768 : && (!is_a <cgraph_node *> (this)
1155 : 5523370 : || !dyn_cast <cgraph_node *> (this)->clone_of
1156 : 5523370 : || 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 : 84036125 : if (symtab->assembler_name_hash)
1163 : : {
1164 : 83447401 : hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
1165 : 83447401 : if (hashed_node)
1166 : : {
1167 : 83445728 : if (hashed_node->previous_sharing_asm_name)
1168 : : {
1169 : 0 : error ("assembler name hash list corrupted");
1170 : 0 : error_found = true;
1171 : : }
1172 : 83445728 : else if (previous_sharing_asm_name == NULL)
1173 : : {
1174 : 77963598 : if (hashed_node != this)
1175 : : {
1176 : 0 : error ("assembler name hash list corrupted");
1177 : 0 : error_found = true;
1178 : : }
1179 : : }
1180 : 5482130 : else if (!(is_a <varpool_node *> (this) && DECL_HARD_REGISTER (decl)))
1181 : : {
1182 : 5482130 : if (!asmname_hasher::equal (previous_sharing_asm_name,
1183 : 5482130 : 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 : 84036125 : if (previous_sharing_asm_name
1192 : 5482547 : && 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 : 84036125 : if (body_removed && definition)
1198 : : {
1199 : 0 : error ("node has body_removed but is definition");
1200 : 0 : error_found = true;
1201 : : }
1202 : 84036125 : if (analyzed && !definition)
1203 : : {
1204 : 0 : error ("node is analyzed but it is not a definition");
1205 : 0 : error_found = true;
1206 : : }
1207 : 84036125 : if (cpp_implicit_alias && !alias)
1208 : : {
1209 : 0 : error ("node is alias but not implicit alias");
1210 : 0 : error_found = true;
1211 : : }
1212 : 84036125 : if (alias && !definition && !weakref)
1213 : : {
1214 : 0 : error ("node is alias but not definition");
1215 : 0 : error_found = true;
1216 : : }
1217 : 84036125 : if (weakref && !transparent_alias)
1218 : : {
1219 : 0 : error ("node is weakref but not an transparent_alias");
1220 : 0 : error_found = true;
1221 : : }
1222 : 84036125 : if (transparent_alias && !alias)
1223 : : {
1224 : 0 : error ("node is transparent_alias but not an alias");
1225 : 0 : error_found = true;
1226 : : }
1227 : 84036125 : 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 : 84036125 : if (symver
1235 : 84036125 : && (!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 : 84036125 : if (symver
1242 : 84036125 : && (!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 : 84036125 : if (same_comdat_group)
1249 : : {
1250 : 3300577 : symtab_node *n = same_comdat_group;
1251 : :
1252 : 3300577 : 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 : 3300577 : 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 : 3300577 : 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 : 3300577 : if (n == this)
1268 : : {
1269 : 0 : error ("node is alone in a comdat group");
1270 : 0 : error_found = true;
1271 : : }
1272 : 5853803 : do
1273 : : {
1274 : 5853803 : 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 : 5853803 : n = n->same_comdat_group;
1281 : : }
1282 : 5853803 : while (n != this);
1283 : 3300577 : if (comdat_local_p ())
1284 : : {
1285 : 53412 : ipa_ref *ref = NULL;
1286 : :
1287 : 54921 : for (int i = 0; iterate_referring (i, ref); ++i)
1288 : : {
1289 : 1509 : 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 : 99409958 : 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 : 99414117 : if (get_section () && get_comdat_group ()
1305 : 2843997 : && !implicit_section
1306 : 15378202 : && !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 : 1516230 : if (alias && definition
1314 : 1574986 : && get_section () != get_alias_target ()->get_section ()
1315 : 84036125 : && (!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 : 1516230 : if (alias && definition
1325 : 85551105 : && 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 : 84036125 : 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 : 84036317 : && 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 : 84036125 : return error_found;
1356 : : }
1357 : :
1358 : : /* Verify consistency of NODE. */
1359 : :
1360 : : DEBUG_FUNCTION void
1361 : 84038471 : symtab_node::verify (void)
1362 : : {
1363 : 84038471 : if (seen_error ())
1364 : : return;
1365 : :
1366 : 84036125 : timevar_push (TV_CGRAPH_VERIFY);
1367 : 84036125 : if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
1368 : 52238114 : node->verify_node ();
1369 : : else
1370 : 31798011 : if (verify_base ())
1371 : : {
1372 : 0 : debug ();
1373 : 0 : internal_error ("symtab_node::verify failed");
1374 : : }
1375 : 84036125 : 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 : 5611356 : check_ifunc_resolver (cgraph_node *node, void *data)
1382 : : {
1383 : 5611356 : if (node->ifunc_resolver)
1384 : : {
1385 : 442 : bool *is_ifunc_resolver = (bool *) data;
1386 : 442 : *is_ifunc_resolver = true;
1387 : 442 : 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 : 5232941 : is_caller_ifunc_resolver (cgraph_node *node)
1398 : : {
1399 : 5232941 : bool is_ifunc_resolver = false;
1400 : :
1401 : 15401538 : 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 : 10168911 : if (e->caller->called_by_ifunc_resolver)
1405 : : return true;
1406 : :
1407 : : /* Check for recursive call. */
1408 : 10168744 : if (e->caller == node)
1409 : 11375 : continue;
1410 : :
1411 : : /* Skip if it has been visited. */
1412 : 10157369 : unsigned int uid = e->caller->get_uid ();
1413 : 10157369 : if (!bitmap_set_bit (ifunc_ref_map, uid))
1414 : 8219128 : continue;
1415 : :
1416 : 1938241 : 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 : 1938219 : e->caller->call_for_symbol_and_aliases (check_ifunc_resolver,
1425 : : &is_ifunc_resolver,
1426 : : true);
1427 : 1938219 : 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 : 244887 : symtab_node::check_ifunc_callee_symtab_nodes (void)
1442 : : {
1443 : 244887 : symtab_node *node;
1444 : :
1445 : 244887 : bitmap_obstack_initialize (NULL);
1446 : 244887 : ifunc_ref_map = BITMAP_ALLOC (NULL);
1447 : :
1448 : 8794537 : FOR_EACH_SYMBOL (node)
1449 : : {
1450 : 8549650 : cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1451 : 8549650 : if (!cnode)
1452 : 5254633 : continue;
1453 : :
1454 : 5233258 : unsigned int uid = cnode->get_uid ();
1455 : 5233258 : if (bitmap_bit_p (ifunc_ref_map, uid))
1456 : 1938241 : continue;
1457 : 3295017 : bitmap_set_bit (ifunc_ref_map, uid);
1458 : :
1459 : 3295017 : bool is_ifunc_resolver = false;
1460 : 3295017 : cnode->call_for_symbol_and_aliases (check_ifunc_resolver,
1461 : : &is_ifunc_resolver, true);
1462 : 3295017 : if (is_ifunc_resolver || is_caller_ifunc_resolver (cnode))
1463 : 609 : cnode->called_by_ifunc_resolver = true;
1464 : : }
1465 : :
1466 : 244887 : BITMAP_FREE (ifunc_ref_map);
1467 : 244887 : bitmap_obstack_release (NULL);
1468 : 244887 : }
1469 : :
1470 : : /* Verify symbol table for internal consistency. */
1471 : :
1472 : : DEBUG_FUNCTION void
1473 : 2181928 : symtab_node::verify_symtab_nodes (void)
1474 : : {
1475 : 2181928 : symtab_node *node;
1476 : 2181928 : hash_map<tree, symtab_node *> comdat_head_map (251);
1477 : 2181928 : asm_node *anode;
1478 : :
1479 : 2303774 : for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
1480 : 121846 : 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 : 75431432 : FOR_EACH_SYMBOL (node)
1487 : : {
1488 : 73249504 : node->verify ();
1489 : 73249504 : if (node->get_comdat_group ())
1490 : : {
1491 : 10717954 : symtab_node **entry, *s;
1492 : 10717954 : bool existed;
1493 : :
1494 : 10717954 : entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
1495 : : &existed);
1496 : 10717954 : if (!existed)
1497 : 9371439 : *entry = node;
1498 : 1346515 : else if (!DECL_EXTERNAL (node->decl))
1499 : : {
1500 : 1346370 : for (s = (*entry)->same_comdat_group;
1501 : 2491736 : s != NULL && s != node && s != *entry;
1502 : 1145366 : s = s->same_comdat_group)
1503 : : ;
1504 : 1346370 : 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 : 2181928 : }
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 : 3646417 : symtab_node::make_decl_local (void)
1526 : : {
1527 : 3646417 : rtx rtl, symbol;
1528 : :
1529 : 3646417 : 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 : 3646417 : else if (TREE_PUBLIC (decl) == 0)
1541 : 3646403 : return;
1542 : :
1543 : : /* Localizing a symbol also make all its transparent aliases local. */
1544 : : ipa_ref *ref;
1545 : 104418 : for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
1546 : : {
1547 : 1833 : struct symtab_node *alias = ref->referring;
1548 : 1833 : if (alias->transparent_alias)
1549 : 5 : alias->make_decl_local ();
1550 : : }
1551 : :
1552 : 102585 : if (VAR_P (decl))
1553 : : {
1554 : 12311 : DECL_COMMON (decl) = 0;
1555 : : /* ADDRESSABLE flag is not defined for public symbols. */
1556 : 12311 : TREE_ADDRESSABLE (decl) = 1;
1557 : 12311 : TREE_STATIC (decl) = 1;
1558 : : }
1559 : : else
1560 : 90274 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1561 : :
1562 : 102585 : DECL_COMDAT (decl) = 0;
1563 : 102585 : DECL_WEAK (decl) = 0;
1564 : 102585 : DECL_EXTERNAL (decl) = 0;
1565 : 102585 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
1566 : 102585 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1567 : 102585 : TREE_PUBLIC (decl) = 0;
1568 : 102585 : DECL_DLLIMPORT_P (decl) = 0;
1569 : 102585 : 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 : 35897552 : symtab_node::ultimate_alias_target_1 (enum availability *availability,
1646 : : symtab_node *ref)
1647 : : {
1648 : 35897552 : 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 : 35897552 : if (availability)
1664 : : {
1665 : 10939830 : transparent_p = transparent_alias;
1666 : 10939830 : if (!transparent_p)
1667 : 10934034 : *availability = get_availability (ref);
1668 : : else
1669 : 5796 : *availability = AVAIL_NOT_AVAILABLE;
1670 : : }
1671 : :
1672 : : symtab_node *node = this;
1673 : 71786379 : while (node)
1674 : : {
1675 : 71786379 : if (node->alias && node->analyzed)
1676 : 35888827 : node = node->get_alias_target ();
1677 : : else
1678 : : {
1679 : 35897552 : if (!availability || (!transparent_p && node->analyzed))
1680 : : ;
1681 : 37718 : else if (node->analyzed && !node->transparent_alias)
1682 : 308 : *availability = node->get_availability (ref);
1683 : : else
1684 : 37410 : *availability = AVAIL_NOT_AVAILABLE;
1685 : 35897552 : return node;
1686 : : }
1687 : 35888827 : if (node && availability && transparent_p
1688 : 448 : && 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 : 7177149 : symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
1708 : : {
1709 : 7177149 : if (is_a <cgraph_node *> (this))
1710 : : {
1711 : 21531300 : DECL_DECLARED_INLINE_P (decl)
1712 : 7177100 : = DECL_DECLARED_INLINE_P (target->decl);
1713 : 21531300 : DECL_DISREGARD_INLINE_LIMITS (decl)
1714 : 7177100 : = 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 : 7177149 : if (TREE_PUBLIC (decl))
1725 : : {
1726 : 7152117 : tree group;
1727 : :
1728 : 7152117 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1729 : 7152117 : DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
1730 : 7152117 : group = target->get_comdat_group ();
1731 : 7152117 : set_comdat_group (group);
1732 : 7152117 : if (group && !same_comdat_group)
1733 : 0 : add_to_same_comdat_group (target);
1734 : : }
1735 : 7177149 : externally_visible = target->externally_visible;
1736 : 7177149 : }
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 : 116369563 : symtab_node::set_section_for_node (const char *section)
1744 : : {
1745 : 116369563 : const char *current = get_section ();
1746 : :
1747 : 116369563 : if (current == section
1748 : 1872709 : || (current && section
1749 : 0 : && !strcmp (current, section)))
1750 : : return;
1751 : :
1752 : 1872709 : release_section_hash_entry (x_section);
1753 : 1872709 : if (!section)
1754 : : {
1755 : 27157 : x_section = NULL;
1756 : 27157 : implicit_section = false;
1757 : 27157 : return;
1758 : : }
1759 : 1845552 : if (!symtab->section_hash)
1760 : 35643 : symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
1761 : 1845552 : section_hash_entry **slot = symtab->section_hash->find_slot_with_hash
1762 : 1845552 : (section, htab_hash_string (section), INSERT);
1763 : 1845552 : if (*slot)
1764 : 40219 : x_section = retain_section_hash_entry (*slot);
1765 : : else
1766 : : {
1767 : 1805333 : int len = strlen (section);
1768 : 1805333 : *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
1769 : 1805333 : x_section->ref_count = 1;
1770 : 1805333 : x_section->name = ggc_vec_alloc<char> (len + 1);
1771 : 1805333 : 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 : 20931302 : symtab_node::set_section_for_node (const symtab_node &other)
1781 : : {
1782 : 20931302 : 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 : 1851890 : symtab_node::set_section_from_string (symtab_node *n, void *s)
1800 : : {
1801 : 1851890 : n->set_section_for_node ((char *)s);
1802 : 1851890 : 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 : 20931302 : symtab_node::set_section_from_node (symtab_node *n, void *o)
1810 : : {
1811 : 20931302 : const symtab_node &other = *static_cast<const symtab_node *> (o);
1812 : 20931302 : n->set_section_for_node (other);
1813 : 20931302 : return false;
1814 : : }
1815 : :
1816 : : /* Set section of symbol and its aliases. */
1817 : :
1818 : : void
1819 : 1810183 : symtab_node::set_section (const char *section)
1820 : : {
1821 : 1810183 : gcc_assert (!this->alias || !this->analyzed);
1822 : 1810183 : call_for_symbol_and_aliases
1823 : 1810183 : (symtab_node::set_section_from_string, const_cast<char *>(section), true);
1824 : 1810183 : }
1825 : :
1826 : : void
1827 : 20931053 : symtab_node::set_section (const symtab_node &other)
1828 : : {
1829 : 20931053 : call_for_symbol_and_aliases
1830 : 20931053 : (symtab_node::set_section_from_node, const_cast<symtab_node *>(&other), true);
1831 : 20931053 : }
1832 : :
1833 : : /* Return the initialization priority. */
1834 : :
1835 : : priority_type
1836 : 43379 : symtab_node::get_init_priority ()
1837 : : {
1838 : 43379 : if (!this->in_init_priority_hash)
1839 : : return DEFAULT_INIT_PRIORITY;
1840 : :
1841 : 3944 : symbol_priority_map *h = symtab->init_priority_hash->get (this);
1842 : 3944 : 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 : 5358 : symtab_node::priority_info (void)
1862 : : {
1863 : 5358 : if (!symtab->init_priority_hash)
1864 : 3592 : symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
1865 : :
1866 : 5358 : bool existed;
1867 : 5358 : symbol_priority_map *h
1868 : 5358 : = &symtab->init_priority_hash->get_or_insert (this, &existed);
1869 : 5358 : if (!existed)
1870 : : {
1871 : 5338 : h->init = DEFAULT_INIT_PRIORITY;
1872 : 5338 : h->fini = DEFAULT_INIT_PRIORITY;
1873 : 5338 : in_init_priority_hash = true;
1874 : : }
1875 : :
1876 : 5358 : return h;
1877 : : }
1878 : :
1879 : : /* Set initialization priority to PRIORITY. */
1880 : :
1881 : : void
1882 : 23859 : symtab_node::set_init_priority (priority_type priority)
1883 : : {
1884 : 23859 : symbol_priority_map *h;
1885 : :
1886 : 23859 : if (is_a <cgraph_node *> (this))
1887 : 23814 : gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
1888 : :
1889 : 23859 : if (priority == DEFAULT_INIT_PRIORITY)
1890 : : {
1891 : 20114 : gcc_assert (get_init_priority() == priority);
1892 : : return;
1893 : : }
1894 : 3745 : h = priority_info ();
1895 : 3745 : 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 : 6841771 : symtab_node::resolve_alias (symtab_node *target, bool transparent)
1932 : : {
1933 : 6841771 : symtab_node *n;
1934 : :
1935 : 6841771 : 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 : 6844234 : for (n = target; n && n->alias;
1940 : 2677 : n = n->analyzed ? n->get_alias_target () : NULL)
1941 : 2679 : 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 : 6841769 : definition = true;
1955 : 6841769 : alias = true;
1956 : 6841769 : analyzed = true;
1957 : 6841769 : transparent |= transparent_alias;
1958 : 6841769 : transparent_alias = transparent;
1959 : 6841769 : if (transparent)
1960 : 54 : while (target->transparent_alias && target->analyzed)
1961 : 0 : target = target->get_alias_target ();
1962 : 6841769 : create_reference (target, IPA_REF_ALIAS, NULL);
1963 : :
1964 : : /* Add alias into the comdat group of its target unless it is already there. */
1965 : 6841769 : if (same_comdat_group)
1966 : 3208802 : remove_from_same_comdat_group ();
1967 : 6841769 : set_comdat_group (NULL);
1968 : 6841769 : if (target->get_comdat_group ())
1969 : 6561323 : add_to_same_comdat_group (target);
1970 : :
1971 : 6841782 : if ((get_section () != target->get_section ()
1972 : 6841774 : || 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 : 6841769 : set_section (*target);
1977 : 6841769 : 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 : 6841769 : alias_target = NULL;
1984 : :
1985 : 6841769 : if (!transparent && cpp_implicit_alias && symtab->state >= CONSTRUCTION)
1986 : 8555 : fixup_same_cpp_alias_visibility (target);
1987 : :
1988 : : /* If alias has address taken, so does the target. */
1989 : 6841769 : 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 : 6842018 : for (unsigned i = 0; iterate_direct_aliases (i, ref);)
1998 : : {
1999 : 249 : struct symtab_node *alias_alias = ref->referring;
2000 : 249 : 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 : 249 : if ((!alias_alias->transparent_alias
2008 : 237 : && !alias_alias->symver)
2009 : 12 : || transparent)
2010 : : {
2011 : 249 : alias_alias->remove_all_references ();
2012 : 249 : 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 : 59729 : symtab_node::noninterposable_alias (symtab_node *node, void *data)
2023 : : {
2024 : 59729 : if (!node->transparent_alias && decl_binds_to_current_def_p (node->decl))
2025 : : {
2026 : 57457 : 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 : 57457 : if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
2032 : 57457 : || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
2033 : 57457 : || (TREE_CODE (node->decl) == FUNCTION_DECL
2034 : 114914 : && flags_from_decl_or_type (node->decl)
2035 : 57457 : != flags_from_decl_or_type (fn->decl))
2036 : 114896 : || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
2037 : 20 : return false;
2038 : 57437 : *(symtab_node **)data = node;
2039 : 57437 : 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 : 58430 : symtab_node::noninterposable_alias (void)
2050 : : {
2051 : 58430 : tree new_decl;
2052 : 58430 : 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 : 58430 : symtab_node *node = ultimate_alias_target ();
2057 : 58430 : gcc_assert (!node->alias && !node->weakref);
2058 : 58430 : node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
2059 : : (void *)&new_node, true);
2060 : 58430 : if (new_node)
2061 : : return new_node;
2062 : :
2063 : : /* If aliases aren't supported by the assembler, fail. */
2064 : 993 : if (!TARGET_SUPPORTS_ALIASES)
2065 : : return NULL;
2066 : 993 : else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)))
2067 : : return NULL;
2068 : :
2069 : : /* Otherwise create a new one. */
2070 : 992 : new_decl = copy_node (node->decl);
2071 : 992 : DECL_DLLIMPORT_P (new_decl) = 0;
2072 : 992 : tree name = clone_function_name (node->decl, "localalias");
2073 : 992 : 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 : 986 : while (symtab_node::get_for_asmname (name))
2080 : 0 : name = clone_function_name (node->decl, "localalias", num++);
2081 : : }
2082 : 992 : DECL_NAME (new_decl) = name;
2083 : 992 : if (TREE_CODE (new_decl) == FUNCTION_DECL)
2084 : 990 : DECL_STRUCT_FUNCTION (new_decl) = NULL;
2085 : 992 : DECL_INITIAL (new_decl) = NULL;
2086 : 992 : SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
2087 : 992 : SET_DECL_RTL (new_decl, NULL);
2088 : :
2089 : : /* Update the properties. */
2090 : 992 : DECL_EXTERNAL (new_decl) = 0;
2091 : 992 : TREE_PUBLIC (new_decl) = 0;
2092 : 992 : DECL_COMDAT (new_decl) = 0;
2093 : 992 : DECL_WEAK (new_decl) = 0;
2094 : :
2095 : : /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
2096 : 992 : DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
2097 : 992 : if (TREE_CODE (new_decl) == FUNCTION_DECL)
2098 : : {
2099 : 990 : DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
2100 : 990 : DECL_STATIC_DESTRUCTOR (new_decl) = 0;
2101 : 990 : new_node = cgraph_node::create_alias (new_decl, node->decl);
2102 : :
2103 : 1980 : cgraph_node *new_cnode = dyn_cast <cgraph_node *> (new_node),
2104 : 990 : *cnode = dyn_cast <cgraph_node *> (node);
2105 : :
2106 : 990 : new_cnode->unit_id = cnode->unit_id;
2107 : 990 : new_cnode->merged_comdat = cnode->merged_comdat;
2108 : 990 : 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 : 992 : new_node->resolve_alias (node);
2117 : 992 : gcc_assert (decl_binds_to_current_def_p (new_decl)
2118 : : && targetm.binds_local_p (new_decl));
2119 : 992 : return new_node;
2120 : : }
2121 : :
2122 : : /* Return true if symtab node and TARGET represents
2123 : : semantically equivalent symbols. */
2124 : :
2125 : : bool
2126 : 371115 : symtab_node::semantically_equivalent_p (symtab_node *target)
2127 : : {
2128 : 371115 : enum availability avail;
2129 : 371115 : symtab_node *ba;
2130 : 371115 : symtab_node *bb;
2131 : :
2132 : : /* Equivalent functions are equivalent. */
2133 : 371115 : 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 : 274353 : ba = ultimate_alias_target (&avail);
2139 : 274353 : if (avail >= AVAIL_AVAILABLE)
2140 : : {
2141 : 61037 : if (target == ba)
2142 : : return true;
2143 : : }
2144 : : else
2145 : : ba = this;
2146 : 274329 : bb = target->ultimate_alias_target (&avail);
2147 : 274329 : if (avail >= AVAIL_AVAILABLE)
2148 : : {
2149 : 60486 : if (this == bb)
2150 : : return true;
2151 : : }
2152 : : else
2153 : : bb = target;
2154 : 274270 : return bb == ba;
2155 : : }
2156 : :
2157 : : /* Classify symbol symtab node for partitioning. */
2158 : :
2159 : : enum symbol_partitioning_class
2160 : 2295734 : symtab_node::get_partitioning_class (void)
2161 : : {
2162 : : /* Inline clones are always duplicated.
2163 : : This include external declarations. */
2164 : 2295734 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2165 : :
2166 : 2295734 : if (DECL_ABSTRACT_P (decl))
2167 : : return SYMBOL_EXTERNAL;
2168 : :
2169 : 2295734 : if (cnode && cnode->inlined_to)
2170 : : return SYMBOL_DUPLICATE;
2171 : :
2172 : : /* Transparent aliases are always duplicated. */
2173 : 2210927 : if (transparent_alias)
2174 : 66 : return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL;
2175 : :
2176 : : /* External declarations are external. */
2177 : 2210861 : 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 : 2059377 : if (alias && DECL_EXTERNAL (ultimate_alias_target ()->decl))
2183 : : return SYMBOL_EXTERNAL;
2184 : :
2185 : 2059377 : if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
2186 : : {
2187 : 927614 : 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 : 927614 : if (DECL_IN_CONSTANT_POOL (decl))
2193 : : return SYMBOL_DUPLICATE;
2194 : 927424 : if (DECL_HARD_REGISTER (decl))
2195 : : return SYMBOL_DUPLICATE;
2196 : 927328 : 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 : 1131763 : 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 : 2069605 : if (DECL_ONE_ONLY (decl)
2208 : 13684 : && !force_output
2209 : 13640 : && !forced_by_abi
2210 : 2067986 : && !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 : 14079670 : symtab_node::nonzero_address (bool delete_null_pointer_checks)
2221 : : {
2222 : : /* Weakrefs may be NULL when their target is not defined. */
2223 : 14079670 : if (alias && weakref)
2224 : : {
2225 : 2747 : 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 : 17842143 : if ((!DECL_WEAK (decl) || DECL_COMDAT (decl))
2261 : 15098661 : && delete_null_pointer_checks)
2262 : : {
2263 : 11322793 : refuse_visibility_changes = true;
2264 : 11322793 : 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 : 2729749 : if (definition && !DECL_EXTERNAL (decl)
2272 : 5483878 : && (delete_null_pointer_checks || !DECL_WEAK (decl)))
2273 : : {
2274 : 2729048 : if (!DECL_WEAK (decl))
2275 : 9098 : refuse_visibility_changes = true;
2276 : 2729048 : return true;
2277 : : }
2278 : :
2279 : : /* As the last resort, check the resolution info. */
2280 : 25082 : if (resolution != LDPR_UNKNOWN
2281 : : && resolution != LDPR_UNDEF
2282 : 0 : && !can_be_discarded_p ()
2283 : 25082 : && 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 : 14078829 : symtab_node::nonzero_address ()
2292 : : {
2293 : 14078829 : 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 : 85557277 : symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed)
2306 : : {
2307 : 85557277 : enum availability avail1, avail2;
2308 : :
2309 : : /* A Shortcut: equivalent symbols are always equivalent. */
2310 : 85557277 : if (this == s2)
2311 : : return 1;
2312 : :
2313 : : /* Unwind transparent aliases first; those are always equal to their
2314 : : target. */
2315 : 85026663 : if (this->transparent_alias && this->analyzed)
2316 : 0 : return this->get_alias_target ()->equal_address_to (s2);
2317 : 85026663 : while (s2->transparent_alias && s2->analyzed)
2318 : 0 : s2 = s2->get_alias_target();
2319 : :
2320 : 85026663 : 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 : 85026663 : symtab_node *rs1 = ultimate_alias_target (&avail1);
2326 : 85026663 : symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
2327 : 85026663 : bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
2328 : 85026663 : bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
2329 : 85026663 : bool really_binds_local1 = binds_local1;
2330 : 85026663 : 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 : 85026663 : if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
2338 : : binds_local1 = true;
2339 : 85026663 : if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
2340 : 85026663 : 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 : 85026663 : if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
2346 : : binds_local1 = binds_local2 = true;
2347 : :
2348 : 85026663 : 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 : 85026305 : if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ())
2361 : : return -1;
2362 : :
2363 : : /* Except for NULL, functions and variables never overlap. */
2364 : 85026246 : if (TREE_CODE (decl) != TREE_CODE (s2->decl))
2365 : : return 0;
2366 : :
2367 : : /* If one of the symbols is unresolved alias, punt. */
2368 : 84870991 : 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 : 84870983 : 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 : 11529845 : || (binds_local1 && binds_local2))
2379 : 73428398 : && 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 : 73428305 : refuse_visibility_changes = true;
2384 : 73428305 : s2->refuse_visibility_changes = true;
2385 : 73428305 : rs1->refuse_visibility_changes = true;
2386 : 73428305 : rs2->refuse_visibility_changes = true;
2387 : 73428305 : return 0;
2388 : : }
2389 : :
2390 : 11442678 : 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 : 11442578 : if (VAR_P (decl)
2396 : 11442578 : && (lookup_attribute ("non overlapping", DECL_ATTRIBUTES (decl))
2397 : 11440442 : || lookup_attribute ("non overlapping", DECL_ATTRIBUTES (s2->decl))))
2398 : 2109 : 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 : 11440469 : 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 : 144460 : symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
2418 : : void *),
2419 : : void *data,
2420 : : bool include_overwritable)
2421 : : {
2422 : 144460 : ipa_ref *ref;
2423 : 308299 : FOR_EACH_ALIAS (this, ref)
2424 : : {
2425 : 165118 : symtab_node *alias = ref->referring;
2426 : 165118 : if (include_overwritable
2427 : 165118 : || alias->get_availability () > AVAIL_INTERPOSABLE)
2428 : 165118 : 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 : 606600 : address_matters_1 (symtab_node *n, void *)
2439 : : {
2440 : 606600 : struct ipa_ref *ref;
2441 : :
2442 : 606600 : if (!n->address_can_be_compared_p ())
2443 : : return false;
2444 : 594200 : if (n->externally_visible || n->force_output)
2445 : : return true;
2446 : :
2447 : 496048 : for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
2448 : 442480 : 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 : 584449 : symtab_node::address_matters_p ()
2458 : : {
2459 : 584449 : gcc_assert (!alias);
2460 : 584449 : 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 : 29251 : symtab_node::can_increase_alignment_p (void)
2467 : : {
2468 : 29251 : symtab_node *target = ultimate_alias_target ();
2469 : :
2470 : : /* For now support only variables. */
2471 : 29251 : if (!VAR_P (decl))
2472 : : return false;
2473 : :
2474 : : /* With -fno-toplevel-reorder we may have already output the constant. */
2475 : 29251 : 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 : 28564 : if (DECL_RTL_SET_P (target->decl)
2481 : 13752 : && MEM_P (DECL_RTL (target->decl))
2482 : 42316 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
2483 : : return false;
2484 : :
2485 : : /* Constant pool entries may be shared. */
2486 : 28564 : 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 : 26442 : 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 : 17439 : if (flag_ltrans
2498 : 17439 : && (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 : 17439 : 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 : 17439 : 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 : 4821 : increase_alignment_1 (symtab_node *n, void *v)
2520 : : {
2521 : 4821 : unsigned int align = (size_t)v;
2522 : 4821 : if (DECL_ALIGN (n->decl) < align
2523 : 4821 : && n->can_increase_alignment_p ())
2524 : : {
2525 : 3852 : SET_DECL_ALIGN (n->decl, align);
2526 : 3852 : DECL_USER_ALIGN (n->decl) = 1;
2527 : : }
2528 : 4821 : return false;
2529 : : }
2530 : :
2531 : : /* Increase alignment of THIS to ALIGN. */
2532 : :
2533 : : void
2534 : 4649 : symtab_node::increase_alignment (unsigned int align)
2535 : : {
2536 : 4649 : gcc_assert (can_increase_alignment_p () && align <= MAX_OFILE_ALIGNMENT);
2537 : 4649 : ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
2538 : 4649 : (void *)(size_t) align,
2539 : : true);
2540 : 4649 : gcc_assert (DECL_ALIGN (decl) >= align);
2541 : 4649 : }
2542 : :
2543 : : /* Helper for symtab_node::definition_alignment. */
2544 : :
2545 : : static bool
2546 : 1685893 : get_alignment_1 (symtab_node *n, void *v)
2547 : : {
2548 : 1685893 : *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
2549 : 1685893 : 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 : 1626569 : symtab_node::definition_alignment ()
2559 : : {
2560 : 1626569 : unsigned int align = 0;
2561 : 1626569 : gcc_assert (!alias);
2562 : 1626569 : call_for_symbol_and_aliases (get_alignment_1, &align, true);
2563 : 1626569 : return align;
2564 : : }
2565 : :
2566 : : /* Return symbol used to separate symbol name from suffix. */
2567 : :
2568 : : char
2569 : 305052 : symbol_table::symbol_suffix_separator ()
2570 : : {
2571 : : #ifndef NO_DOT_IN_LABEL
2572 : 305052 : 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 : 94256235 : symtab_node::binds_to_current_def_p (symtab_node *ref)
2585 : : {
2586 : 94256235 : if (!definition && !in_other_partition)
2587 : : return false;
2588 : 46400990 : if (transparent_alias)
2589 : 13 : return definition
2590 : 13 : && get_alias_target()->binds_to_current_def_p (ref);
2591 : 46400977 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2592 : 46400977 : if (cnode && cnode->ifunc_resolver)
2593 : : return false;
2594 : 46400877 : if (decl_binds_to_current_def_p (decl))
2595 : : return true;
2596 : :
2597 : : /* Inline clones always binds locally. */
2598 : 22052633 : if (cnode && cnode->inlined_to)
2599 : : return true;
2600 : :
2601 : 22026897 : if (DECL_EXTERNAL (decl))
2602 : : return false;
2603 : :
2604 : 18903326 : gcc_assert (externally_visible);
2605 : :
2606 : 18903326 : if (ref)
2607 : : {
2608 : 157928 : cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
2609 : 157928 : if (cref)
2610 : 157928 : 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 : 4387 : if (this == ref && !has_aliases_p ()
2622 : 162248 : && (!cnode
2623 : 4320 : || symtab->state >= IPA_SSA_AFTER_INLINING
2624 : 0 : || get_availability () >= AVAIL_INTERPOSABLE))
2625 : 4320 : return true;
2626 : :
2627 : :
2628 : : /* References within one comdat group are always bound in a group. */
2629 : 18899006 : if (ref
2630 : 87884 : && symtab->state >= IPA_SSA_AFTER_INLINING
2631 : 87884 : && get_comdat_group ()
2632 : 18986886 : && 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 : 1194976 : symtab_node::output_to_lto_symbol_table_p (void)
2642 : : {
2643 : : /* Only externally visible symbols matter. */
2644 : 1194976 : if (!TREE_PUBLIC (decl))
2645 : : return false;
2646 : 1125178 : if (!real_symbol_p ())
2647 : : return false;
2648 : : /* FIXME: variables probably should not be considered as real symbols at
2649 : : first place. */
2650 : 1125178 : if (VAR_P (decl) && DECL_HARD_REGISTER (decl))
2651 : : return false;
2652 : 658840 : if (TREE_CODE (decl) == FUNCTION_DECL && !definition
2653 : 1589114 : && 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 : 40674 : 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 : 1084480 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2672 : 618166 : if (cnode && (!definition || DECL_EXTERNAL (decl))
2673 : 423590 : && 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 : 1062782 : if (!definition || DECL_EXTERNAL (decl))
2681 : : {
2682 : : int i;
2683 : : struct ipa_ref *ref;
2684 : 408388 : for (i = 0; iterate_referring (i, ref); i++)
2685 : : {
2686 : 408340 : if (ref->use == IPA_REF_ALIAS)
2687 : 48 : continue;
2688 : 816632 : 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 : : }
|