2 Copyright (C) 2012-2017 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"
31 #include "lto-streamer.h"
32 #include "print-tree.h"
34 #include "langhooks.h"
36 #include "ipa-utils.h"
39 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias","chkp"};
41 const char * const ld_plugin_symbol_resolution_names
[]=
46 "prevailing_def_ironly",
52 "prevailing_def_ironly_exp"
55 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at ALIAS
56 until we find an identifier that is not itself a transparent alias. */
59 ultimate_transparent_alias_target (tree alias
)
63 while (IDENTIFIER_TRANSPARENT_ALIAS (target
))
65 gcc_checking_assert (TREE_CHAIN (target
));
66 target
= TREE_CHAIN (target
);
68 gcc_checking_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
69 && ! TREE_CHAIN (target
));
75 /* Hash asmnames ignoring the user specified marks. */
78 symbol_table::decl_assembler_name_hash (const_tree asmname
)
80 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
82 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
83 size_t ulp_len
= strlen (user_label_prefix
);
87 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
90 return htab_hash_string (decl_str
);
93 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
96 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
100 symbol_table::assembler_names_equal_p (const char *name1
, const char *name2
)
106 size_t ulp_len
= strlen (user_label_prefix
);
112 else if (strncmp (name1
, user_label_prefix
, ulp_len
) == 0)
119 size_t ulp_len
= strlen (user_label_prefix
);
125 else if (strncmp (name2
, user_label_prefix
, ulp_len
) == 0)
130 return !strcmp (name1
, name2
);
135 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
138 symbol_table::decl_assembler_name_equal (tree decl
, const_tree asmname
)
140 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
141 const char *decl_str
;
142 const char *asmname_str
;
144 if (decl_asmname
== asmname
)
147 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
148 asmname_str
= IDENTIFIER_POINTER (asmname
);
149 return assembler_names_equal_p (decl_str
, asmname_str
);
153 /* Returns nonzero if P1 and P2 are equal. */
155 /* Insert NODE to assembler name hash. */
158 symbol_table::insert_to_assembler_name_hash (symtab_node
*node
,
161 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
163 gcc_checking_assert (!node
->previous_sharing_asm_name
164 && !node
->next_sharing_asm_name
);
165 if (assembler_name_hash
)
169 tree decl
= node
->decl
;
171 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
173 /* C++ FE can produce decls without associated assembler name and insert
174 them to symtab to hold section or TLS information. */
178 hashval_t hash
= decl_assembler_name_hash (name
);
179 aslot
= assembler_name_hash
->find_slot_with_hash (name
, hash
, INSERT
);
180 gcc_assert (*aslot
!= node
);
181 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
183 (*aslot
)->previous_sharing_asm_name
= node
;
186 /* Update also possible inline clones sharing a decl. */
187 cnode
= dyn_cast
<cgraph_node
*> (node
);
188 if (cnode
&& cnode
->clones
&& with_clones
)
189 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
190 if (cnode
->decl
== decl
)
191 insert_to_assembler_name_hash (cnode
, true);
196 /* Remove NODE from assembler name hash. */
199 symbol_table::unlink_from_assembler_name_hash (symtab_node
*node
,
202 if (assembler_name_hash
)
205 tree decl
= node
->decl
;
207 if (node
->next_sharing_asm_name
)
208 node
->next_sharing_asm_name
->previous_sharing_asm_name
209 = node
->previous_sharing_asm_name
;
210 if (node
->previous_sharing_asm_name
)
212 node
->previous_sharing_asm_name
->next_sharing_asm_name
213 = node
->next_sharing_asm_name
;
217 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
223 hashval_t hash
= decl_assembler_name_hash (name
);
224 slot
= assembler_name_hash
->find_slot_with_hash (name
, hash
,
226 gcc_assert (*slot
== node
);
227 if (!node
->next_sharing_asm_name
)
228 assembler_name_hash
->clear_slot (slot
);
230 *slot
= node
->next_sharing_asm_name
;
232 node
->next_sharing_asm_name
= NULL
;
233 node
->previous_sharing_asm_name
= NULL
;
235 /* Update also possible inline clones sharing a decl. */
236 cnode
= dyn_cast
<cgraph_node
*> (node
);
237 if (cnode
&& cnode
->clones
&& with_clones
)
238 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
239 if (cnode
->decl
== decl
)
240 unlink_from_assembler_name_hash (cnode
, true);
244 /* Arrange node to be first in its entry of assembler_name_hash. */
247 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node
*node
)
249 unlink_from_assembler_name_hash (node
, false);
250 insert_to_assembler_name_hash (node
, false);
253 /* Initalize asm name hash unless. */
256 symbol_table::symtab_initialize_asm_name_hash (void)
259 if (!assembler_name_hash
)
261 assembler_name_hash
= hash_table
<asmname_hasher
>::create_ggc (10);
262 FOR_EACH_SYMBOL (node
)
263 insert_to_assembler_name_hash (node
, false);
267 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
270 symbol_table::change_decl_assembler_name (tree decl
, tree name
)
272 symtab_node
*node
= NULL
;
274 /* We can have user ASM names on things, like global register variables, that
275 are not in the symbol table. */
276 if ((VAR_P (decl
) && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
277 || TREE_CODE (decl
) == FUNCTION_DECL
)
278 node
= symtab_node::get (decl
);
279 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
281 SET_DECL_ASSEMBLER_NAME (decl
, name
);
283 insert_to_assembler_name_hash (node
, true);
287 if (name
== DECL_ASSEMBLER_NAME (decl
))
290 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
291 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
294 unlink_from_assembler_name_hash (node
, true);
296 const char *old_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
297 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
298 && DECL_RTL_SET_P (decl
))
299 warning (0, "%qD renamed after being referenced in assembly", decl
);
301 SET_DECL_ASSEMBLER_NAME (decl
, name
);
304 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
305 TREE_CHAIN (name
) = alias
;
307 /* If we change assembler name, also all transparent aliases must
308 be updated. There are three kinds - those having same assembler name,
309 those being renamed in varasm.c and weakref being renamed by the
313 insert_to_assembler_name_hash (node
, true);
315 for (unsigned i
= 0; node
->iterate_direct_aliases (i
, ref
); i
++)
317 struct symtab_node
*alias
= ref
->referring
;
318 if (alias
->transparent_alias
&& !alias
->weakref
319 && symbol_table::assembler_names_equal_p
320 (old_name
, IDENTIFIER_POINTER (
321 DECL_ASSEMBLER_NAME (alias
->decl
))))
322 change_decl_assembler_name (alias
->decl
, name
);
323 else if (alias
->transparent_alias
324 && IDENTIFIER_TRANSPARENT_ALIAS (alias
->decl
))
326 gcc_assert (TREE_CHAIN (DECL_ASSEMBLER_NAME (alias
->decl
))
327 && IDENTIFIER_TRANSPARENT_ALIAS
328 (DECL_ASSEMBLER_NAME (alias
->decl
)));
330 TREE_CHAIN (DECL_ASSEMBLER_NAME (alias
->decl
)) =
331 ultimate_transparent_alias_target
332 (DECL_ASSEMBLER_NAME (node
->decl
));
334 #ifdef ASM_OUTPUT_WEAKREF
335 else gcc_assert (!alias
->transparent_alias
|| alias
->weakref
);
337 else gcc_assert (!alias
->transparent_alias
);
340 gcc_assert (!node
->transparent_alias
|| !node
->definition
342 || TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
343 || symbol_table::assembler_names_equal_p
344 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
347 (node
->get_alias_target ()->decl
))));
352 /* Hash sections by their names. */
355 section_name_hasher::hash (section_hash_entry
*n
)
357 return htab_hash_string (n
->name
);
360 /* Return true if section P1 name equals to P2. */
363 section_name_hasher::equal (section_hash_entry
*n1
, const char *name
)
365 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
368 /* Add node into symbol table. This function is not used directly, but via
369 cgraph/varpool node creation routines. */
372 symtab_node::register_symbol (void)
374 symtab
->register_symbol (this);
376 if (!decl
->decl_with_vis
.symtab_node
)
377 decl
->decl_with_vis
.symtab_node
= this;
381 /* Be sure to do this last; C++ FE might create new nodes via
382 DECL_ASSEMBLER_NAME langhook! */
383 symtab
->insert_to_assembler_name_hash (this, false);
386 /* Remove NODE from same comdat group. */
389 symtab_node::remove_from_same_comdat_group (void)
391 if (same_comdat_group
)
394 for (prev
= same_comdat_group
;
395 prev
->same_comdat_group
!= this;
396 prev
= prev
->same_comdat_group
)
398 if (same_comdat_group
== prev
)
399 prev
->same_comdat_group
= NULL
;
401 prev
->same_comdat_group
= same_comdat_group
;
402 same_comdat_group
= NULL
;
403 set_comdat_group (NULL
);
407 /* Remove node from symbol table. This function is not used directly, but via
408 cgraph/varpool node removal routines. */
411 symtab_node::unregister (void)
413 remove_all_references ();
414 remove_all_referring ();
416 /* Remove reference to section. */
417 set_section_for_node (NULL
);
419 remove_from_same_comdat_group ();
421 symtab
->unregister (this);
423 /* During LTO symtab merging we temporarily corrupt decl to symtab node
425 gcc_assert (decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
426 if (decl
->decl_with_vis
.symtab_node
== this)
428 symtab_node
*replacement_node
= NULL
;
429 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
430 replacement_node
= cnode
->find_replacement ();
431 decl
->decl_with_vis
.symtab_node
= replacement_node
;
433 if (!is_a
<varpool_node
*> (this) || !DECL_HARD_REGISTER (decl
))
434 symtab
->unlink_from_assembler_name_hash (this, false);
435 if (in_init_priority_hash
)
436 symtab
->init_priority_hash
->remove (this);
440 /* Remove symbol from symbol table. */
443 symtab_node::remove (void)
445 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
447 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
451 /* Add NEW_ to the same comdat group that OLD is in. */
454 symtab_node::add_to_same_comdat_group (symtab_node
*old_node
)
456 gcc_assert (old_node
->get_comdat_group ());
457 gcc_assert (!same_comdat_group
);
458 gcc_assert (this != old_node
);
460 set_comdat_group (old_node
->get_comdat_group ());
461 same_comdat_group
= old_node
;
462 if (!old_node
->same_comdat_group
)
463 old_node
->same_comdat_group
= this;
467 for (n
= old_node
->same_comdat_group
;
468 n
->same_comdat_group
!= old_node
;
469 n
= n
->same_comdat_group
)
471 n
->same_comdat_group
= this;
475 /* Dissolve the same_comdat_group list in which NODE resides. */
478 symtab_node::dissolve_same_comdat_group_list (void)
480 symtab_node
*n
= this;
483 if (!same_comdat_group
)
487 next
= n
->same_comdat_group
;
488 n
->same_comdat_group
= NULL
;
489 /* Clear comdat_group for comdat locals, since
490 make_decl_local doesn't. */
491 if (!TREE_PUBLIC (n
->decl
))
492 n
->set_comdat_group (NULL
);
498 /* Return printable assembler name of NODE.
499 This function is used only for debugging. When assembler name
500 is unknown go with identifier name. */
503 symtab_node::asm_name () const
505 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
507 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
510 /* Return printable identifier name. */
513 symtab_node::name () const
515 if (!DECL_NAME (decl
))
517 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
522 return lang_hooks
.decl_printable_name (decl
, 2);
526 symtab_node::get_dump_name (bool asm_name_p
) const
529 const char *fname
= asm_name_p
? asm_name () : name ();
530 unsigned l
= strlen (fname
);
532 char *s
= (char *)ggc_internal_cleared_alloc (l
+ EXTRA
);
533 snprintf (s
, l
+ EXTRA
, "%s/%d", fname
, order
);
539 symtab_node::dump_name () const
541 return get_dump_name (false);
545 symtab_node::dump_asm_name () const
547 return get_dump_name (true);
550 /* Return ipa reference from this symtab_node to
551 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
555 symtab_node::create_reference (symtab_node
*referred_node
,
556 enum ipa_ref_use use_type
)
558 return create_reference (referred_node
, use_type
, NULL
);
562 /* Return ipa reference from this symtab_node to
563 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
564 of the use and STMT the statement (if it exists). */
567 symtab_node::create_reference (symtab_node
*referred_node
,
568 enum ipa_ref_use use_type
, gimple
*stmt
)
570 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
571 ipa_ref_list
*list
, *list2
;
572 ipa_ref_t
*old_references
;
574 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
575 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
578 old_references
= vec_safe_address (list
->references
);
579 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
580 ref
= &list
->references
->last ();
582 list2
= &referred_node
->ref_list
;
584 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
585 if(use_type
== IPA_REF_ALIAS
)
587 list2
->referring
.safe_insert (0, ref
);
588 ref
->referred_index
= 0;
590 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
591 list2
->referring
[i
]->referred_index
= i
;
595 list2
->referring
.safe_push (ref
);
596 ref
->referred_index
= list2
->referring
.length () - 1;
599 ref
->referring
= this;
600 ref
->referred
= referred_node
;
602 ref
->lto_stmt_uid
= 0;
604 ref
->speculative
= 0;
606 /* If vector was moved in memory, update pointers. */
607 if (old_references
!= list
->references
->address ())
610 for (i
= 0; iterate_reference(i
, ref2
); i
++)
611 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
617 symtab_node::maybe_create_reference (tree val
, gimple
*stmt
)
620 ipa_ref_use use_type
;
622 switch (TREE_CODE (val
))
625 use_type
= IPA_REF_LOAD
;
628 use_type
= IPA_REF_ADDR
;
631 gcc_assert (!handled_component_p (val
));
635 val
= get_base_var (val
);
636 if (val
&& VAR_OR_FUNCTION_DECL_P (val
))
638 symtab_node
*referred
= symtab_node::get (val
);
639 gcc_checking_assert (referred
);
640 return create_reference (referred
, use_type
, stmt
);
645 /* Clone all references from symtab NODE to this symtab_node. */
648 symtab_node::clone_references (symtab_node
*node
)
650 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
652 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
654 bool speculative
= ref
->speculative
;
655 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
657 ref2
= create_reference (ref
->referred
, ref
->use
, ref
->stmt
);
658 ref2
->speculative
= speculative
;
659 ref2
->lto_stmt_uid
= stmt_uid
;
663 /* Clone all referring from symtab NODE to this symtab_node. */
666 symtab_node::clone_referring (symtab_node
*node
)
668 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
670 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
672 bool speculative
= ref
->speculative
;
673 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
675 ref2
= ref
->referring
->create_reference (this, ref
->use
, ref
->stmt
);
676 ref2
->speculative
= speculative
;
677 ref2
->lto_stmt_uid
= stmt_uid
;
681 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
684 symtab_node::clone_reference (ipa_ref
*ref
, gimple
*stmt
)
686 bool speculative
= ref
->speculative
;
687 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
690 ref2
= create_reference (ref
->referred
, ref
->use
, stmt
);
691 ref2
->speculative
= speculative
;
692 ref2
->lto_stmt_uid
= stmt_uid
;
696 /* Find the structure describing a reference to REFERRED_NODE
697 and associated with statement STMT. */
700 symtab_node::find_reference (symtab_node
*referred_node
,
701 gimple
*stmt
, unsigned int lto_stmt_uid
)
706 for (i
= 0; iterate_reference (i
, r
); i
++)
707 if (r
->referred
== referred_node
709 && ((stmt
&& r
->stmt
== stmt
)
710 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
711 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
716 /* Remove all references that are associated with statement STMT. */
719 symtab_node::remove_stmt_references (gimple
*stmt
)
724 while (iterate_reference (i
, r
))
726 r
->remove_reference ();
731 /* Remove all stmt references in non-speculative references.
732 Those are not maintained during inlining & clonning.
733 The exception are speculative references that are updated along
734 with callgraph edges associated with them. */
737 symtab_node::clear_stmts_in_references (void)
742 for (i
= 0; iterate_reference (i
, r
); i
++)
750 /* Remove all references in ref list. */
753 symtab_node::remove_all_references (void)
755 while (vec_safe_length (ref_list
.references
))
756 ref_list
.references
->last ().remove_reference ();
757 vec_free (ref_list
.references
);
760 /* Remove all referring items in ref list. */
763 symtab_node::remove_all_referring (void)
765 while (ref_list
.referring
.length ())
766 ref_list
.referring
.last ()->remove_reference ();
767 ref_list
.referring
.release ();
770 /* Dump references in ref list to FILE. */
773 symtab_node::dump_references (FILE *file
)
777 for (i
= 0; iterate_reference (i
, ref
); i
++)
779 fprintf (file
, "%s (%s)",
780 ref
->referred
->dump_asm_name (),
781 ipa_ref_use_name
[ref
->use
]);
782 if (ref
->speculative
)
783 fprintf (file
, " (speculative)");
785 fprintf (file
, "\n");
788 /* Dump referring in list to FILE. */
791 symtab_node::dump_referring (FILE *file
)
795 for (i
= 0; iterate_referring(i
, ref
); i
++)
797 fprintf (file
, "%s (%s)",
798 ref
->referring
->dump_asm_name (),
799 ipa_ref_use_name
[ref
->use
]);
800 if (ref
->speculative
)
801 fprintf (file
, " (speculative)");
803 fprintf (file
, "\n");
806 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
808 /* Dump base fields of symtab nodes to F. Not to be used directly. */
811 symtab_node::dump_base (FILE *f
)
813 static const char * const visibility_types
[] = {
814 "default", "protected", "hidden", "internal"
817 fprintf (f
, "%s (%s)", dump_asm_name (), name ());
818 dump_addr (f
, " @", (void *)this);
819 fprintf (f
, "\n Type: %s", symtab_type_names
[type
]);
822 fprintf (f
, " definition");
824 fprintf (f
, " analyzed");
826 fprintf (f
, " alias");
827 if (transparent_alias
)
828 fprintf (f
, " transparent_alias");
830 fprintf (f
, " weakref");
831 if (cpp_implicit_alias
)
832 fprintf (f
, " cpp_implicit_alias");
834 fprintf (f
, " target:%s",
835 DECL_P (alias_target
)
836 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
838 : IDENTIFIER_POINTER (alias_target
));
840 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
841 fprintf (f
, "\n Visibility:");
842 if (in_other_partition
)
843 fprintf (f
, " in_other_partition");
844 if (used_from_other_partition
)
845 fprintf (f
, " used_from_other_partition");
847 fprintf (f
, " force_output");
849 fprintf (f
, " forced_by_abi");
850 if (externally_visible
)
851 fprintf (f
, " externally_visible");
853 fprintf (f
, " no_reorder");
854 if (resolution
!= LDPR_UNKNOWN
)
856 ld_plugin_symbol_resolution_names
[(int)resolution
]);
857 if (TREE_ASM_WRITTEN (decl
))
858 fprintf (f
, " asm_written");
859 if (DECL_EXTERNAL (decl
))
860 fprintf (f
, " external");
861 if (TREE_PUBLIC (decl
))
862 fprintf (f
, " public");
863 if (DECL_COMMON (decl
))
864 fprintf (f
, " common");
865 if (DECL_WEAK (decl
))
866 fprintf (f
, " weak");
867 if (DECL_DLLIMPORT_P (decl
))
868 fprintf (f
, " dll_import");
869 if (DECL_COMDAT (decl
))
870 fprintf (f
, " comdat");
871 if (get_comdat_group ())
872 fprintf (f
, " comdat_group:%s",
873 IDENTIFIER_POINTER (get_comdat_group_id ()));
874 if (DECL_ONE_ONLY (decl
))
875 fprintf (f
, " one_only");
877 fprintf (f
, " section:%s",
879 if (implicit_section
)
880 fprintf (f
," (implicit_section)");
881 if (DECL_VISIBILITY_SPECIFIED (decl
))
882 fprintf (f
, " visibility_specified");
883 if (DECL_VISIBILITY (decl
))
884 fprintf (f
, " visibility:%s",
885 visibility_types
[DECL_VISIBILITY (decl
)]);
886 if (DECL_VIRTUAL_P (decl
))
887 fprintf (f
, " virtual");
888 if (DECL_ARTIFICIAL (decl
))
889 fprintf (f
, " artificial");
890 if (TREE_CODE (decl
) == FUNCTION_DECL
)
892 if (DECL_STATIC_CONSTRUCTOR (decl
))
893 fprintf (f
, " constructor");
894 if (DECL_STATIC_DESTRUCTOR (decl
))
895 fprintf (f
, " destructor");
899 if (same_comdat_group
)
900 fprintf (f
, " Same comdat group as: %s\n",
901 same_comdat_group
->dump_asm_name ());
902 if (next_sharing_asm_name
)
903 fprintf (f
, " next sharing asm name: %i\n",
904 next_sharing_asm_name
->order
);
905 if (previous_sharing_asm_name
)
906 fprintf (f
, " previous sharing asm name: %i\n",
907 previous_sharing_asm_name
->order
);
910 fprintf (f
, " Address is taken.\n");
913 fprintf (f
, " Aux:");
914 dump_addr (f
, " @", (void *)aux
);
918 fprintf (f
, " References: ");
920 fprintf (f
, " Referring: ");
923 fprintf (f
, " Read from file: %s\n",
924 lto_file_data
->file_name
);
927 /* Dump symtab node to F. */
930 symtab_node::dump (FILE *f
)
932 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
934 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
939 symbol_table::dump (FILE *f
)
942 fprintf (f
, "Symbol table:\n\n");
943 FOR_EACH_SYMBOL (node
)
947 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
948 Return NULL if there's no such node. */
951 symtab_node::get_for_asmname (const_tree asmname
)
955 symtab
->symtab_initialize_asm_name_hash ();
956 hashval_t hash
= symtab
->decl_assembler_name_hash (asmname
);
958 = symtab
->assembler_name_hash
->find_slot_with_hash (asmname
, hash
,
969 /* Dump symtab node NODE to stderr. */
972 symtab_node::debug (void)
977 /* Verify common part of symtab nodes. */
980 symtab_node::verify_base (void)
982 bool error_found
= false;
983 symtab_node
*hashed_node
;
985 if (is_a
<cgraph_node
*> (this))
987 if (TREE_CODE (decl
) != FUNCTION_DECL
)
989 error ("function symbol is not function");
993 else if (is_a
<varpool_node
*> (this))
997 error ("variable symbol is not variable");
1003 error ("node has unknown type");
1007 if (symtab
->state
!= LTO_STREAMING
)
1009 hashed_node
= symtab_node::get (decl
);
1012 error ("node not found node->decl->decl_with_vis.symtab_node");
1015 if (hashed_node
!= this
1016 && (!is_a
<cgraph_node
*> (this)
1017 || !dyn_cast
<cgraph_node
*> (this)->clone_of
1018 || dyn_cast
<cgraph_node
*> (this)->clone_of
->decl
!= decl
))
1020 error ("node differs from node->decl->decl_with_vis.symtab_node");
1024 if (symtab
->assembler_name_hash
)
1026 hashed_node
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
1027 if (hashed_node
&& hashed_node
->previous_sharing_asm_name
)
1029 error ("assembler name hash list corrupted");
1034 if (hashed_node
== this)
1036 hashed_node
= hashed_node
->next_sharing_asm_name
;
1039 && !(is_a
<varpool_node
*> (this)
1040 && DECL_HARD_REGISTER (decl
)))
1042 error ("node not found in symtab assembler name hash");
1046 if (previous_sharing_asm_name
1047 && previous_sharing_asm_name
->next_sharing_asm_name
!= this)
1049 error ("double linked list of assembler names corrupted");
1052 if (body_removed
&& definition
)
1054 error ("node has body_removed but is definition");
1057 if (analyzed
&& !definition
)
1059 error ("node is analyzed but it is not a definition");
1062 if (cpp_implicit_alias
&& !alias
)
1064 error ("node is alias but not implicit alias");
1067 if (alias
&& !definition
&& !weakref
)
1069 error ("node is alias but not definition");
1072 if (weakref
&& !transparent_alias
)
1074 error ("node is weakref but not an transparent_alias");
1077 if (transparent_alias
&& !alias
)
1079 error ("node is transparent_alias but not an alias");
1082 if (same_comdat_group
)
1084 symtab_node
*n
= same_comdat_group
;
1086 if (!n
->get_comdat_group ())
1088 error ("node is in same_comdat_group list but has no comdat_group");
1091 if (n
->get_comdat_group () != get_comdat_group ())
1093 error ("same_comdat_group list across different groups");
1096 if (n
->type
!= type
)
1098 error ("mixing different types of symbol in same comdat groups is not supported");
1103 error ("node is alone in a comdat group");
1108 if (!n
->same_comdat_group
)
1110 error ("same_comdat_group is not a circular list");
1114 n
= n
->same_comdat_group
;
1117 if (comdat_local_p ())
1119 ipa_ref
*ref
= NULL
;
1121 for (int i
= 0; iterate_referring (i
, ref
); ++i
)
1123 if (!in_same_comdat_group_p (ref
->referring
))
1125 error ("comdat-local symbol referred to by %s outside its "
1127 identifier_to_locale (ref
->referring
->name()));
1133 if (implicit_section
&& !get_section ())
1135 error ("implicit_section flag is set but section isn't");
1138 if (get_section () && get_comdat_group ()
1139 && !implicit_section
1140 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl
)))
1142 error ("Both section and comdat group is set");
1145 /* TODO: Add string table for sections, so we do not keep holding duplicated
1147 if (alias
&& definition
1148 && get_section () != get_alias_target ()->get_section ()
1150 || !get_alias_target ()->get_section ()
1151 || strcmp (get_section(),
1152 get_alias_target ()->get_section ())))
1154 error ("Alias and target's section differs");
1155 get_alias_target ()->dump (stderr
);
1158 if (alias
&& definition
1159 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1161 error ("Alias and target's comdat groups differs");
1162 get_alias_target ()->dump (stderr
);
1165 if (transparent_alias
&& definition
&& !weakref
)
1167 symtab_node
*to
= get_alias_target ();
1169 = IDENTIFIER_POINTER (
1170 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl
)));
1172 = IDENTIFIER_POINTER (
1173 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to
->decl
)));
1174 if (!symbol_table::assembler_names_equal_p (name1
, name2
))
1176 error ("Transparent alias and target's assembler names differs");
1177 get_alias_target ()->dump (stderr
);
1181 if (transparent_alias
&& definition
1182 && get_alias_target()->transparent_alias
&& get_alias_target()->analyzed
)
1184 error ("Chained transparent aliases");
1185 get_alias_target ()->dump (stderr
);
1192 /* Verify consistency of NODE. */
1195 symtab_node::verify (void)
1200 timevar_push (TV_CGRAPH_VERIFY
);
1201 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (this))
1202 node
->verify_node ();
1207 internal_error ("symtab_node::verify failed");
1209 timevar_pop (TV_CGRAPH_VERIFY
);
1212 /* Verify symbol table for internal consistency. */
1215 symtab_node::verify_symtab_nodes (void)
1218 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1220 FOR_EACH_SYMBOL (node
)
1223 if (node
->get_comdat_group ())
1225 symtab_node
**entry
, *s
;
1228 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1232 else if (!DECL_EXTERNAL (node
->decl
))
1234 for (s
= (*entry
)->same_comdat_group
;
1235 s
!= NULL
&& s
!= node
&& s
!= *entry
;
1236 s
= s
->same_comdat_group
)
1238 if (!s
|| s
== *entry
)
1240 error ("Two symbols with same comdat_group are not linked by "
1241 "the same_comdat_group list.");
1244 internal_error ("symtab_node::verify failed");
1251 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1252 but other code such as notice_global_symbol generates rtl. */
1255 symtab_node::make_decl_local (void)
1262 IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
)) = 0;
1263 TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
)) = NULL_TREE
;
1264 symtab
->change_decl_assembler_name
1265 (decl
, DECL_ASSEMBLER_NAME (get_alias_target ()->decl
));
1266 DECL_ATTRIBUTES (decl
) = remove_attribute ("weakref",
1267 DECL_ATTRIBUTES (decl
));
1269 /* Avoid clearing comdat_groups on comdat-local decls. */
1270 else if (TREE_PUBLIC (decl
) == 0)
1273 /* Localizing a symbol also make all its transparent aliases local. */
1275 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
); i
++)
1277 struct symtab_node
*alias
= ref
->referring
;
1278 if (alias
->transparent_alias
)
1279 alias
->make_decl_local ();
1284 DECL_COMMON (decl
) = 0;
1285 /* ADDRESSABLE flag is not defined for public symbols. */
1286 TREE_ADDRESSABLE (decl
) = 1;
1287 TREE_STATIC (decl
) = 1;
1290 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1292 DECL_COMDAT (decl
) = 0;
1293 DECL_WEAK (decl
) = 0;
1294 DECL_EXTERNAL (decl
) = 0;
1295 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1296 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1297 TREE_PUBLIC (decl
) = 0;
1298 DECL_DLLIMPORT_P (decl
) = 0;
1299 if (!DECL_RTL_SET_P (decl
))
1302 /* Update rtl flags. */
1303 make_decl_rtl (decl
);
1305 rtl
= DECL_RTL (decl
);
1309 symbol
= XEXP (rtl
, 0);
1310 if (GET_CODE (symbol
) != SYMBOL_REF
)
1313 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1316 /* Copy visibility from N.
1317 This is useful when THIS becomes a transparent alias of N. */
1320 symtab_node::copy_visibility_from (symtab_node
*n
)
1322 gcc_checking_assert (n
->weakref
== weakref
);
1325 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
); i
++)
1327 struct symtab_node
*alias
= ref
->referring
;
1328 if (alias
->transparent_alias
)
1329 alias
->copy_visibility_from (n
);
1334 DECL_COMMON (decl
) = DECL_COMMON (n
->decl
);
1335 /* ADDRESSABLE flag is not defined for public symbols. */
1336 if (TREE_PUBLIC (decl
) && !TREE_PUBLIC (n
->decl
))
1337 TREE_ADDRESSABLE (decl
) = 1;
1338 TREE_STATIC (decl
) = TREE_STATIC (n
->decl
);
1340 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1342 DECL_COMDAT (decl
) = DECL_COMDAT (n
->decl
);
1343 DECL_WEAK (decl
) = DECL_WEAK (n
->decl
);
1344 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (n
->decl
);
1345 DECL_VISIBILITY_SPECIFIED (decl
) = DECL_VISIBILITY_SPECIFIED (n
->decl
);
1346 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (n
->decl
);
1347 TREE_PUBLIC (decl
) = TREE_PUBLIC (n
->decl
);
1348 DECL_DLLIMPORT_P (decl
) = DECL_DLLIMPORT_P (n
->decl
);
1349 resolution
= n
->resolution
;
1350 set_comdat_group (n
->get_comdat_group ());
1351 call_for_symbol_and_aliases (symtab_node::set_section
,
1352 const_cast<char *>(n
->get_section ()), true);
1353 externally_visible
= n
->externally_visible
;
1354 if (!DECL_RTL_SET_P (decl
))
1357 /* Update rtl flags. */
1358 make_decl_rtl (decl
);
1360 rtx rtl
= DECL_RTL (decl
);
1364 rtx symbol
= XEXP (rtl
, 0);
1365 if (GET_CODE (symbol
) != SYMBOL_REF
)
1368 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1371 /* Walk the alias chain to return the symbol NODE is alias of.
1372 If NODE is not an alias, return NODE.
1373 Assumes NODE is known to be alias. */
1376 symtab_node::ultimate_alias_target_1 (enum availability
*availability
,
1379 bool transparent_p
= false;
1381 /* To determine visibility of the target, we follow ELF semantic of aliases.
1382 Here alias is an alternative assembler name of a given definition. Its
1383 availability prevails the availability of its target (i.e. static alias of
1384 weak definition is available.
1386 Transaparent alias is just alternative anme of a given symbol used within
1387 one compilation unit and is translated prior hitting the object file. It
1388 inherits the visibility of its target.
1389 Weakref is a different animal (and noweak definition is weak).
1391 If we ever get into supporting targets with different semantics, a target
1392 hook will be needed here. */
1396 transparent_p
= transparent_alias
;
1398 *availability
= get_availability (ref
);
1400 *availability
= AVAIL_NOT_AVAILABLE
;
1403 symtab_node
*node
= this;
1406 if (node
->alias
&& node
->analyzed
)
1407 node
= node
->get_alias_target ();
1410 if (!availability
|| (!transparent_p
&& node
->analyzed
))
1412 else if (node
->analyzed
&& !node
->transparent_alias
)
1413 *availability
= node
->get_availability (ref
);
1415 *availability
= AVAIL_NOT_AVAILABLE
;
1418 if (node
&& availability
&& transparent_p
1419 && node
->transparent_alias
)
1421 *availability
= node
->get_availability (ref
);
1422 transparent_p
= false;
1426 *availability
= AVAIL_NOT_AVAILABLE
;
1430 /* C++ FE sometimes change linkage flags after producing same body aliases.
1432 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1433 are obviously equivalent. The way it is doing so is however somewhat
1434 kludgy and interferes with the visibility code. As a result we need to
1435 copy the visibility from the target to get things right. */
1438 symtab_node::fixup_same_cpp_alias_visibility (symtab_node
*target
)
1440 if (is_a
<cgraph_node
*> (this))
1442 DECL_DECLARED_INLINE_P (decl
)
1443 = DECL_DECLARED_INLINE_P (target
->decl
);
1444 DECL_DISREGARD_INLINE_LIMITS (decl
)
1445 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1447 /* FIXME: It is not really clear why those flags should not be copied for
1451 DECL_WEAK (decl
) = DECL_WEAK (target
->decl
);
1452 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1453 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (target
->decl
);
1455 if (TREE_PUBLIC (decl
))
1459 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1460 DECL_COMDAT (decl
) = DECL_COMDAT (target
->decl
);
1461 group
= target
->get_comdat_group ();
1462 set_comdat_group (group
);
1463 if (group
&& !same_comdat_group
)
1464 add_to_same_comdat_group (target
);
1466 externally_visible
= target
->externally_visible
;
1469 /* Set section, do not recurse into aliases.
1470 When one wants to change section of a symbol and its aliases,
1474 symtab_node::set_section_for_node (const char *section
)
1476 const char *current
= get_section ();
1477 section_hash_entry
**slot
;
1479 if (current
== section
1480 || (current
&& section
1481 && !strcmp (current
, section
)))
1486 x_section
->ref_count
--;
1487 if (!x_section
->ref_count
)
1489 hashval_t hash
= htab_hash_string (x_section
->name
);
1490 slot
= symtab
->section_hash
->find_slot_with_hash (x_section
->name
,
1492 ggc_free (x_section
);
1493 symtab
->section_hash
->clear_slot (slot
);
1499 implicit_section
= false;
1502 if (!symtab
->section_hash
)
1503 symtab
->section_hash
= hash_table
<section_name_hasher
>::create_ggc (10);
1504 slot
= symtab
->section_hash
->find_slot_with_hash (section
,
1505 htab_hash_string (section
),
1508 x_section
= (section_hash_entry
*)*slot
;
1511 int len
= strlen (section
);
1512 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1513 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1514 memcpy (x_section
->name
, section
, len
+ 1);
1516 x_section
->ref_count
++;
1519 /* Worker for set_section. */
1522 symtab_node::set_section (symtab_node
*n
, void *s
)
1524 n
->set_section_for_node ((char *)s
);
1528 /* Set section of symbol and its aliases. */
1531 symtab_node::set_section (const char *section
)
1533 gcc_assert (!this->alias
);
1534 call_for_symbol_and_aliases
1535 (symtab_node::set_section
, const_cast<char *>(section
), true);
1538 /* Return the initialization priority. */
1541 symtab_node::get_init_priority ()
1543 if (!this->in_init_priority_hash
)
1544 return DEFAULT_INIT_PRIORITY
;
1546 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1547 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1550 /* Return the finalization priority. */
1553 cgraph_node::get_fini_priority ()
1555 if (!this->in_init_priority_hash
)
1556 return DEFAULT_INIT_PRIORITY
;
1557 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1558 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1561 /* Return the initialization and finalization priority information for
1562 DECL. If there is no previous priority information, a freshly
1563 allocated structure is returned. */
1565 symbol_priority_map
*
1566 symtab_node::priority_info (void)
1568 if (!symtab
->init_priority_hash
)
1569 symtab
->init_priority_hash
= hash_map
<symtab_node
*, symbol_priority_map
>::create_ggc (13);
1572 symbol_priority_map
*h
1573 = &symtab
->init_priority_hash
->get_or_insert (this, &existed
);
1576 h
->init
= DEFAULT_INIT_PRIORITY
;
1577 h
->fini
= DEFAULT_INIT_PRIORITY
;
1578 in_init_priority_hash
= true;
1584 /* Set initialization priority to PRIORITY. */
1587 symtab_node::set_init_priority (priority_type priority
)
1589 symbol_priority_map
*h
;
1591 if (is_a
<cgraph_node
*> (this))
1592 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1594 if (priority
== DEFAULT_INIT_PRIORITY
)
1596 gcc_assert (get_init_priority() == priority
);
1599 h
= priority_info ();
1603 /* Set fialization priority to PRIORITY. */
1606 cgraph_node::set_fini_priority (priority_type priority
)
1608 symbol_priority_map
*h
;
1610 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1612 if (priority
== DEFAULT_INIT_PRIORITY
)
1614 gcc_assert (get_fini_priority() == priority
);
1617 h
= priority_info ();
1621 /* Worker for symtab_resolve_alias. */
1624 symtab_node::set_implicit_section (symtab_node
*n
,
1625 void *data ATTRIBUTE_UNUSED
)
1627 n
->implicit_section
= true;
1631 /* Add reference recording that symtab node is alias of TARGET.
1632 The function can fail in the case of aliasing cycles; in this case
1633 it returns false. */
1636 symtab_node::resolve_alias (symtab_node
*target
, bool transparent
)
1640 gcc_assert (!analyzed
&& !vec_safe_length (ref_list
.references
));
1642 /* Never let cycles to creep into the symbol table alias references;
1643 those will make alias walkers to be infinite. */
1644 for (n
= target
; n
&& n
->alias
;
1645 n
= n
->analyzed
? n
->get_alias_target () : NULL
)
1648 if (is_a
<cgraph_node
*> (this))
1649 error ("function %q+D part of alias cycle", decl
);
1650 else if (is_a
<varpool_node
*> (this))
1651 error ("variable %q+D part of alias cycle", decl
);
1658 /* "analyze" the node - i.e. mark the reference. */
1662 transparent
|= transparent_alias
;
1663 transparent_alias
= transparent
;
1665 while (target
->transparent_alias
&& target
->analyzed
)
1666 target
= target
->get_alias_target ();
1667 create_reference (target
, IPA_REF_ALIAS
, NULL
);
1669 /* Add alias into the comdat group of its target unless it is already there. */
1670 if (same_comdat_group
)
1671 remove_from_same_comdat_group ();
1672 set_comdat_group (NULL
);
1673 if (target
->get_comdat_group ())
1674 add_to_same_comdat_group (target
);
1676 if ((get_section () != target
->get_section ()
1677 || target
->get_comdat_group ()) && get_section () && !implicit_section
)
1679 error ("section of alias %q+D must match section of its target", decl
);
1681 call_for_symbol_and_aliases (symtab_node::set_section
,
1682 const_cast<char *>(target
->get_section ()), true);
1683 if (target
->implicit_section
)
1684 call_for_symbol_and_aliases (set_implicit_section
, NULL
, true);
1686 /* Alias targets become redundant after alias is resolved into an reference.
1687 We do not want to keep it around or we would have to mind updating them
1688 when renaming symbols. */
1689 alias_target
= NULL
;
1691 if (!transparent
&& cpp_implicit_alias
&& symtab
->state
>= CONSTRUCTION
)
1692 fixup_same_cpp_alias_visibility (target
);
1694 /* If alias has address taken, so does the target. */
1696 target
->ultimate_alias_target ()->address_taken
= true;
1698 /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
1699 If alias is transparent, also all transparent aliases of THIS are now
1701 Also merge same comdat group lists. */
1703 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
);)
1705 struct symtab_node
*alias_alias
= ref
->referring
;
1706 if (alias_alias
->get_comdat_group ())
1708 alias_alias
->remove_from_same_comdat_group ();
1709 alias_alias
->set_comdat_group (NULL
);
1710 if (target
->get_comdat_group ())
1711 alias_alias
->add_to_same_comdat_group (target
);
1713 if (!alias_alias
->transparent_alias
|| transparent
)
1715 alias_alias
->remove_all_references ();
1716 alias_alias
->create_reference (target
, IPA_REF_ALIAS
, NULL
);
1723 /* Worker searching noninterposable alias. */
1726 symtab_node::noninterposable_alias (symtab_node
*node
, void *data
)
1728 if (!node
->transparent_alias
&& decl_binds_to_current_def_p (node
->decl
))
1730 symtab_node
*fn
= node
->ultimate_alias_target ();
1732 /* Ensure that the alias is well formed this may not be the case
1733 of user defined aliases and currently it is not always the case
1734 of C++ same body aliases (that is a bug). */
1735 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
1736 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
1737 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
1738 && flags_from_decl_or_type (node
->decl
)
1739 != flags_from_decl_or_type (fn
->decl
))
1740 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
1742 *(symtab_node
**)data
= node
;
1748 /* If node can not be overwriten by static or dynamic linker to point to
1749 different definition, return NODE. Otherwise look for alias with such
1750 property and if none exists, introduce new one. */
1753 symtab_node::noninterposable_alias (void)
1756 symtab_node
*new_node
= NULL
;
1758 /* First try to look up existing alias or base object
1759 (if that is already non-overwritable). */
1760 symtab_node
*node
= ultimate_alias_target ();
1761 gcc_assert (!node
->alias
&& !node
->weakref
);
1762 node
->call_for_symbol_and_aliases (symtab_node::noninterposable_alias
,
1763 (void *)&new_node
, true);
1766 #ifndef ASM_OUTPUT_DEF
1767 /* If aliases aren't supported by the assembler, fail. */
1771 /* Otherwise create a new one. */
1772 new_decl
= copy_node (node
->decl
);
1773 DECL_DLLIMPORT_P (new_decl
) = 0;
1774 DECL_NAME (new_decl
) = clone_function_name (node
->decl
, "localalias");
1775 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1776 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1777 DECL_INITIAL (new_decl
) = NULL
;
1778 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1779 SET_DECL_RTL (new_decl
, NULL
);
1781 /* Update the properties. */
1782 DECL_EXTERNAL (new_decl
) = 0;
1783 TREE_PUBLIC (new_decl
) = 0;
1784 DECL_COMDAT (new_decl
) = 0;
1785 DECL_WEAK (new_decl
) = 0;
1787 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1788 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1789 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1791 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1792 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1793 new_node
= cgraph_node::create_alias (new_decl
, node
->decl
);
1797 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
1798 DECL_INITIAL (new_decl
) = error_mark_node
;
1799 new_node
= varpool_node::create_alias (new_decl
, node
->decl
);
1801 new_node
->resolve_alias (node
);
1802 gcc_assert (decl_binds_to_current_def_p (new_decl
)
1803 && targetm
.binds_local_p (new_decl
));
1807 /* Return true if symtab node and TARGET represents
1808 semantically equivalent symbols. */
1811 symtab_node::semantically_equivalent_p (symtab_node
*target
)
1813 enum availability avail
;
1817 /* Equivalent functions are equivalent. */
1818 if (decl
== target
->decl
)
1821 /* If symbol is not overwritable by different implementation,
1822 walk to the base object it defines. */
1823 ba
= ultimate_alias_target (&avail
);
1824 if (avail
>= AVAIL_AVAILABLE
)
1831 bb
= target
->ultimate_alias_target (&avail
);
1832 if (avail
>= AVAIL_AVAILABLE
)
1842 /* Classify symbol symtab node for partitioning. */
1844 enum symbol_partitioning_class
1845 symtab_node::get_partitioning_class (void)
1847 /* Inline clones are always duplicated.
1848 This include external delcarations. */
1849 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
1851 if (DECL_ABSTRACT_P (decl
))
1852 return SYMBOL_EXTERNAL
;
1854 if (cnode
&& cnode
->global
.inlined_to
)
1855 return SYMBOL_DUPLICATE
;
1857 /* Transparent aliases are always duplicated. */
1858 if (transparent_alias
)
1859 return definition
? SYMBOL_DUPLICATE
: SYMBOL_EXTERNAL
;
1861 /* External declarations are external. */
1862 if (DECL_EXTERNAL (decl
))
1863 return SYMBOL_EXTERNAL
;
1865 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
1867 if (alias
&& definition
&& !ultimate_alias_target ()->definition
)
1868 return SYMBOL_EXTERNAL
;
1869 /* Constant pool references use local symbol names that can not
1870 be promoted global. We should never put into a constant pool
1871 objects that can not be duplicated across partitions. */
1872 if (DECL_IN_CONSTANT_POOL (decl
))
1873 return SYMBOL_DUPLICATE
;
1874 if (DECL_HARD_REGISTER (decl
))
1875 return SYMBOL_DUPLICATE
;
1876 gcc_checking_assert (vnode
->definition
);
1878 /* Functions that are cloned may stay in callgraph even if they are unused.
1879 Handle them as external; compute_ltrans_boundary take care to make
1880 proper things to happen (i.e. to make them appear in the boundary but
1881 with body streamed, so clone can me materialized). */
1882 else if (!dyn_cast
<cgraph_node
*> (this)->function_symbol ()->definition
)
1883 return SYMBOL_EXTERNAL
;
1885 /* Linker discardable symbols are duplicated to every use unless they are
1887 if (DECL_ONE_ONLY (decl
)
1890 && !used_from_object_file_p ())
1891 return SYMBOL_DUPLICATE
;
1893 return SYMBOL_PARTITION
;
1896 /* Return true when symbol is known to be non-zero. */
1899 symtab_node::nonzero_address ()
1901 /* Weakrefs may be NULL when their target is not defined. */
1902 if (alias
&& weakref
)
1906 symtab_node
*target
= ultimate_alias_target ();
1908 if (target
->alias
&& target
->weakref
)
1910 /* We can not recurse to target::nonzero. It is possible that the
1911 target is used only via the alias.
1912 We may walk references and look for strong use, but we do not know
1913 if this strong use will survive to final binary, so be
1915 ??? Maybe we could do the lookup during late optimization that
1916 could be useful to eliminate the NULL pointer checks in LTO
1918 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
1920 if (target
->resolution
!= LDPR_UNKNOWN
1921 && target
->resolution
!= LDPR_UNDEF
1922 && !target
->can_be_discarded_p ()
1923 && flag_delete_null_pointer_checks
)
1931 /* With !flag_delete_null_pointer_checks we assume that symbols may
1932 bind to NULL. This is on by default on embedded targets only.
1934 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1935 linking fails. Important case of WEAK we want to do well are comdats.
1936 Those are handled by later check for definition.
1938 When parsing, beware the cases when WEAK attribute is added later. */
1939 if (!DECL_WEAK (decl
)
1940 && flag_delete_null_pointer_checks
)
1942 refuse_visibility_changes
= true;
1946 /* If target is defined and not extern, we know it will be output and thus
1947 it will bind to non-NULL.
1948 Play safe for flag_delete_null_pointer_checks where weak definition maye
1949 be re-defined by NULL. */
1950 if (definition
&& !DECL_EXTERNAL (decl
)
1951 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (decl
)))
1953 if (!DECL_WEAK (decl
))
1954 refuse_visibility_changes
= true;
1958 /* As the last resort, check the resolution info. */
1959 if (resolution
!= LDPR_UNKNOWN
1960 && resolution
!= LDPR_UNDEF
1961 && !can_be_discarded_p ()
1962 && flag_delete_null_pointer_checks
)
1967 /* Return 0 if symbol is known to have different address than S2,
1968 Return 1 if symbol is known to have same address as S2,
1969 return -1 otherwise.
1971 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
1972 and S2 is going to be accessed. This eliminates the situations when
1973 either THIS or S2 is NULL and is seful for comparing bases when deciding
1974 about memory aliasing. */
1976 symtab_node::equal_address_to (symtab_node
*s2
, bool memory_accessed
)
1978 enum availability avail1
, avail2
;
1980 /* A Shortcut: equivalent symbols are always equivalent. */
1984 /* Unwind transparent aliases first; those are always equal to their
1986 if (this->transparent_alias
&& this->analyzed
)
1987 return this->get_alias_target ()->equal_address_to (s2
);
1988 while (s2
->transparent_alias
&& s2
->analyzed
)
1989 s2
= s2
->get_alias_target();
1994 /* For non-interposable aliases, lookup and compare their actual definitions.
1995 Also check if the symbol needs to bind to given definition. */
1996 symtab_node
*rs1
= ultimate_alias_target (&avail1
);
1997 symtab_node
*rs2
= s2
->ultimate_alias_target (&avail2
);
1998 bool binds_local1
= rs1
->analyzed
&& decl_binds_to_current_def_p (this->decl
);
1999 bool binds_local2
= rs2
->analyzed
&& decl_binds_to_current_def_p (s2
->decl
);
2000 bool really_binds_local1
= binds_local1
;
2001 bool really_binds_local2
= binds_local2
;
2003 /* Addresses of vtables and virtual functions can not be used by user
2004 code and are used only within speculation. In this case we may make
2005 symbol equivalent to its alias even if interposition may break this
2006 rule. Doing so will allow us to turn speculative inlining into
2007 non-speculative more agressively. */
2008 if (DECL_VIRTUAL_P (this->decl
) && avail1
>= AVAIL_AVAILABLE
)
2009 binds_local1
= true;
2010 if (DECL_VIRTUAL_P (s2
->decl
) && avail2
>= AVAIL_AVAILABLE
)
2011 binds_local2
= true;
2013 /* If both definitions are available we know that even if they are bound
2014 to other unit they must be defined same way and therefore we can use
2015 equivalence test. */
2016 if (rs1
!= rs2
&& avail1
>= AVAIL_AVAILABLE
&& avail2
>= AVAIL_AVAILABLE
)
2017 binds_local1
= binds_local2
= true;
2019 if (binds_local1
&& binds_local2
&& rs1
== rs2
)
2021 /* We made use of the fact that alias is not weak. */
2023 refuse_visibility_changes
= true;
2025 s2
->refuse_visibility_changes
= true;
2029 /* If both symbols may resolve to NULL, we can not really prove them
2031 if (!memory_accessed
&& !nonzero_address () && !s2
->nonzero_address ())
2034 /* Except for NULL, functions and variables never overlap. */
2035 if (TREE_CODE (decl
) != TREE_CODE (s2
->decl
))
2038 /* If one of the symbols is unresolved alias, punt. */
2039 if (rs1
->alias
|| rs2
->alias
)
2042 /* If we have a non-interposale definition of at least one of the symbols
2043 and the other symbol is different, we know other unit can not interpose
2044 it to the first symbol; all aliases of the definition needs to be
2045 present in the current unit. */
2046 if (((really_binds_local1
|| really_binds_local2
)
2047 /* If we have both definitions and they are different, we know they
2048 will be different even in units they binds to. */
2049 || (binds_local1
&& binds_local2
))
2052 /* We make use of the fact that one symbol is not alias of the other
2053 and that the definition is non-interposable. */
2054 refuse_visibility_changes
= true;
2055 s2
->refuse_visibility_changes
= true;
2056 rs1
->refuse_visibility_changes
= true;
2057 rs2
->refuse_visibility_changes
= true;
2061 /* TODO: Alias oracle basically assume that addresses of global variables
2062 are different unless they are declared as alias of one to another while
2063 the code folding comparsions doesn't.
2064 We probably should be consistent and use this fact here, too, but for
2065 the moment return false only when we are called from the alias oracle. */
2067 return memory_accessed
&& rs1
!= rs2
? 0 : -1;
2070 /* Worker for call_for_symbol_and_aliases. */
2073 symtab_node::call_for_symbol_and_aliases_1 (bool (*callback
) (symtab_node
*,
2076 bool include_overwritable
)
2079 FOR_EACH_ALIAS (this, ref
)
2081 symtab_node
*alias
= ref
->referring
;
2082 if (include_overwritable
2083 || alias
->get_availability () > AVAIL_INTERPOSABLE
)
2084 if (alias
->call_for_symbol_and_aliases (callback
, data
,
2085 include_overwritable
))
2091 /* Return true if address of N is possibly compared. */
2094 address_matters_1 (symtab_node
*n
, void *)
2096 struct ipa_ref
*ref
;
2098 if (!n
->address_can_be_compared_p ())
2100 if (n
->externally_visible
|| n
->force_output
)
2103 for (unsigned int i
= 0; n
->iterate_referring (i
, ref
); i
++)
2104 if (ref
->address_matters_p ())
2109 /* Return true if symbol's address may possibly be compared to other
2110 symbol's address. */
2113 symtab_node::address_matters_p ()
2115 gcc_assert (!alias
);
2116 return call_for_symbol_and_aliases (address_matters_1
, NULL
, true);
2119 /* Return true if symbol's alignment may be increased. */
2122 symtab_node::can_increase_alignment_p (void)
2124 symtab_node
*target
= ultimate_alias_target ();
2126 /* For now support only variables. */
2130 /* With -fno-toplevel-reorder we may have already output the constant. */
2131 if (TREE_ASM_WRITTEN (target
->decl
))
2134 /* If target is already placed in an anchor, we can not touch its
2136 if (DECL_RTL_SET_P (target
->decl
)
2137 && MEM_P (DECL_RTL (target
->decl
))
2138 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target
->decl
), 0)))
2141 /* Constant pool entries may be shared. */
2142 if (DECL_IN_CONSTANT_POOL (target
->decl
))
2145 /* We cannot change alignment of symbols that may bind to symbols
2146 in other translation unit that may contain a definition with lower
2148 if (!decl_binds_to_current_def_p (decl
))
2151 /* When compiling partition, be sure the symbol is not output by other
2154 && (target
->in_other_partition
2155 || target
->get_partitioning_class () == SYMBOL_DUPLICATE
))
2158 /* Do not override the alignment as specified by the ABI when the used
2159 attribute is set. */
2160 if (DECL_PRESERVE_P (decl
) || DECL_PRESERVE_P (target
->decl
))
2163 /* Do not override explicit alignment set by the user when an explicit
2164 section name is also used. This is a common idiom used by many
2165 software projects. */
2166 if (DECL_SECTION_NAME (target
->decl
) != NULL
&& !target
->implicit_section
)
2172 /* Worker for symtab_node::increase_alignment. */
2175 increase_alignment_1 (symtab_node
*n
, void *v
)
2177 unsigned int align
= (size_t)v
;
2178 if (DECL_ALIGN (n
->decl
) < align
2179 && n
->can_increase_alignment_p ())
2181 SET_DECL_ALIGN (n
->decl
, align
);
2182 DECL_USER_ALIGN (n
->decl
) = 1;
2187 /* Increase alignment of THIS to ALIGN. */
2190 symtab_node::increase_alignment (unsigned int align
)
2192 gcc_assert (can_increase_alignment_p () && align
< MAX_OFILE_ALIGNMENT
);
2193 ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1
,
2194 (void *)(size_t) align
,
2196 gcc_assert (DECL_ALIGN (decl
) >= align
);
2199 /* Helper for symtab_node::definition_alignment. */
2202 get_alignment_1 (symtab_node
*n
, void *v
)
2204 *((unsigned int *)v
) = MAX (*((unsigned int *)v
), DECL_ALIGN (n
->decl
));
2208 /* Return desired alignment of the definition. This is NOT alignment useful
2209 to access THIS, because THIS may be interposable and DECL_ALIGN should
2210 be used instead. It however must be guaranteed when output definition
2214 symtab_node::definition_alignment ()
2216 unsigned int align
= 0;
2217 gcc_assert (!alias
);
2218 call_for_symbol_and_aliases (get_alignment_1
, &align
, true);
2222 /* Return symbol used to separate symbol name from suffix. */
2225 symbol_table::symbol_suffix_separator ()
2227 #ifndef NO_DOT_IN_LABEL
2229 #elif !defined NO_DOLLAR_IN_LABEL
2236 /* Return true when references to this symbol from REF must bind to current
2237 definition in final executable. */
2240 symtab_node::binds_to_current_def_p (symtab_node
*ref
)
2244 if (transparent_alias
)
2246 && get_alias_target()->binds_to_current_def_p (ref
);
2247 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
)))
2249 if (decl_binds_to_current_def_p (decl
))
2252 /* Inline clones always binds locally. */
2253 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2254 if (cnode
&& cnode
->global
.inlined_to
)
2257 if (DECL_EXTERNAL (decl
))
2260 gcc_assert (externally_visible
);
2264 cgraph_node
*cref
= dyn_cast
<cgraph_node
*> (ref
);
2266 ref
= cref
->global
.inlined_to
;
2269 /* If this is a reference from symbol itself and there are no aliases, we
2270 may be sure that the symbol was not interposed by something else because
2271 the symbol itself would be unreachable otherwise. This is important
2272 to optimize recursive functions well.
2274 This assumption may be broken by inlining: if symbol is interposable
2275 but the body is available (i.e. declared inline), inliner may make
2276 the body reachable even with interposition. */
2277 if (this == ref
&& !has_aliases_p ()
2279 || symtab
->state
>= IPA_SSA_AFTER_INLINING
2280 || get_availability () >= AVAIL_INTERPOSABLE
))
2284 /* References within one comdat group are always bound in a group. */
2286 && symtab
->state
>= IPA_SSA_AFTER_INLINING
2287 && get_comdat_group ()
2288 && get_comdat_group () == ref
->get_comdat_group ())