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