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
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
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/>. */
23 #include "coretypes.h"
27 #include "print-tree.h"
33 #include "hard-reg-set.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
41 #include "gimple-expr.h"
44 #include "tree-inline.h"
45 #include "langhooks.h"
47 #include "plugin-api.h"
50 #include "diagnostic.h"
52 #include "lto-streamer.h"
54 #include "ipa-utils.h"
57 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias","chkp"};
59 const char * const ld_plugin_symbol_resolution_names
[]=
64 "prevailing_def_ironly",
70 "prevailing_def_ironly_exp"
73 /* Hash asmnames ignoring the user specified marks. */
76 symbol_table::decl_assembler_name_hash (const_tree asmname
)
78 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
80 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
81 size_t ulp_len
= strlen (user_label_prefix
);
85 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
88 return htab_hash_string (decl_str
);
91 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
95 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
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
;
105 if (decl_asmname
== asmname
)
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
);
126 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
127 decl_str
+= ulp_len
, test
=true;
131 if (asmname_str
[0] == '*')
133 size_t ulp_len
= strlen (user_label_prefix
);
139 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
140 asmname_str
+= ulp_len
, test
=true;
147 return strcmp (decl_str
, asmname_str
) == 0;
151 /* Returns nonzero if P1 and P2 are equal. */
153 /* Insert NODE to assembler name hash. */
156 symbol_table::insert_to_assembler_name_hash (symtab_node
*node
,
159 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
161 gcc_checking_assert (!node
->previous_sharing_asm_name
162 && !node
->next_sharing_asm_name
);
163 if (assembler_name_hash
)
167 tree decl
= node
->decl
;
169 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
171 /* C++ FE can produce decls without associated assembler name and insert
172 them to symtab to hold section or TLS information. */
176 hashval_t hash
= decl_assembler_name_hash (name
);
177 aslot
= assembler_name_hash
->find_slot_with_hash (name
, hash
, INSERT
);
178 gcc_assert (*aslot
!= node
);
179 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
181 (*aslot
)->previous_sharing_asm_name
= node
;
184 /* Update also possible inline clones sharing a decl. */
185 cnode
= dyn_cast
<cgraph_node
*> (node
);
186 if (cnode
&& cnode
->clones
&& with_clones
)
187 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
188 if (cnode
->decl
== decl
)
189 insert_to_assembler_name_hash (cnode
, true);
194 /* Remove NODE from assembler name hash. */
197 symbol_table::unlink_from_assembler_name_hash (symtab_node
*node
,
200 if (assembler_name_hash
)
203 tree decl
= node
->decl
;
205 if (node
->next_sharing_asm_name
)
206 node
->next_sharing_asm_name
->previous_sharing_asm_name
207 = node
->previous_sharing_asm_name
;
208 if (node
->previous_sharing_asm_name
)
210 node
->previous_sharing_asm_name
->next_sharing_asm_name
211 = node
->next_sharing_asm_name
;
215 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
221 hashval_t hash
= decl_assembler_name_hash (name
);
222 slot
= assembler_name_hash
->find_slot_with_hash (name
, hash
,
224 gcc_assert (*slot
== node
);
225 if (!node
->next_sharing_asm_name
)
226 assembler_name_hash
->clear_slot (slot
);
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. */
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. */
254 symbol_table::symtab_initialize_asm_name_hash (void)
257 if (!assembler_name_hash
)
259 assembler_name_hash
= hash_table
<asmname_hasher
>::create_ggc (10);
260 FOR_EACH_SYMBOL (node
)
261 insert_to_assembler_name_hash (node
, false);
265 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
268 symbol_table::change_decl_assembler_name (tree decl
, tree name
)
270 symtab_node
*node
= NULL
;
272 /* We can have user ASM names on things, like global register variables, that
273 are not in the symbol table. */
274 if ((TREE_CODE (decl
) == VAR_DECL
275 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
276 || TREE_CODE (decl
) == FUNCTION_DECL
)
277 node
= symtab_node::get (decl
);
278 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
280 SET_DECL_ASSEMBLER_NAME (decl
, name
);
282 insert_to_assembler_name_hash (node
, true);
286 if (name
== DECL_ASSEMBLER_NAME (decl
))
289 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
290 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
293 unlink_from_assembler_name_hash (node
, true);
294 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
295 && DECL_RTL_SET_P (decl
))
296 warning (0, "%D renamed after being referenced in assembly", decl
);
298 SET_DECL_ASSEMBLER_NAME (decl
, name
);
301 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
302 TREE_CHAIN (name
) = alias
;
305 insert_to_assembler_name_hash (node
, true);
309 /* Return true when RESOLUTION indicate that linker will use
310 the symbol from non-LTO object files. */
313 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
315 return (resolution
== LDPR_PREVAILING_DEF
316 || resolution
== LDPR_PREEMPTED_REG
317 || resolution
== LDPR_RESOLVED_EXEC
318 || resolution
== LDPR_RESOLVED_DYN
);
321 /* Hash sections by their names. */
324 section_name_hasher::hash (section_hash_entry
*n
)
326 return htab_hash_string (n
->name
);
329 /* Return true if section P1 name equals to P2. */
332 section_name_hasher::equal (section_hash_entry
*n1
, const char *name
)
334 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
337 /* Add node into symbol table. This function is not used directly, but via
338 cgraph/varpool node creation routines. */
341 symtab_node::register_symbol (void)
343 symtab
->register_symbol (this);
345 if (!decl
->decl_with_vis
.symtab_node
)
346 decl
->decl_with_vis
.symtab_node
= this;
350 /* Be sure to do this last; C++ FE might create new nodes via
351 DECL_ASSEMBLER_NAME langhook! */
352 symtab
->insert_to_assembler_name_hash (this, false);
355 /* Remove NODE from same comdat group. */
358 symtab_node::remove_from_same_comdat_group (void)
360 if (same_comdat_group
)
363 for (prev
= same_comdat_group
;
364 prev
->same_comdat_group
!= this;
365 prev
= prev
->same_comdat_group
)
367 if (same_comdat_group
== prev
)
368 prev
->same_comdat_group
= NULL
;
370 prev
->same_comdat_group
= same_comdat_group
;
371 same_comdat_group
= NULL
;
372 set_comdat_group (NULL
);
376 /* Remove node from symbol table. This function is not used directly, but via
377 cgraph/varpool node removal routines. */
380 symtab_node::unregister (void)
382 remove_all_references ();
383 remove_all_referring ();
385 /* Remove reference to section. */
386 set_section_for_node (NULL
);
388 remove_from_same_comdat_group ();
390 symtab
->unregister (this);
392 /* During LTO symtab merging we temporarily corrupt decl to symtab node
394 gcc_assert (decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
395 if (decl
->decl_with_vis
.symtab_node
== this)
397 symtab_node
*replacement_node
= NULL
;
398 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
399 replacement_node
= cnode
->find_replacement ();
400 decl
->decl_with_vis
.symtab_node
= replacement_node
;
402 if (!is_a
<varpool_node
*> (this) || !DECL_HARD_REGISTER (decl
))
403 symtab
->unlink_from_assembler_name_hash (this, false);
404 if (in_init_priority_hash
)
405 symtab
->init_priority_hash
->remove (this);
409 /* Remove symbol from symbol table. */
412 symtab_node::remove (void)
414 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
416 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
420 /* Add NEW_ to the same comdat group that OLD is in. */
423 symtab_node::add_to_same_comdat_group (symtab_node
*old_node
)
425 gcc_assert (old_node
->get_comdat_group ());
426 gcc_assert (!same_comdat_group
);
427 gcc_assert (this != old_node
);
429 set_comdat_group (old_node
->get_comdat_group ());
430 same_comdat_group
= old_node
;
431 if (!old_node
->same_comdat_group
)
432 old_node
->same_comdat_group
= this;
436 for (n
= old_node
->same_comdat_group
;
437 n
->same_comdat_group
!= old_node
;
438 n
= n
->same_comdat_group
)
440 n
->same_comdat_group
= this;
444 /* Dissolve the same_comdat_group list in which NODE resides. */
447 symtab_node::dissolve_same_comdat_group_list (void)
449 symtab_node
*n
= this;
452 if (!same_comdat_group
)
456 next
= n
->same_comdat_group
;
457 n
->same_comdat_group
= NULL
;
458 /* Clear comdat_group for comdat locals, since
459 make_decl_local doesn't. */
460 if (!TREE_PUBLIC (n
->decl
))
461 n
->set_comdat_group (NULL
);
467 /* Return printable assembler name of NODE.
468 This function is used only for debugging. When assembler name
469 is unknown go with identifier name. */
472 symtab_node::asm_name () const
474 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
475 return lang_hooks
.decl_printable_name (decl
, 2);
476 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
479 /* Return printable identifier name. */
482 symtab_node::name () const
484 return lang_hooks
.decl_printable_name (decl
, 2);
487 /* Return ipa reference from this symtab_node to
488 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
492 symtab_node::create_reference (symtab_node
*referred_node
,
493 enum ipa_ref_use use_type
)
495 return create_reference (referred_node
, use_type
, NULL
);
499 /* Return ipa reference from this symtab_node to
500 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
501 of the use and STMT the statement (if it exists). */
504 symtab_node::create_reference (symtab_node
*referred_node
,
505 enum ipa_ref_use use_type
, gimple stmt
)
507 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
508 ipa_ref_list
*list
, *list2
;
509 ipa_ref_t
*old_references
;
511 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
512 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
515 old_references
= vec_safe_address (list
->references
);
516 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
517 ref
= &list
->references
->last ();
519 list2
= &referred_node
->ref_list
;
521 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
522 if(use_type
== IPA_REF_ALIAS
)
524 list2
->referring
.safe_insert (0, ref
);
525 ref
->referred_index
= 0;
527 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
528 list2
->referring
[i
]->referred_index
= i
;
532 list2
->referring
.safe_push (ref
);
533 ref
->referred_index
= list2
->referring
.length () - 1;
536 ref
->referring
= this;
537 ref
->referred
= referred_node
;
539 ref
->lto_stmt_uid
= 0;
541 ref
->speculative
= 0;
543 /* If vector was moved in memory, update pointers. */
544 if (old_references
!= list
->references
->address ())
547 for (i
= 0; iterate_reference(i
, ref2
); i
++)
548 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
553 /* If VAL is a reference to a function or a variable, add a reference from
554 this symtab_node to the corresponding symbol table node. USE_TYPE specify
555 type of the use and STMT the statement (if it exists). Return the new
556 reference or NULL if none was created. */
559 symtab_node::maybe_create_reference (tree val
, enum ipa_ref_use use_type
,
563 if (TREE_CODE (val
) != ADDR_EXPR
)
565 val
= get_base_var (val
);
566 if (val
&& (TREE_CODE (val
) == FUNCTION_DECL
567 || TREE_CODE (val
) == VAR_DECL
))
569 symtab_node
*referred
= symtab_node::get (val
);
570 gcc_checking_assert (referred
);
571 return create_reference (referred
, use_type
, stmt
);
576 /* Clone all references from symtab NODE to this symtab_node. */
579 symtab_node::clone_references (symtab_node
*node
)
581 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
583 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
585 bool speculative
= ref
->speculative
;
586 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
588 ref2
= create_reference (ref
->referred
, ref
->use
, ref
->stmt
);
589 ref2
->speculative
= speculative
;
590 ref2
->lto_stmt_uid
= stmt_uid
;
594 /* Clone all referring from symtab NODE to this symtab_node. */
597 symtab_node::clone_referring (symtab_node
*node
)
599 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
601 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
603 bool speculative
= ref
->speculative
;
604 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
606 ref2
= ref
->referring
->create_reference (this, ref
->use
, ref
->stmt
);
607 ref2
->speculative
= speculative
;
608 ref2
->lto_stmt_uid
= stmt_uid
;
612 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
615 symtab_node::clone_reference (ipa_ref
*ref
, gimple stmt
)
617 bool speculative
= ref
->speculative
;
618 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
621 ref2
= create_reference (ref
->referred
, ref
->use
, stmt
);
622 ref2
->speculative
= speculative
;
623 ref2
->lto_stmt_uid
= stmt_uid
;
627 /* Find the structure describing a reference to REFERRED_NODE
628 and associated with statement STMT. */
631 symtab_node::find_reference (symtab_node
*referred_node
,
632 gimple stmt
, unsigned int lto_stmt_uid
)
637 for (i
= 0; iterate_reference (i
, r
); i
++)
638 if (r
->referred
== referred_node
640 && ((stmt
&& r
->stmt
== stmt
)
641 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
642 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
647 /* Remove all references that are associated with statement STMT. */
650 symtab_node::remove_stmt_references (gimple stmt
)
655 while (iterate_reference (i
, r
))
657 r
->remove_reference ();
662 /* Remove all stmt references in non-speculative references.
663 Those are not maintained during inlining & clonning.
664 The exception are speculative references that are updated along
665 with callgraph edges associated with them. */
668 symtab_node::clear_stmts_in_references (void)
673 for (i
= 0; iterate_reference (i
, r
); i
++)
681 /* Remove all references in ref list. */
684 symtab_node::remove_all_references (void)
686 while (vec_safe_length (ref_list
.references
))
687 ref_list
.references
->last ().remove_reference ();
688 vec_free (ref_list
.references
);
691 /* Remove all referring items in ref list. */
694 symtab_node::remove_all_referring (void)
696 while (ref_list
.referring
.length ())
697 ref_list
.referring
.last ()->remove_reference ();
698 ref_list
.referring
.release ();
701 /* Dump references in ref list to FILE. */
704 symtab_node::dump_references (FILE *file
)
708 for (i
= 0; iterate_reference (i
, ref
); i
++)
710 fprintf (file
, "%s/%i (%s)",
711 ref
->referred
->asm_name (),
712 ref
->referred
->order
,
713 ipa_ref_use_name
[ref
->use
]);
714 if (ref
->speculative
)
715 fprintf (file
, " (speculative)");
717 fprintf (file
, "\n");
720 /* Dump referring in list to FILE. */
723 symtab_node::dump_referring (FILE *file
)
727 for (i
= 0; iterate_referring(i
, ref
); i
++)
729 fprintf (file
, "%s/%i (%s)",
730 ref
->referring
->asm_name (),
731 ref
->referring
->order
,
732 ipa_ref_use_name
[ref
->use
]);
733 if (ref
->speculative
)
734 fprintf (file
, " (speculative)");
736 fprintf (file
, "\n");
739 /* Return true if list contains an alias. */
741 symtab_node::has_aliases_p (void)
746 for (i
= 0; iterate_referring (i
, ref
); i
++)
747 if (ref
->use
== IPA_REF_ALIAS
)
752 /* Iterates I-th reference in the list, REF is also set. */
755 symtab_node::iterate_reference (unsigned i
, ipa_ref
*&ref
)
757 vec_safe_iterate (ref_list
.references
, i
, &ref
);
762 /* Iterates I-th referring item in the list, REF is also set. */
765 symtab_node::iterate_referring (unsigned i
, ipa_ref
*&ref
)
767 ref_list
.referring
.iterate (i
, &ref
);
772 /* Iterates I-th referring alias item in the list, REF is also set. */
775 symtab_node::iterate_direct_aliases (unsigned i
, ipa_ref
*&ref
)
777 ref_list
.referring
.iterate (i
, &ref
);
779 if (ref
&& ref
->use
!= IPA_REF_ALIAS
)
785 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
787 /* Dump base fields of symtab nodes to F. Not to be used directly. */
790 symtab_node::dump_base (FILE *f
)
792 static const char * const visibility_types
[] = {
793 "default", "protected", "hidden", "internal"
796 fprintf (f
, "%s/%i (%s)", asm_name (), order
, name ());
797 dump_addr (f
, " @", (void *)this);
798 fprintf (f
, "\n Type: %s", symtab_type_names
[type
]);
801 fprintf (f
, " definition");
803 fprintf (f
, " analyzed");
805 fprintf (f
, " alias");
807 fprintf (f
, " weakref");
808 if (cpp_implicit_alias
)
809 fprintf (f
, " cpp_implicit_alias");
811 fprintf (f
, " target:%s",
812 DECL_P (alias_target
)
813 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
815 : IDENTIFIER_POINTER (alias_target
));
817 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
818 fprintf (f
, "\n Visibility:");
819 if (in_other_partition
)
820 fprintf (f
, " in_other_partition");
821 if (used_from_other_partition
)
822 fprintf (f
, " used_from_other_partition");
824 fprintf (f
, " force_output");
826 fprintf (f
, " forced_by_abi");
827 if (externally_visible
)
828 fprintf (f
, " externally_visible");
830 fprintf (f
, " no_reorder");
831 if (resolution
!= LDPR_UNKNOWN
)
833 ld_plugin_symbol_resolution_names
[(int)resolution
]);
834 if (TREE_ASM_WRITTEN (decl
))
835 fprintf (f
, " asm_written");
836 if (DECL_EXTERNAL (decl
))
837 fprintf (f
, " external");
838 if (TREE_PUBLIC (decl
))
839 fprintf (f
, " public");
840 if (DECL_COMMON (decl
))
841 fprintf (f
, " common");
842 if (DECL_WEAK (decl
))
843 fprintf (f
, " weak");
844 if (DECL_DLLIMPORT_P (decl
))
845 fprintf (f
, " dll_import");
846 if (DECL_COMDAT (decl
))
847 fprintf (f
, " comdat");
848 if (get_comdat_group ())
849 fprintf (f
, " comdat_group:%s",
850 IDENTIFIER_POINTER (get_comdat_group_id ()));
851 if (DECL_ONE_ONLY (decl
))
852 fprintf (f
, " one_only");
854 fprintf (f
, " section:%s",
856 if (implicit_section
)
857 fprintf (f
," (implicit_section)");
858 if (DECL_VISIBILITY_SPECIFIED (decl
))
859 fprintf (f
, " visibility_specified");
860 if (DECL_VISIBILITY (decl
))
861 fprintf (f
, " visibility:%s",
862 visibility_types
[DECL_VISIBILITY (decl
)]);
863 if (DECL_VIRTUAL_P (decl
))
864 fprintf (f
, " virtual");
865 if (DECL_ARTIFICIAL (decl
))
866 fprintf (f
, " artificial");
867 if (TREE_CODE (decl
) == FUNCTION_DECL
)
869 if (DECL_STATIC_CONSTRUCTOR (decl
))
870 fprintf (f
, " constructor");
871 if (DECL_STATIC_DESTRUCTOR (decl
))
872 fprintf (f
, " destructor");
876 if (same_comdat_group
)
877 fprintf (f
, " Same comdat group as: %s/%i\n",
878 same_comdat_group
->asm_name (),
879 same_comdat_group
->order
);
880 if (next_sharing_asm_name
)
881 fprintf (f
, " next sharing asm name: %i\n",
882 next_sharing_asm_name
->order
);
883 if (previous_sharing_asm_name
)
884 fprintf (f
, " previous sharing asm name: %i\n",
885 previous_sharing_asm_name
->order
);
888 fprintf (f
, " Address is taken.\n");
891 fprintf (f
, " Aux:");
892 dump_addr (f
, " @", (void *)aux
);
895 fprintf (f
, " References: ");
897 fprintf (f
, " Referring: ");
900 fprintf (f
, " Read from file: %s\n",
901 lto_file_data
->file_name
);
904 /* Dump symtab node to F. */
907 symtab_node::dump (FILE *f
)
909 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
911 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
915 /* Dump symbol table to F. */
918 symtab_node::dump_table (FILE *f
)
921 fprintf (f
, "Symbol table:\n\n");
922 FOR_EACH_SYMBOL (node
)
927 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
928 Return NULL if there's no such node. */
931 symtab_node::get_for_asmname (const_tree asmname
)
935 symtab
->symtab_initialize_asm_name_hash ();
936 hashval_t hash
= symtab
->decl_assembler_name_hash (asmname
);
938 = symtab
->assembler_name_hash
->find_slot_with_hash (asmname
, hash
,
949 /* Dump symtab node NODE to stderr. */
952 symtab_node::debug (void)
957 /* Verify common part of symtab nodes. */
960 symtab_node::verify_base (void)
962 bool error_found
= false;
963 symtab_node
*hashed_node
;
965 if (is_a
<cgraph_node
*> (this))
967 if (TREE_CODE (decl
) != FUNCTION_DECL
)
969 error ("function symbol is not function");
973 else if (is_a
<varpool_node
*> (this))
975 if (TREE_CODE (decl
) != VAR_DECL
)
977 error ("variable symbol is not variable");
983 error ("node has unknown type");
987 if (symtab
->state
!= LTO_STREAMING
)
989 hashed_node
= symtab_node::get (decl
);
992 error ("node not found node->decl->decl_with_vis.symtab_node");
995 if (hashed_node
!= this
996 && (!is_a
<cgraph_node
*> (this)
997 || !dyn_cast
<cgraph_node
*> (this)->clone_of
998 || dyn_cast
<cgraph_node
*> (this)->clone_of
->decl
!= decl
))
1000 error ("node differs from node->decl->decl_with_vis.symtab_node");
1004 if (symtab
->assembler_name_hash
)
1006 hashed_node
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
1007 if (hashed_node
&& hashed_node
->previous_sharing_asm_name
)
1009 error ("assembler name hash list corrupted");
1014 if (hashed_node
== this)
1016 hashed_node
= hashed_node
->next_sharing_asm_name
;
1019 && !(is_a
<varpool_node
*> (this)
1020 || DECL_HARD_REGISTER (decl
)))
1022 error ("node not found in symtab assembler name hash");
1026 if (previous_sharing_asm_name
1027 && previous_sharing_asm_name
->next_sharing_asm_name
!= this)
1029 error ("double linked list of assembler names corrupted");
1032 if (analyzed
&& !definition
)
1034 error ("node is analyzed byt it is not a definition");
1037 if (cpp_implicit_alias
&& !alias
)
1039 error ("node is alias but not implicit alias");
1042 if (alias
&& !definition
&& !weakref
)
1044 error ("node is alias but not definition");
1047 if (weakref
&& !alias
)
1049 error ("node is weakref but not an alias");
1052 if (same_comdat_group
)
1054 symtab_node
*n
= same_comdat_group
;
1056 if (!n
->get_comdat_group ())
1058 error ("node is in same_comdat_group list but has no comdat_group");
1061 if (n
->get_comdat_group () != get_comdat_group ())
1063 error ("same_comdat_group list across different groups");
1068 error ("Node has same_comdat_group but it is not a definition");
1071 if (n
->type
!= type
)
1073 error ("mixing different types of symbol in same comdat groups is not supported");
1078 error ("node is alone in a comdat group");
1083 if (!n
->same_comdat_group
)
1085 error ("same_comdat_group is not a circular list");
1089 n
= n
->same_comdat_group
;
1092 if (comdat_local_p ())
1094 ipa_ref
*ref
= NULL
;
1096 for (int i
= 0; iterate_referring (i
, ref
); ++i
)
1098 if (!in_same_comdat_group_p (ref
->referring
))
1100 error ("comdat-local symbol referred to by %s outside its "
1102 identifier_to_locale (ref
->referring
->name()));
1108 if (implicit_section
&& !get_section ())
1110 error ("implicit_section flag is set but section isn't");
1113 if (get_section () && get_comdat_group ()
1114 && !implicit_section
1115 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl
)))
1117 error ("Both section and comdat group is set");
1120 /* TODO: Add string table for sections, so we do not keep holding duplicated
1122 if (alias
&& definition
1123 && get_section () != get_alias_target ()->get_section ()
1125 || !get_alias_target ()->get_section ()
1126 || strcmp (get_section(),
1127 get_alias_target ()->get_section ())))
1129 error ("Alias and target's section differs");
1130 get_alias_target ()->dump (stderr
);
1133 if (alias
&& definition
1134 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1136 error ("Alias and target's comdat groups differs");
1137 get_alias_target ()->dump (stderr
);
1144 /* Verify consistency of NODE. */
1147 symtab_node::verify (void)
1152 timevar_push (TV_CGRAPH_VERIFY
);
1153 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (this))
1154 node
->verify_node ();
1159 internal_error ("symtab_node::verify failed");
1161 timevar_pop (TV_CGRAPH_VERIFY
);
1164 /* Verify symbol table for internal consistency. */
1167 symtab_node::verify_symtab_nodes (void)
1170 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1172 FOR_EACH_SYMBOL (node
)
1175 if (node
->get_comdat_group ())
1177 symtab_node
**entry
, *s
;
1180 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1185 for (s
= (*entry
)->same_comdat_group
; s
!= NULL
&& s
!= node
; s
= s
->same_comdat_group
)
1186 if (!s
|| s
== *entry
)
1188 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1191 internal_error ("symtab_node::verify failed");
1197 /* Return true when NODE is known to be used from other (non-LTO)
1198 object file. Known only when doing LTO via linker plugin. */
1201 symtab_node::used_from_object_file_p_worker (symtab_node
*node
)
1203 if (!TREE_PUBLIC (node
->decl
) || DECL_EXTERNAL (node
->decl
))
1205 if (resolution_used_from_other_file_p (node
->resolution
))
1211 /* Return true when symtab_node is known to be used from other (non-LTO)
1212 object file. Known only when doing LTO via linker plugin. */
1215 symtab_node::used_from_object_file_p (void)
1217 return symtab_node::used_from_object_file_p_worker (this);
1220 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1221 but other code such as notice_global_symbol generates rtl. */
1224 symtab_node::make_decl_local (void)
1228 /* Avoid clearing comdat_groups on comdat-local decls. */
1229 if (TREE_PUBLIC (decl
) == 0)
1232 if (TREE_CODE (decl
) == VAR_DECL
)
1233 DECL_COMMON (decl
) = 0;
1234 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1236 DECL_COMDAT (decl
) = 0;
1237 DECL_WEAK (decl
) = 0;
1238 DECL_EXTERNAL (decl
) = 0;
1239 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1240 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1241 TREE_PUBLIC (decl
) = 0;
1242 if (!DECL_RTL_SET_P (decl
))
1245 /* Update rtl flags. */
1246 make_decl_rtl (decl
);
1248 rtl
= DECL_RTL (decl
);
1252 symbol
= XEXP (rtl
, 0);
1253 if (GET_CODE (symbol
) != SYMBOL_REF
)
1256 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1259 /* Walk the alias chain to return the symbol NODE is alias of.
1260 If NODE is not an alias, return NODE.
1261 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1264 symtab_node::ultimate_alias_target (enum availability
*availability
)
1266 bool weakref_p
= false;
1271 *availability
= get_availability ();
1275 /* To determine visibility of the target, we follow ELF semantic of aliases.
1276 Here alias is an alternative assembler name of a given definition. Its
1277 availability prevails the availability of its target (i.e. static alias of
1278 weak definition is available.
1280 Weakref is a different animal (and not part of ELF per se). It is just
1281 alternative name of a given symbol used within one complation unit
1282 and is translated prior hitting the object file. It inherits the
1283 visibility of its target (i.e. weakref of non-overwritable definition
1284 is non-overwritable, while weakref of weak definition is weak).
1286 If we ever get into supporting targets with different semantics, a target
1287 hook will be needed here. */
1291 weakref_p
= weakref
;
1293 *availability
= get_availability ();
1295 *availability
= AVAIL_LOCAL
;
1298 symtab_node
*node
= this;
1301 if (node
->alias
&& node
->analyzed
)
1302 node
= node
->get_alias_target ();
1307 else if (node
->analyzed
)
1311 enum availability a
= node
->get_availability ();
1312 if (a
< *availability
)
1317 *availability
= AVAIL_NOT_AVAILABLE
;
1320 if (node
&& availability
&& weakref_p
)
1322 enum availability a
= node
->get_availability ();
1323 if (a
< *availability
)
1325 weakref_p
= node
->weakref
;
1329 *availability
= AVAIL_NOT_AVAILABLE
;
1333 /* C++ FE sometimes change linkage flags after producing same body aliases.
1335 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1336 are obviously equivalent. The way it is doing so is however somewhat
1337 kludgy and interferes with the visibility code. As a result we need to
1338 copy the visibility from the target to get things right. */
1341 symtab_node::fixup_same_cpp_alias_visibility (symtab_node
*target
)
1343 if (is_a
<cgraph_node
*> (this))
1345 DECL_DECLARED_INLINE_P (decl
)
1346 = DECL_DECLARED_INLINE_P (target
->decl
);
1347 DECL_DISREGARD_INLINE_LIMITS (decl
)
1348 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1350 /* FIXME: It is not really clear why those flags should not be copied for
1354 DECL_WEAK (decl
) = DECL_WEAK (target
->decl
);
1355 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1356 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (target
->decl
);
1358 DECL_VIRTUAL_P (decl
) = DECL_VIRTUAL_P (target
->decl
);
1359 if (TREE_PUBLIC (decl
))
1363 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1364 DECL_COMDAT (decl
) = DECL_COMDAT (target
->decl
);
1365 group
= target
->get_comdat_group ();
1366 set_comdat_group (group
);
1367 if (group
&& !same_comdat_group
)
1368 add_to_same_comdat_group (target
);
1370 externally_visible
= target
->externally_visible
;
1373 /* Set section, do not recurse into aliases.
1374 When one wants to change section of symbol and its aliases,
1378 symtab_node::set_section_for_node (const char *section
)
1380 const char *current
= get_section ();
1381 section_hash_entry
**slot
;
1383 if (current
== section
1384 || (current
&& section
1385 && !strcmp (current
, section
)))
1390 x_section
->ref_count
--;
1391 if (!x_section
->ref_count
)
1393 hashval_t hash
= htab_hash_string (x_section
->name
);
1394 slot
= symtab
->section_hash
->find_slot_with_hash (x_section
->name
,
1396 ggc_free (x_section
);
1397 symtab
->section_hash
->clear_slot (slot
);
1403 implicit_section
= false;
1406 if (!symtab
->section_hash
)
1407 symtab
->section_hash
= hash_table
<section_name_hasher
>::create_ggc (10);
1408 slot
= symtab
->section_hash
->find_slot_with_hash (section
,
1409 htab_hash_string (section
),
1412 x_section
= (section_hash_entry
*)*slot
;
1415 int len
= strlen (section
);
1416 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1417 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1418 memcpy (x_section
->name
, section
, len
+ 1);
1420 x_section
->ref_count
++;
1423 /* Worker for set_section. */
1426 symtab_node::set_section (symtab_node
*n
, void *s
)
1428 n
->set_section_for_node ((char *)s
);
1432 /* Set section of symbol and its aliases. */
1435 symtab_node::set_section (const char *section
)
1437 gcc_assert (!this->alias
);
1438 call_for_symbol_and_aliases
1439 (symtab_node::set_section
, const_cast<char *>(section
), true);
1442 /* Return the initialization priority. */
1445 symtab_node::get_init_priority ()
1447 if (!this->in_init_priority_hash
)
1448 return DEFAULT_INIT_PRIORITY
;
1450 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1451 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1454 /* Return availability of NODE. */
1455 enum availability
symtab_node::get_availability (void)
1457 if (is_a
<cgraph_node
*> (this))
1458 return dyn_cast
<cgraph_node
*> (this)->get_availability ();
1460 return dyn_cast
<varpool_node
*> (this)->get_availability ();;
1464 /* Return the finalization priority. */
1467 cgraph_node::get_fini_priority ()
1469 if (!this->in_init_priority_hash
)
1470 return DEFAULT_INIT_PRIORITY
;
1471 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1472 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1475 /* Return the initialization and finalization priority information for
1476 DECL. If there is no previous priority information, a freshly
1477 allocated structure is returned. */
1479 symbol_priority_map
*
1480 symtab_node::priority_info (void)
1482 if (!symtab
->init_priority_hash
)
1483 symtab
->init_priority_hash
= hash_map
<symtab_node
*, symbol_priority_map
>::create_ggc (13);
1486 symbol_priority_map
*h
1487 = &symtab
->init_priority_hash
->get_or_insert (this, &existed
);
1490 h
->init
= DEFAULT_INIT_PRIORITY
;
1491 h
->fini
= DEFAULT_INIT_PRIORITY
;
1492 in_init_priority_hash
= true;
1498 /* Set initialization priority to PRIORITY. */
1501 symtab_node::set_init_priority (priority_type priority
)
1503 symbol_priority_map
*h
;
1505 if (is_a
<cgraph_node
*> (this))
1506 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1508 if (priority
== DEFAULT_INIT_PRIORITY
)
1510 gcc_assert (get_init_priority() == priority
);
1513 h
= priority_info ();
1517 /* Set fialization priority to PRIORITY. */
1520 cgraph_node::set_fini_priority (priority_type priority
)
1522 symbol_priority_map
*h
;
1524 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1526 if (priority
== DEFAULT_INIT_PRIORITY
)
1528 gcc_assert (get_fini_priority() == priority
);
1531 h
= priority_info ();
1535 /* Worker for symtab_resolve_alias. */
1538 symtab_node::set_implicit_section (symtab_node
*n
,
1539 void *data ATTRIBUTE_UNUSED
)
1541 n
->implicit_section
= true;
1545 /* Add reference recording that symtab node is alias of TARGET.
1546 The function can fail in the case of aliasing cycles; in this case
1547 it returns false. */
1550 symtab_node::resolve_alias (symtab_node
*target
)
1554 gcc_assert (!analyzed
&& !vec_safe_length (ref_list
.references
));
1556 /* Never let cycles to creep into the symbol table alias references;
1557 those will make alias walkers to be infinite. */
1558 for (n
= target
; n
&& n
->alias
;
1559 n
= n
->analyzed
? n
->get_alias_target () : NULL
)
1562 if (is_a
<cgraph_node
*> (this))
1563 error ("function %q+D part of alias cycle", decl
);
1564 else if (is_a
<varpool_node
*> (this))
1565 error ("variable %q+D part of alias cycle", decl
);
1572 /* "analyze" the node - i.e. mark the reference. */
1576 create_reference (target
, IPA_REF_ALIAS
, NULL
);
1578 /* Add alias into the comdat group of its target unless it is already there. */
1579 if (same_comdat_group
)
1580 remove_from_same_comdat_group ();
1581 set_comdat_group (NULL
);
1582 if (target
->get_comdat_group ())
1583 add_to_same_comdat_group (target
);
1585 if ((get_section () != target
->get_section ()
1586 || target
->get_comdat_group ()) && get_section () && !implicit_section
)
1588 error ("section of alias %q+D must match section of its target", decl
);
1590 call_for_symbol_and_aliases (symtab_node::set_section
,
1591 const_cast<char *>(target
->get_section ()), true);
1592 if (target
->implicit_section
)
1593 call_for_symbol_and_aliases (set_implicit_section
, NULL
, true);
1595 /* Alias targets become redundant after alias is resolved into an reference.
1596 We do not want to keep it around or we would have to mind updating them
1597 when renaming symbols. */
1598 alias_target
= NULL
;
1600 if (cpp_implicit_alias
&& symtab
->state
>= CONSTRUCTION
)
1601 fixup_same_cpp_alias_visibility (target
);
1603 /* If alias has address taken, so does the target. */
1605 target
->ultimate_alias_target ()->address_taken
= true;
1609 /* Call calback on symtab node and aliases associated to this node.
1610 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1614 symtab_node::call_for_symbol_and_aliases (bool (*callback
) (symtab_node
*,
1616 void *data
, bool include_overwritable
)
1621 if (callback (this, data
))
1623 for (i
= 0; iterate_referring (i
, ref
); i
++)
1624 if (ref
->use
== IPA_REF_ALIAS
)
1626 symtab_node
*alias
= ref
->referring
;
1627 if (include_overwritable
1628 || alias
->get_availability () > AVAIL_INTERPOSABLE
)
1629 if (alias
->call_for_symbol_and_aliases (callback
, data
,
1630 include_overwritable
))
1636 /* Worker searching noninterposable alias. */
1639 symtab_node::noninterposable_alias (symtab_node
*node
, void *data
)
1641 if (decl_binds_to_current_def_p (node
->decl
))
1643 symtab_node
*fn
= node
->ultimate_alias_target ();
1645 /* Ensure that the alias is well formed this may not be the case
1646 of user defined aliases and currently it is not always the case
1647 of C++ same body aliases (that is a bug). */
1648 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
1649 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
1650 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
1651 && flags_from_decl_or_type (node
->decl
)
1652 != flags_from_decl_or_type (fn
->decl
))
1653 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
1656 *(symtab_node
**)data
= node
;
1662 /* If node can not be overwriten by static or dynamic linker to point to
1663 different definition, return NODE. Otherwise look for alias with such
1664 property and if none exists, introduce new one. */
1667 symtab_node::noninterposable_alias (void)
1670 symtab_node
*new_node
= NULL
;
1672 /* First try to look up existing alias or base object
1673 (if that is already non-overwritable). */
1674 symtab_node
*node
= ultimate_alias_target ();
1675 gcc_assert (!node
->alias
&& !node
->weakref
);
1676 node
->call_for_symbol_and_aliases (symtab_node::noninterposable_alias
,
1677 (void *)&new_node
, true);
1680 #ifndef ASM_OUTPUT_DEF
1681 /* If aliases aren't supported by the assembler, fail. */
1685 /* Otherwise create a new one. */
1686 new_decl
= copy_node (node
->decl
);
1687 DECL_NAME (new_decl
) = clone_function_name (node
->decl
, "localalias");
1688 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1689 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1690 DECL_INITIAL (new_decl
) = NULL
;
1691 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1692 SET_DECL_RTL (new_decl
, NULL
);
1694 /* Update the properties. */
1695 DECL_EXTERNAL (new_decl
) = 0;
1696 TREE_PUBLIC (new_decl
) = 0;
1697 DECL_COMDAT (new_decl
) = 0;
1698 DECL_WEAK (new_decl
) = 0;
1700 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1701 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1702 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1704 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1705 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1706 new_node
= cgraph_node::create_alias (new_decl
, node
->decl
);
1710 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
1711 DECL_INITIAL (new_decl
) = error_mark_node
;
1712 new_node
= varpool_node::create_alias (new_decl
, node
->decl
);
1714 new_node
->resolve_alias (node
);
1715 gcc_assert (decl_binds_to_current_def_p (new_decl
)
1716 && targetm
.binds_local_p (new_decl
));
1720 /* Return true if symtab node and TARGET represents
1721 semantically equivalent symbols. */
1724 symtab_node::semantically_equivalent_p (symtab_node
*target
)
1726 enum availability avail
;
1730 /* Equivalent functions are equivalent. */
1731 if (decl
== target
->decl
)
1734 /* If symbol is not overwritable by different implementation,
1735 walk to the base object it defines. */
1736 ba
= ultimate_alias_target (&avail
);
1737 if (avail
>= AVAIL_AVAILABLE
)
1744 bb
= target
->ultimate_alias_target (&avail
);
1745 if (avail
>= AVAIL_AVAILABLE
)
1755 /* Classify symbol symtab node for partitioning. */
1757 enum symbol_partitioning_class
1758 symtab_node::get_partitioning_class (void)
1760 /* Inline clones are always duplicated.
1761 This include external delcarations. */
1762 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
1764 if (DECL_ABSTRACT_P (decl
))
1765 return SYMBOL_EXTERNAL
;
1767 if (cnode
&& cnode
->global
.inlined_to
)
1768 return SYMBOL_DUPLICATE
;
1770 /* Weakref aliases are always duplicated. */
1772 return SYMBOL_DUPLICATE
;
1774 /* External declarations are external. */
1775 if (DECL_EXTERNAL (decl
))
1776 return SYMBOL_EXTERNAL
;
1778 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
1780 /* Constant pool references use local symbol names that can not
1781 be promoted global. We should never put into a constant pool
1782 objects that can not be duplicated across partitions. */
1783 if (DECL_IN_CONSTANT_POOL (decl
))
1784 return SYMBOL_DUPLICATE
;
1785 gcc_checking_assert (vnode
->definition
);
1787 /* Functions that are cloned may stay in callgraph even if they are unused.
1788 Handle them as external; compute_ltrans_boundary take care to make
1789 proper things to happen (i.e. to make them appear in the boundary but
1790 with body streamed, so clone can me materialized). */
1791 else if (!dyn_cast
<cgraph_node
*> (this)->definition
)
1792 return SYMBOL_EXTERNAL
;
1794 /* Linker discardable symbols are duplicated to every use unless they are
1796 if (DECL_ONE_ONLY (decl
)
1799 && !used_from_object_file_p ())
1800 return SYMBOL_DUPLICATE
;
1802 return SYMBOL_PARTITION
;
1805 /* Return true when symbol is known to be non-zero. */
1808 symtab_node::nonzero_address ()
1810 /* Weakrefs may be NULL when their target is not defined. */
1811 if (alias
&& weakref
)
1815 symtab_node
*target
= ultimate_alias_target ();
1817 if (target
->alias
&& target
->weakref
)
1819 /* We can not recurse to target::nonzero. It is possible that the
1820 target is used only via the alias.
1821 We may walk references and look for strong use, but we do not know
1822 if this strong use will survive to final binary, so be
1824 ??? Maybe we could do the lookup during late optimization that
1825 could be useful to eliminate the NULL pointer checks in LTO
1827 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
1829 if (target
->resolution
!= LDPR_UNKNOWN
1830 && target
->resolution
!= LDPR_UNDEF
1831 && flag_delete_null_pointer_checks
)
1839 /* With !flag_delete_null_pointer_checks we assume that symbols may
1840 bind to NULL. This is on by default on embedded targets only.
1842 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1843 linking fails. Important case of WEAK we want to do well are comdats.
1844 Those are handled by later check for definition.
1846 When parsing, beware the cases when WEAK attribute is added later. */
1847 if (!DECL_WEAK (decl
)
1848 && flag_delete_null_pointer_checks
)
1850 refuse_visibility_changes
= true;
1854 /* If target is defined and not extern, we know it will be output and thus
1855 it will bind to non-NULL.
1856 Play safe for flag_delete_null_pointer_checks where weak definition maye
1857 be re-defined by NULL. */
1858 if (definition
&& !DECL_EXTERNAL (decl
)
1859 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (decl
)))
1861 if (!DECL_WEAK (decl
))
1862 refuse_visibility_changes
= true;
1866 /* As the last resort, check the resolution info. */
1867 if (resolution
!= LDPR_UNKNOWN
1868 && resolution
!= LDPR_UNDEF
1869 && flag_delete_null_pointer_checks
)
1874 /* Return 0 if symbol is known to have different address than S2,
1875 Return 1 if symbol is known to have same address as S2,
1876 return 2 otherwise. */
1878 symtab_node::equal_address_to (symtab_node
*s2
)
1880 enum availability avail1
, avail2
;
1882 /* A Shortcut: equivalent symbols are always equivalent. */
1886 /* For non-interposable aliases, lookup and compare their actual definitions.
1887 Also check if the symbol needs to bind to given definition. */
1888 symtab_node
*rs1
= ultimate_alias_target (&avail1
);
1889 symtab_node
*rs2
= s2
->ultimate_alias_target (&avail2
);
1890 bool binds_local1
= rs1
->analyzed
&& decl_binds_to_current_def_p (this->decl
);
1891 bool binds_local2
= rs2
->analyzed
&& decl_binds_to_current_def_p (s2
->decl
);
1892 bool really_binds_local1
= binds_local1
;
1893 bool really_binds_local2
= binds_local2
;
1895 /* Addresses of vtables and virtual functions can not be used by user
1896 code and are used only within speculation. In this case we may make
1897 symbol equivalent to its alias even if interposition may break this
1898 rule. Doing so will allow us to turn speculative inlining into
1899 non-speculative more agressively. */
1900 if (DECL_VIRTUAL_P (this->decl
) && avail1
>= AVAIL_AVAILABLE
)
1901 binds_local1
= true;
1902 if (DECL_VIRTUAL_P (s2
->decl
) && avail2
>= AVAIL_AVAILABLE
)
1903 binds_local2
= true;
1905 /* If both definitions are available we know that even if they are bound
1906 to other unit they must be defined same way and therefore we can use
1907 equivalence test. */
1908 if (rs1
!= rs2
&& avail1
>= AVAIL_AVAILABLE
&& avail2
>= AVAIL_AVAILABLE
)
1909 binds_local1
= binds_local2
= true;
1911 if ((binds_local1
? rs1
: this)
1912 == (binds_local2
? rs2
: s2
))
1914 /* We made use of the fact that alias is not weak. */
1915 if (binds_local1
&& rs1
!= this)
1916 refuse_visibility_changes
= true;
1917 if (binds_local2
&& rs2
!= s2
)
1918 s2
->refuse_visibility_changes
= true;
1922 /* If both symbols may resolve to NULL, we can not really prove them different. */
1923 if (!nonzero_address () && !s2
->nonzero_address ())
1926 /* Except for NULL, functions and variables never overlap. */
1927 if (TREE_CODE (decl
) != TREE_CODE (s2
->decl
))
1930 /* If one of the symbols is unresolved alias, punt. */
1931 if (rs1
->alias
|| rs2
->alias
)
1934 /* If we have a non-interposale definition of at least one of the symbols
1935 and the other symbol is different, we know other unit can not interpose
1936 it to the first symbol; all aliases of the definition needs to be
1937 present in the current unit. */
1938 if (((really_binds_local1
|| really_binds_local2
)
1939 /* If we have both definitions and they are different, we know they
1940 will be different even in units they binds to. */
1941 || (binds_local1
&& binds_local2
))
1944 /* We make use of the fact that one symbol is not alias of the other
1945 and that the definition is non-interposable. */
1946 refuse_visibility_changes
= true;
1947 s2
->refuse_visibility_changes
= true;
1948 rs1
->refuse_visibility_changes
= true;
1949 rs2
->refuse_visibility_changes
= true;
1953 /* TODO: Alias oracle basically assume that addresses of global variables
1954 are different unless they are declared as alias of one to another.
1955 We probably should be consistent and use this fact here, too, and update
1956 alias oracle to use this predicate. */