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 : 559293296 : symbol_table::decl_assembler_name_hash (const_tree asmname)
83 : : {
84 : 559293296 : if (IDENTIFIER_POINTER (asmname)[0] == '*')
85 : : {
86 : 2932502 : const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
87 : 2932502 : size_t ulp_len = strlen (user_label_prefix);
88 : :
89 : 2932502 : 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 : 2932502 : return htab_hash_string (decl_str);
95 : : }
96 : :
97 : 556360794 : 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 : 484153606 : symbol_table::assembler_names_equal_p (const char *name1, const char *name2)
105 : : {
106 : 484153606 : if (name1 != name2)
107 : : {
108 : 484153507 : if (name1[0] == '*')
109 : : {
110 : 2474110 : size_t ulp_len = strlen (user_label_prefix);
111 : :
112 : 2474110 : name1 ++;
113 : :
114 : 2474110 : 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 : 484153507 : if (name2[0] == '*')
122 : : {
123 : 2309685 : size_t ulp_len = strlen (user_label_prefix);
124 : :
125 : 2309685 : name2 ++;
126 : :
127 : 2309685 : 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 : 484153507 : return !strcmp (name1, name2);
135 : : }
136 : : return true;
137 : : }
138 : :
139 : : /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
140 : :
141 : : bool
142 : 580792065 : symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
143 : : {
144 : 580792065 : tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
145 : 580792065 : const char *decl_str;
146 : 580792065 : const char *asmname_str;
147 : :
148 : 580792065 : if (decl_asmname == asmname)
149 : : return true;
150 : :
151 : 484153507 : decl_str = IDENTIFIER_POINTER (decl_asmname);
152 : 484153507 : asmname_str = IDENTIFIER_POINTER (asmname);
153 : 484153507 : 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 : 131955689 : symbol_table::insert_to_assembler_name_hash (symtab_node *node,
163 : : bool with_clones)
164 : : {
165 : 159257707 : if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
166 : : return;
167 : 131955480 : gcc_checking_assert (!node->previous_sharing_asm_name
168 : : && !node->next_sharing_asm_name);
169 : 131955480 : if (assembler_name_hash)
170 : : {
171 : 11916769 : symtab_node **aslot;
172 : 11916769 : cgraph_node *cnode;
173 : 11916769 : tree decl = node->decl;
174 : :
175 : 11916769 : 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 : 11916769 : if (!name)
180 : 0 : return;
181 : :
182 : 11916769 : hashval_t hash = decl_assembler_name_hash (name);
183 : 11916769 : aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
184 : 11916769 : gcc_assert (*aslot != node);
185 : 11916769 : node->next_sharing_asm_name = (symtab_node *)*aslot;
186 : 11916769 : if (*aslot != NULL)
187 : 3200662 : (*aslot)->previous_sharing_asm_name = node;
188 : 11916769 : *aslot = node;
189 : :
190 : : /* Update also possible inline clones sharing a decl. */
191 : 23833538 : cnode = dyn_cast <cgraph_node *> (node);
192 : 8557364 : 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 : 116306439 : symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
204 : : bool with_clones)
205 : : {
206 : 116306439 : if (assembler_name_hash)
207 : : {
208 : 5125387 : cgraph_node *cnode;
209 : 5125387 : tree decl = node->decl;
210 : :
211 : 5125387 : if (node->next_sharing_asm_name)
212 : 2766806 : node->next_sharing_asm_name->previous_sharing_asm_name
213 : 2766806 : = node->previous_sharing_asm_name;
214 : 5125387 : if (node->previous_sharing_asm_name)
215 : : {
216 : 1037345 : node->previous_sharing_asm_name->next_sharing_asm_name
217 : 1037345 : = node->next_sharing_asm_name;
218 : : }
219 : : else
220 : : {
221 : 4088042 : tree name = DECL_ASSEMBLER_NAME (node->decl);
222 : 4088042 : symtab_node **slot;
223 : :
224 : 4088042 : if (!name)
225 : 0 : return;
226 : :
227 : 4088042 : hashval_t hash = decl_assembler_name_hash (name);
228 : 4088042 : slot = assembler_name_hash->find_slot_with_hash (name, hash,
229 : : NO_INSERT);
230 : 4088042 : gcc_assert (*slot == node);
231 : 4088042 : if (!node->next_sharing_asm_name)
232 : 2103466 : assembler_name_hash->clear_slot (slot);
233 : : else
234 : 1984576 : *slot = node->next_sharing_asm_name;
235 : : }
236 : 5125387 : node->next_sharing_asm_name = NULL;
237 : 5125387 : node->previous_sharing_asm_name = NULL;
238 : :
239 : : /* Update also possible inline clones sharing a decl. */
240 : 5125387 : cnode = dyn_cast <cgraph_node *> (node);
241 : 5022036 : 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 : 2057 : symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
252 : : {
253 : 2057 : unlink_from_assembler_name_hash (node, false);
254 : 2057 : insert_to_assembler_name_hash (node, false);
255 : 2057 : }
256 : :
257 : : /* Initialize asm name hash unless. */
258 : :
259 : : void
260 : 84300155 : symbol_table::symtab_initialize_asm_name_hash (void)
261 : : {
262 : 84300155 : symtab_node *node;
263 : 84300155 : if (!assembler_name_hash)
264 : : {
265 : 244785 : assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
266 : 8815094 : FOR_EACH_SYMBOL (node)
267 : 8570309 : insert_to_assembler_name_hash (node, false);
268 : : }
269 : 84300155 : }
270 : :
271 : : /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
272 : :
273 : : void
274 : 2849065 : symbol_table::change_decl_assembler_name (tree decl, tree name)
275 : : {
276 : 2849065 : 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 : 13512 : if ((VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
281 : 2850152 : || TREE_CODE (decl) == FUNCTION_DECL)
282 : 2847978 : node = symtab_node::get (decl);
283 : 2849065 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
284 : : {
285 : 1843420 : SET_DECL_ASSEMBLER_NAME (decl, name);
286 : 1843420 : if (node)
287 : 11 : insert_to_assembler_name_hash (node, true);
288 : : }
289 : : else
290 : : {
291 : 1005645 : if (name == DECL_ASSEMBLER_NAME (decl))
292 : : return;
293 : :
294 : 157543 : tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
295 : 157543 : ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
296 : 0 : : NULL);
297 : 157543 : if (node)
298 : 7952 : unlink_from_assembler_name_hash (node, true);
299 : :
300 : 157543 : const char *old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
301 : 157543 : if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
302 : 157543 : && DECL_RTL_SET_P (decl))
303 : 0 : warning (0, "%qD renamed after being referenced in assembly", decl);
304 : :
305 : 157543 : SET_DECL_ASSEMBLER_NAME (decl, name);
306 : 157543 : if (DECL_RTL_SET_P (decl))
307 : : {
308 : 1 : SET_DECL_RTL (decl, NULL);
309 : 1 : make_decl_rtl (decl);
310 : : }
311 : 157543 : 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 : 157543 : if (node)
322 : : {
323 : 7952 : insert_to_assembler_name_hash (node, true);
324 : 7952 : ipa_ref *ref;
325 : 7978 : 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 : 7952 : 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 : 12366653 : section_name_hasher::hash (section_hash_entry *n)
366 : : {
367 : 12366653 : return htab_hash_string (n->name);
368 : : }
369 : :
370 : : /* Return true if section P1 name equals to P2. */
371 : :
372 : : bool
373 : 12306387 : section_name_hasher::equal (section_hash_entry *n1, const char *name)
374 : : {
375 : 12306387 : 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 : 47438 : retain_section_hash_entry (section_hash_entry *entry)
382 : : {
383 : 47438 : entry->ref_count++;
384 : 47438 : 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 : 1883201 : release_section_hash_entry (section_hash_entry *entry)
392 : : {
393 : 1883201 : if (entry)
394 : : {
395 : 27771 : entry->ref_count--;
396 : 27771 : if (!entry->ref_count)
397 : : {
398 : 24219 : hashval_t hash = htab_hash_string (entry->name);
399 : 24219 : section_hash_entry **slot
400 : 24219 : = symtab->section_hash->find_slot_with_hash (entry->name,
401 : : hash, INSERT);
402 : 24219 : ggc_free (entry);
403 : 24219 : symtab->section_hash->clear_slot (slot);
404 : : }
405 : : }
406 : 1883201 : }
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 : 123375358 : symtab_node::register_symbol (void)
413 : : {
414 : 123375358 : symtab->register_symbol (this);
415 : :
416 : 123375358 : if (!decl->decl_with_vis.symtab_node)
417 : 120302544 : decl->decl_with_vis.symtab_node = this;
418 : :
419 : 123375358 : ref_list.clear ();
420 : :
421 : : /* Be sure to do this last; C++ FE might create new nodes via
422 : : DECL_ASSEMBLER_NAME langhook! */
423 : 123375358 : symtab->insert_to_assembler_name_hash (this, false);
424 : 123375358 : }
425 : :
426 : : /* Remove NODE from same comdat group. */
427 : :
428 : : void
429 : 126690147 : symtab_node::remove_from_same_comdat_group (void)
430 : : {
431 : 126690147 : if (same_comdat_group)
432 : : {
433 : : symtab_node *prev;
434 : : for (prev = same_comdat_group;
435 : 14071499 : prev->same_comdat_group != this;
436 : : prev = prev->same_comdat_group)
437 : : ;
438 : 13433235 : if (same_comdat_group == prev)
439 : 13034418 : prev->same_comdat_group = NULL;
440 : : else
441 : 398817 : prev->same_comdat_group = same_comdat_group;
442 : 13433235 : same_comdat_group = NULL;
443 : 13433235 : set_comdat_group (NULL);
444 : : }
445 : 126690147 : }
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 : 116296429 : symtab_node::unregister (clone_info *info)
453 : : {
454 : 116296429 : remove_all_references ();
455 : 116296429 : remove_all_referring ();
456 : :
457 : : /* Remove reference to section. */
458 : 116296429 : set_section_for_node (NULL);
459 : :
460 : 116296429 : remove_from_same_comdat_group ();
461 : :
462 : 116296429 : symtab->unregister (this);
463 : :
464 : : /* During LTO symtab merging we temporarily corrupt decl to symtab node
465 : : hash. */
466 : 116296429 : gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
467 : 116296429 : if (decl->decl_with_vis.symtab_node == this)
468 : : {
469 : 113727938 : symtab_node *replacement_node = NULL;
470 : 113727938 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
471 : 93094075 : replacement_node = cnode->find_replacement (info);
472 : 113727938 : decl->decl_with_vis.symtab_node = replacement_node;
473 : : }
474 : 116296429 : if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
475 : 116296428 : symtab->unlink_from_assembler_name_hash (this, false);
476 : 116296429 : if (in_init_priority_hash)
477 : 107 : symtab->init_priority_hash->remove (this);
478 : 116296429 : }
479 : :
480 : :
481 : : /* Remove symbol from symbol table. */
482 : :
483 : : void
484 : 111176813 : symtab_node::remove (void)
485 : : {
486 : 111176813 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
487 : 90642772 : cnode->remove ();
488 : 20534041 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
489 : 20534041 : vnode->remove ();
490 : 111176813 : }
491 : :
492 : : /* Add NEW_ to the same comdat group that OLD is in. */
493 : :
494 : : void
495 : 13507409 : symtab_node::add_to_same_comdat_group (symtab_node *old_node)
496 : : {
497 : 13507409 : gcc_assert (old_node->get_comdat_group ());
498 : 13507409 : gcc_assert (!same_comdat_group);
499 : 13507409 : gcc_assert (this != old_node);
500 : :
501 : 13507409 : set_comdat_group (old_node->get_comdat_group ());
502 : 13507409 : same_comdat_group = old_node;
503 : 13507409 : if (!old_node->same_comdat_group)
504 : 13090116 : old_node->same_comdat_group = this;
505 : : else
506 : : {
507 : : symtab_node *n;
508 : : for (n = old_node->same_comdat_group;
509 : 761762 : n->same_comdat_group != old_node;
510 : : n = n->same_comdat_group)
511 : : ;
512 : 417293 : n->same_comdat_group = this;
513 : : }
514 : :
515 : 13507409 : cgraph_node *n;
516 : 13519951 : if (comdat_local_p ()
517 : 13519944 : && (n = dyn_cast <cgraph_node *> (this)) != NULL)
518 : : {
519 : 27336 : for (cgraph_edge *e = n->callers; e; e = e->next_caller)
520 : 14801 : if (e->caller->inlined_to)
521 : 3547 : e->caller->inlined_to->calls_comdat_local = true;
522 : : else
523 : 11254 : e->caller->calls_comdat_local = true;
524 : : }
525 : 13507409 : }
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 : 44480 : symtab_node::asm_name () const
558 : : {
559 : 44480 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
560 : 195 : return name ();
561 : 44285 : return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
562 : : }
563 : :
564 : : /* Return printable identifier name. */
565 : :
566 : : const char *
567 : 44839 : symtab_node::name () const
568 : : {
569 : 44839 : 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 : 44839 : return lang_hooks.decl_printable_name (decl, 2);
577 : : }
578 : :
579 : : const char *
580 : 80293 : symtab_node::get_dump_name (bool asm_name_p) const
581 : : {
582 : : #define EXTRA 16
583 : 80293 : const char *fname = asm_name_p ? asm_name () : name ();
584 : 80293 : unsigned l = strlen (fname);
585 : :
586 : 80293 : char *s = (char *)ggc_internal_cleared_alloc (l + EXTRA);
587 : 80293 : snprintf (s, l + EXTRA, "%s/%d", fname, m_uid);
588 : :
589 : 80293 : return s;
590 : : }
591 : :
592 : : const char *
593 : 36122 : symtab_node::dump_name () const
594 : : {
595 : 36122 : return get_dump_name (false);
596 : : }
597 : :
598 : : const char *
599 : 44171 : symtab_node::dump_asm_name () const
600 : : {
601 : 44171 : 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 : 6752915 : symtab_node::create_reference (symtab_node *referred_node,
610 : : enum ipa_ref_use use_type)
611 : : {
612 : 6752915 : 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 : 40466455 : symtab_node::create_reference (symtab_node *referred_node,
622 : : enum ipa_ref_use use_type, gimple *stmt)
623 : : {
624 : 40466455 : ipa_ref *ref = NULL, *ref2 = NULL;
625 : 40466455 : ipa_ref_list *list, *list2;
626 : 40466455 : ipa_ref_t *old_references;
627 : :
628 : 40466455 : gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
629 : 40466455 : gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
630 : :
631 : 40466455 : list = &ref_list;
632 : 40466455 : old_references = list->references.address ();
633 : 67888538 : list->references.safe_grow (list->references.length () + 1, false);
634 : 40466455 : ref = &list->references.last ();
635 : :
636 : 40466455 : list2 = &referred_node->ref_list;
637 : :
638 : : /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
639 : 40466455 : if(use_type == IPA_REF_ALIAS)
640 : : {
641 : 6910041 : list2->referring.safe_insert (0, ref);
642 : 6910041 : ref->referred_index = 0;
643 : :
644 : 7052593 : for (unsigned int i = 1; i < list2->referring.length (); i++)
645 : 142552 : list2->referring[i]->referred_index = i;
646 : : }
647 : : else
648 : : {
649 : 33556414 : list2->referring.safe_push (ref);
650 : 67112828 : ref->referred_index = list2->referring.length () - 1;
651 : : }
652 : :
653 : 40466455 : ref->referring = this;
654 : 40466455 : ref->referred = referred_node;
655 : 40466455 : ref->stmt = stmt;
656 : 40466455 : ref->lto_stmt_uid = 0;
657 : 40466455 : ref->speculative_id = 0;
658 : 40466455 : ref->use = use_type;
659 : 40466455 : ref->speculative = 0;
660 : :
661 : : /* If vector was moved in memory, update pointers. */
662 : 80932910 : if (old_references != list->references.address ())
663 : : {
664 : : int i;
665 : 50533486 : for (i = 0; iterate_reference(i, ref2); i++)
666 : 36163117 : ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
667 : : }
668 : 40466455 : return ref;
669 : : }
670 : :
671 : : ipa_ref *
672 : 53633 : symtab_node::maybe_create_reference (tree val, gimple *stmt)
673 : : {
674 : 53633 : STRIP_NOPS (val);
675 : 53633 : ipa_ref_use use_type;
676 : :
677 : 53633 : switch (TREE_CODE (val))
678 : : {
679 : : case VAR_DECL:
680 : : use_type = IPA_REF_LOAD;
681 : : break;
682 : 8223 : case ADDR_EXPR:
683 : 8223 : use_type = IPA_REF_ADDR;
684 : 8223 : break;
685 : 45020 : default:
686 : 45020 : gcc_assert (!handled_component_p (val));
687 : : return NULL;
688 : : }
689 : :
690 : 8613 : val = get_base_var (val);
691 : 8613 : if (val && VAR_OR_FUNCTION_DECL_P (val))
692 : : {
693 : 4948 : symtab_node *referred = symtab_node::get (val);
694 : 4948 : gcc_checking_assert (referred);
695 : 4948 : 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 : 3200783 : symtab_node::clone_references (symtab_node *node)
704 : : {
705 : 3200783 : ipa_ref *ref = NULL, *ref2 = NULL;
706 : 3200783 : int i;
707 : 4012716 : for (i = 0; node->iterate_reference (i, ref); i++)
708 : : {
709 : 811933 : bool speculative = ref->speculative;
710 : 811933 : unsigned int stmt_uid = ref->lto_stmt_uid;
711 : 811933 : unsigned int spec_id = ref->speculative_id;
712 : :
713 : 811933 : ref2 = create_reference (ref->referred, ref->use, ref->stmt);
714 : 811933 : ref2->speculative = speculative;
715 : 811933 : ref2->lto_stmt_uid = stmt_uid;
716 : 811933 : ref2->speculative_id = spec_id;
717 : : }
718 : 3200783 : }
719 : :
720 : : /* Clone all referring from symtab NODE to this symtab_node. */
721 : :
722 : : void
723 : 2655 : symtab_node::clone_referring (symtab_node *node)
724 : : {
725 : 2655 : ipa_ref *ref = NULL, *ref2 = NULL;
726 : 2655 : int i;
727 : 4574 : 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 : 2655 : }
739 : :
740 : : /* Clone reference REF to this symtab_node and set its stmt to STMT. */
741 : :
742 : : ipa_ref *
743 : 26572 : symtab_node::clone_reference (ipa_ref *ref, gimple *stmt)
744 : : {
745 : 26572 : bool speculative = ref->speculative;
746 : 26572 : unsigned int stmt_uid = ref->lto_stmt_uid;
747 : 26572 : unsigned int spec_id = ref->speculative_id;
748 : 26572 : ipa_ref *ref2;
749 : :
750 : 26572 : ref2 = create_reference (ref->referred, ref->use, stmt);
751 : 26572 : ref2->speculative = speculative;
752 : 26572 : ref2->lto_stmt_uid = stmt_uid;
753 : 26572 : ref2->speculative_id = spec_id;
754 : 26572 : 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 : 10623 : 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 : 10623 : ipa_ref *r = NULL;
766 : 10623 : int i;
767 : :
768 : 56876 : for (i = 0; iterate_reference (i, r); i++)
769 : 56873 : if (r->referred == referred_node
770 : 17343 : && !r->speculative
771 : 17343 : && r->use == use_type
772 : 14232 : && ((stmt && r->stmt == stmt)
773 : 4232 : || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
774 : 4068 : || (!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 : 73372 : symtab_node::remove_stmt_references (gimple *stmt)
783 : : {
784 : 73372 : ipa_ref *r = NULL;
785 : 73372 : int i = 0;
786 : :
787 : 77024 : while (iterate_reference (i, r))
788 : 3652 : if (r->stmt == stmt)
789 : 0 : r->remove_reference ();
790 : : else
791 : 3652 : i++;
792 : 73372 : }
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 : 2153228 : symtab_node::clear_stmts_in_references (void)
802 : : {
803 : 2153228 : ipa_ref *r = NULL;
804 : 2153228 : int i;
805 : :
806 : 8624795 : for (i = 0; iterate_reference (i, r); i++)
807 : 6471567 : if (!r->speculative)
808 : : {
809 : 6458252 : r->stmt = NULL;
810 : 6458252 : r->lto_stmt_uid = 0;
811 : 6458252 : r->speculative_id = 0;
812 : : }
813 : 2153228 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
814 : 2153228 : if (cnode)
815 : : {
816 : 2153228 : if (cnode->clones)
817 : 678469 : for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
818 : 559939 : cnode->clear_stmts_in_references ();
819 : : }
820 : 2153228 : }
821 : :
822 : : /* Remove all references in ref list. */
823 : :
824 : : void
825 : 241158011 : symtab_node::remove_all_references (void)
826 : : {
827 : 277360972 : while (ref_list.references.length ())
828 : 36202961 : ref_list.references.last ().remove_reference ();
829 : 241158011 : ref_list.references.release ();
830 : 241158011 : }
831 : :
832 : : /* Remove all referring items in ref list. */
833 : :
834 : : void
835 : 116296429 : symtab_node::remove_all_referring (void)
836 : : {
837 : 116396860 : while (ref_list.referring.length ())
838 : 100431 : ref_list.referring.last ()->remove_reference ();
839 : 116296429 : ref_list.referring.release ();
840 : 116296429 : }
841 : :
842 : : /* Dump references in ref list to FILE. */
843 : :
844 : : void
845 : 8318 : symtab_node::dump_references (FILE *file)
846 : : {
847 : 8318 : ipa_ref *ref = NULL;
848 : 8318 : int i;
849 : 15445 : for (i = 0; iterate_reference (i, ref); i++)
850 : : {
851 : 7127 : fprintf (file, "%s (%s) ", ref->referred->dump_asm_name (),
852 : 7127 : ipa_ref_use_name[ref->use]);
853 : 7127 : if (ref->speculative)
854 : 107 : fprintf (file, "(speculative) ");
855 : : }
856 : 8318 : fprintf (file, "\n");
857 : 8318 : }
858 : :
859 : : /* Dump referring in list to FILE. */
860 : :
861 : : void
862 : 8318 : symtab_node::dump_referring (FILE *file)
863 : : {
864 : 8318 : ipa_ref *ref = NULL;
865 : 8318 : int i;
866 : 13376 : for (i = 0; iterate_referring(i, ref); i++)
867 : : {
868 : 5058 : fprintf (file, "%s (%s) ", ref->referring->dump_asm_name (),
869 : 5058 : ipa_ref_use_name[ref->use]);
870 : 5058 : if (ref->speculative)
871 : 101 : fprintf (file, "(speculative) ");
872 : : }
873 : 8318 : fprintf (file, "\n");
874 : 8318 : }
875 : :
876 : : static const char * const toplevel_type_names[] =
877 : : {
878 : : "base",
879 : : "asm",
880 : : "symbol",
881 : : "function",
882 : : "variable",
883 : : };
884 : :
885 : : static_assert (ARRAY_SIZE(toplevel_type_names) == TOPLEVEL_MAX, "");
886 : :
887 : : /* Dump the visibility of the symbol. */
888 : :
889 : : const char *
890 : 0 : symtab_node::get_visibility_string () const
891 : : {
892 : 0 : static const char * const visibility_types[]
893 : : = { "default", "protected", "hidden", "internal" };
894 : 0 : return visibility_types[DECL_VISIBILITY (decl)];
895 : : }
896 : :
897 : : /* Dump the type_name of the symbol. */
898 : : const char *
899 : 0 : symtab_node::get_symtab_type_string () const
900 : : {
901 : 0 : return toplevel_type_names[type];
902 : : }
903 : :
904 : : /* Dump base fields of symtab nodes to F. Not to be used directly. */
905 : :
906 : : void
907 : 8318 : symtab_node::dump_base (FILE *f)
908 : : {
909 : 8318 : static const char * const visibility_types[] = {
910 : : "default", "protected", "hidden", "internal"
911 : : };
912 : :
913 : 8318 : fprintf (f, "%s (%s)", dump_asm_name (), name ());
914 : 8318 : if (dump_flags & TDF_ADDRESS)
915 : 103 : dump_addr (f, " @", (void *)this);
916 : 8318 : fprintf (f, "\n Type: %s", toplevel_type_names[type]);
917 : :
918 : 8318 : if (definition)
919 : 6374 : fprintf (f, " definition");
920 : 8318 : if (analyzed)
921 : 6371 : fprintf (f, " analyzed");
922 : 8318 : if (alias)
923 : 100 : fprintf (f, " alias");
924 : 8318 : if (transparent_alias)
925 : 0 : fprintf (f, " transparent_alias");
926 : 8318 : if (weakref)
927 : 0 : fprintf (f, " weakref");
928 : 8318 : if (symver)
929 : 0 : fprintf (f, " symver");
930 : 8318 : if (cpp_implicit_alias)
931 : 81 : fprintf (f, " cpp_implicit_alias");
932 : 8318 : if (alias_target)
933 : 0 : fprintf (f, " target:%s",
934 : 0 : DECL_P (alias_target)
935 : 0 : ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
936 : : (alias_target))
937 : 0 : : IDENTIFIER_POINTER (alias_target));
938 : 8318 : if (body_removed)
939 : 626 : fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
940 : 8318 : fprintf (f, "\n Visibility:");
941 : 8318 : if (in_other_partition)
942 : 0 : fprintf (f, " in_other_partition");
943 : 8318 : if (used_from_other_partition)
944 : 0 : fprintf (f, " used_from_other_partition");
945 : 8318 : if (force_output)
946 : 640 : fprintf (f, " force_output");
947 : 8318 : if (forced_by_abi)
948 : 540 : fprintf (f, " forced_by_abi");
949 : 8318 : if (externally_visible)
950 : 3885 : fprintf (f, " externally_visible");
951 : 8318 : if (semantic_interposition)
952 : 7883 : fprintf (f, " semantic_interposition");
953 : 8318 : if (no_reorder)
954 : 555 : fprintf (f, " no_reorder");
955 : 8318 : if (resolution != LDPR_UNKNOWN)
956 : 1070 : fprintf (f, " %s",
957 : 1070 : ld_plugin_symbol_resolution_names[(int)resolution]);
958 : 8318 : if (TREE_ASM_WRITTEN (decl))
959 : 194 : fprintf (f, " asm_written");
960 : 8318 : if (DECL_EXTERNAL (decl))
961 : 1694 : fprintf (f, " external");
962 : 8318 : if (TREE_PUBLIC (decl))
963 : 6464 : fprintf (f, " public");
964 : 8318 : if (DECL_COMMON (decl))
965 : 22 : fprintf (f, " common");
966 : 8318 : if (DECL_WEAK (decl))
967 : 1494 : fprintf (f, " weak");
968 : 8318 : if (DECL_DLLIMPORT_P (decl))
969 : 0 : fprintf (f, " dll_import");
970 : 8318 : if (DECL_COMDAT (decl))
971 : 1458 : fprintf (f, " comdat");
972 : 8318 : if (get_comdat_group ())
973 : 2710 : fprintf (f, " comdat_group:%s",
974 : 1355 : IDENTIFIER_POINTER (get_comdat_group_id ()));
975 : 8318 : if (DECL_ONE_ONLY (decl))
976 : 1407 : fprintf (f, " one_only");
977 : 8318 : if (get_section ())
978 : 38 : fprintf (f, " section:%s",
979 : : get_section ());
980 : 8318 : if (implicit_section)
981 : 36 : fprintf (f," (implicit_section)");
982 : 8318 : if (DECL_VISIBILITY_SPECIFIED (decl))
983 : 577 : fprintf (f, " visibility_specified");
984 : 8318 : if (DECL_VISIBILITY (decl))
985 : 40 : fprintf (f, " visibility:%s",
986 : 20 : visibility_types [DECL_VISIBILITY (decl)]);
987 : 8318 : if (DECL_VIRTUAL_P (decl))
988 : 1330 : fprintf (f, " virtual");
989 : 8318 : if (DECL_ARTIFICIAL (decl))
990 : 2308 : fprintf (f, " artificial");
991 : 8318 : if (TREE_CODE (decl) == FUNCTION_DECL)
992 : : {
993 : 5857 : if (DECL_STATIC_CONSTRUCTOR (decl))
994 : 48 : fprintf (f, " constructor");
995 : 5857 : if (DECL_STATIC_DESTRUCTOR (decl))
996 : 7 : fprintf (f, " destructor");
997 : : }
998 : 8318 : if (ifunc_resolver)
999 : 3 : fprintf (f, " ifunc_resolver");
1000 : 8318 : fprintf (f, "\n");
1001 : :
1002 : 8318 : if (same_comdat_group)
1003 : 158 : fprintf (f, " Same comdat group as: %s\n",
1004 : : same_comdat_group->dump_asm_name ());
1005 : 8318 : if (next_sharing_asm_name)
1006 : 410 : fprintf (f, " next sharing asm name: %i\n",
1007 : 410 : next_sharing_asm_name->get_uid ());
1008 : 8318 : if (previous_sharing_asm_name)
1009 : 374 : fprintf (f, " previous sharing asm name: %i\n",
1010 : 374 : previous_sharing_asm_name->get_uid ());
1011 : :
1012 : 8318 : if (address_taken)
1013 : 874 : fprintf (f, " Address is taken.\n");
1014 : 8318 : if (aux)
1015 : : {
1016 : 511 : fprintf (f, " Aux:");
1017 : 511 : dump_addr (f, " @", (void *)aux);
1018 : 511 : fprintf (f, "\n");
1019 : : }
1020 : :
1021 : 8318 : fprintf (f, " References: ");
1022 : 8318 : dump_references (f);
1023 : 8318 : fprintf (f, " Referring: ");
1024 : 8318 : dump_referring (f);
1025 : 8318 : if (lto_file_data)
1026 : 232 : fprintf (f, " Read from file: %s\n",
1027 : : lto_file_data->file_name);
1028 : 8318 : }
1029 : :
1030 : : /* Dump symtab node to F. */
1031 : :
1032 : : void
1033 : 7463 : symtab_node::dump (FILE *f)
1034 : : {
1035 : 7463 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
1036 : 5002 : cnode->dump (f);
1037 : 2461 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
1038 : 2461 : vnode->dump (f);
1039 : 7463 : }
1040 : :
1041 : : void
1042 : 0 : symtab_node::dump_graphviz (FILE *f)
1043 : : {
1044 : 0 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
1045 : 0 : cnode->dump_graphviz (f);
1046 : 0 : }
1047 : :
1048 : : void
1049 : 1251 : symbol_table::dump (FILE *f)
1050 : : {
1051 : 1251 : symtab_node *node;
1052 : 1251 : fprintf (f, "Symbol table:\n\n");
1053 : 8711 : FOR_EACH_SYMBOL (node)
1054 : 7460 : node->dump (f);
1055 : 1251 : }
1056 : :
1057 : : void
1058 : 0 : symbol_table::dump_graphviz (FILE *f)
1059 : : {
1060 : 0 : symtab_node *node;
1061 : 0 : fprintf (f, "digraph symtab {\n");
1062 : 0 : FOR_EACH_SYMBOL (node)
1063 : 0 : node->dump_graphviz (f);
1064 : 0 : fprintf (f, "}\n");
1065 : 0 : }
1066 : :
1067 : : DEBUG_FUNCTION void
1068 : 0 : symbol_table::debug (void)
1069 : : {
1070 : 0 : dump (stderr);
1071 : 0 : }
1072 : :
1073 : : /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1074 : : Return NULL if there's no such node. */
1075 : :
1076 : : symtab_node *
1077 : 83810639 : symtab_node::get_for_asmname (const_tree asmname)
1078 : : {
1079 : 83810639 : symtab_node *node;
1080 : :
1081 : 83810639 : symtab->symtab_initialize_asm_name_hash ();
1082 : 83810639 : hashval_t hash = symtab->decl_assembler_name_hash (asmname);
1083 : 83810639 : symtab_node **slot
1084 : 83810639 : = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
1085 : : NO_INSERT);
1086 : :
1087 : 83810639 : if (slot)
1088 : : {
1089 : 83806880 : node = *slot;
1090 : 83806880 : return node;
1091 : : }
1092 : : return NULL;
1093 : : }
1094 : :
1095 : : /* Dump symtab node NODE to stderr. */
1096 : :
1097 : : DEBUG_FUNCTION void
1098 : 0 : symtab_node::debug (void)
1099 : : {
1100 : 0 : dump (stderr);
1101 : 0 : }
1102 : :
1103 : : /* Verify common part of symtab nodes. */
1104 : :
1105 : : #if __GNUC__ >= 10
1106 : : /* Disable warnings about missing quoting in GCC diagnostics for
1107 : : the verification errors. Their format strings don't follow GCC
1108 : : diagnostic conventions and the calls are ultimately followed by
1109 : : one to internal_error. */
1110 : : # pragma GCC diagnostic push
1111 : : # pragma GCC diagnostic ignored "-Wformat-diag"
1112 : : #endif
1113 : :
1114 : : DEBUG_FUNCTION bool
1115 : 84319018 : symtab_node::verify_base (void)
1116 : : {
1117 : 84319018 : bool error_found = false;
1118 : 84319018 : symtab_node *hashed_node;
1119 : :
1120 : 84319018 : if (is_a <cgraph_node *> (this))
1121 : : {
1122 : 52511846 : if (TREE_CODE (decl) != FUNCTION_DECL)
1123 : : {
1124 : 0 : error ("function symbol is not function");
1125 : 0 : error_found = true;
1126 : : }
1127 : 52511846 : else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))
1128 : 52511846 : != NULL)
1129 : 52511846 : != dyn_cast <cgraph_node *> (this)->ifunc_resolver)
1130 : : {
1131 : 0 : error ("inconsistent %<ifunc%> attribute");
1132 : 0 : error_found = true;
1133 : : }
1134 : : }
1135 : 31807172 : else if (is_a <varpool_node *> (this))
1136 : : {
1137 : 31807172 : if (!VAR_P (decl))
1138 : : {
1139 : 0 : error ("variable symbol is not variable");
1140 : 0 : error_found = true;
1141 : : }
1142 : : }
1143 : : else
1144 : : {
1145 : 0 : error ("node has unknown type");
1146 : 0 : error_found = true;
1147 : : }
1148 : 84319018 : if (order < 0 || order >= symtab->order)
1149 : : {
1150 : 0 : error ("node has invalid order %i", order);
1151 : 0 : error_found = true;
1152 : : }
1153 : :
1154 : 84319018 : if (symtab->state != LTO_STREAMING)
1155 : : {
1156 : 84164211 : hashed_node = symtab_node::get (decl);
1157 : 84164211 : if (!hashed_node)
1158 : : {
1159 : 0 : error ("node not found node->decl->decl_with_vis.symtab_node");
1160 : 0 : error_found = true;
1161 : : }
1162 : 84164211 : if (hashed_node != this
1163 : 89765499 : && (!is_a <cgraph_node *> (this)
1164 : 5601288 : || !dyn_cast <cgraph_node *> (this)->clone_of
1165 : 5601288 : || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
1166 : : {
1167 : 0 : error ("node differs from node->decl->decl_with_vis.symtab_node");
1168 : 0 : error_found = true;
1169 : : }
1170 : : }
1171 : 84319018 : if (symtab->assembler_name_hash)
1172 : : {
1173 : 83730331 : hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
1174 : 83730331 : if (hashed_node)
1175 : : {
1176 : 83728658 : if (hashed_node->previous_sharing_asm_name)
1177 : : {
1178 : 0 : error ("assembler name hash list corrupted");
1179 : 0 : error_found = true;
1180 : : }
1181 : 83728658 : else if (previous_sharing_asm_name == NULL)
1182 : : {
1183 : 78177483 : if (hashed_node != this)
1184 : : {
1185 : 0 : error ("assembler name hash list corrupted");
1186 : 0 : error_found = true;
1187 : : }
1188 : : }
1189 : 5551175 : else if (!(is_a <varpool_node *> (this) && DECL_HARD_REGISTER (decl)))
1190 : : {
1191 : 5551175 : if (!asmname_hasher::equal (previous_sharing_asm_name,
1192 : 5551175 : DECL_ASSEMBLER_NAME (decl)))
1193 : : {
1194 : 0 : error ("node not found in symtab assembler name hash");
1195 : 0 : error_found = true;
1196 : : }
1197 : : }
1198 : : }
1199 : : }
1200 : 84319018 : if (previous_sharing_asm_name
1201 : 5551592 : && previous_sharing_asm_name->next_sharing_asm_name != this)
1202 : : {
1203 : 0 : error ("double linked list of assembler names corrupted");
1204 : 0 : error_found = true;
1205 : : }
1206 : 84319018 : if (body_removed && definition)
1207 : : {
1208 : 0 : error ("node has body_removed but is definition");
1209 : 0 : error_found = true;
1210 : : }
1211 : 84319018 : if (analyzed && !definition)
1212 : : {
1213 : 0 : error ("node is analyzed but it is not a definition");
1214 : 0 : error_found = true;
1215 : : }
1216 : 84319018 : if (cpp_implicit_alias && !alias)
1217 : : {
1218 : 0 : error ("node is alias but not implicit alias");
1219 : 0 : error_found = true;
1220 : : }
1221 : 84319018 : if (alias && !definition && !weakref)
1222 : : {
1223 : 0 : error ("node is alias but not definition");
1224 : 0 : error_found = true;
1225 : : }
1226 : 84319018 : if (weakref && !transparent_alias)
1227 : : {
1228 : 0 : error ("node is weakref but not an transparent_alias");
1229 : 0 : error_found = true;
1230 : : }
1231 : 84319018 : if (transparent_alias && !alias)
1232 : : {
1233 : 0 : error ("node is transparent_alias but not an alias");
1234 : 0 : error_found = true;
1235 : : }
1236 : 84319018 : if (symver && !alias)
1237 : : {
1238 : 0 : error ("node is symver but not alias");
1239 : 0 : error_found = true;
1240 : : }
1241 : : /* Limitation of gas requires us to output targets of symver aliases as
1242 : : global symbols. This is binutils PR 25295. */
1243 : 84319018 : if (symver
1244 : 84319018 : && (!TREE_PUBLIC (get_alias_target ()->decl)
1245 : 16 : || DECL_VISIBILITY (get_alias_target ()->decl) != VISIBILITY_DEFAULT))
1246 : : {
1247 : 0 : error ("symver target is not exported with default visibility");
1248 : 0 : error_found = true;
1249 : : }
1250 : 84319018 : if (symver
1251 : 84319018 : && (!TREE_PUBLIC (decl)
1252 : 16 : || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT))
1253 : : {
1254 : 0 : error ("symver is not exported with default visibility");
1255 : 0 : error_found = true;
1256 : : }
1257 : 84319018 : if (same_comdat_group)
1258 : : {
1259 : 3326931 : symtab_node *n = same_comdat_group;
1260 : :
1261 : 3326931 : if (!n->get_comdat_group ())
1262 : : {
1263 : 0 : error ("node is in same_comdat_group list but has no comdat_group");
1264 : 0 : error_found = true;
1265 : : }
1266 : 3326931 : if (n->get_comdat_group () != get_comdat_group ())
1267 : : {
1268 : 0 : error ("same_comdat_group list across different groups");
1269 : 0 : error_found = true;
1270 : : }
1271 : 3326931 : if (n->type != type)
1272 : : {
1273 : 0 : error ("mixing different types of symbol in same comdat groups is not supported");
1274 : 0 : error_found = true;
1275 : : }
1276 : 3326931 : if (n == this)
1277 : : {
1278 : 0 : error ("node is alone in a comdat group");
1279 : 0 : error_found = true;
1280 : : }
1281 : 5875925 : do
1282 : : {
1283 : 5875925 : if (!n->same_comdat_group)
1284 : : {
1285 : 0 : error ("same_comdat_group is not a circular list");
1286 : 0 : error_found = true;
1287 : 0 : break;
1288 : : }
1289 : 5875925 : n = n->same_comdat_group;
1290 : : }
1291 : 5875925 : while (n != this);
1292 : 3326931 : if (comdat_local_p ())
1293 : : {
1294 : 53614 : ipa_ref *ref = NULL;
1295 : :
1296 : 55055 : for (int i = 0; iterate_referring (i, ref); ++i)
1297 : : {
1298 : 1441 : if (!in_same_comdat_group_p (ref->referring))
1299 : : {
1300 : 0 : error ("comdat-local symbol referred to by %s outside its "
1301 : : "comdat",
1302 : : identifier_to_locale (ref->referring->name()));
1303 : 0 : error_found = true;
1304 : : }
1305 : : }
1306 : : }
1307 : : }
1308 : 99696345 : if (implicit_section && !get_section ())
1309 : : {
1310 : 0 : error ("implicit_section flag is set but section isn%'t");
1311 : 0 : error_found = true;
1312 : : }
1313 : 99700520 : if (get_section () && get_comdat_group ()
1314 : 2846175 : && !implicit_section
1315 : 15381712 : && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
1316 : : {
1317 : 0 : error ("Both section and comdat group is set");
1318 : 0 : error_found = true;
1319 : : }
1320 : : /* TODO: Add string table for sections, so we do not keep holding duplicated
1321 : : strings. */
1322 : 1527543 : if (alias && definition
1323 : 1586648 : && get_section () != get_alias_target ()->get_section ()
1324 : 84319018 : && (!get_section()
1325 : 0 : || !get_alias_target ()->get_section ()
1326 : 0 : || strcmp (get_section(),
1327 : : get_alias_target ()->get_section ())))
1328 : : {
1329 : 0 : error ("Alias and target%'s section differs");
1330 : 0 : get_alias_target ()->dump (stderr);
1331 : 0 : error_found = true;
1332 : : }
1333 : 1527543 : if (alias && definition
1334 : 85845311 : && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1335 : : {
1336 : 0 : error ("Alias and target%'s comdat groups differs");
1337 : 0 : get_alias_target ()->dump (stderr);
1338 : 0 : error_found = true;
1339 : : }
1340 : 84319018 : if (transparent_alias && definition && !weakref)
1341 : : {
1342 : 93 : symtab_node *to = get_alias_target ();
1343 : 93 : const char *name1
1344 : 93 : = IDENTIFIER_POINTER (
1345 : : ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl)));
1346 : 93 : const char *name2
1347 : 93 : = IDENTIFIER_POINTER (
1348 : : ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to->decl)));
1349 : 93 : if (!symbol_table::assembler_names_equal_p (name1, name2))
1350 : : {
1351 : 0 : error ("Transparent alias and target%'s assembler names differs");
1352 : 0 : get_alias_target ()->dump (stderr);
1353 : 0 : error_found = true;
1354 : : }
1355 : : }
1356 : 1442 : if (transparent_alias && definition
1357 : 84319210 : && get_alias_target()->transparent_alias && get_alias_target()->analyzed)
1358 : : {
1359 : 0 : error ("Chained transparent aliases");
1360 : 0 : get_alias_target ()->dump (stderr);
1361 : 0 : error_found = true;
1362 : : }
1363 : :
1364 : 84319018 : return error_found;
1365 : : }
1366 : :
1367 : : /* Verify consistency of NODE. */
1368 : :
1369 : : DEBUG_FUNCTION void
1370 : 84321364 : symtab_node::verify (void)
1371 : : {
1372 : 84321364 : if (seen_error ())
1373 : : return;
1374 : :
1375 : 84319018 : timevar_push (TV_CGRAPH_VERIFY);
1376 : 84319018 : if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
1377 : 52511846 : node->verify_node ();
1378 : : else
1379 : 31807172 : if (verify_base ())
1380 : : {
1381 : 0 : debug ();
1382 : 0 : internal_error ("symtab_node::verify failed");
1383 : : }
1384 : 84319018 : timevar_pop (TV_CGRAPH_VERIFY);
1385 : : }
1386 : :
1387 : : /* Return true and set *DATA to true if NODE is an ifunc resolver. */
1388 : :
1389 : : static bool
1390 : 5635029 : check_ifunc_resolver (cgraph_node *node, void *data)
1391 : : {
1392 : 5635029 : if (node->ifunc_resolver)
1393 : : {
1394 : 434 : bool *is_ifunc_resolver = (bool *) data;
1395 : 434 : *is_ifunc_resolver = true;
1396 : 434 : return true;
1397 : : }
1398 : : return false;
1399 : : }
1400 : :
1401 : : static bitmap ifunc_ref_map;
1402 : :
1403 : : /* Return true if any caller of NODE is an ifunc resolver. */
1404 : :
1405 : : static bool
1406 : 5253630 : is_caller_ifunc_resolver (cgraph_node *node)
1407 : : {
1408 : 5253630 : bool is_ifunc_resolver = false;
1409 : :
1410 : 15466182 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
1411 : : {
1412 : : /* Return true if caller is known to be an IFUNC resolver. */
1413 : 10212866 : if (e->caller->called_by_ifunc_resolver)
1414 : : return true;
1415 : :
1416 : : /* Check for recursive call. */
1417 : 10212699 : if (e->caller == node)
1418 : 11463 : continue;
1419 : :
1420 : : /* Skip if it has been visited. */
1421 : 10201236 : unsigned int uid = e->caller->get_uid ();
1422 : 10201236 : if (!bitmap_set_bit (ifunc_ref_map, uid))
1423 : 8251706 : continue;
1424 : :
1425 : 1949530 : if (is_caller_ifunc_resolver (e->caller))
1426 : : {
1427 : : /* Return true if caller is an IFUNC resolver. */
1428 : 22 : e->caller->called_by_ifunc_resolver = true;
1429 : 22 : return true;
1430 : : }
1431 : :
1432 : : /* Check if caller's alias is an IFUNC resolver. */
1433 : 1949508 : e->caller->call_for_symbol_and_aliases (check_ifunc_resolver,
1434 : : &is_ifunc_resolver,
1435 : : true);
1436 : 1949508 : if (is_ifunc_resolver)
1437 : : {
1438 : : /* Return true if caller's alias is an IFUNC resolver. */
1439 : 125 : e->caller->called_by_ifunc_resolver = true;
1440 : 125 : return true;
1441 : : }
1442 : : }
1443 : :
1444 : : return false;
1445 : : }
1446 : :
1447 : : /* Check symbol table for callees of IFUNC resolvers. */
1448 : :
1449 : : void
1450 : 245141 : symtab_node::check_ifunc_callee_symtab_nodes (void)
1451 : : {
1452 : 245141 : symtab_node *node;
1453 : :
1454 : 245141 : bitmap_obstack_initialize (NULL);
1455 : 245141 : ifunc_ref_map = BITMAP_ALLOC (NULL);
1456 : :
1457 : 8816184 : FOR_EACH_SYMBOL (node)
1458 : : {
1459 : 8571043 : cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1460 : 8571043 : if (!cnode)
1461 : 5266634 : continue;
1462 : :
1463 : 5253939 : unsigned int uid = cnode->get_uid ();
1464 : 5253939 : if (bitmap_bit_p (ifunc_ref_map, uid))
1465 : 1949530 : continue;
1466 : 3304409 : bitmap_set_bit (ifunc_ref_map, uid);
1467 : :
1468 : 3304409 : bool is_ifunc_resolver = false;
1469 : 3304409 : cnode->call_for_symbol_and_aliases (check_ifunc_resolver,
1470 : : &is_ifunc_resolver, true);
1471 : 3304409 : if (is_ifunc_resolver || is_caller_ifunc_resolver (cnode))
1472 : 601 : cnode->called_by_ifunc_resolver = true;
1473 : : }
1474 : :
1475 : 245141 : BITMAP_FREE (ifunc_ref_map);
1476 : 245141 : bitmap_obstack_release (NULL);
1477 : 245141 : }
1478 : :
1479 : : /* Verify symbol table for internal consistency. */
1480 : :
1481 : : DEBUG_FUNCTION void
1482 : 2185835 : symtab_node::verify_symtab_nodes (void)
1483 : : {
1484 : 2185835 : symtab_node *node;
1485 : 2185835 : hash_map<tree, symtab_node *> comdat_head_map (251);
1486 : 2185835 : asm_node *anode;
1487 : :
1488 : 2308550 : for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
1489 : 122715 : if (anode->order < 0 || anode->order >= symtab->order)
1490 : : {
1491 : 0 : error ("invalid order in asm node %i", anode->order);
1492 : 0 : internal_error ("symtab_node::verify failed");
1493 : : }
1494 : :
1495 : 75628881 : FOR_EACH_SYMBOL (node)
1496 : : {
1497 : 73443046 : node->verify ();
1498 : 73443046 : if (node->get_comdat_group ())
1499 : : {
1500 : 10784712 : symtab_node **entry, *s;
1501 : 10784712 : bool existed;
1502 : :
1503 : 10784712 : entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
1504 : : &existed);
1505 : 10784712 : if (!existed)
1506 : 9428321 : *entry = node;
1507 : 1356391 : else if (!DECL_EXTERNAL (node->decl))
1508 : : {
1509 : 1356246 : for (s = (*entry)->same_comdat_group;
1510 : 2499440 : s != NULL && s != node && s != *entry;
1511 : 1143194 : s = s->same_comdat_group)
1512 : : ;
1513 : 1356246 : if (!s || s == *entry)
1514 : : {
1515 : 0 : error ("Two symbols with same comdat_group are not linked by "
1516 : : "the same_comdat_group list.");
1517 : 0 : (*entry)->debug ();
1518 : 0 : node->debug ();
1519 : 0 : internal_error ("symtab_node::verify failed");
1520 : : }
1521 : : }
1522 : : }
1523 : : }
1524 : 2185835 : }
1525 : :
1526 : : #if __GNUC__ >= 10
1527 : : # pragma GCC diagnostic pop
1528 : : #endif
1529 : :
1530 : : /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1531 : : but other code such as notice_global_symbol generates rtl. */
1532 : :
1533 : : void
1534 : 3653129 : symtab_node::make_decl_local (void)
1535 : : {
1536 : 3653129 : rtx rtl, symbol;
1537 : :
1538 : 3653129 : if (weakref)
1539 : : {
1540 : 0 : weakref = false;
1541 : 0 : IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl)) = 0;
1542 : 0 : TREE_CHAIN (DECL_ASSEMBLER_NAME (decl)) = NULL_TREE;
1543 : 0 : symtab->change_decl_assembler_name
1544 : 0 : (decl, DECL_ASSEMBLER_NAME (get_alias_target ()->decl));
1545 : 0 : DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
1546 : 0 : DECL_ATTRIBUTES (decl));
1547 : : }
1548 : : /* Avoid clearing comdat_groups on comdat-local decls. */
1549 : 3653129 : else if (TREE_PUBLIC (decl) == 0)
1550 : 3653115 : return;
1551 : :
1552 : : /* Localizing a symbol also make all its transparent aliases local. */
1553 : : ipa_ref *ref;
1554 : 106307 : for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
1555 : : {
1556 : 1833 : struct symtab_node *alias = ref->referring;
1557 : 1833 : if (alias->transparent_alias)
1558 : 5 : alias->make_decl_local ();
1559 : : }
1560 : :
1561 : 104474 : if (VAR_P (decl))
1562 : : {
1563 : 12330 : DECL_COMMON (decl) = 0;
1564 : : /* ADDRESSABLE flag is not defined for public symbols. */
1565 : 12330 : TREE_ADDRESSABLE (decl) = 1;
1566 : 12330 : TREE_STATIC (decl) = 1;
1567 : : }
1568 : : else
1569 : 92144 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1570 : :
1571 : 104474 : DECL_COMDAT (decl) = 0;
1572 : 104474 : DECL_WEAK (decl) = 0;
1573 : 104474 : DECL_EXTERNAL (decl) = 0;
1574 : 104474 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
1575 : 104474 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1576 : 104474 : TREE_PUBLIC (decl) = 0;
1577 : 104474 : DECL_DLLIMPORT_P (decl) = 0;
1578 : 104474 : if (!DECL_RTL_SET_P (decl))
1579 : : return;
1580 : :
1581 : : /* Update rtl flags. */
1582 : 14 : make_decl_rtl (decl);
1583 : :
1584 : 14 : rtl = DECL_RTL (decl);
1585 : 14 : if (!MEM_P (rtl))
1586 : : return;
1587 : :
1588 : 14 : symbol = XEXP (rtl, 0);
1589 : 14 : if (GET_CODE (symbol) != SYMBOL_REF)
1590 : : return;
1591 : :
1592 : 14 : SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
1593 : : }
1594 : :
1595 : : /* Copy visibility from N.
1596 : : This is useful when THIS becomes a transparent alias of N. */
1597 : :
1598 : : void
1599 : 0 : symtab_node::copy_visibility_from (symtab_node *n)
1600 : : {
1601 : 0 : gcc_checking_assert (n->weakref == weakref);
1602 : :
1603 : : ipa_ref *ref;
1604 : 0 : for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
1605 : : {
1606 : 0 : struct symtab_node *alias = ref->referring;
1607 : 0 : if (alias->transparent_alias)
1608 : 0 : alias->copy_visibility_from (n);
1609 : : }
1610 : :
1611 : 0 : if (VAR_P (decl))
1612 : : {
1613 : 0 : DECL_COMMON (decl) = DECL_COMMON (n->decl);
1614 : : /* ADDRESSABLE flag is not defined for public symbols. */
1615 : 0 : if (TREE_PUBLIC (decl) && !TREE_PUBLIC (n->decl))
1616 : 0 : TREE_ADDRESSABLE (decl) = 1;
1617 : 0 : TREE_STATIC (decl) = TREE_STATIC (n->decl);
1618 : : }
1619 : 0 : else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1620 : :
1621 : 0 : DECL_COMDAT (decl) = DECL_COMDAT (n->decl);
1622 : 0 : DECL_WEAK (decl) = DECL_WEAK (n->decl);
1623 : 0 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (n->decl);
1624 : 0 : DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (n->decl);
1625 : 0 : DECL_VISIBILITY (decl) = DECL_VISIBILITY (n->decl);
1626 : 0 : TREE_PUBLIC (decl) = TREE_PUBLIC (n->decl);
1627 : 0 : DECL_DLLIMPORT_P (decl) = DECL_DLLIMPORT_P (n->decl);
1628 : 0 : resolution = n->resolution;
1629 : 0 : set_comdat_group (n->get_comdat_group ());
1630 : 0 : set_section (*n);
1631 : 0 : externally_visible = n->externally_visible;
1632 : 0 : if (!DECL_RTL_SET_P (decl))
1633 : 0 : return;
1634 : :
1635 : : /* Update rtl flags. */
1636 : 0 : make_decl_rtl (decl);
1637 : :
1638 : 0 : rtx rtl = DECL_RTL (decl);
1639 : 0 : if (!MEM_P (rtl))
1640 : : return;
1641 : :
1642 : 0 : rtx symbol = XEXP (rtl, 0);
1643 : 0 : if (GET_CODE (symbol) != SYMBOL_REF)
1644 : : return;
1645 : :
1646 : 0 : SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
1647 : : }
1648 : :
1649 : : /* Walk the alias chain to return the symbol NODE is alias of.
1650 : : If NODE is not an alias, return NODE.
1651 : : Assumes NODE is known to be alias. */
1652 : :
1653 : : symtab_node *
1654 : 36519262 : symtab_node::ultimate_alias_target_1 (enum availability *availability,
1655 : : symtab_node *ref)
1656 : : {
1657 : 36519262 : bool transparent_p = false;
1658 : :
1659 : : /* To determine visibility of the target, we follow ELF semantic of aliases.
1660 : : Here alias is an alternative assembler name of a given definition. Its
1661 : : availability prevails the availability of its target (i.e. static alias of
1662 : : weak definition is available.
1663 : :
1664 : : Transparent alias is just alternative name of a given symbol used within
1665 : : one compilation unit and is translated prior hitting the object file. It
1666 : : inherits the visibility of its target.
1667 : : Weakref is a different animal (and noweak definition is weak).
1668 : :
1669 : : If we ever get into supporting targets with different semantics, a target
1670 : : hook will be needed here. */
1671 : :
1672 : 36519262 : if (availability)
1673 : : {
1674 : 11233637 : transparent_p = transparent_alias;
1675 : 11233637 : if (!transparent_p)
1676 : 11227841 : *availability = get_availability (ref);
1677 : : else
1678 : 5796 : *availability = AVAIL_NOT_AVAILABLE;
1679 : : }
1680 : :
1681 : : symtab_node *node = this;
1682 : 73029803 : while (node)
1683 : : {
1684 : 73029803 : if (node->alias && node->analyzed)
1685 : 36510541 : node = node->get_alias_target ();
1686 : : else
1687 : : {
1688 : 36519262 : if (!availability || (!transparent_p && node->analyzed))
1689 : : ;
1690 : 39006 : else if (node->analyzed && !node->transparent_alias)
1691 : 308 : *availability = node->get_availability (ref);
1692 : : else
1693 : 38698 : *availability = AVAIL_NOT_AVAILABLE;
1694 : 36519262 : return node;
1695 : : }
1696 : 36510541 : if (node && availability && transparent_p
1697 : 448 : && node->transparent_alias)
1698 : : {
1699 : 22 : *availability = node->get_availability (ref);
1700 : 22 : transparent_p = false;
1701 : : }
1702 : : }
1703 : 0 : if (availability)
1704 : 0 : *availability = AVAIL_NOT_AVAILABLE;
1705 : : return NULL;
1706 : : }
1707 : :
1708 : : /* C++ FE sometimes change linkage flags after producing same body aliases.
1709 : :
1710 : : FIXME: C++ produce implicit aliases for virtual functions and vtables that
1711 : : are obviously equivalent. The way it is doing so is however somewhat
1712 : : kludgy and interferes with the visibility code. As a result we need to
1713 : : copy the visibility from the target to get things right. */
1714 : :
1715 : : void
1716 : 7235560 : symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
1717 : : {
1718 : 7235560 : if (is_a <cgraph_node *> (this))
1719 : : {
1720 : 21706533 : DECL_DECLARED_INLINE_P (decl)
1721 : 7235511 : = DECL_DECLARED_INLINE_P (target->decl);
1722 : 21706533 : DECL_DISREGARD_INLINE_LIMITS (decl)
1723 : 7235511 : = DECL_DISREGARD_INLINE_LIMITS (target->decl);
1724 : : }
1725 : : /* FIXME: It is not really clear why those flags should not be copied for
1726 : : functions, too. */
1727 : : else
1728 : : {
1729 : 49 : DECL_WEAK (decl) = DECL_WEAK (target->decl);
1730 : 49 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1731 : 49 : DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
1732 : : }
1733 : 7235560 : if (TREE_PUBLIC (decl))
1734 : : {
1735 : 7210471 : tree group;
1736 : :
1737 : 7210471 : DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1738 : 7210471 : DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
1739 : 7210471 : group = target->get_comdat_group ();
1740 : 7210471 : set_comdat_group (group);
1741 : 7210471 : if (group && !same_comdat_group)
1742 : 0 : add_to_same_comdat_group (target);
1743 : : }
1744 : 7235560 : externally_visible = target->externally_visible;
1745 : 7235560 : }
1746 : :
1747 : : /* Set section, do not recurse into aliases.
1748 : : When one wants to change section of a symbol and its aliases,
1749 : : use set_section. */
1750 : :
1751 : : void
1752 : 118154455 : symtab_node::set_section_for_node (const char *section)
1753 : : {
1754 : 118154455 : const char *current = get_section ();
1755 : :
1756 : 118154455 : if (current == section
1757 : 1876337 : || (current && section
1758 : 0 : && !strcmp (current, section)))
1759 : : return;
1760 : :
1761 : 1876337 : release_section_hash_entry (x_section);
1762 : 1876337 : if (!section)
1763 : : {
1764 : 27151 : x_section = NULL;
1765 : 27151 : implicit_section = false;
1766 : 27151 : return;
1767 : : }
1768 : 1849186 : if (!symtab->section_hash)
1769 : 35876 : symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
1770 : 1849186 : section_hash_entry **slot = symtab->section_hash->find_slot_with_hash
1771 : 1849186 : (section, htab_hash_string (section), INSERT);
1772 : 1849186 : if (*slot)
1773 : 40582 : x_section = retain_section_hash_entry (*slot);
1774 : : else
1775 : : {
1776 : 1808604 : int len = strlen (section);
1777 : 1808604 : *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
1778 : 1808604 : x_section->ref_count = 1;
1779 : 1808604 : x_section->name = ggc_vec_alloc<char> (len + 1);
1780 : 1808604 : memcpy (x_section->name, section, len + 1);
1781 : : }
1782 : : }
1783 : :
1784 : : /* Set the section of node THIS to be the same as the section
1785 : : of node OTHER. Keep reference counts of the sections
1786 : : up-to-date as needed. */
1787 : :
1788 : : void
1789 : 21101049 : symtab_node::set_section_for_node (const symtab_node &other)
1790 : : {
1791 : 21101049 : if (x_section == other.x_section)
1792 : : return;
1793 : 7476 : if (get_section () && other.get_section ())
1794 : 612 : gcc_checking_assert (strcmp (get_section (), other.get_section ()) != 0);
1795 : 6864 : release_section_hash_entry (x_section);
1796 : 6864 : if (other.x_section)
1797 : 6856 : x_section = retain_section_hash_entry (other.x_section);
1798 : : else
1799 : : {
1800 : 8 : x_section = NULL;
1801 : 8 : implicit_section = false;
1802 : : }
1803 : : }
1804 : :
1805 : : /* Workers for set_section. */
1806 : :
1807 : : bool
1808 : 1855524 : symtab_node::set_section_from_string (symtab_node *n, void *s)
1809 : : {
1810 : 1855524 : n->set_section_for_node ((char *)s);
1811 : 1855524 : return false;
1812 : : }
1813 : :
1814 : : /* Set the section of node N to be the same as the section
1815 : : of node O. */
1816 : :
1817 : : bool
1818 : 21101049 : symtab_node::set_section_from_node (symtab_node *n, void *o)
1819 : : {
1820 : 21101049 : const symtab_node &other = *static_cast<const symtab_node *> (o);
1821 : 21101049 : n->set_section_for_node (other);
1822 : 21101049 : return false;
1823 : : }
1824 : :
1825 : : /* Set section of symbol and its aliases. */
1826 : :
1827 : : void
1828 : 1813454 : symtab_node::set_section (const char *section)
1829 : : {
1830 : 1813454 : gcc_assert (!this->alias || !this->analyzed);
1831 : 1813454 : call_for_symbol_and_aliases
1832 : 1813454 : (symtab_node::set_section_from_string, const_cast<char *>(section), true);
1833 : 1813454 : }
1834 : :
1835 : : void
1836 : 21100800 : symtab_node::set_section (const symtab_node &other)
1837 : : {
1838 : 21100800 : call_for_symbol_and_aliases
1839 : 21100800 : (symtab_node::set_section_from_node, const_cast<symtab_node *>(&other), true);
1840 : 21100800 : }
1841 : :
1842 : : /* Return the initialization priority. */
1843 : :
1844 : : priority_type
1845 : 42737 : symtab_node::get_init_priority ()
1846 : : {
1847 : 42737 : if (!this->in_init_priority_hash)
1848 : : return DEFAULT_INIT_PRIORITY;
1849 : :
1850 : 3881 : symbol_priority_map *h = symtab->init_priority_hash->get (this);
1851 : 3881 : return h ? h->init : DEFAULT_INIT_PRIORITY;
1852 : : }
1853 : :
1854 : : /* Return the finalization priority. */
1855 : :
1856 : : priority_type
1857 : 1899 : cgraph_node::get_fini_priority ()
1858 : : {
1859 : 1899 : if (!this->in_init_priority_hash)
1860 : : return DEFAULT_INIT_PRIORITY;
1861 : 1821 : symbol_priority_map *h = symtab->init_priority_hash->get (this);
1862 : 1821 : return h ? h->fini : DEFAULT_INIT_PRIORITY;
1863 : : }
1864 : :
1865 : : /* Return the initialization and finalization priority information for
1866 : : DECL. If there is no previous priority information, a freshly
1867 : : allocated structure is returned. */
1868 : :
1869 : : symbol_priority_map *
1870 : 5297 : symtab_node::priority_info (void)
1871 : : {
1872 : 5297 : if (!symtab->init_priority_hash)
1873 : 3529 : symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
1874 : :
1875 : 5297 : bool existed;
1876 : 5297 : symbol_priority_map *h
1877 : 5297 : = &symtab->init_priority_hash->get_or_insert (this, &existed);
1878 : 5297 : if (!existed)
1879 : : {
1880 : 5277 : h->init = DEFAULT_INIT_PRIORITY;
1881 : 5277 : h->fini = DEFAULT_INIT_PRIORITY;
1882 : 5277 : in_init_priority_hash = true;
1883 : : }
1884 : :
1885 : 5297 : return h;
1886 : : }
1887 : :
1888 : : /* Set initialization priority to PRIORITY. */
1889 : :
1890 : : void
1891 : 23512 : symtab_node::set_init_priority (priority_type priority)
1892 : : {
1893 : 23512 : symbol_priority_map *h;
1894 : :
1895 : 23512 : if (is_a <cgraph_node *> (this))
1896 : 23467 : gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
1897 : :
1898 : 23512 : if (priority == DEFAULT_INIT_PRIORITY)
1899 : : {
1900 : 19830 : gcc_assert (get_init_priority() == priority);
1901 : : return;
1902 : : }
1903 : 3682 : h = priority_info ();
1904 : 3682 : h->init = priority;
1905 : : }
1906 : :
1907 : : /* Set finalization priority to PRIORITY. */
1908 : :
1909 : : void
1910 : 1628 : cgraph_node::set_fini_priority (priority_type priority)
1911 : : {
1912 : 1628 : symbol_priority_map *h;
1913 : :
1914 : 1628 : gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
1915 : :
1916 : 1628 : if (priority == DEFAULT_INIT_PRIORITY)
1917 : : {
1918 : 13 : gcc_assert (get_fini_priority() == priority);
1919 : : return;
1920 : : }
1921 : 1615 : h = priority_info ();
1922 : 1615 : h->fini = priority;
1923 : : }
1924 : :
1925 : : /* Worker for symtab_resolve_alias. */
1926 : :
1927 : : bool
1928 : 3153 : symtab_node::set_implicit_section (symtab_node *n,
1929 : : void *data ATTRIBUTE_UNUSED)
1930 : : {
1931 : 3153 : n->implicit_section = true;
1932 : 3153 : return false;
1933 : : }
1934 : :
1935 : : /* Add reference recording that symtab node is alias of TARGET.
1936 : : The function can fail in the case of aliasing cycles; in this case
1937 : : it returns false. */
1938 : :
1939 : : bool
1940 : 6897535 : symtab_node::resolve_alias (symtab_node *target, bool transparent)
1941 : : {
1942 : 6897535 : symtab_node *n;
1943 : :
1944 : 6897535 : gcc_assert (!analyzed && !ref_list.references.length ());
1945 : :
1946 : : /* Never let cycles to creep into the symbol table alias references;
1947 : : those will make alias walkers to be infinite. */
1948 : 6899996 : for (n = target; n && n->alias;
1949 : 2675 : n = n->analyzed ? n->get_alias_target () : NULL)
1950 : 2677 : if (n == this)
1951 : : {
1952 : 2 : if (is_a <cgraph_node *> (this))
1953 : 2 : error ("function %q+D part of alias cycle", decl);
1954 : 0 : else if (is_a <varpool_node *> (this))
1955 : 0 : error ("variable %q+D part of alias cycle", decl);
1956 : : else
1957 : 0 : gcc_unreachable ();
1958 : 2 : alias = false;
1959 : 2 : return false;
1960 : : }
1961 : :
1962 : : /* "analyze" the node - i.e. mark the reference. */
1963 : 6897533 : definition = true;
1964 : 6897533 : alias = true;
1965 : 6897533 : analyzed = true;
1966 : 6897533 : transparent |= transparent_alias;
1967 : 6897533 : transparent_alias = transparent;
1968 : 6897533 : if (transparent)
1969 : 54 : while (target->transparent_alias && target->analyzed)
1970 : 0 : target = target->get_alias_target ();
1971 : 6897533 : create_reference (target, IPA_REF_ALIAS, NULL);
1972 : :
1973 : : /* Add alias into the comdat group of its target unless it is already there. */
1974 : 6897533 : if (same_comdat_group)
1975 : 3229655 : remove_from_same_comdat_group ();
1976 : 6897533 : set_comdat_group (NULL);
1977 : 6897533 : if (target->get_comdat_group ())
1978 : 6614835 : add_to_same_comdat_group (target);
1979 : :
1980 : 6897546 : if ((get_section () != target->get_section ()
1981 : 6897538 : || target->get_comdat_group ()) && get_section () && !implicit_section)
1982 : : {
1983 : 2 : error ("section of alias %q+D must match section of its target", decl);
1984 : : }
1985 : 6897533 : set_section (*target);
1986 : 6897533 : if (target->implicit_section)
1987 : 2967 : call_for_symbol_and_aliases (set_implicit_section, NULL, true);
1988 : :
1989 : : /* Alias targets become redundant after alias is resolved into an reference.
1990 : : We do not want to keep it around or we would have to mind updating them
1991 : : when renaming symbols. */
1992 : 6897533 : alias_target = NULL;
1993 : :
1994 : 6897533 : if (!transparent && cpp_implicit_alias && symtab->state >= CONSTRUCTION)
1995 : 8846 : fixup_same_cpp_alias_visibility (target);
1996 : :
1997 : : /* If alias has address taken, so does the target. */
1998 : 6897533 : if (address_taken)
1999 : 982 : target->ultimate_alias_target ()->address_taken = true;
2000 : :
2001 : : /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
2002 : : If alias is transparent, also all transparent aliases of THIS are now
2003 : : aliases of TARGET.
2004 : : Also merge same comdat group lists. */
2005 : : ipa_ref *ref;
2006 : 6897782 : for (unsigned i = 0; iterate_direct_aliases (i, ref);)
2007 : : {
2008 : 249 : struct symtab_node *alias_alias = ref->referring;
2009 : 249 : if (alias_alias->get_comdat_group ())
2010 : : {
2011 : 184 : alias_alias->remove_from_same_comdat_group ();
2012 : 184 : alias_alias->set_comdat_group (NULL);
2013 : 184 : if (target->get_comdat_group ())
2014 : 184 : alias_alias->add_to_same_comdat_group (target);
2015 : : }
2016 : 249 : if ((!alias_alias->transparent_alias
2017 : 237 : && !alias_alias->symver)
2018 : 12 : || transparent)
2019 : : {
2020 : 249 : alias_alias->remove_all_references ();
2021 : 249 : alias_alias->create_reference (target, IPA_REF_ALIAS, NULL);
2022 : : }
2023 : 0 : else i++;
2024 : : }
2025 : : return true;
2026 : : }
2027 : :
2028 : : /* Worker searching noninterposable alias. */
2029 : :
2030 : : bool
2031 : 59844 : symtab_node::noninterposable_alias (symtab_node *node, void *data)
2032 : : {
2033 : 59844 : if (!node->transparent_alias && decl_binds_to_current_def_p (node->decl))
2034 : : {
2035 : 57568 : symtab_node *fn = node->ultimate_alias_target ();
2036 : :
2037 : : /* Ensure that the alias is well formed this may not be the case
2038 : : of user defined aliases and currently it is not always the case
2039 : : of C++ same body aliases (that is a bug). */
2040 : 57568 : if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
2041 : 57568 : || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
2042 : 57568 : || (TREE_CODE (node->decl) == FUNCTION_DECL
2043 : 115136 : && flags_from_decl_or_type (node->decl)
2044 : 57568 : != flags_from_decl_or_type (fn->decl))
2045 : 115118 : || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
2046 : 20 : return false;
2047 : 57548 : *(symtab_node **)data = node;
2048 : 57548 : return true;
2049 : : }
2050 : : return false;
2051 : : }
2052 : :
2053 : : /* If node cannot be overwriten by static or dynamic linker to point to
2054 : : different definition, return NODE. Otherwise look for alias with such
2055 : : property and if none exists, introduce new one. */
2056 : :
2057 : : symtab_node *
2058 : 58545 : symtab_node::noninterposable_alias (void)
2059 : : {
2060 : 58545 : tree new_decl;
2061 : 58545 : symtab_node *new_node = NULL;
2062 : :
2063 : : /* First try to look up existing alias or base object
2064 : : (if that is already non-overwritable). */
2065 : 58545 : symtab_node *node = ultimate_alias_target ();
2066 : 58545 : gcc_assert (!node->alias && !node->weakref);
2067 : 58545 : node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
2068 : : (void *)&new_node, true);
2069 : 58545 : if (new_node)
2070 : : return new_node;
2071 : :
2072 : : /* If aliases aren't supported by the assembler, fail. */
2073 : 997 : if (!TARGET_SUPPORTS_ALIASES)
2074 : : return NULL;
2075 : 997 : else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)))
2076 : : return NULL;
2077 : :
2078 : : /* Otherwise create a new one. */
2079 : 996 : new_decl = copy_node (node->decl);
2080 : 996 : DECL_DLLIMPORT_P (new_decl) = 0;
2081 : 996 : tree name = clone_function_name (node->decl, "localalias");
2082 : 996 : if (!flag_wpa)
2083 : : {
2084 : : unsigned long num = 0;
2085 : : /* In the rare case we already have a localalias, but the above
2086 : : node->call_for_symbol_and_aliases call didn't find any suitable,
2087 : : iterate until we find one not used yet. */
2088 : 990 : while (symtab_node::get_for_asmname (name))
2089 : 0 : name = clone_function_name (node->decl, "localalias", num++);
2090 : : }
2091 : 996 : DECL_NAME (new_decl) = name;
2092 : 996 : if (TREE_CODE (new_decl) == FUNCTION_DECL)
2093 : 994 : DECL_STRUCT_FUNCTION (new_decl) = NULL;
2094 : 996 : DECL_INITIAL (new_decl) = NULL;
2095 : 996 : SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
2096 : 996 : SET_DECL_RTL (new_decl, NULL);
2097 : :
2098 : : /* Update the properties. */
2099 : 996 : DECL_EXTERNAL (new_decl) = 0;
2100 : 996 : TREE_PUBLIC (new_decl) = 0;
2101 : 996 : DECL_COMDAT (new_decl) = 0;
2102 : 996 : DECL_WEAK (new_decl) = 0;
2103 : :
2104 : : /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
2105 : 996 : DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
2106 : 996 : if (TREE_CODE (new_decl) == FUNCTION_DECL)
2107 : : {
2108 : 994 : DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
2109 : 994 : DECL_STATIC_DESTRUCTOR (new_decl) = 0;
2110 : 994 : new_node = cgraph_node::create_alias (new_decl, node->decl);
2111 : :
2112 : 1988 : cgraph_node *new_cnode = dyn_cast <cgraph_node *> (new_node),
2113 : 994 : *cnode = dyn_cast <cgraph_node *> (node);
2114 : :
2115 : 994 : new_cnode->unit_id = cnode->unit_id;
2116 : 994 : new_cnode->merged_comdat = cnode->merged_comdat;
2117 : 994 : new_cnode->merged_extern_inline = cnode->merged_extern_inline;
2118 : : }
2119 : : else
2120 : : {
2121 : 2 : TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
2122 : 2 : DECL_INITIAL (new_decl) = error_mark_node;
2123 : 2 : new_node = varpool_node::create_alias (new_decl, node->decl);
2124 : : }
2125 : 996 : new_node->resolve_alias (node);
2126 : 996 : gcc_assert (decl_binds_to_current_def_p (new_decl)
2127 : : && targetm.binds_local_p (new_decl));
2128 : 996 : return new_node;
2129 : : }
2130 : :
2131 : : /* Return true if symtab node and TARGET represents
2132 : : semantically equivalent symbols. */
2133 : :
2134 : : bool
2135 : 371598 : symtab_node::semantically_equivalent_p (symtab_node *target)
2136 : : {
2137 : 371598 : enum availability avail;
2138 : 371598 : symtab_node *ba;
2139 : 371598 : symtab_node *bb;
2140 : :
2141 : : /* Equivalent functions are equivalent. */
2142 : 371598 : if (decl == target->decl)
2143 : : return true;
2144 : :
2145 : : /* If symbol is not overwritable by different implementation,
2146 : : walk to the base object it defines. */
2147 : 274618 : ba = ultimate_alias_target (&avail);
2148 : 274618 : if (avail >= AVAIL_AVAILABLE)
2149 : : {
2150 : 61275 : if (target == ba)
2151 : : return true;
2152 : : }
2153 : : else
2154 : : ba = this;
2155 : 274594 : bb = target->ultimate_alias_target (&avail);
2156 : 274594 : if (avail >= AVAIL_AVAILABLE)
2157 : : {
2158 : 60731 : if (this == bb)
2159 : : return true;
2160 : : }
2161 : : else
2162 : : bb = target;
2163 : 274535 : return bb == ba;
2164 : : }
2165 : :
2166 : : /* Classify symbol symtab node for partitioning. */
2167 : :
2168 : : enum symbol_partitioning_class
2169 : 2319932 : symtab_node::get_partitioning_class (void)
2170 : : {
2171 : : /* Inline clones are always duplicated.
2172 : : This include external declarations. */
2173 : 2319932 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2174 : :
2175 : 2319932 : if (DECL_ABSTRACT_P (decl))
2176 : : return SYMBOL_EXTERNAL;
2177 : :
2178 : 2319932 : if (cnode && cnode->inlined_to)
2179 : : return SYMBOL_DUPLICATE;
2180 : :
2181 : : /* Transparent aliases are always duplicated. */
2182 : 2235122 : if (transparent_alias)
2183 : 66 : return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL;
2184 : :
2185 : : /* External declarations are external. */
2186 : 2235056 : if (DECL_EXTERNAL (decl))
2187 : : return SYMBOL_EXTERNAL;
2188 : :
2189 : : /* Even static aliases of external functions as external. Those can happen
2190 : : when COMDAT got resolved to non-IL implementation. */
2191 : 2083743 : if (alias && DECL_EXTERNAL (ultimate_alias_target ()->decl))
2192 : : return SYMBOL_EXTERNAL;
2193 : :
2194 : 2083743 : if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
2195 : : {
2196 : 927815 : if (alias && definition && !ultimate_alias_target ()->definition)
2197 : : return SYMBOL_EXTERNAL;
2198 : : /* Constant pool references use local symbol names that cannot
2199 : : be promoted global. We should never put into a constant pool
2200 : : objects that cannot be duplicated across partitions. */
2201 : 927815 : if (DECL_IN_CONSTANT_POOL (decl))
2202 : : return SYMBOL_DUPLICATE;
2203 : 927625 : if (DECL_HARD_REGISTER (decl))
2204 : : return SYMBOL_DUPLICATE;
2205 : 927529 : gcc_checking_assert (vnode->definition);
2206 : : }
2207 : : /* Functions that are cloned may stay in callgraph even if they are unused.
2208 : : Handle them as external; compute_ltrans_boundary take care to make
2209 : : proper things to happen (i.e. to make them appear in the boundary but
2210 : : with body streamed, so clone can me materialized). */
2211 : 1155928 : else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
2212 : : return SYMBOL_EXTERNAL;
2213 : :
2214 : : /* Linker discardable symbols are duplicated to every use unless they are
2215 : : keyed. */
2216 : 2093984 : if (DECL_ONE_ONLY (decl)
2217 : 13700 : && !force_output
2218 : 13656 : && !forced_by_abi
2219 : 2092361 : && !used_from_object_file_p ())
2220 : : return SYMBOL_DUPLICATE;
2221 : :
2222 : : return SYMBOL_PARTITION;
2223 : : }
2224 : :
2225 : : /* Return true when symbol is known to be non-zero, assume that
2226 : : flag_delete_null_pointer_checks is equal to delete_null_pointer_checks. */
2227 : :
2228 : : bool
2229 : 14261814 : symtab_node::nonzero_address (bool delete_null_pointer_checks)
2230 : : {
2231 : : /* Weakrefs may be NULL when their target is not defined. */
2232 : 14261814 : if (alias && weakref)
2233 : : {
2234 : 2757 : if (analyzed)
2235 : : {
2236 : 188 : symtab_node *target = ultimate_alias_target ();
2237 : :
2238 : 188 : if (target->alias && target->weakref)
2239 : : return false;
2240 : : /* We cannot recurse to target::nonzero. It is possible that the
2241 : : target is used only via the alias.
2242 : : We may walk references and look for strong use, but we do not know
2243 : : if this strong use will survive to final binary, so be
2244 : : conservative here.
2245 : : ??? Maybe we could do the lookup during late optimization that
2246 : : could be useful to eliminate the NULL pointer checks in LTO
2247 : : programs. */
2248 : 0 : if (target->definition && !DECL_EXTERNAL (target->decl))
2249 : : return true;
2250 : 0 : if (target->resolution != LDPR_UNKNOWN
2251 : : && target->resolution != LDPR_UNDEF
2252 : 0 : && !target->can_be_discarded_p ()
2253 : 0 : && delete_null_pointer_checks)
2254 : : return true;
2255 : 0 : return false;
2256 : : }
2257 : : else
2258 : : return false;
2259 : : }
2260 : :
2261 : : /* With !flag_delete_null_pointer_checks we assume that symbols may
2262 : : bind to NULL. This is on by default on embedded targets only.
2263 : :
2264 : : Otherwise all non-WEAK symbols must be defined and thus non-NULL or
2265 : : linking fails. Important case of WEAK we want to do well are comdats,
2266 : : which also must be defined somewhere.
2267 : :
2268 : : When parsing, beware the cases when WEAK attribute is added later. */
2269 : 18069623 : if ((!DECL_WEAK (decl) || DECL_COMDAT (decl))
2270 : 15313769 : && delete_null_pointer_checks)
2271 : : {
2272 : 11492550 : refuse_visibility_changes = true;
2273 : 11492550 : return true;
2274 : : }
2275 : :
2276 : : /* If target is defined and not extern, we know it will be
2277 : : output and thus it will bind to non-NULL.
2278 : : Play safe for flag_delete_null_pointer_checks where weak definition may
2279 : : be re-defined by NULL. */
2280 : 2741683 : if (definition && !DECL_EXTERNAL (decl)
2281 : 5508189 : && (delete_null_pointer_checks || !DECL_WEAK (decl)))
2282 : : {
2283 : 2740965 : if (!DECL_WEAK (decl))
2284 : 9153 : refuse_visibility_changes = true;
2285 : 2740965 : return true;
2286 : : }
2287 : :
2288 : : /* As the last resort, check the resolution info. */
2289 : 25542 : if (resolution != LDPR_UNKNOWN
2290 : : && resolution != LDPR_UNDEF
2291 : 0 : && !can_be_discarded_p ()
2292 : 25542 : && delete_null_pointer_checks)
2293 : : return true;
2294 : : return false;
2295 : : }
2296 : :
2297 : : /* Return true when symbol is known to be non-zero. */
2298 : :
2299 : : bool
2300 : 14260973 : symtab_node::nonzero_address ()
2301 : : {
2302 : 14260973 : return nonzero_address (flag_delete_null_pointer_checks);
2303 : : }
2304 : :
2305 : : /* Return 0 if symbol is known to have different address than S2,
2306 : : Return 1 if symbol is known to have same address as S2,
2307 : : return -1 otherwise.
2308 : :
2309 : : If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
2310 : : and S2 is going to be accessed. This eliminates the situations when
2311 : : either THIS or S2 is NULL and is useful for comparing bases when deciding
2312 : : about memory aliasing. */
2313 : : int
2314 : 85600334 : symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed)
2315 : : {
2316 : 85600334 : enum availability avail1, avail2;
2317 : :
2318 : : /* A Shortcut: equivalent symbols are always equivalent. */
2319 : 85600334 : if (this == s2)
2320 : : return 1;
2321 : :
2322 : : /* Unwind transparent aliases first; those are always equal to their
2323 : : target. */
2324 : 85069188 : if (this->transparent_alias && this->analyzed)
2325 : 0 : return this->get_alias_target ()->equal_address_to (s2);
2326 : 85069188 : while (s2->transparent_alias && s2->analyzed)
2327 : 0 : s2 = s2->get_alias_target();
2328 : :
2329 : 85069188 : if (this == s2)
2330 : : return 1;
2331 : :
2332 : : /* For non-interposable aliases, lookup and compare their actual definitions.
2333 : : Also check if the symbol needs to bind to given definition. */
2334 : 85069188 : symtab_node *rs1 = ultimate_alias_target (&avail1);
2335 : 85069188 : symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
2336 : 85069188 : bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
2337 : 85069188 : bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
2338 : 85069188 : bool really_binds_local1 = binds_local1;
2339 : 85069188 : bool really_binds_local2 = binds_local2;
2340 : :
2341 : : /* Addresses of vtables and virtual functions cannot be used by user
2342 : : code and are used only within speculation. In this case we may make
2343 : : symbol equivalent to its alias even if interposition may break this
2344 : : rule. Doing so will allow us to turn speculative inlining into
2345 : : non-speculative more aggressively. */
2346 : 85069188 : if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
2347 : : binds_local1 = true;
2348 : 85069188 : if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
2349 : 85069188 : binds_local2 = true;
2350 : :
2351 : : /* If both definitions are available we know that even if they are bound
2352 : : to other unit they must be defined same way and therefore we can use
2353 : : equivalence test. */
2354 : 85069188 : if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
2355 : : binds_local1 = binds_local2 = true;
2356 : :
2357 : 85069188 : if (binds_local1 && binds_local2 && rs1 == rs2)
2358 : : {
2359 : : /* We made use of the fact that alias is not weak. */
2360 : 358 : if (rs1 != this)
2361 : 232 : refuse_visibility_changes = true;
2362 : 358 : if (rs2 != s2)
2363 : 126 : s2->refuse_visibility_changes = true;
2364 : 358 : return 1;
2365 : : }
2366 : :
2367 : : /* If both symbols may resolve to NULL, we cannot really prove them
2368 : : different. */
2369 : 85068830 : if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ())
2370 : : return -1;
2371 : :
2372 : : /* Except for NULL, functions and variables never overlap. */
2373 : 85068771 : if (TREE_CODE (decl) != TREE_CODE (s2->decl))
2374 : : return 0;
2375 : :
2376 : : /* If one of the symbols is unresolved alias, punt. */
2377 : 84900218 : if (rs1->alias || rs2->alias)
2378 : : return -1;
2379 : :
2380 : : /* If we have a non-interposable definition of at least one of the symbols
2381 : : and the other symbol is different, we know other unit cannot interpose
2382 : : it to the first symbol; all aliases of the definition needs to be
2383 : : present in the current unit. */
2384 : 84900210 : if (((really_binds_local1 || really_binds_local2)
2385 : : /* If we have both definitions and they are different, we know they
2386 : : will be different even in units they binds to. */
2387 : 11534366 : || (binds_local1 && binds_local2))
2388 : 73453116 : && rs1 != rs2)
2389 : : {
2390 : : /* We make use of the fact that one symbol is not alias of the other
2391 : : and that the definition is non-interposable. */
2392 : 73453023 : refuse_visibility_changes = true;
2393 : 73453023 : s2->refuse_visibility_changes = true;
2394 : 73453023 : rs1->refuse_visibility_changes = true;
2395 : 73453023 : rs2->refuse_visibility_changes = true;
2396 : 73453023 : return 0;
2397 : : }
2398 : :
2399 : 11447187 : if (rs1 == rs2)
2400 : : return -1;
2401 : :
2402 : : /* If the FE tells us at least one of the decls will never be aliased nor
2403 : : overlapping with other vars in some other way, return 0. */
2404 : 11447087 : if (VAR_P (decl)
2405 : 11447087 : && (lookup_attribute ("non overlapping", DECL_ATTRIBUTES (decl))
2406 : 11442867 : || lookup_attribute ("non overlapping", DECL_ATTRIBUTES (s2->decl))))
2407 : 4193 : return 0;
2408 : :
2409 : : /* TODO: Alias oracle basically assume that addresses of global variables
2410 : : are different unless they are declared as alias of one to another while
2411 : : the code folding comparisons doesn't.
2412 : : We probably should be consistent and use this fact here, too, but for
2413 : : the moment return false only when we are called from the alias oracle.
2414 : : Return 0 in C constant initializers and C++ manifestly constant
2415 : : expressions, the likelyhood that different vars will be aliases is
2416 : : small and returning -1 lets us reject too many initializers. */
2417 : 11442894 : if (memory_accessed || folding_initializer)
2418 : : return 0;
2419 : :
2420 : : return -1;
2421 : : }
2422 : :
2423 : : /* Worker for call_for_symbol_and_aliases. */
2424 : :
2425 : : bool
2426 : 145715 : symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
2427 : : void *),
2428 : : void *data,
2429 : : bool include_overwritable)
2430 : : {
2431 : 145715 : ipa_ref *ref;
2432 : 310812 : FOR_EACH_ALIAS (this, ref)
2433 : : {
2434 : 166376 : symtab_node *alias = ref->referring;
2435 : 166376 : if (include_overwritable
2436 : 166376 : || alias->get_availability () > AVAIL_INTERPOSABLE)
2437 : 166376 : if (alias->call_for_symbol_and_aliases (callback, data,
2438 : : include_overwritable))
2439 : : return true;
2440 : : }
2441 : : return false;
2442 : : }
2443 : :
2444 : : /* Return true if address of N is possibly compared. */
2445 : :
2446 : : static bool
2447 : 608080 : address_matters_1 (symtab_node *n, void *)
2448 : : {
2449 : 608080 : struct ipa_ref *ref;
2450 : :
2451 : 608080 : if (!n->address_can_be_compared_p ())
2452 : : return false;
2453 : 595552 : if (n->externally_visible || n->force_output)
2454 : : return true;
2455 : :
2456 : 497076 : for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
2457 : 442692 : if (ref->address_matters_p ())
2458 : : return true;
2459 : : return false;
2460 : : }
2461 : :
2462 : : /* Return true if symbol's address may possibly be compared to other
2463 : : symbol's address. */
2464 : :
2465 : : bool
2466 : 585755 : symtab_node::address_matters_p ()
2467 : : {
2468 : 585755 : gcc_assert (!alias);
2469 : 585755 : return call_for_symbol_and_aliases (address_matters_1, NULL, true);
2470 : : }
2471 : :
2472 : : /* Return true if symbol's alignment may be increased. */
2473 : :
2474 : : bool
2475 : 29291 : symtab_node::can_increase_alignment_p (void)
2476 : : {
2477 : 29291 : symtab_node *target = ultimate_alias_target ();
2478 : :
2479 : : /* For now support only variables. */
2480 : 29291 : if (!VAR_P (decl))
2481 : : return false;
2482 : :
2483 : : /* With -fno-toplevel-reorder we may have already output the constant. */
2484 : 29291 : if (TREE_ASM_WRITTEN (target->decl))
2485 : : return false;
2486 : :
2487 : : /* If target is already placed in an anchor, we cannot touch its
2488 : : alignment. */
2489 : 28604 : if (DECL_RTL_SET_P (target->decl)
2490 : 13776 : && MEM_P (DECL_RTL (target->decl))
2491 : 42380 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
2492 : : return false;
2493 : :
2494 : : /* Constant pool entries may be shared. */
2495 : 28604 : if (DECL_IN_CONSTANT_POOL (target->decl))
2496 : : return false;
2497 : :
2498 : : /* We cannot change alignment of symbols that may bind to symbols
2499 : : in other translation unit that may contain a definition with lower
2500 : : alignment. */
2501 : 26482 : if (!decl_binds_to_current_def_p (decl))
2502 : : return false;
2503 : :
2504 : : /* When compiling partition, be sure the symbol is not output by other
2505 : : partition. */
2506 : 17445 : if (flag_ltrans
2507 : 17445 : && (target->in_other_partition
2508 : 321 : || target->get_partitioning_class () == SYMBOL_DUPLICATE))
2509 : 0 : return false;
2510 : :
2511 : : /* Do not override the alignment as specified by the ABI when the used
2512 : : attribute is set. */
2513 : 17445 : if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl))
2514 : : return false;
2515 : :
2516 : : /* Do not override explicit alignment set by the user when an explicit
2517 : : section name is also used. This is a common idiom used by many
2518 : : software projects. */
2519 : 17445 : if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section)
2520 : : return false;
2521 : :
2522 : : return true;
2523 : : }
2524 : :
2525 : : /* Worker for symtab_node::increase_alignment. */
2526 : :
2527 : : static bool
2528 : 4821 : increase_alignment_1 (symtab_node *n, void *v)
2529 : : {
2530 : 4821 : unsigned int align = (size_t)v;
2531 : 4821 : if (DECL_ALIGN (n->decl) < align
2532 : 4821 : && n->can_increase_alignment_p ())
2533 : : {
2534 : 3856 : SET_DECL_ALIGN (n->decl, align);
2535 : 3856 : DECL_USER_ALIGN (n->decl) = 1;
2536 : : }
2537 : 4821 : return false;
2538 : : }
2539 : :
2540 : : /* Increase alignment of THIS to ALIGN. */
2541 : :
2542 : : void
2543 : 4649 : symtab_node::increase_alignment (unsigned int align)
2544 : : {
2545 : 4649 : gcc_assert (can_increase_alignment_p () && align <= MAX_OFILE_ALIGNMENT);
2546 : 4649 : ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
2547 : 4649 : (void *)(size_t) align,
2548 : : true);
2549 : 4649 : gcc_assert (DECL_ALIGN (decl) >= align);
2550 : 4649 : }
2551 : :
2552 : : /* Helper for symtab_node::definition_alignment. */
2553 : :
2554 : : static bool
2555 : 1689964 : get_alignment_1 (symtab_node *n, void *v)
2556 : : {
2557 : 1689964 : *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
2558 : 1689964 : return false;
2559 : : }
2560 : :
2561 : : /* Return desired alignment of the definition. This is NOT alignment useful
2562 : : to access THIS, because THIS may be interposable and DECL_ALIGN should
2563 : : be used instead. It however must be guaranteed when output definition
2564 : : of THIS. */
2565 : :
2566 : : unsigned int
2567 : 1630282 : symtab_node::definition_alignment ()
2568 : : {
2569 : 1630282 : unsigned int align = 0;
2570 : 1630282 : gcc_assert (!alias);
2571 : 1630282 : call_for_symbol_and_aliases (get_alignment_1, &align, true);
2572 : 1630282 : return align;
2573 : : }
2574 : :
2575 : : /* Return symbol used to separate symbol name from suffix. */
2576 : :
2577 : : char
2578 : 308539 : symbol_table::symbol_suffix_separator ()
2579 : : {
2580 : : #ifndef NO_DOT_IN_LABEL
2581 : 308539 : return '.';
2582 : : #elif !defined NO_DOLLAR_IN_LABEL
2583 : : return '$';
2584 : : #else
2585 : : return '_';
2586 : : #endif
2587 : : }
2588 : :
2589 : : /* Return true when references to this symbol from REF must bind to current
2590 : : definition in final executable. */
2591 : :
2592 : : bool
2593 : 95184752 : symtab_node::binds_to_current_def_p (symtab_node *ref)
2594 : : {
2595 : 95184752 : if (!definition && !in_other_partition)
2596 : : return false;
2597 : 47130196 : if (transparent_alias)
2598 : 13 : return definition
2599 : 13 : && get_alias_target()->binds_to_current_def_p (ref);
2600 : 47130183 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2601 : 47130183 : if (cnode && cnode->ifunc_resolver)
2602 : : return false;
2603 : 47130083 : if (decl_binds_to_current_def_p (decl))
2604 : : return true;
2605 : :
2606 : : /* Inline clones always binds locally. */
2607 : 22519934 : if (cnode && cnode->inlined_to)
2608 : : return true;
2609 : :
2610 : 22494197 : if (DECL_EXTERNAL (decl))
2611 : : return false;
2612 : :
2613 : 19325679 : gcc_assert (externally_visible);
2614 : :
2615 : 19325679 : if (ref)
2616 : : {
2617 : 160479 : cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
2618 : 160479 : if (cref)
2619 : 160479 : ref = cref->inlined_to;
2620 : : }
2621 : :
2622 : : /* If this is a reference from symbol itself and there are no aliases, we
2623 : : may be sure that the symbol was not interposed by something else because
2624 : : the symbol itself would be unreachable otherwise. This is important
2625 : : to optimize recursive functions well.
2626 : :
2627 : : This assumption may be broken by inlining: if symbol is interposable
2628 : : but the body is available (i.e. declared inline), inliner may make
2629 : : the body reachable even with interposition. */
2630 : 4387 : if (this == ref && !has_aliases_p ()
2631 : 164799 : && (!cnode
2632 : 4320 : || symtab->state >= IPA_SSA_AFTER_INLINING
2633 : 0 : || get_availability () >= AVAIL_INTERPOSABLE))
2634 : 4320 : return true;
2635 : :
2636 : :
2637 : : /* References within one comdat group are always bound in a group. */
2638 : 19321359 : if (ref
2639 : 88856 : && symtab->state >= IPA_SSA_AFTER_INLINING
2640 : 88856 : && get_comdat_group ()
2641 : 19410211 : && get_comdat_group () == ref->get_comdat_group ())
2642 : : return true;
2643 : :
2644 : : return false;
2645 : : }
2646 : :
2647 : : /* Return true if symbol should be output to the symbol table. */
2648 : :
2649 : : bool
2650 : 1195292 : symtab_node::output_to_lto_symbol_table_p (void)
2651 : : {
2652 : : /* Only externally visible symbols matter. */
2653 : 1195292 : if (!TREE_PUBLIC (decl))
2654 : : return false;
2655 : 1125442 : if (!real_symbol_p ())
2656 : : return false;
2657 : : /* FIXME: variables probably should not be considered as real symbols at
2658 : : first place. */
2659 : 1125442 : if (VAR_P (decl) && DECL_HARD_REGISTER (decl))
2660 : : return false;
2661 : 658932 : if (TREE_CODE (decl) == FUNCTION_DECL && !definition
2662 : 1589616 : && fndecl_built_in_p (decl))
2663 : : {
2664 : : /* Builtins like those for most math functions have actual implementations
2665 : : in libraries so make sure to output references into the symbol table to
2666 : : make those libraries referenced. Note this is incomplete handling for
2667 : : now and only covers math functions. */
2668 : 40794 : return builtin_with_linkage_p (decl);
2669 : : }
2670 : :
2671 : : /* We have real symbol that should be in symbol table. However try to trim
2672 : : down the references to libraries bit more because linker will otherwise
2673 : : bring unnecessary object files into the final link.
2674 : : FIXME: The following checks can easily be confused i.e. by self recursive
2675 : : function or self-referring variable. */
2676 : :
2677 : : /* We keep external functions in symtab for sake of inlining
2678 : : and devirtualization. We do not want to see them in symbol table as
2679 : : references unless they are really used. */
2680 : 1084624 : cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
2681 : 618138 : if (cnode && (!definition || DECL_EXTERNAL (decl))
2682 : 423708 : && cnode->callers)
2683 : : return true;
2684 : :
2685 : : /* Ignore all references from external vars initializers - they are not really
2686 : : part of the compilation unit until they are used by folding. Some symbols,
2687 : : like references to external construction vtables cannot be referred to at
2688 : : all. We decide this at can_refer_decl_in_current_unit_p. */
2689 : 1062814 : if (!definition || DECL_EXTERNAL (decl))
2690 : : {
2691 : : int i;
2692 : : struct ipa_ref *ref;
2693 : 408394 : for (i = 0; iterate_referring (i, ref); i++)
2694 : : {
2695 : 408346 : if (ref->use == IPA_REF_ALIAS)
2696 : 48 : continue;
2697 : 816644 : if (is_a <cgraph_node *> (ref->referring))
2698 : : return true;
2699 : 403070 : if (!DECL_EXTERNAL (ref->referring->decl))
2700 : : return true;
2701 : : }
2702 : : return false;
2703 : : }
2704 : : return true;
2705 : : }
|