Daily bump.
[official-gcc.git] / gcc / symtab.c
blobf23bd83f4698b91ec799542fa4488404e4e2edba
1 /* Symbol table.
2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "print-tree.h"
28 #include "varasm.h"
29 #include "function.h"
30 #include "emit-rtl.h"
31 #include "basic-block.h"
32 #include "tree-ssa-alias.h"
33 #include "internal-fn.h"
34 #include "gimple-expr.h"
35 #include "is-a.h"
36 #include "gimple.h"
37 #include "tree-inline.h"
38 #include "langhooks.h"
39 #include "hashtab.h"
40 #include "cgraph.h"
41 #include "diagnostic.h"
42 #include "timevar.h"
43 #include "lto-streamer.h"
44 #include "output.h"
45 #include "ipa-utils.h"
46 #include "calls.h"
48 static const char *ipa_ref_use_name[] = {"read","write","addr","alias"};
50 const char * const ld_plugin_symbol_resolution_names[]=
52 "",
53 "undef",
54 "prevailing_def",
55 "prevailing_def_ironly",
56 "preempted_reg",
57 "preempted_ir",
58 "resolved_ir",
59 "resolved_exec",
60 "resolved_dyn",
61 "prevailing_def_ironly_exp"
64 /* Hash asmnames ignoring the user specified marks. */
66 hashval_t
67 symbol_table::decl_assembler_name_hash (const_tree asmname)
69 if (IDENTIFIER_POINTER (asmname)[0] == '*')
71 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
72 size_t ulp_len = strlen (user_label_prefix);
74 if (ulp_len == 0)
76 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
77 decl_str += ulp_len;
79 return htab_hash_string (decl_str);
82 return htab_hash_string (IDENTIFIER_POINTER (asmname));
86 /* Returns a hash code for P. */
88 hashval_t
89 symbol_table::hash_node_by_assembler_name (const void *p)
91 const symtab_node *n = (const symtab_node *) p;
92 return (hashval_t) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n->decl));
95 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
97 bool
98 symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
100 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
101 const char *decl_str;
102 const char *asmname_str;
103 bool test = false;
105 if (decl_asmname == asmname)
106 return true;
108 decl_str = IDENTIFIER_POINTER (decl_asmname);
109 asmname_str = IDENTIFIER_POINTER (asmname);
112 /* If the target assembler name was set by the user, things are trickier.
113 We have a leading '*' to begin with. After that, it's arguable what
114 is the correct thing to do with -fleading-underscore. Arguably, we've
115 historically been doing the wrong thing in assemble_alias by always
116 printing the leading underscore. Since we're not changing that, make
117 sure user_label_prefix follows the '*' before matching. */
118 if (decl_str[0] == '*')
120 size_t ulp_len = strlen (user_label_prefix);
122 decl_str ++;
124 if (ulp_len == 0)
125 test = true;
126 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
127 decl_str += ulp_len, test=true;
128 else
129 decl_str --;
131 if (asmname_str[0] == '*')
133 size_t ulp_len = strlen (user_label_prefix);
135 asmname_str ++;
137 if (ulp_len == 0)
138 test = true;
139 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
140 asmname_str += ulp_len, test=true;
141 else
142 asmname_str --;
145 if (!test)
146 return false;
147 return strcmp (decl_str, asmname_str) == 0;
151 /* Returns nonzero if P1 and P2 are equal. */
154 symbol_table::eq_assembler_name (const void *p1, const void *p2)
156 const symtab_node *n1 = (const symtab_node *) p1;
157 const_tree name = (const_tree)p2;
158 return (decl_assembler_name_equal (n1->decl, name));
161 /* Insert NODE to assembler name hash. */
163 void
164 symbol_table::insert_to_assembler_name_hash (symtab_node *node,
165 bool with_clones)
167 if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
168 return;
169 gcc_checking_assert (!node->previous_sharing_asm_name
170 && !node->next_sharing_asm_name);
171 if (assembler_name_hash)
173 void **aslot;
174 cgraph_node *cnode;
175 tree decl = node->decl;
177 tree name = DECL_ASSEMBLER_NAME (node->decl);
179 aslot = htab_find_slot_with_hash (assembler_name_hash, name,
180 decl_assembler_name_hash (name),
181 INSERT);
182 gcc_assert (*aslot != node);
183 node->next_sharing_asm_name = (symtab_node *)*aslot;
184 if (*aslot != NULL)
185 ((symtab_node *)*aslot)->previous_sharing_asm_name = node;
186 *aslot = node;
188 /* Update also possible inline clones sharing a decl. */
189 cnode = dyn_cast <cgraph_node *> (node);
190 if (cnode && cnode->clones && with_clones)
191 for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
192 if (cnode->decl == decl)
193 insert_to_assembler_name_hash (cnode, true);
198 /* Remove NODE from assembler name hash. */
200 void
201 symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
202 bool with_clones)
204 if (assembler_name_hash)
206 cgraph_node *cnode;
207 tree decl = node->decl;
209 if (node->next_sharing_asm_name)
210 node->next_sharing_asm_name->previous_sharing_asm_name
211 = node->previous_sharing_asm_name;
212 if (node->previous_sharing_asm_name)
214 node->previous_sharing_asm_name->next_sharing_asm_name
215 = node->next_sharing_asm_name;
217 else
219 tree name = DECL_ASSEMBLER_NAME (node->decl);
220 void **slot;
221 slot = htab_find_slot_with_hash (assembler_name_hash, name,
222 decl_assembler_name_hash (name),
223 NO_INSERT);
224 gcc_assert (*slot == node);
225 if (!node->next_sharing_asm_name)
226 htab_clear_slot (assembler_name_hash, slot);
227 else
228 *slot = node->next_sharing_asm_name;
230 node->next_sharing_asm_name = NULL;
231 node->previous_sharing_asm_name = NULL;
233 /* Update also possible inline clones sharing a decl. */
234 cnode = dyn_cast <cgraph_node *> (node);
235 if (cnode && cnode->clones && with_clones)
236 for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
237 if (cnode->decl == decl)
238 unlink_from_assembler_name_hash (cnode, true);
242 /* Arrange node to be first in its entry of assembler_name_hash. */
244 void
245 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
247 unlink_from_assembler_name_hash (node, false);
248 insert_to_assembler_name_hash (node, false);
251 /* Initalize asm name hash unless. */
253 void
254 symbol_table::symtab_initialize_asm_name_hash (void)
256 symtab_node *node;
257 if (!assembler_name_hash)
259 assembler_name_hash =
260 htab_create_ggc (10, hash_node_by_assembler_name, eq_assembler_name,
261 NULL);
262 FOR_EACH_SYMBOL (node)
263 insert_to_assembler_name_hash (node, false);
267 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
269 void
270 symbol_table::change_decl_assembler_name (tree decl, tree name)
272 symtab_node *node = NULL;
274 /* We can have user ASM names on things, like global register variables, that
275 are not in the symbol table. */
276 if ((TREE_CODE (decl) == VAR_DECL
277 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
278 || TREE_CODE (decl) == FUNCTION_DECL)
279 node = symtab_node::get (decl);
280 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
282 SET_DECL_ASSEMBLER_NAME (decl, name);
283 if (node)
284 insert_to_assembler_name_hash (node, true);
286 else
288 if (name == DECL_ASSEMBLER_NAME (decl))
289 return;
291 tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
292 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
293 : NULL);
294 if (node)
295 unlink_from_assembler_name_hash (node, true);
296 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
297 && DECL_RTL_SET_P (decl))
298 warning (0, "%D renamed after being referenced in assembly", decl);
300 SET_DECL_ASSEMBLER_NAME (decl, name);
301 if (alias)
303 IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
304 TREE_CHAIN (name) = alias;
306 if (node)
307 insert_to_assembler_name_hash (node, true);
311 /* Return true when RESOLUTION indicate that linker will use
312 the symbol from non-LTO object files. */
314 bool
315 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
317 return (resolution == LDPR_PREVAILING_DEF
318 || resolution == LDPR_PREEMPTED_REG
319 || resolution == LDPR_RESOLVED_EXEC
320 || resolution == LDPR_RESOLVED_DYN);
323 /* Hash sections by their names. */
325 static hashval_t
326 hash_section_hash_entry (const void *p)
328 const section_hash_entry *n = (const section_hash_entry *) p;
329 return htab_hash_string (n->name);
332 /* Return true if section P1 name equals to P2. */
334 static int
335 eq_sections (const void *p1, const void *p2)
337 const section_hash_entry *n1 = (const section_hash_entry *) p1;
338 const char *name = (const char *)p2;
339 return n1->name == name || !strcmp (n1->name, name);
342 /* Add node into symbol table. This function is not used directly, but via
343 cgraph/varpool node creation routines. */
345 void
346 symtab_node::register_symbol (void)
348 symtab->register_symbol (this);
350 if (!decl->decl_with_vis.symtab_node)
351 decl->decl_with_vis.symtab_node = this;
353 ref_list.clear ();
355 /* Be sure to do this last; C++ FE might create new nodes via
356 DECL_ASSEMBLER_NAME langhook! */
357 symtab->insert_to_assembler_name_hash (this, false);
360 /* Remove NODE from same comdat group. */
362 void
363 symtab_node::remove_from_same_comdat_group (void)
365 if (same_comdat_group)
367 symtab_node *prev;
368 for (prev = same_comdat_group;
369 prev->same_comdat_group != this;
370 prev = prev->same_comdat_group)
372 if (same_comdat_group == prev)
373 prev->same_comdat_group = NULL;
374 else
375 prev->same_comdat_group = same_comdat_group;
376 same_comdat_group = NULL;
377 set_comdat_group (NULL);
381 /* Remove node from symbol table. This function is not used directly, but via
382 cgraph/varpool node removal routines. */
384 void
385 symtab_node::unregister (void)
387 remove_all_references ();
388 remove_all_referring ();
390 /* Remove reference to section. */
391 set_section_for_node (NULL);
393 remove_from_same_comdat_group ();
395 symtab->unregister (this);
397 /* During LTO symtab merging we temporarily corrupt decl to symtab node
398 hash. */
399 gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
400 if (decl->decl_with_vis.symtab_node == this)
402 symtab_node *replacement_node = NULL;
403 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
404 replacement_node = cnode->find_replacement ();
405 decl->decl_with_vis.symtab_node = replacement_node;
407 if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
408 symtab->unlink_from_assembler_name_hash (this, false);
409 if (in_init_priority_hash)
410 symtab->init_priority_hash->remove (this);
414 /* Remove symbol from symbol table. */
416 void
417 symtab_node::remove (void)
419 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
420 cnode->remove ();
421 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
422 vnode->remove ();
425 /* Add NEW_ to the same comdat group that OLD is in. */
427 void
428 symtab_node::add_to_same_comdat_group (symtab_node *old_node)
430 gcc_assert (old_node->get_comdat_group ());
431 gcc_assert (!same_comdat_group);
432 gcc_assert (this != old_node);
434 set_comdat_group (old_node->get_comdat_group ());
435 same_comdat_group = old_node;
436 if (!old_node->same_comdat_group)
437 old_node->same_comdat_group = this;
438 else
440 symtab_node *n;
441 for (n = old_node->same_comdat_group;
442 n->same_comdat_group != old_node;
443 n = n->same_comdat_group)
445 n->same_comdat_group = this;
449 /* Dissolve the same_comdat_group list in which NODE resides. */
451 void
452 symtab_node::dissolve_same_comdat_group_list (void)
454 symtab_node *n = this;
455 symtab_node *next;
457 if (!same_comdat_group)
458 return;
461 next = n->same_comdat_group;
462 n->same_comdat_group = NULL;
463 /* Clear comdat_group for comdat locals, since
464 make_decl_local doesn't. */
465 if (!TREE_PUBLIC (n->decl))
466 n->set_comdat_group (NULL);
467 n = next;
469 while (n != this);
472 /* Return printable assembler name of NODE.
473 This function is used only for debugging. When assembler name
474 is unknown go with identifier name. */
476 const char *
477 symtab_node::asm_name () const
479 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
480 return lang_hooks.decl_printable_name (decl, 2);
481 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
484 /* Return printable identifier name. */
486 const char *
487 symtab_node::name () const
489 return lang_hooks.decl_printable_name (decl, 2);
492 /* Return ipa reference from this symtab_node to
493 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
494 of the use. */
496 ipa_ref *
497 symtab_node::create_reference (symtab_node *referred_node,
498 enum ipa_ref_use use_type)
500 return create_reference (referred_node, use_type, NULL);
504 /* Return ipa reference from this symtab_node to
505 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
506 of the use and STMT the statement (if it exists). */
508 ipa_ref *
509 symtab_node::create_reference (symtab_node *referred_node,
510 enum ipa_ref_use use_type, gimple stmt)
512 ipa_ref *ref = NULL, *ref2 = NULL;
513 ipa_ref_list *list, *list2;
514 ipa_ref_t *old_references;
516 gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
517 gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
519 list = &ref_list;
520 old_references = vec_safe_address (list->references);
521 vec_safe_grow (list->references, vec_safe_length (list->references) + 1);
522 ref = &list->references->last ();
524 list2 = &referred_node->ref_list;
526 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
527 if(use_type == IPA_REF_ALIAS)
529 list2->referring.safe_insert (0, ref);
530 ref->referred_index = 0;
532 for (unsigned int i = 1; i < list2->referring.length (); i++)
533 list2->referring[i]->referred_index = i;
535 else
537 list2->referring.safe_push (ref);
538 ref->referred_index = list2->referring.length () - 1;
541 ref->referring = this;
542 ref->referred = referred_node;
543 ref->stmt = stmt;
544 ref->lto_stmt_uid = 0;
545 ref->use = use_type;
546 ref->speculative = 0;
548 /* If vector was moved in memory, update pointers. */
549 if (old_references != list->references->address ())
551 int i;
552 for (i = 0; iterate_reference(i, ref2); i++)
553 ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
555 return ref;
558 /* If VAL is a reference to a function or a variable, add a reference from
559 this symtab_node to the corresponding symbol table node. USE_TYPE specify
560 type of the use and STMT the statement (if it exists). Return the new
561 reference or NULL if none was created. */
563 ipa_ref *
564 symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
565 gimple stmt)
567 STRIP_NOPS (val);
568 if (TREE_CODE (val) != ADDR_EXPR)
569 return NULL;
570 val = get_base_var (val);
571 if (val && (TREE_CODE (val) == FUNCTION_DECL
572 || TREE_CODE (val) == VAR_DECL))
574 symtab_node *referred = symtab_node::get (val);
575 gcc_checking_assert (referred);
576 return create_reference (referred, use_type, stmt);
578 return NULL;
581 /* Clone all references from symtab NODE to this symtab_node. */
583 void
584 symtab_node::clone_references (symtab_node *node)
586 ipa_ref *ref = NULL, *ref2 = NULL;
587 int i;
588 for (i = 0; node->iterate_reference (i, ref); i++)
590 bool speculative = ref->speculative;
591 unsigned int stmt_uid = ref->lto_stmt_uid;
593 ref2 = create_reference (ref->referred, ref->use, ref->stmt);
594 ref2->speculative = speculative;
595 ref2->lto_stmt_uid = stmt_uid;
599 /* Clone all referring from symtab NODE to this symtab_node. */
601 void
602 symtab_node::clone_referring (symtab_node *node)
604 ipa_ref *ref = NULL, *ref2 = NULL;
605 int i;
606 for (i = 0; node->iterate_referring(i, ref); i++)
608 bool speculative = ref->speculative;
609 unsigned int stmt_uid = ref->lto_stmt_uid;
611 ref2 = ref->referring->create_reference (this, ref->use, ref->stmt);
612 ref2->speculative = speculative;
613 ref2->lto_stmt_uid = stmt_uid;
617 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
619 ipa_ref *
620 symtab_node::clone_reference (ipa_ref *ref, gimple stmt)
622 bool speculative = ref->speculative;
623 unsigned int stmt_uid = ref->lto_stmt_uid;
624 ipa_ref *ref2;
626 ref2 = create_reference (ref->referred, ref->use, stmt);
627 ref2->speculative = speculative;
628 ref2->lto_stmt_uid = stmt_uid;
629 return ref2;
632 /* Find the structure describing a reference to REFERRED_NODE
633 and associated with statement STMT. */
635 ipa_ref *
636 symtab_node::find_reference (symtab_node *referred_node,
637 gimple stmt, unsigned int lto_stmt_uid)
639 ipa_ref *r = NULL;
640 int i;
642 for (i = 0; iterate_reference (i, r); i++)
643 if (r->referred == referred_node
644 && !r->speculative
645 && ((stmt && r->stmt == stmt)
646 || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
647 || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid)))
648 return r;
649 return NULL;
652 /* Remove all references that are associated with statement STMT. */
654 void
655 symtab_node::remove_stmt_references (gimple stmt)
657 ipa_ref *r = NULL;
658 int i = 0;
660 while (iterate_reference (i, r))
661 if (r->stmt == stmt)
662 r->remove_reference ();
663 else
664 i++;
667 /* Remove all stmt references in non-speculative references.
668 Those are not maintained during inlining & clonning.
669 The exception are speculative references that are updated along
670 with callgraph edges associated with them. */
672 void
673 symtab_node::clear_stmts_in_references (void)
675 ipa_ref *r = NULL;
676 int i;
678 for (i = 0; iterate_reference (i, r); i++)
679 if (!r->speculative)
681 r->stmt = NULL;
682 r->lto_stmt_uid = 0;
686 /* Remove all references in ref list. */
688 void
689 symtab_node::remove_all_references (void)
691 while (vec_safe_length (ref_list.references))
692 ref_list.references->last ().remove_reference ();
693 vec_free (ref_list.references);
696 /* Remove all referring items in ref list. */
698 void
699 symtab_node::remove_all_referring (void)
701 while (ref_list.referring.length ())
702 ref_list.referring.last ()->remove_reference ();
703 ref_list.referring.release ();
706 /* Dump references in ref list to FILE. */
708 void
709 symtab_node::dump_references (FILE *file)
711 ipa_ref *ref = NULL;
712 int i;
713 for (i = 0; iterate_reference (i, ref); i++)
715 fprintf (file, "%s/%i (%s)",
716 ref->referred->asm_name (),
717 ref->referred->order,
718 ipa_ref_use_name [ref->use]);
719 if (ref->speculative)
720 fprintf (file, " (speculative)");
722 fprintf (file, "\n");
725 /* Dump referring in list to FILE. */
727 void
728 symtab_node::dump_referring (FILE *file)
730 ipa_ref *ref = NULL;
731 int i;
732 for (i = 0; iterate_referring(i, ref); i++)
734 fprintf (file, "%s/%i (%s)",
735 ref->referring->asm_name (),
736 ref->referring->order,
737 ipa_ref_use_name [ref->use]);
738 if (ref->speculative)
739 fprintf (file, " (speculative)");
741 fprintf (file, "\n");
744 /* Return true if list contains an alias. */
745 bool
746 symtab_node::has_aliases_p (void)
748 ipa_ref *ref = NULL;
749 int i;
751 for (i = 0; iterate_referring (i, ref); i++)
752 if (ref->use == IPA_REF_ALIAS)
753 return true;
754 return false;
757 /* Iterates I-th reference in the list, REF is also set. */
759 ipa_ref *
760 symtab_node::iterate_reference (unsigned i, ipa_ref *&ref)
762 vec_safe_iterate (ref_list.references, i, &ref);
764 return ref;
767 /* Iterates I-th referring item in the list, REF is also set. */
769 ipa_ref *
770 symtab_node::iterate_referring (unsigned i, ipa_ref *&ref)
772 ref_list.referring.iterate (i, &ref);
774 return ref;
777 /* Iterates I-th referring alias item in the list, REF is also set. */
779 ipa_ref *
780 symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref)
782 ref_list.referring.iterate (i, &ref);
784 if (ref && ref->use != IPA_REF_ALIAS)
785 return NULL;
787 return ref;
790 static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
792 /* Dump base fields of symtab nodes to F. Not to be used directly. */
794 void
795 symtab_node::dump_base (FILE *f)
797 static const char * const visibility_types[] = {
798 "default", "protected", "hidden", "internal"
801 fprintf (f, "%s/%i (%s)", asm_name (), order, name ());
802 dump_addr (f, " @", (void *)this);
803 fprintf (f, "\n Type: %s", symtab_type_names[type]);
805 if (definition)
806 fprintf (f, " definition");
807 if (analyzed)
808 fprintf (f, " analyzed");
809 if (alias)
810 fprintf (f, " alias");
811 if (weakref)
812 fprintf (f, " weakref");
813 if (cpp_implicit_alias)
814 fprintf (f, " cpp_implicit_alias");
815 if (alias_target)
816 fprintf (f, " target:%s",
817 DECL_P (alias_target)
818 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
819 (alias_target))
820 : IDENTIFIER_POINTER (alias_target));
821 if (body_removed)
822 fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
823 fprintf (f, "\n Visibility:");
824 if (in_other_partition)
825 fprintf (f, " in_other_partition");
826 if (used_from_other_partition)
827 fprintf (f, " used_from_other_partition");
828 if (force_output)
829 fprintf (f, " force_output");
830 if (forced_by_abi)
831 fprintf (f, " forced_by_abi");
832 if (externally_visible)
833 fprintf (f, " externally_visible");
834 if (no_reorder)
835 fprintf (f, " no_reorder");
836 if (resolution != LDPR_UNKNOWN)
837 fprintf (f, " %s",
838 ld_plugin_symbol_resolution_names[(int)resolution]);
839 if (TREE_ASM_WRITTEN (decl))
840 fprintf (f, " asm_written");
841 if (DECL_EXTERNAL (decl))
842 fprintf (f, " external");
843 if (TREE_PUBLIC (decl))
844 fprintf (f, " public");
845 if (DECL_COMMON (decl))
846 fprintf (f, " common");
847 if (DECL_WEAK (decl))
848 fprintf (f, " weak");
849 if (DECL_DLLIMPORT_P (decl))
850 fprintf (f, " dll_import");
851 if (DECL_COMDAT (decl))
852 fprintf (f, " comdat");
853 if (get_comdat_group ())
854 fprintf (f, " comdat_group:%s",
855 IDENTIFIER_POINTER (get_comdat_group_id ()));
856 if (DECL_ONE_ONLY (decl))
857 fprintf (f, " one_only");
858 if (get_section ())
859 fprintf (f, " section:%s",
860 get_section ());
861 if (implicit_section)
862 fprintf (f," (implicit_section)");
863 if (DECL_VISIBILITY_SPECIFIED (decl))
864 fprintf (f, " visibility_specified");
865 if (DECL_VISIBILITY (decl))
866 fprintf (f, " visibility:%s",
867 visibility_types [DECL_VISIBILITY (decl)]);
868 if (DECL_VIRTUAL_P (decl))
869 fprintf (f, " virtual");
870 if (DECL_ARTIFICIAL (decl))
871 fprintf (f, " artificial");
872 if (TREE_CODE (decl) == FUNCTION_DECL)
874 if (DECL_STATIC_CONSTRUCTOR (decl))
875 fprintf (f, " constructor");
876 if (DECL_STATIC_DESTRUCTOR (decl))
877 fprintf (f, " destructor");
879 fprintf (f, "\n");
881 if (same_comdat_group)
882 fprintf (f, " Same comdat group as: %s/%i\n",
883 same_comdat_group->asm_name (),
884 same_comdat_group->order);
885 if (next_sharing_asm_name)
886 fprintf (f, " next sharing asm name: %i\n",
887 next_sharing_asm_name->order);
888 if (previous_sharing_asm_name)
889 fprintf (f, " previous sharing asm name: %i\n",
890 previous_sharing_asm_name->order);
892 if (address_taken)
893 fprintf (f, " Address is taken.\n");
894 if (aux)
896 fprintf (f, " Aux:");
897 dump_addr (f, " @", (void *)aux);
900 fprintf (f, " References: ");
901 dump_references (f);
902 fprintf (f, " Referring: ");
903 dump_referring (f);
904 if (lto_file_data)
905 fprintf (f, " Read from file: %s\n",
906 lto_file_data->file_name);
909 /* Dump symtab node to F. */
911 void
912 symtab_node::dump (FILE *f)
914 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
915 cnode->dump (f);
916 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
917 vnode->dump (f);
920 /* Dump symbol table to F. */
922 void
923 symtab_node::dump_table (FILE *f)
925 symtab_node *node;
926 fprintf (f, "Symbol table:\n\n");
927 FOR_EACH_SYMBOL (node)
928 node->dump (f);
932 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
933 Return NULL if there's no such node. */
935 symtab_node *
936 symtab_node::get_for_asmname (const_tree asmname)
938 symtab_node *node;
939 void **slot;
941 symtab->symtab_initialize_asm_name_hash ();
942 slot = htab_find_slot_with_hash (symtab->assembler_name_hash, asmname,
943 symtab->decl_assembler_name_hash (asmname),
944 NO_INSERT);
946 if (slot)
948 node = (symtab_node *) *slot;
949 return node;
951 return NULL;
954 /* Dump symtab node NODE to stderr. */
956 DEBUG_FUNCTION void
957 symtab_node::debug (void)
959 dump (stderr);
962 /* Verify common part of symtab nodes. */
964 DEBUG_FUNCTION bool
965 symtab_node::verify_base (void)
967 bool error_found = false;
968 symtab_node *hashed_node;
970 if (is_a <cgraph_node *> (this))
972 if (TREE_CODE (decl) != FUNCTION_DECL)
974 error ("function symbol is not function");
975 error_found = true;
978 else if (is_a <varpool_node *> (this))
980 if (TREE_CODE (decl) != VAR_DECL)
982 error ("variable symbol is not variable");
983 error_found = true;
986 else
988 error ("node has unknown type");
989 error_found = true;
992 if (symtab->state != LTO_STREAMING)
994 hashed_node = symtab_node::get (decl);
995 if (!hashed_node)
997 error ("node not found node->decl->decl_with_vis.symtab_node");
998 error_found = true;
1000 if (hashed_node != this
1001 && (!is_a <cgraph_node *> (this)
1002 || !dyn_cast <cgraph_node *> (this)->clone_of
1003 || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
1005 error ("node differs from node->decl->decl_with_vis.symtab_node");
1006 error_found = true;
1009 if (symtab->assembler_name_hash)
1011 hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
1012 if (hashed_node && hashed_node->previous_sharing_asm_name)
1014 error ("assembler name hash list corrupted");
1015 error_found = true;
1017 while (hashed_node)
1019 if (hashed_node == this)
1020 break;
1021 hashed_node = hashed_node->next_sharing_asm_name;
1023 if (!hashed_node
1024 && !(is_a <varpool_node *> (this)
1025 || DECL_HARD_REGISTER (decl)))
1027 error ("node not found in symtab assembler name hash");
1028 error_found = true;
1031 if (previous_sharing_asm_name
1032 && previous_sharing_asm_name->next_sharing_asm_name != this)
1034 error ("double linked list of assembler names corrupted");
1035 error_found = true;
1037 if (analyzed && !definition)
1039 error ("node is analyzed byt it is not a definition");
1040 error_found = true;
1042 if (cpp_implicit_alias && !alias)
1044 error ("node is alias but not implicit alias");
1045 error_found = true;
1047 if (alias && !definition && !weakref)
1049 error ("node is alias but not definition");
1050 error_found = true;
1052 if (weakref && !alias)
1054 error ("node is weakref but not an alias");
1055 error_found = true;
1057 if (same_comdat_group)
1059 symtab_node *n = same_comdat_group;
1061 if (!n->get_comdat_group ())
1063 error ("node is in same_comdat_group list but has no comdat_group");
1064 error_found = true;
1066 if (n->get_comdat_group () != get_comdat_group ())
1068 error ("same_comdat_group list across different groups");
1069 error_found = true;
1071 if (!n->definition)
1073 error ("Node has same_comdat_group but it is not a definition");
1074 error_found = true;
1076 if (n->type != type)
1078 error ("mixing different types of symbol in same comdat groups is not supported");
1079 error_found = true;
1081 if (n == this)
1083 error ("node is alone in a comdat group");
1084 error_found = true;
1088 if (!n->same_comdat_group)
1090 error ("same_comdat_group is not a circular list");
1091 error_found = true;
1092 break;
1094 n = n->same_comdat_group;
1096 while (n != this);
1097 if (comdat_local_p ())
1099 ipa_ref *ref = NULL;
1101 for (int i = 0; iterate_referring (i, ref); ++i)
1103 if (!in_same_comdat_group_p (ref->referring))
1105 error ("comdat-local symbol referred to by %s outside its "
1106 "comdat",
1107 identifier_to_locale (ref->referring->name()));
1108 error_found = true;
1113 if (implicit_section && !get_section ())
1115 error ("implicit_section flag is set but section isn't");
1116 error_found = true;
1118 if (get_section () && get_comdat_group ()
1119 && !implicit_section)
1121 error ("Both section and comdat group is set");
1122 error_found = true;
1124 /* TODO: Add string table for sections, so we do not keep holding duplicated
1125 strings. */
1126 if (alias && definition
1127 && get_section () != get_alias_target ()->get_section ()
1128 && (!get_section()
1129 || !get_alias_target ()->get_section ()
1130 || strcmp (get_section(),
1131 get_alias_target ()->get_section ())))
1133 error ("Alias and target's section differs");
1134 get_alias_target ()->dump (stderr);
1135 error_found = true;
1137 if (alias && definition
1138 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1140 error ("Alias and target's comdat groups differs");
1141 get_alias_target ()->dump (stderr);
1142 error_found = true;
1145 return error_found;
1148 /* Verify consistency of NODE. */
1150 DEBUG_FUNCTION void
1151 symtab_node::verify (void)
1153 if (seen_error ())
1154 return;
1156 timevar_push (TV_CGRAPH_VERIFY);
1157 if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
1158 node->verify_node ();
1159 else
1160 if (verify_base ())
1162 debug ();
1163 internal_error ("symtab_node::verify failed");
1165 timevar_pop (TV_CGRAPH_VERIFY);
1168 /* Verify symbol table for internal consistency. */
1170 DEBUG_FUNCTION void
1171 symtab_node::verify_symtab_nodes (void)
1173 symtab_node *node;
1174 hash_map<tree, symtab_node *> comdat_head_map (251);
1176 FOR_EACH_SYMBOL (node)
1178 node->verify ();
1179 if (node->get_comdat_group ())
1181 symtab_node **entry, *s;
1182 bool existed;
1184 entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
1185 &existed);
1186 if (!existed)
1187 *entry = node;
1188 else
1189 for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
1190 if (!s || s == *entry)
1192 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1193 (*entry)->debug ();
1194 node->debug ();
1195 internal_error ("symtab_node::verify failed");
1201 /* Return true when NODE is known to be used from other (non-LTO)
1202 object file. Known only when doing LTO via linker plugin. */
1204 bool
1205 symtab_node::used_from_object_file_p_worker (symtab_node *node)
1207 if (!TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl))
1208 return false;
1209 if (resolution_used_from_other_file_p (node->resolution))
1210 return true;
1211 return false;
1215 /* Return true when symtab_node is known to be used from other (non-LTO)
1216 object file. Known only when doing LTO via linker plugin. */
1218 bool
1219 symtab_node::used_from_object_file_p (void)
1221 return symtab_node::used_from_object_file_p_worker (this);
1224 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1225 but other code such as notice_global_symbol generates rtl. */
1227 void
1228 symtab_node::make_decl_local (void)
1230 rtx rtl, symbol;
1232 /* Avoid clearing comdat_groups on comdat-local decls. */
1233 if (TREE_PUBLIC (decl) == 0)
1234 return;
1236 if (TREE_CODE (decl) == VAR_DECL)
1237 DECL_COMMON (decl) = 0;
1238 else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1240 DECL_COMDAT (decl) = 0;
1241 DECL_WEAK (decl) = 0;
1242 DECL_EXTERNAL (decl) = 0;
1243 DECL_VISIBILITY_SPECIFIED (decl) = 0;
1244 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1245 TREE_PUBLIC (decl) = 0;
1246 if (!DECL_RTL_SET_P (decl))
1247 return;
1249 /* Update rtl flags. */
1250 make_decl_rtl (decl);
1252 rtl = DECL_RTL (decl);
1253 if (!MEM_P (rtl))
1254 return;
1256 symbol = XEXP (rtl, 0);
1257 if (GET_CODE (symbol) != SYMBOL_REF)
1258 return;
1260 SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
1263 /* Walk the alias chain to return the symbol NODE is alias of.
1264 If NODE is not an alias, return NODE.
1265 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1267 symtab_node *
1268 symtab_node::ultimate_alias_target (enum availability *availability)
1270 bool weakref_p = false;
1272 if (!alias)
1274 if (availability)
1275 *availability = get_availability ();
1276 return this;
1279 /* To determine visibility of the target, we follow ELF semantic of aliases.
1280 Here alias is an alternative assembler name of a given definition. Its
1281 availability prevails the availability of its target (i.e. static alias of
1282 weak definition is available.
1284 Weakref is a different animal (and not part of ELF per se). It is just
1285 alternative name of a given symbol used within one complation unit
1286 and is translated prior hitting the object file. It inherits the
1287 visibility of its target (i.e. weakref of non-overwritable definition
1288 is non-overwritable, while weakref of weak definition is weak).
1290 If we ever get into supporting targets with different semantics, a target
1291 hook will be needed here. */
1293 if (availability)
1295 weakref_p = weakref;
1296 if (!weakref_p)
1297 *availability = get_availability ();
1298 else
1299 *availability = AVAIL_LOCAL;
1302 symtab_node *node = this;
1303 while (node)
1305 if (node->alias && node->analyzed)
1306 node = node->get_alias_target ();
1307 else
1309 if (!availability)
1311 else if (node->analyzed)
1313 if (weakref_p)
1315 enum availability a = node->get_availability ();
1316 if (a < *availability)
1317 *availability = a;
1320 else
1321 *availability = AVAIL_NOT_AVAILABLE;
1322 return node;
1324 if (node && availability && weakref_p)
1326 enum availability a = node->get_availability ();
1327 if (a < *availability)
1328 *availability = a;
1329 weakref_p = node->weakref;
1332 if (availability)
1333 *availability = AVAIL_NOT_AVAILABLE;
1334 return NULL;
1337 /* C++ FE sometimes change linkage flags after producing same body aliases.
1339 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1340 are obviously equivalent. The way it is doing so is however somewhat
1341 kludgy and interferes with the visibility code. As a result we need to
1342 copy the visibility from the target to get things right. */
1344 void
1345 symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
1347 if (is_a <cgraph_node *> (this))
1349 DECL_DECLARED_INLINE_P (decl)
1350 = DECL_DECLARED_INLINE_P (target->decl);
1351 DECL_DISREGARD_INLINE_LIMITS (decl)
1352 = DECL_DISREGARD_INLINE_LIMITS (target->decl);
1354 /* FIXME: It is not really clear why those flags should not be copied for
1355 functions, too. */
1356 else
1358 DECL_WEAK (decl) = DECL_WEAK (target->decl);
1359 DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1360 DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
1362 DECL_VIRTUAL_P (decl) = DECL_VIRTUAL_P (target->decl);
1363 if (TREE_PUBLIC (decl))
1365 tree group;
1367 DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1368 DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
1369 group = target->get_comdat_group ();
1370 set_comdat_group (group);
1371 if (group && !same_comdat_group)
1372 add_to_same_comdat_group (target);
1374 externally_visible = target->externally_visible;
1377 /* Set section, do not recurse into aliases.
1378 When one wants to change section of symbol and its aliases,
1379 use set_section. */
1381 void
1382 symtab_node::set_section_for_node (const char *section)
1384 const char *current = get_section ();
1385 void **slot;
1387 if (current == section
1388 || (current && section
1389 && !strcmp (current, section)))
1390 return;
1392 if (current)
1394 x_section->ref_count--;
1395 if (!x_section->ref_count)
1397 slot = htab_find_slot_with_hash (symtab->section_hash, x_section->name,
1398 htab_hash_string (x_section->name),
1399 INSERT);
1400 ggc_free (x_section);
1401 htab_clear_slot (symtab->section_hash, slot);
1403 x_section = NULL;
1405 if (!section)
1407 implicit_section = false;
1408 return;
1410 if (!symtab->section_hash)
1411 symtab->section_hash = htab_create_ggc (10, hash_section_hash_entry,
1412 eq_sections, NULL);
1413 slot = htab_find_slot_with_hash (symtab->section_hash, section,
1414 htab_hash_string (section),
1415 INSERT);
1416 if (*slot)
1417 x_section = (section_hash_entry *)*slot;
1418 else
1420 int len = strlen (section);
1421 *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
1422 x_section->name = ggc_vec_alloc<char> (len + 1);
1423 memcpy (x_section->name, section, len + 1);
1425 x_section->ref_count++;
1428 /* Worker for set_section. */
1430 bool
1431 symtab_node::set_section (symtab_node *n, void *s)
1433 n->set_section_for_node ((char *)s);
1434 return false;
1437 /* Set section of symbol and its aliases. */
1439 void
1440 symtab_node::set_section (const char *section)
1442 gcc_assert (!this->alias);
1443 call_for_symbol_and_aliases
1444 (symtab_node::set_section, const_cast<char *>(section), true);
1447 /* Return the initialization priority. */
1449 priority_type
1450 symtab_node::get_init_priority ()
1452 if (!this->in_init_priority_hash)
1453 return DEFAULT_INIT_PRIORITY;
1455 symbol_priority_map *h = symtab->init_priority_hash->get (this);
1456 return h ? h->init : DEFAULT_INIT_PRIORITY;
1459 /* Return availability of NODE. */
1460 enum availability symtab_node::get_availability (void)
1462 if (is_a <cgraph_node *> (this))
1463 return dyn_cast <cgraph_node *> (this)->get_availability ();
1464 else
1465 return dyn_cast <varpool_node *> (this)->get_availability ();;
1469 /* Return the finalization priority. */
1471 priority_type
1472 cgraph_node::get_fini_priority ()
1474 if (!this->in_init_priority_hash)
1475 return DEFAULT_INIT_PRIORITY;
1476 symbol_priority_map *h = symtab->init_priority_hash->get (this);
1477 return h ? h->fini : DEFAULT_INIT_PRIORITY;
1480 /* Return the initialization and finalization priority information for
1481 DECL. If there is no previous priority information, a freshly
1482 allocated structure is returned. */
1484 symbol_priority_map *
1485 symtab_node::priority_info (void)
1487 if (!symtab->init_priority_hash)
1488 symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
1490 bool existed;
1491 symbol_priority_map *h
1492 = &symtab->init_priority_hash->get_or_insert (this, &existed);
1493 if (!existed)
1495 h->init = DEFAULT_INIT_PRIORITY;
1496 h->fini = DEFAULT_INIT_PRIORITY;
1497 in_init_priority_hash = true;
1500 return h;
1503 /* Set initialization priority to PRIORITY. */
1505 void
1506 symtab_node::set_init_priority (priority_type priority)
1508 symbol_priority_map *h;
1510 if (is_a <cgraph_node *> (this))
1511 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
1513 if (priority == DEFAULT_INIT_PRIORITY)
1515 gcc_assert (get_init_priority() == priority);
1516 return;
1518 h = priority_info ();
1519 h->init = priority;
1522 /* Set fialization priority to PRIORITY. */
1524 void
1525 cgraph_node::set_fini_priority (priority_type priority)
1527 symbol_priority_map *h;
1529 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
1531 if (priority == DEFAULT_INIT_PRIORITY)
1533 gcc_assert (get_fini_priority() == priority);
1534 return;
1536 h = priority_info ();
1537 h->fini = priority;
1540 /* Worker for symtab_resolve_alias. */
1542 bool
1543 symtab_node::set_implicit_section (symtab_node *n,
1544 void *data ATTRIBUTE_UNUSED)
1546 n->implicit_section = true;
1547 return false;
1550 /* Add reference recording that symtab node is alias of TARGET.
1551 The function can fail in the case of aliasing cycles; in this case
1552 it returns false. */
1554 bool
1555 symtab_node::resolve_alias (symtab_node *target)
1557 symtab_node *n;
1559 gcc_assert (!analyzed && !vec_safe_length (ref_list.references));
1561 /* Never let cycles to creep into the symbol table alias references;
1562 those will make alias walkers to be infinite. */
1563 for (n = target; n && n->alias;
1564 n = n->analyzed ? n->get_alias_target () : NULL)
1565 if (n == this)
1567 if (is_a <cgraph_node *> (this))
1568 error ("function %q+D part of alias cycle", decl);
1569 else if (is_a <varpool_node *> (this))
1570 error ("variable %q+D part of alias cycle", decl);
1571 else
1572 gcc_unreachable ();
1573 alias = false;
1574 return false;
1577 /* "analyze" the node - i.e. mark the reference. */
1578 definition = true;
1579 alias = true;
1580 analyzed = true;
1581 create_reference (target, IPA_REF_ALIAS, NULL);
1583 /* Add alias into the comdat group of its target unless it is already there. */
1584 if (same_comdat_group)
1585 remove_from_same_comdat_group ();
1586 set_comdat_group (NULL);
1587 if (target->get_comdat_group ())
1588 add_to_same_comdat_group (target);
1590 if ((get_section () != target->get_section ()
1591 || target->get_comdat_group ()) && get_section () && !implicit_section)
1593 error ("section of alias %q+D must match section of its target", decl);
1595 call_for_symbol_and_aliases (symtab_node::set_section,
1596 const_cast<char *>(target->get_section ()), true);
1597 if (target->implicit_section)
1598 call_for_symbol_and_aliases (set_implicit_section, NULL, true);
1600 /* Alias targets become redundant after alias is resolved into an reference.
1601 We do not want to keep it around or we would have to mind updating them
1602 when renaming symbols. */
1603 alias_target = NULL;
1605 if (cpp_implicit_alias && symtab->state >= CONSTRUCTION)
1606 fixup_same_cpp_alias_visibility (target);
1608 /* If alias has address taken, so does the target. */
1609 if (address_taken)
1610 target->ultimate_alias_target ()->address_taken = true;
1611 return true;
1614 /* Call calback on symtab node and aliases associated to this node.
1615 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1616 skipped. */
1618 bool
1619 symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
1620 void *),
1621 void *data, bool include_overwritable)
1623 int i;
1624 ipa_ref *ref;
1626 if (callback (this, data))
1627 return true;
1628 for (i = 0; iterate_referring (i, ref); i++)
1629 if (ref->use == IPA_REF_ALIAS)
1631 symtab_node *alias = ref->referring;
1632 if (include_overwritable
1633 || alias->get_availability () > AVAIL_INTERPOSABLE)
1634 if (alias->call_for_symbol_and_aliases (callback, data,
1635 include_overwritable))
1636 return true;
1638 return false;
1641 /* Worker searching noninterposable alias. */
1643 bool
1644 symtab_node::noninterposable_alias (symtab_node *node, void *data)
1646 if (decl_binds_to_current_def_p (node->decl))
1648 symtab_node *fn = node->ultimate_alias_target ();
1650 /* Ensure that the alias is well formed this may not be the case
1651 of user defined aliases and currently it is not always the case
1652 of C++ same body aliases (that is a bug). */
1653 if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
1654 || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
1655 || (TREE_CODE (node->decl) == FUNCTION_DECL
1656 && flags_from_decl_or_type (node->decl)
1657 != flags_from_decl_or_type (fn->decl))
1658 || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
1659 return false;
1661 *(symtab_node **)data = node;
1662 return true;
1664 return false;
1667 /* If node can not be overwriten by static or dynamic linker to point to
1668 different definition, return NODE. Otherwise look for alias with such
1669 property and if none exists, introduce new one. */
1671 symtab_node *
1672 symtab_node::noninterposable_alias (void)
1674 tree new_decl;
1675 symtab_node *new_node = NULL;
1677 /* First try to look up existing alias or base object
1678 (if that is already non-overwritable). */
1679 symtab_node *node = ultimate_alias_target ();
1680 gcc_assert (!node->alias && !node->weakref);
1681 node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
1682 (void *)&new_node, true);
1683 if (new_node)
1684 return new_node;
1685 #ifndef ASM_OUTPUT_DEF
1686 /* If aliases aren't supported by the assembler, fail. */
1687 return NULL;
1688 #endif
1690 /* Otherwise create a new one. */
1691 new_decl = copy_node (node->decl);
1692 DECL_NAME (new_decl) = clone_function_name (node->decl, "localalias");
1693 if (TREE_CODE (new_decl) == FUNCTION_DECL)
1694 DECL_STRUCT_FUNCTION (new_decl) = NULL;
1695 DECL_INITIAL (new_decl) = NULL;
1696 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
1697 SET_DECL_RTL (new_decl, NULL);
1699 /* Update the properties. */
1700 DECL_EXTERNAL (new_decl) = 0;
1701 TREE_PUBLIC (new_decl) = 0;
1702 DECL_COMDAT (new_decl) = 0;
1703 DECL_WEAK (new_decl) = 0;
1705 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1706 DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
1707 if (TREE_CODE (new_decl) == FUNCTION_DECL)
1709 DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
1710 DECL_STATIC_DESTRUCTOR (new_decl) = 0;
1711 new_node = cgraph_node::create_alias (new_decl, node->decl);
1713 else
1715 TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
1716 DECL_INITIAL (new_decl) = error_mark_node;
1717 new_node = varpool_node::create_alias (new_decl, node->decl);
1719 new_node->resolve_alias (node);
1720 gcc_assert (decl_binds_to_current_def_p (new_decl)
1721 && targetm.binds_local_p (new_decl));
1722 return new_node;
1725 /* Return true if symtab node and TARGET represents
1726 semantically equivalent symbols. */
1728 bool
1729 symtab_node::semantically_equivalent_p (symtab_node *target)
1731 enum availability avail;
1732 symtab_node *ba;
1733 symtab_node *bb;
1735 /* Equivalent functions are equivalent. */
1736 if (decl == target->decl)
1737 return true;
1739 /* If symbol is not overwritable by different implementation,
1740 walk to the base object it defines. */
1741 ba = ultimate_alias_target (&avail);
1742 if (avail >= AVAIL_AVAILABLE)
1744 if (target == ba)
1745 return true;
1747 else
1748 ba = this;
1749 bb = target->ultimate_alias_target (&avail);
1750 if (avail >= AVAIL_AVAILABLE)
1752 if (this == bb)
1753 return true;
1755 else
1756 bb = target;
1757 return bb == ba;
1760 /* Classify symbol symtab node for partitioning. */
1762 enum symbol_partitioning_class
1763 symtab_node::get_partitioning_class (void)
1765 /* Inline clones are always duplicated.
1766 This include external delcarations. */
1767 cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
1769 if (DECL_ABSTRACT_P (decl))
1770 return SYMBOL_EXTERNAL;
1772 if (cnode && cnode->global.inlined_to)
1773 return SYMBOL_DUPLICATE;
1775 /* Weakref aliases are always duplicated. */
1776 if (weakref)
1777 return SYMBOL_DUPLICATE;
1779 /* External declarations are external. */
1780 if (DECL_EXTERNAL (decl))
1781 return SYMBOL_EXTERNAL;
1783 if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
1785 /* Constant pool references use local symbol names that can not
1786 be promoted global. We should never put into a constant pool
1787 objects that can not be duplicated across partitions. */
1788 if (DECL_IN_CONSTANT_POOL (decl))
1789 return SYMBOL_DUPLICATE;
1790 gcc_checking_assert (vnode->definition);
1792 /* Functions that are cloned may stay in callgraph even if they are unused.
1793 Handle them as external; compute_ltrans_boundary take care to make
1794 proper things to happen (i.e. to make them appear in the boundary but
1795 with body streamed, so clone can me materialized). */
1796 else if (!dyn_cast <cgraph_node *> (this)->definition)
1797 return SYMBOL_EXTERNAL;
1799 /* Linker discardable symbols are duplicated to every use unless they are
1800 keyed. */
1801 if (DECL_ONE_ONLY (decl)
1802 && !force_output
1803 && !forced_by_abi
1804 && !used_from_object_file_p ())
1805 return SYMBOL_DUPLICATE;
1807 return SYMBOL_PARTITION;
1810 /* Return true when symbol is known to be non-zero. */
1812 bool
1813 symtab_node::nonzero_address ()
1815 /* Weakrefs may be NULL when their target is not defined. */
1816 if (alias && weakref)
1818 if (analyzed)
1820 symtab_node *target = ultimate_alias_target ();
1822 if (target->alias && target->weakref)
1823 return false;
1824 /* We can not recurse to target::nonzero. It is possible that the
1825 target is used only via the alias.
1826 We may walk references and look for strong use, but we do not know
1827 if this strong use will survive to final binary, so be
1828 conservative here.
1829 ??? Maybe we could do the lookup during late optimization that
1830 could be useful to eliminate the NULL pointer checks in LTO
1831 programs. */
1832 if (target->definition && !DECL_EXTERNAL (target->decl))
1833 return true;
1834 if (target->resolution != LDPR_UNKNOWN
1835 && target->resolution != LDPR_UNDEF
1836 && flag_delete_null_pointer_checks)
1837 return true;
1838 return false;
1840 else
1841 return false;
1844 /* With !flag_delete_null_pointer_checks we assume that symbols may
1845 bind to NULL. This is on by default on embedded targets only.
1847 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1848 linking fails. Important case of WEAK we want to do well are comdats.
1849 Those are handled by later check for definition.
1851 When parsing, beware the cases when WEAK attribute is added later. */
1852 if (!DECL_WEAK (decl)
1853 && flag_delete_null_pointer_checks)
1855 refuse_visibility_changes = true;
1856 return true;
1859 /* If target is defined and not extern, we know it will be output and thus
1860 it will bind to non-NULL.
1861 Play safe for flag_delete_null_pointer_checks where weak definition maye
1862 be re-defined by NULL. */
1863 if (definition && !DECL_EXTERNAL (decl)
1864 && (flag_delete_null_pointer_checks || !DECL_WEAK (decl)))
1866 if (!DECL_WEAK (decl))
1867 refuse_visibility_changes = true;
1868 return true;
1871 /* As the last resort, check the resolution info. */
1872 if (resolution != LDPR_UNKNOWN
1873 && resolution != LDPR_UNDEF
1874 && flag_delete_null_pointer_checks)
1875 return true;
1876 return false;