2 Copyright (C) 2012-2015 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"
29 #include "double-int.h"
36 #include "fold-const.h"
37 #include "print-tree.h"
40 #include "hard-reg-set.h"
45 #include "basic-block.h"
46 #include "tree-ssa-alias.h"
47 #include "internal-fn.h"
48 #include "gimple-expr.h"
51 #include "tree-inline.h"
52 #include "langhooks.h"
54 #include "plugin-api.h"
57 #include "diagnostic.h"
59 #include "lto-streamer.h"
61 #include "ipa-utils.h"
64 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias","chkp"};
66 const char * const ld_plugin_symbol_resolution_names
[]=
71 "prevailing_def_ironly",
77 "prevailing_def_ironly_exp"
80 /* Hash asmnames ignoring the user specified marks. */
83 symbol_table::decl_assembler_name_hash (const_tree asmname
)
85 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
87 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
88 size_t ulp_len
= strlen (user_label_prefix
);
92 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
95 return htab_hash_string (decl_str
);
98 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
102 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
105 symbol_table::decl_assembler_name_equal (tree decl
, const_tree asmname
)
107 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
108 const char *decl_str
;
109 const char *asmname_str
;
112 if (decl_asmname
== asmname
)
115 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
116 asmname_str
= IDENTIFIER_POINTER (asmname
);
119 /* If the target assembler name was set by the user, things are trickier.
120 We have a leading '*' to begin with. After that, it's arguable what
121 is the correct thing to do with -fleading-underscore. Arguably, we've
122 historically been doing the wrong thing in assemble_alias by always
123 printing the leading underscore. Since we're not changing that, make
124 sure user_label_prefix follows the '*' before matching. */
125 if (decl_str
[0] == '*')
127 size_t ulp_len
= strlen (user_label_prefix
);
133 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
134 decl_str
+= ulp_len
, test
=true;
138 if (asmname_str
[0] == '*')
140 size_t ulp_len
= strlen (user_label_prefix
);
146 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
147 asmname_str
+= ulp_len
, test
=true;
154 return strcmp (decl_str
, asmname_str
) == 0;
158 /* Returns nonzero if P1 and P2 are equal. */
160 /* Insert NODE to assembler name hash. */
163 symbol_table::insert_to_assembler_name_hash (symtab_node
*node
,
166 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
168 gcc_checking_assert (!node
->previous_sharing_asm_name
169 && !node
->next_sharing_asm_name
);
170 if (assembler_name_hash
)
174 tree decl
= node
->decl
;
176 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
178 /* C++ FE can produce decls without associated assembler name and insert
179 them to symtab to hold section or TLS information. */
183 hashval_t hash
= decl_assembler_name_hash (name
);
184 aslot
= assembler_name_hash
->find_slot_with_hash (name
, hash
, INSERT
);
185 gcc_assert (*aslot
!= node
);
186 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
188 (*aslot
)->previous_sharing_asm_name
= node
;
191 /* Update also possible inline clones sharing a decl. */
192 cnode
= dyn_cast
<cgraph_node
*> (node
);
193 if (cnode
&& cnode
->clones
&& with_clones
)
194 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
195 if (cnode
->decl
== decl
)
196 insert_to_assembler_name_hash (cnode
, true);
201 /* Remove NODE from assembler name hash. */
204 symbol_table::unlink_from_assembler_name_hash (symtab_node
*node
,
207 if (assembler_name_hash
)
210 tree decl
= node
->decl
;
212 if (node
->next_sharing_asm_name
)
213 node
->next_sharing_asm_name
->previous_sharing_asm_name
214 = node
->previous_sharing_asm_name
;
215 if (node
->previous_sharing_asm_name
)
217 node
->previous_sharing_asm_name
->next_sharing_asm_name
218 = node
->next_sharing_asm_name
;
222 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
228 hashval_t hash
= decl_assembler_name_hash (name
);
229 slot
= assembler_name_hash
->find_slot_with_hash (name
, hash
,
231 gcc_assert (*slot
== node
);
232 if (!node
->next_sharing_asm_name
)
233 assembler_name_hash
->clear_slot (slot
);
235 *slot
= node
->next_sharing_asm_name
;
237 node
->next_sharing_asm_name
= NULL
;
238 node
->previous_sharing_asm_name
= NULL
;
240 /* Update also possible inline clones sharing a decl. */
241 cnode
= dyn_cast
<cgraph_node
*> (node
);
242 if (cnode
&& cnode
->clones
&& with_clones
)
243 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
244 if (cnode
->decl
== decl
)
245 unlink_from_assembler_name_hash (cnode
, true);
249 /* Arrange node to be first in its entry of assembler_name_hash. */
252 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node
*node
)
254 unlink_from_assembler_name_hash (node
, false);
255 insert_to_assembler_name_hash (node
, false);
258 /* Initalize asm name hash unless. */
261 symbol_table::symtab_initialize_asm_name_hash (void)
264 if (!assembler_name_hash
)
266 assembler_name_hash
= hash_table
<asmname_hasher
>::create_ggc (10);
267 FOR_EACH_SYMBOL (node
)
268 insert_to_assembler_name_hash (node
, false);
272 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
275 symbol_table::change_decl_assembler_name (tree decl
, tree name
)
277 symtab_node
*node
= NULL
;
279 /* We can have user ASM names on things, like global register variables, that
280 are not in the symbol table. */
281 if ((TREE_CODE (decl
) == VAR_DECL
282 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
283 || TREE_CODE (decl
) == FUNCTION_DECL
)
284 node
= symtab_node::get (decl
);
285 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
287 SET_DECL_ASSEMBLER_NAME (decl
, name
);
289 insert_to_assembler_name_hash (node
, true);
293 if (name
== DECL_ASSEMBLER_NAME (decl
))
296 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
297 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
300 unlink_from_assembler_name_hash (node
, true);
301 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
302 && DECL_RTL_SET_P (decl
))
303 warning (0, "%D renamed after being referenced in assembly", decl
);
305 SET_DECL_ASSEMBLER_NAME (decl
, name
);
308 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
309 TREE_CHAIN (name
) = alias
;
312 insert_to_assembler_name_hash (node
, true);
316 /* Return true when RESOLUTION indicate that linker will use
317 the symbol from non-LTO object files. */
320 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
322 return (resolution
== LDPR_PREVAILING_DEF
323 || resolution
== LDPR_PREEMPTED_REG
324 || resolution
== LDPR_RESOLVED_EXEC
325 || resolution
== LDPR_RESOLVED_DYN
);
328 /* Hash sections by their names. */
331 section_name_hasher::hash (section_hash_entry
*n
)
333 return htab_hash_string (n
->name
);
336 /* Return true if section P1 name equals to P2. */
339 section_name_hasher::equal (section_hash_entry
*n1
, const char *name
)
341 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
344 /* Add node into symbol table. This function is not used directly, but via
345 cgraph/varpool node creation routines. */
348 symtab_node::register_symbol (void)
350 symtab
->register_symbol (this);
352 if (!decl
->decl_with_vis
.symtab_node
)
353 decl
->decl_with_vis
.symtab_node
= this;
357 /* Be sure to do this last; C++ FE might create new nodes via
358 DECL_ASSEMBLER_NAME langhook! */
359 symtab
->insert_to_assembler_name_hash (this, false);
362 /* Remove NODE from same comdat group. */
365 symtab_node::remove_from_same_comdat_group (void)
367 if (same_comdat_group
)
370 for (prev
= same_comdat_group
;
371 prev
->same_comdat_group
!= this;
372 prev
= prev
->same_comdat_group
)
374 if (same_comdat_group
== prev
)
375 prev
->same_comdat_group
= NULL
;
377 prev
->same_comdat_group
= same_comdat_group
;
378 same_comdat_group
= NULL
;
379 set_comdat_group (NULL
);
383 /* Remove node from symbol table. This function is not used directly, but via
384 cgraph/varpool node removal routines. */
387 symtab_node::unregister (void)
389 remove_all_references ();
390 remove_all_referring ();
392 /* Remove reference to section. */
393 set_section_for_node (NULL
);
395 remove_from_same_comdat_group ();
397 symtab
->unregister (this);
399 /* During LTO symtab merging we temporarily corrupt decl to symtab node
401 gcc_assert (decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
402 if (decl
->decl_with_vis
.symtab_node
== this)
404 symtab_node
*replacement_node
= NULL
;
405 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
406 replacement_node
= cnode
->find_replacement ();
407 decl
->decl_with_vis
.symtab_node
= replacement_node
;
409 if (!is_a
<varpool_node
*> (this) || !DECL_HARD_REGISTER (decl
))
410 symtab
->unlink_from_assembler_name_hash (this, false);
411 if (in_init_priority_hash
)
412 symtab
->init_priority_hash
->remove (this);
416 /* Remove symbol from symbol table. */
419 symtab_node::remove (void)
421 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
423 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
427 /* Add NEW_ to the same comdat group that OLD is in. */
430 symtab_node::add_to_same_comdat_group (symtab_node
*old_node
)
432 gcc_assert (old_node
->get_comdat_group ());
433 gcc_assert (!same_comdat_group
);
434 gcc_assert (this != old_node
);
436 set_comdat_group (old_node
->get_comdat_group ());
437 same_comdat_group
= old_node
;
438 if (!old_node
->same_comdat_group
)
439 old_node
->same_comdat_group
= this;
443 for (n
= old_node
->same_comdat_group
;
444 n
->same_comdat_group
!= old_node
;
445 n
= n
->same_comdat_group
)
447 n
->same_comdat_group
= this;
451 /* Dissolve the same_comdat_group list in which NODE resides. */
454 symtab_node::dissolve_same_comdat_group_list (void)
456 symtab_node
*n
= this;
459 if (!same_comdat_group
)
463 next
= n
->same_comdat_group
;
464 n
->same_comdat_group
= NULL
;
465 /* Clear comdat_group for comdat locals, since
466 make_decl_local doesn't. */
467 if (!TREE_PUBLIC (n
->decl
))
468 n
->set_comdat_group (NULL
);
474 /* Return printable assembler name of NODE.
475 This function is used only for debugging. When assembler name
476 is unknown go with identifier name. */
479 symtab_node::asm_name () const
481 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
482 return lang_hooks
.decl_printable_name (decl
, 2);
483 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
486 /* Return printable identifier name. */
489 symtab_node::name () const
491 return lang_hooks
.decl_printable_name (decl
, 2);
494 /* Return ipa reference from this symtab_node to
495 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
499 symtab_node::create_reference (symtab_node
*referred_node
,
500 enum ipa_ref_use use_type
)
502 return create_reference (referred_node
, use_type
, NULL
);
506 /* Return ipa reference from this symtab_node to
507 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
508 of the use and STMT the statement (if it exists). */
511 symtab_node::create_reference (symtab_node
*referred_node
,
512 enum ipa_ref_use use_type
, gimple stmt
)
514 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
515 ipa_ref_list
*list
, *list2
;
516 ipa_ref_t
*old_references
;
518 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
519 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
522 old_references
= vec_safe_address (list
->references
);
523 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
524 ref
= &list
->references
->last ();
526 list2
= &referred_node
->ref_list
;
528 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
529 if(use_type
== IPA_REF_ALIAS
)
531 list2
->referring
.safe_insert (0, ref
);
532 ref
->referred_index
= 0;
534 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
535 list2
->referring
[i
]->referred_index
= i
;
539 list2
->referring
.safe_push (ref
);
540 ref
->referred_index
= list2
->referring
.length () - 1;
543 ref
->referring
= this;
544 ref
->referred
= referred_node
;
546 ref
->lto_stmt_uid
= 0;
548 ref
->speculative
= 0;
550 /* If vector was moved in memory, update pointers. */
551 if (old_references
!= list
->references
->address ())
554 for (i
= 0; iterate_reference(i
, ref2
); i
++)
555 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
560 /* If VAL is a reference to a function or a variable, add a reference from
561 this symtab_node to the corresponding symbol table node. USE_TYPE specify
562 type of the use and STMT the statement (if it exists). Return the new
563 reference or NULL if none was created. */
566 symtab_node::maybe_create_reference (tree val
, enum ipa_ref_use use_type
,
570 if (TREE_CODE (val
) != ADDR_EXPR
)
572 val
= get_base_var (val
);
573 if (val
&& (TREE_CODE (val
) == FUNCTION_DECL
574 || TREE_CODE (val
) == VAR_DECL
))
576 symtab_node
*referred
= symtab_node::get (val
);
577 gcc_checking_assert (referred
);
578 return create_reference (referred
, use_type
, stmt
);
583 /* Clone all references from symtab NODE to this symtab_node. */
586 symtab_node::clone_references (symtab_node
*node
)
588 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
590 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
592 bool speculative
= ref
->speculative
;
593 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
595 ref2
= create_reference (ref
->referred
, ref
->use
, ref
->stmt
);
596 ref2
->speculative
= speculative
;
597 ref2
->lto_stmt_uid
= stmt_uid
;
601 /* Clone all referring from symtab NODE to this symtab_node. */
604 symtab_node::clone_referring (symtab_node
*node
)
606 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
608 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
610 bool speculative
= ref
->speculative
;
611 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
613 ref2
= ref
->referring
->create_reference (this, ref
->use
, ref
->stmt
);
614 ref2
->speculative
= speculative
;
615 ref2
->lto_stmt_uid
= stmt_uid
;
619 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
622 symtab_node::clone_reference (ipa_ref
*ref
, gimple stmt
)
624 bool speculative
= ref
->speculative
;
625 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
628 ref2
= create_reference (ref
->referred
, ref
->use
, stmt
);
629 ref2
->speculative
= speculative
;
630 ref2
->lto_stmt_uid
= stmt_uid
;
634 /* Find the structure describing a reference to REFERRED_NODE
635 and associated with statement STMT. */
638 symtab_node::find_reference (symtab_node
*referred_node
,
639 gimple stmt
, unsigned int lto_stmt_uid
)
644 for (i
= 0; iterate_reference (i
, r
); i
++)
645 if (r
->referred
== referred_node
647 && ((stmt
&& r
->stmt
== stmt
)
648 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
649 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
654 /* Remove all references that are associated with statement STMT. */
657 symtab_node::remove_stmt_references (gimple stmt
)
662 while (iterate_reference (i
, r
))
664 r
->remove_reference ();
669 /* Remove all stmt references in non-speculative references.
670 Those are not maintained during inlining & clonning.
671 The exception are speculative references that are updated along
672 with callgraph edges associated with them. */
675 symtab_node::clear_stmts_in_references (void)
680 for (i
= 0; iterate_reference (i
, r
); i
++)
688 /* Remove all references in ref list. */
691 symtab_node::remove_all_references (void)
693 while (vec_safe_length (ref_list
.references
))
694 ref_list
.references
->last ().remove_reference ();
695 vec_free (ref_list
.references
);
698 /* Remove all referring items in ref list. */
701 symtab_node::remove_all_referring (void)
703 while (ref_list
.referring
.length ())
704 ref_list
.referring
.last ()->remove_reference ();
705 ref_list
.referring
.release ();
708 /* Dump references in ref list to FILE. */
711 symtab_node::dump_references (FILE *file
)
715 for (i
= 0; iterate_reference (i
, ref
); i
++)
717 fprintf (file
, "%s/%i (%s)",
718 ref
->referred
->asm_name (),
719 ref
->referred
->order
,
720 ipa_ref_use_name
[ref
->use
]);
721 if (ref
->speculative
)
722 fprintf (file
, " (speculative)");
724 fprintf (file
, "\n");
727 /* Dump referring in list to FILE. */
730 symtab_node::dump_referring (FILE *file
)
734 for (i
= 0; iterate_referring(i
, ref
); i
++)
736 fprintf (file
, "%s/%i (%s)",
737 ref
->referring
->asm_name (),
738 ref
->referring
->order
,
739 ipa_ref_use_name
[ref
->use
]);
740 if (ref
->speculative
)
741 fprintf (file
, " (speculative)");
743 fprintf (file
, "\n");
746 /* Return true if list contains an alias. */
748 symtab_node::has_aliases_p (void)
753 for (i
= 0; iterate_referring (i
, ref
); i
++)
754 if (ref
->use
== IPA_REF_ALIAS
)
759 /* Iterates I-th reference in the list, REF is also set. */
762 symtab_node::iterate_reference (unsigned i
, ipa_ref
*&ref
)
764 vec_safe_iterate (ref_list
.references
, i
, &ref
);
769 /* Iterates I-th referring item in the list, REF is also set. */
772 symtab_node::iterate_referring (unsigned i
, ipa_ref
*&ref
)
774 ref_list
.referring
.iterate (i
, &ref
);
779 /* Iterates I-th referring alias item in the list, REF is also set. */
782 symtab_node::iterate_direct_aliases (unsigned i
, ipa_ref
*&ref
)
784 ref_list
.referring
.iterate (i
, &ref
);
786 if (ref
&& ref
->use
!= IPA_REF_ALIAS
)
792 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
794 /* Dump base fields of symtab nodes to F. Not to be used directly. */
797 symtab_node::dump_base (FILE *f
)
799 static const char * const visibility_types
[] = {
800 "default", "protected", "hidden", "internal"
803 fprintf (f
, "%s/%i (%s)", asm_name (), order
, name ());
804 dump_addr (f
, " @", (void *)this);
805 fprintf (f
, "\n Type: %s", symtab_type_names
[type
]);
808 fprintf (f
, " definition");
810 fprintf (f
, " analyzed");
812 fprintf (f
, " alias");
814 fprintf (f
, " weakref");
815 if (cpp_implicit_alias
)
816 fprintf (f
, " cpp_implicit_alias");
818 fprintf (f
, " target:%s",
819 DECL_P (alias_target
)
820 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
822 : IDENTIFIER_POINTER (alias_target
));
824 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
825 fprintf (f
, "\n Visibility:");
826 if (in_other_partition
)
827 fprintf (f
, " in_other_partition");
828 if (used_from_other_partition
)
829 fprintf (f
, " used_from_other_partition");
831 fprintf (f
, " force_output");
833 fprintf (f
, " forced_by_abi");
834 if (externally_visible
)
835 fprintf (f
, " externally_visible");
837 fprintf (f
, " no_reorder");
838 if (resolution
!= LDPR_UNKNOWN
)
840 ld_plugin_symbol_resolution_names
[(int)resolution
]);
841 if (TREE_ASM_WRITTEN (decl
))
842 fprintf (f
, " asm_written");
843 if (DECL_EXTERNAL (decl
))
844 fprintf (f
, " external");
845 if (TREE_PUBLIC (decl
))
846 fprintf (f
, " public");
847 if (DECL_COMMON (decl
))
848 fprintf (f
, " common");
849 if (DECL_WEAK (decl
))
850 fprintf (f
, " weak");
851 if (DECL_DLLIMPORT_P (decl
))
852 fprintf (f
, " dll_import");
853 if (DECL_COMDAT (decl
))
854 fprintf (f
, " comdat");
855 if (get_comdat_group ())
856 fprintf (f
, " comdat_group:%s",
857 IDENTIFIER_POINTER (get_comdat_group_id ()));
858 if (DECL_ONE_ONLY (decl
))
859 fprintf (f
, " one_only");
861 fprintf (f
, " section:%s",
863 if (implicit_section
)
864 fprintf (f
," (implicit_section)");
865 if (DECL_VISIBILITY_SPECIFIED (decl
))
866 fprintf (f
, " visibility_specified");
867 if (DECL_VISIBILITY (decl
))
868 fprintf (f
, " visibility:%s",
869 visibility_types
[DECL_VISIBILITY (decl
)]);
870 if (DECL_VIRTUAL_P (decl
))
871 fprintf (f
, " virtual");
872 if (DECL_ARTIFICIAL (decl
))
873 fprintf (f
, " artificial");
874 if (TREE_CODE (decl
) == FUNCTION_DECL
)
876 if (DECL_STATIC_CONSTRUCTOR (decl
))
877 fprintf (f
, " constructor");
878 if (DECL_STATIC_DESTRUCTOR (decl
))
879 fprintf (f
, " destructor");
883 if (same_comdat_group
)
884 fprintf (f
, " Same comdat group as: %s/%i\n",
885 same_comdat_group
->asm_name (),
886 same_comdat_group
->order
);
887 if (next_sharing_asm_name
)
888 fprintf (f
, " next sharing asm name: %i\n",
889 next_sharing_asm_name
->order
);
890 if (previous_sharing_asm_name
)
891 fprintf (f
, " previous sharing asm name: %i\n",
892 previous_sharing_asm_name
->order
);
895 fprintf (f
, " Address is taken.\n");
898 fprintf (f
, " Aux:");
899 dump_addr (f
, " @", (void *)aux
);
902 fprintf (f
, " References: ");
904 fprintf (f
, " Referring: ");
907 fprintf (f
, " Read from file: %s\n",
908 lto_file_data
->file_name
);
911 /* Dump symtab node to F. */
914 symtab_node::dump (FILE *f
)
916 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
918 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
922 /* Dump symbol table to F. */
925 symtab_node::dump_table (FILE *f
)
928 fprintf (f
, "Symbol table:\n\n");
929 FOR_EACH_SYMBOL (node
)
934 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
935 Return NULL if there's no such node. */
938 symtab_node::get_for_asmname (const_tree asmname
)
942 symtab
->symtab_initialize_asm_name_hash ();
943 hashval_t hash
= symtab
->decl_assembler_name_hash (asmname
);
945 = symtab
->assembler_name_hash
->find_slot_with_hash (asmname
, hash
,
956 /* Dump symtab node NODE to stderr. */
959 symtab_node::debug (void)
964 /* Verify common part of symtab nodes. */
967 symtab_node::verify_base (void)
969 bool error_found
= false;
970 symtab_node
*hashed_node
;
972 if (is_a
<cgraph_node
*> (this))
974 if (TREE_CODE (decl
) != FUNCTION_DECL
)
976 error ("function symbol is not function");
980 else if (is_a
<varpool_node
*> (this))
982 if (TREE_CODE (decl
) != VAR_DECL
)
984 error ("variable symbol is not variable");
990 error ("node has unknown type");
994 if (symtab
->state
!= LTO_STREAMING
)
996 hashed_node
= symtab_node::get (decl
);
999 error ("node not found node->decl->decl_with_vis.symtab_node");
1002 if (hashed_node
!= this
1003 && (!is_a
<cgraph_node
*> (this)
1004 || !dyn_cast
<cgraph_node
*> (this)->clone_of
1005 || dyn_cast
<cgraph_node
*> (this)->clone_of
->decl
!= decl
))
1007 error ("node differs from node->decl->decl_with_vis.symtab_node");
1011 if (symtab
->assembler_name_hash
)
1013 hashed_node
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
1014 if (hashed_node
&& hashed_node
->previous_sharing_asm_name
)
1016 error ("assembler name hash list corrupted");
1021 if (hashed_node
== this)
1023 hashed_node
= hashed_node
->next_sharing_asm_name
;
1026 && !(is_a
<varpool_node
*> (this)
1027 || DECL_HARD_REGISTER (decl
)))
1029 error ("node not found in symtab assembler name hash");
1033 if (previous_sharing_asm_name
1034 && previous_sharing_asm_name
->next_sharing_asm_name
!= this)
1036 error ("double linked list of assembler names corrupted");
1039 if (analyzed
&& !definition
)
1041 error ("node is analyzed byt it is not a definition");
1044 if (cpp_implicit_alias
&& !alias
)
1046 error ("node is alias but not implicit alias");
1049 if (alias
&& !definition
&& !weakref
)
1051 error ("node is alias but not definition");
1054 if (weakref
&& !alias
)
1056 error ("node is weakref but not an alias");
1059 if (same_comdat_group
)
1061 symtab_node
*n
= same_comdat_group
;
1063 if (!n
->get_comdat_group ())
1065 error ("node is in same_comdat_group list but has no comdat_group");
1068 if (n
->get_comdat_group () != get_comdat_group ())
1070 error ("same_comdat_group list across different groups");
1075 error ("Node has same_comdat_group but it is not a definition");
1078 if (n
->type
!= type
)
1080 error ("mixing different types of symbol in same comdat groups is not supported");
1085 error ("node is alone in a comdat group");
1090 if (!n
->same_comdat_group
)
1092 error ("same_comdat_group is not a circular list");
1096 n
= n
->same_comdat_group
;
1099 if (comdat_local_p ())
1101 ipa_ref
*ref
= NULL
;
1103 for (int i
= 0; iterate_referring (i
, ref
); ++i
)
1105 if (!in_same_comdat_group_p (ref
->referring
))
1107 error ("comdat-local symbol referred to by %s outside its "
1109 identifier_to_locale (ref
->referring
->name()));
1115 if (implicit_section
&& !get_section ())
1117 error ("implicit_section flag is set but section isn't");
1120 if (get_section () && get_comdat_group ()
1121 && !implicit_section
1122 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl
)))
1124 error ("Both section and comdat group is set");
1127 /* TODO: Add string table for sections, so we do not keep holding duplicated
1129 if (alias
&& definition
1130 && get_section () != get_alias_target ()->get_section ()
1132 || !get_alias_target ()->get_section ()
1133 || strcmp (get_section(),
1134 get_alias_target ()->get_section ())))
1136 error ("Alias and target's section differs");
1137 get_alias_target ()->dump (stderr
);
1140 if (alias
&& definition
1141 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1143 error ("Alias and target's comdat groups differs");
1144 get_alias_target ()->dump (stderr
);
1151 /* Verify consistency of NODE. */
1154 symtab_node::verify (void)
1159 timevar_push (TV_CGRAPH_VERIFY
);
1160 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (this))
1161 node
->verify_node ();
1166 internal_error ("symtab_node::verify failed");
1168 timevar_pop (TV_CGRAPH_VERIFY
);
1171 /* Verify symbol table for internal consistency. */
1174 symtab_node::verify_symtab_nodes (void)
1177 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1179 FOR_EACH_SYMBOL (node
)
1182 if (node
->get_comdat_group ())
1184 symtab_node
**entry
, *s
;
1187 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1192 for (s
= (*entry
)->same_comdat_group
; s
!= NULL
&& s
!= node
; s
= s
->same_comdat_group
)
1193 if (!s
|| s
== *entry
)
1195 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1198 internal_error ("symtab_node::verify failed");
1204 /* Return true when NODE is known to be used from other (non-LTO)
1205 object file. Known only when doing LTO via linker plugin. */
1208 symtab_node::used_from_object_file_p_worker (symtab_node
*node
)
1210 if (!TREE_PUBLIC (node
->decl
) || DECL_EXTERNAL (node
->decl
))
1212 if (resolution_used_from_other_file_p (node
->resolution
))
1218 /* Return true when symtab_node is known to be used from other (non-LTO)
1219 object file. Known only when doing LTO via linker plugin. */
1222 symtab_node::used_from_object_file_p (void)
1224 return symtab_node::used_from_object_file_p_worker (this);
1227 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1228 but other code such as notice_global_symbol generates rtl. */
1231 symtab_node::make_decl_local (void)
1235 /* Avoid clearing comdat_groups on comdat-local decls. */
1236 if (TREE_PUBLIC (decl
) == 0)
1239 if (TREE_CODE (decl
) == VAR_DECL
)
1240 DECL_COMMON (decl
) = 0;
1241 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1243 DECL_COMDAT (decl
) = 0;
1244 DECL_WEAK (decl
) = 0;
1245 DECL_EXTERNAL (decl
) = 0;
1246 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1247 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1248 TREE_PUBLIC (decl
) = 0;
1249 if (!DECL_RTL_SET_P (decl
))
1252 /* Update rtl flags. */
1253 make_decl_rtl (decl
);
1255 rtl
= DECL_RTL (decl
);
1259 symbol
= XEXP (rtl
, 0);
1260 if (GET_CODE (symbol
) != SYMBOL_REF
)
1263 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1266 /* Walk the alias chain to return the symbol NODE is alias of.
1267 If NODE is not an alias, return NODE.
1268 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1271 symtab_node::ultimate_alias_target (enum availability
*availability
)
1273 bool weakref_p
= false;
1278 *availability
= get_availability ();
1282 /* To determine visibility of the target, we follow ELF semantic of aliases.
1283 Here alias is an alternative assembler name of a given definition. Its
1284 availability prevails the availability of its target (i.e. static alias of
1285 weak definition is available.
1287 Weakref is a different animal (and not part of ELF per se). It is just
1288 alternative name of a given symbol used within one complation unit
1289 and is translated prior hitting the object file. It inherits the
1290 visibility of its target (i.e. weakref of non-overwritable definition
1291 is non-overwritable, while weakref of weak definition is weak).
1293 If we ever get into supporting targets with different semantics, a target
1294 hook will be needed here. */
1298 weakref_p
= weakref
;
1300 *availability
= get_availability ();
1302 *availability
= AVAIL_LOCAL
;
1305 symtab_node
*node
= this;
1308 if (node
->alias
&& node
->analyzed
)
1309 node
= node
->get_alias_target ();
1314 else if (node
->analyzed
)
1318 enum availability a
= node
->get_availability ();
1319 if (a
< *availability
)
1324 *availability
= AVAIL_NOT_AVAILABLE
;
1327 if (node
&& availability
&& weakref_p
)
1329 enum availability a
= node
->get_availability ();
1330 if (a
< *availability
)
1332 weakref_p
= node
->weakref
;
1336 *availability
= AVAIL_NOT_AVAILABLE
;
1340 /* C++ FE sometimes change linkage flags after producing same body aliases.
1342 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1343 are obviously equivalent. The way it is doing so is however somewhat
1344 kludgy and interferes with the visibility code. As a result we need to
1345 copy the visibility from the target to get things right. */
1348 symtab_node::fixup_same_cpp_alias_visibility (symtab_node
*target
)
1350 if (is_a
<cgraph_node
*> (this))
1352 DECL_DECLARED_INLINE_P (decl
)
1353 = DECL_DECLARED_INLINE_P (target
->decl
);
1354 DECL_DISREGARD_INLINE_LIMITS (decl
)
1355 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1357 /* FIXME: It is not really clear why those flags should not be copied for
1361 DECL_WEAK (decl
) = DECL_WEAK (target
->decl
);
1362 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1363 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (target
->decl
);
1365 DECL_VIRTUAL_P (decl
) = DECL_VIRTUAL_P (target
->decl
);
1366 if (TREE_PUBLIC (decl
))
1370 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1371 DECL_COMDAT (decl
) = DECL_COMDAT (target
->decl
);
1372 group
= target
->get_comdat_group ();
1373 set_comdat_group (group
);
1374 if (group
&& !same_comdat_group
)
1375 add_to_same_comdat_group (target
);
1377 externally_visible
= target
->externally_visible
;
1380 /* Set section, do not recurse into aliases.
1381 When one wants to change section of symbol and its aliases,
1385 symtab_node::set_section_for_node (const char *section
)
1387 const char *current
= get_section ();
1388 section_hash_entry
**slot
;
1390 if (current
== section
1391 || (current
&& section
1392 && !strcmp (current
, section
)))
1397 x_section
->ref_count
--;
1398 if (!x_section
->ref_count
)
1400 hashval_t hash
= htab_hash_string (x_section
->name
);
1401 slot
= symtab
->section_hash
->find_slot_with_hash (x_section
->name
,
1403 ggc_free (x_section
);
1404 symtab
->section_hash
->clear_slot (slot
);
1410 implicit_section
= false;
1413 if (!symtab
->section_hash
)
1414 symtab
->section_hash
= hash_table
<section_name_hasher
>::create_ggc (10);
1415 slot
= symtab
->section_hash
->find_slot_with_hash (section
,
1416 htab_hash_string (section
),
1419 x_section
= (section_hash_entry
*)*slot
;
1422 int len
= strlen (section
);
1423 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1424 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1425 memcpy (x_section
->name
, section
, len
+ 1);
1427 x_section
->ref_count
++;
1430 /* Worker for set_section. */
1433 symtab_node::set_section (symtab_node
*n
, void *s
)
1435 n
->set_section_for_node ((char *)s
);
1439 /* Set section of symbol and its aliases. */
1442 symtab_node::set_section (const char *section
)
1444 gcc_assert (!this->alias
);
1445 call_for_symbol_and_aliases
1446 (symtab_node::set_section
, const_cast<char *>(section
), true);
1449 /* Return the initialization priority. */
1452 symtab_node::get_init_priority ()
1454 if (!this->in_init_priority_hash
)
1455 return DEFAULT_INIT_PRIORITY
;
1457 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1458 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1461 /* Return availability of NODE. */
1462 enum availability
symtab_node::get_availability (void)
1464 if (is_a
<cgraph_node
*> (this))
1465 return dyn_cast
<cgraph_node
*> (this)->get_availability ();
1467 return dyn_cast
<varpool_node
*> (this)->get_availability ();;
1471 /* Return the finalization priority. */
1474 cgraph_node::get_fini_priority ()
1476 if (!this->in_init_priority_hash
)
1477 return DEFAULT_INIT_PRIORITY
;
1478 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1479 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1482 /* Return the initialization and finalization priority information for
1483 DECL. If there is no previous priority information, a freshly
1484 allocated structure is returned. */
1486 symbol_priority_map
*
1487 symtab_node::priority_info (void)
1489 if (!symtab
->init_priority_hash
)
1490 symtab
->init_priority_hash
= hash_map
<symtab_node
*, symbol_priority_map
>::create_ggc (13);
1493 symbol_priority_map
*h
1494 = &symtab
->init_priority_hash
->get_or_insert (this, &existed
);
1497 h
->init
= DEFAULT_INIT_PRIORITY
;
1498 h
->fini
= DEFAULT_INIT_PRIORITY
;
1499 in_init_priority_hash
= true;
1505 /* Set initialization priority to PRIORITY. */
1508 symtab_node::set_init_priority (priority_type priority
)
1510 symbol_priority_map
*h
;
1512 if (is_a
<cgraph_node
*> (this))
1513 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1515 if (priority
== DEFAULT_INIT_PRIORITY
)
1517 gcc_assert (get_init_priority() == priority
);
1520 h
= priority_info ();
1524 /* Set fialization priority to PRIORITY. */
1527 cgraph_node::set_fini_priority (priority_type priority
)
1529 symbol_priority_map
*h
;
1531 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1533 if (priority
== DEFAULT_INIT_PRIORITY
)
1535 gcc_assert (get_fini_priority() == priority
);
1538 h
= priority_info ();
1542 /* Worker for symtab_resolve_alias. */
1545 symtab_node::set_implicit_section (symtab_node
*n
,
1546 void *data ATTRIBUTE_UNUSED
)
1548 n
->implicit_section
= true;
1552 /* Add reference recording that symtab node is alias of TARGET.
1553 The function can fail in the case of aliasing cycles; in this case
1554 it returns false. */
1557 symtab_node::resolve_alias (symtab_node
*target
)
1561 gcc_assert (!analyzed
&& !vec_safe_length (ref_list
.references
));
1563 /* Never let cycles to creep into the symbol table alias references;
1564 those will make alias walkers to be infinite. */
1565 for (n
= target
; n
&& n
->alias
;
1566 n
= n
->analyzed
? n
->get_alias_target () : NULL
)
1569 if (is_a
<cgraph_node
*> (this))
1570 error ("function %q+D part of alias cycle", decl
);
1571 else if (is_a
<varpool_node
*> (this))
1572 error ("variable %q+D part of alias cycle", decl
);
1579 /* "analyze" the node - i.e. mark the reference. */
1583 create_reference (target
, IPA_REF_ALIAS
, NULL
);
1585 /* Add alias into the comdat group of its target unless it is already there. */
1586 if (same_comdat_group
)
1587 remove_from_same_comdat_group ();
1588 set_comdat_group (NULL
);
1589 if (target
->get_comdat_group ())
1590 add_to_same_comdat_group (target
);
1592 if ((get_section () != target
->get_section ()
1593 || target
->get_comdat_group ()) && get_section () && !implicit_section
)
1595 error ("section of alias %q+D must match section of its target", decl
);
1597 call_for_symbol_and_aliases (symtab_node::set_section
,
1598 const_cast<char *>(target
->get_section ()), true);
1599 if (target
->implicit_section
)
1600 call_for_symbol_and_aliases (set_implicit_section
, NULL
, true);
1602 /* Alias targets become redundant after alias is resolved into an reference.
1603 We do not want to keep it around or we would have to mind updating them
1604 when renaming symbols. */
1605 alias_target
= NULL
;
1607 if (cpp_implicit_alias
&& symtab
->state
>= CONSTRUCTION
)
1608 fixup_same_cpp_alias_visibility (target
);
1610 /* If alias has address taken, so does the target. */
1612 target
->ultimate_alias_target ()->address_taken
= true;
1616 /* Call calback on symtab node and aliases associated to this node.
1617 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1621 symtab_node::call_for_symbol_and_aliases (bool (*callback
) (symtab_node
*,
1623 void *data
, bool include_overwritable
)
1628 if (callback (this, data
))
1630 for (i
= 0; iterate_referring (i
, ref
); i
++)
1631 if (ref
->use
== IPA_REF_ALIAS
)
1633 symtab_node
*alias
= ref
->referring
;
1634 if (include_overwritable
1635 || alias
->get_availability () > AVAIL_INTERPOSABLE
)
1636 if (alias
->call_for_symbol_and_aliases (callback
, data
,
1637 include_overwritable
))
1643 /* Worker searching noninterposable alias. */
1646 symtab_node::noninterposable_alias (symtab_node
*node
, void *data
)
1648 if (decl_binds_to_current_def_p (node
->decl
))
1650 symtab_node
*fn
= node
->ultimate_alias_target ();
1652 /* Ensure that the alias is well formed this may not be the case
1653 of user defined aliases and currently it is not always the case
1654 of C++ same body aliases (that is a bug). */
1655 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
1656 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
1657 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
1658 && flags_from_decl_or_type (node
->decl
)
1659 != flags_from_decl_or_type (fn
->decl
))
1660 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
1663 *(symtab_node
**)data
= node
;
1669 /* If node can not be overwriten by static or dynamic linker to point to
1670 different definition, return NODE. Otherwise look for alias with such
1671 property and if none exists, introduce new one. */
1674 symtab_node::noninterposable_alias (void)
1677 symtab_node
*new_node
= NULL
;
1679 /* First try to look up existing alias or base object
1680 (if that is already non-overwritable). */
1681 symtab_node
*node
= ultimate_alias_target ();
1682 gcc_assert (!node
->alias
&& !node
->weakref
);
1683 node
->call_for_symbol_and_aliases (symtab_node::noninterposable_alias
,
1684 (void *)&new_node
, true);
1687 #ifndef ASM_OUTPUT_DEF
1688 /* If aliases aren't supported by the assembler, fail. */
1692 /* Otherwise create a new one. */
1693 new_decl
= copy_node (node
->decl
);
1694 DECL_NAME (new_decl
) = clone_function_name (node
->decl
, "localalias");
1695 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1696 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1697 DECL_INITIAL (new_decl
) = NULL
;
1698 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1699 SET_DECL_RTL (new_decl
, NULL
);
1701 /* Update the properties. */
1702 DECL_EXTERNAL (new_decl
) = 0;
1703 TREE_PUBLIC (new_decl
) = 0;
1704 DECL_COMDAT (new_decl
) = 0;
1705 DECL_WEAK (new_decl
) = 0;
1707 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1708 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1709 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1711 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1712 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1713 new_node
= cgraph_node::create_alias (new_decl
, node
->decl
);
1717 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
1718 DECL_INITIAL (new_decl
) = error_mark_node
;
1719 new_node
= varpool_node::create_alias (new_decl
, node
->decl
);
1721 new_node
->resolve_alias (node
);
1722 gcc_assert (decl_binds_to_current_def_p (new_decl
)
1723 && targetm
.binds_local_p (new_decl
));
1727 /* Return true if symtab node and TARGET represents
1728 semantically equivalent symbols. */
1731 symtab_node::semantically_equivalent_p (symtab_node
*target
)
1733 enum availability avail
;
1737 /* Equivalent functions are equivalent. */
1738 if (decl
== target
->decl
)
1741 /* If symbol is not overwritable by different implementation,
1742 walk to the base object it defines. */
1743 ba
= ultimate_alias_target (&avail
);
1744 if (avail
>= AVAIL_AVAILABLE
)
1751 bb
= target
->ultimate_alias_target (&avail
);
1752 if (avail
>= AVAIL_AVAILABLE
)
1762 /* Classify symbol symtab node for partitioning. */
1764 enum symbol_partitioning_class
1765 symtab_node::get_partitioning_class (void)
1767 /* Inline clones are always duplicated.
1768 This include external delcarations. */
1769 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
1771 if (DECL_ABSTRACT_P (decl
))
1772 return SYMBOL_EXTERNAL
;
1774 if (cnode
&& cnode
->global
.inlined_to
)
1775 return SYMBOL_DUPLICATE
;
1777 /* Weakref aliases are always duplicated. */
1779 return SYMBOL_DUPLICATE
;
1781 /* External declarations are external. */
1782 if (DECL_EXTERNAL (decl
))
1783 return SYMBOL_EXTERNAL
;
1785 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
1787 /* Constant pool references use local symbol names that can not
1788 be promoted global. We should never put into a constant pool
1789 objects that can not be duplicated across partitions. */
1790 if (DECL_IN_CONSTANT_POOL (decl
))
1791 return SYMBOL_DUPLICATE
;
1792 gcc_checking_assert (vnode
->definition
);
1794 /* Functions that are cloned may stay in callgraph even if they are unused.
1795 Handle them as external; compute_ltrans_boundary take care to make
1796 proper things to happen (i.e. to make them appear in the boundary but
1797 with body streamed, so clone can me materialized). */
1798 else if (!dyn_cast
<cgraph_node
*> (this)->definition
)
1799 return SYMBOL_EXTERNAL
;
1801 /* Linker discardable symbols are duplicated to every use unless they are
1803 if (DECL_ONE_ONLY (decl
)
1806 && !used_from_object_file_p ())
1807 return SYMBOL_DUPLICATE
;
1809 return SYMBOL_PARTITION
;
1812 /* Return true when symbol is known to be non-zero. */
1815 symtab_node::nonzero_address ()
1817 /* Weakrefs may be NULL when their target is not defined. */
1818 if (alias
&& weakref
)
1822 symtab_node
*target
= ultimate_alias_target ();
1824 if (target
->alias
&& target
->weakref
)
1826 /* We can not recurse to target::nonzero. It is possible that the
1827 target is used only via the alias.
1828 We may walk references and look for strong use, but we do not know
1829 if this strong use will survive to final binary, so be
1831 ??? Maybe we could do the lookup during late optimization that
1832 could be useful to eliminate the NULL pointer checks in LTO
1834 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
1836 if (target
->resolution
!= LDPR_UNKNOWN
1837 && target
->resolution
!= LDPR_UNDEF
1838 && flag_delete_null_pointer_checks
)
1846 /* With !flag_delete_null_pointer_checks we assume that symbols may
1847 bind to NULL. This is on by default on embedded targets only.
1849 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1850 linking fails. Important case of WEAK we want to do well are comdats.
1851 Those are handled by later check for definition.
1853 When parsing, beware the cases when WEAK attribute is added later. */
1854 if (!DECL_WEAK (decl
)
1855 && flag_delete_null_pointer_checks
)
1857 refuse_visibility_changes
= true;
1861 /* If target is defined and not extern, we know it will be output and thus
1862 it will bind to non-NULL.
1863 Play safe for flag_delete_null_pointer_checks where weak definition maye
1864 be re-defined by NULL. */
1865 if (definition
&& !DECL_EXTERNAL (decl
)
1866 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (decl
)))
1868 if (!DECL_WEAK (decl
))
1869 refuse_visibility_changes
= true;
1873 /* As the last resort, check the resolution info. */
1874 if (resolution
!= LDPR_UNKNOWN
1875 && resolution
!= LDPR_UNDEF
1876 && flag_delete_null_pointer_checks
)
1881 /* Return 0 if symbol is known to have different address than S2,
1882 Return 1 if symbol is known to have same address as S2,
1883 return 2 otherwise. */
1885 symtab_node::equal_address_to (symtab_node
*s2
)
1887 enum availability avail1
, avail2
;
1889 /* A Shortcut: equivalent symbols are always equivalent. */
1893 /* For non-interposable aliases, lookup and compare their actual definitions.
1894 Also check if the symbol needs to bind to given definition. */
1895 symtab_node
*rs1
= ultimate_alias_target (&avail1
);
1896 symtab_node
*rs2
= s2
->ultimate_alias_target (&avail2
);
1897 bool binds_local1
= rs1
->analyzed
&& decl_binds_to_current_def_p (this->decl
);
1898 bool binds_local2
= rs2
->analyzed
&& decl_binds_to_current_def_p (s2
->decl
);
1899 bool really_binds_local1
= binds_local1
;
1900 bool really_binds_local2
= binds_local2
;
1902 /* Addresses of vtables and virtual functions can not be used by user
1903 code and are used only within speculation. In this case we may make
1904 symbol equivalent to its alias even if interposition may break this
1905 rule. Doing so will allow us to turn speculative inlining into
1906 non-speculative more agressively. */
1907 if (DECL_VIRTUAL_P (this->decl
) && avail1
>= AVAIL_AVAILABLE
)
1908 binds_local1
= true;
1909 if (DECL_VIRTUAL_P (s2
->decl
) && avail2
>= AVAIL_AVAILABLE
)
1910 binds_local2
= true;
1912 /* If both definitions are available we know that even if they are bound
1913 to other unit they must be defined same way and therefore we can use
1914 equivalence test. */
1915 if (rs1
!= rs2
&& avail1
>= AVAIL_AVAILABLE
&& avail2
>= AVAIL_AVAILABLE
)
1916 binds_local1
= binds_local2
= true;
1918 if ((binds_local1
? rs1
: this)
1919 == (binds_local2
? rs2
: s2
))
1921 /* We made use of the fact that alias is not weak. */
1922 if (binds_local1
&& rs1
!= this)
1923 refuse_visibility_changes
= true;
1924 if (binds_local2
&& rs2
!= s2
)
1925 s2
->refuse_visibility_changes
= true;
1929 /* If both symbols may resolve to NULL, we can not really prove them different. */
1930 if (!nonzero_address () && !s2
->nonzero_address ())
1933 /* Except for NULL, functions and variables never overlap. */
1934 if (TREE_CODE (decl
) != TREE_CODE (s2
->decl
))
1937 /* If one of the symbols is unresolved alias, punt. */
1938 if (rs1
->alias
|| rs2
->alias
)
1941 /* If we have a non-interposale definition of at least one of the symbols
1942 and the other symbol is different, we know other unit can not interpose
1943 it to the first symbol; all aliases of the definition needs to be
1944 present in the current unit. */
1945 if (((really_binds_local1
|| really_binds_local2
)
1946 /* If we have both definitions and they are different, we know they
1947 will be different even in units they binds to. */
1948 || (binds_local1
&& binds_local2
))
1951 /* We make use of the fact that one symbol is not alias of the other
1952 and that the definition is non-interposable. */
1953 refuse_visibility_changes
= true;
1954 s2
->refuse_visibility_changes
= true;
1955 rs1
->refuse_visibility_changes
= true;
1956 rs2
->refuse_visibility_changes
= true;
1960 /* TODO: Alias oracle basically assume that addresses of global variables
1961 are different unless they are declared as alias of one to another.
1962 We probably should be consistent and use this fact here, too, and update
1963 alias oracle to use this predicate. */