2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "print-tree.h"
31 #include "basic-block.h"
32 #include "tree-ssa-alias.h"
33 #include "internal-fn.h"
34 #include "gimple-expr.h"
37 #include "tree-inline.h"
38 #include "langhooks.h"
41 #include "diagnostic.h"
43 #include "lto-streamer.h"
45 #include "ipa-utils.h"
48 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias"};
50 const char * const ld_plugin_symbol_resolution_names
[]=
55 "prevailing_def_ironly",
61 "prevailing_def_ironly_exp"
65 /* Hash table used to hold sectoons. */
66 static GTY((param_is (section_hash_entry
))) htab_t section_hash
;
68 /* Hash table used to convert assembler names into nodes. */
69 static GTY((param_is (symtab_node
))) htab_t assembler_name_hash
;
71 /* Map from a symbol to initialization/finalization priorities. */
72 struct GTY(()) symbol_priority_map
{
78 /* Hash table used to hold init priorities. */
79 static GTY ((param_is (struct symbol_priority_map
)))
80 htab_t init_priority_hash
;
82 /* Linked list of symbol table nodes. */
83 symtab_node
*symtab_nodes
;
85 /* The order index of the next symtab node to be created. This is
86 used so that we can sort the cgraph nodes in order by when we saw
87 them, to support -fno-toplevel-reorder. */
90 /* Hash asmnames ignoring the user specified marks. */
93 decl_assembler_name_hash (const_tree asmname
)
95 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
97 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
98 size_t ulp_len
= strlen (user_label_prefix
);
102 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
105 return htab_hash_string (decl_str
);
108 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
112 /* Returns a hash code for P. */
115 hash_node_by_assembler_name (const void *p
)
117 const symtab_node
*n
= (const symtab_node
*) p
;
118 return (hashval_t
) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n
->decl
));
121 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
124 decl_assembler_name_equal (tree decl
, const_tree asmname
)
126 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
127 const char *decl_str
;
128 const char *asmname_str
;
131 if (decl_asmname
== asmname
)
134 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
135 asmname_str
= IDENTIFIER_POINTER (asmname
);
138 /* If the target assembler name was set by the user, things are trickier.
139 We have a leading '*' to begin with. After that, it's arguable what
140 is the correct thing to do with -fleading-underscore. Arguably, we've
141 historically been doing the wrong thing in assemble_alias by always
142 printing the leading underscore. Since we're not changing that, make
143 sure user_label_prefix follows the '*' before matching. */
144 if (decl_str
[0] == '*')
146 size_t ulp_len
= strlen (user_label_prefix
);
152 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
153 decl_str
+= ulp_len
, test
=true;
157 if (asmname_str
[0] == '*')
159 size_t ulp_len
= strlen (user_label_prefix
);
165 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
166 asmname_str
+= ulp_len
, test
=true;
173 return strcmp (decl_str
, asmname_str
) == 0;
177 /* Returns nonzero if P1 and P2 are equal. */
180 eq_assembler_name (const void *p1
, const void *p2
)
182 const symtab_node
*n1
= (const symtab_node
*) p1
;
183 const_tree name
= (const_tree
)p2
;
184 return (decl_assembler_name_equal (n1
->decl
, name
));
187 /* Insert NODE to assembler name hash. */
190 insert_to_assembler_name_hash (symtab_node
*node
, bool with_clones
)
192 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
194 gcc_checking_assert (!node
->previous_sharing_asm_name
195 && !node
->next_sharing_asm_name
);
196 if (assembler_name_hash
)
199 struct cgraph_node
*cnode
;
200 tree decl
= node
->decl
;
202 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
204 aslot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
205 decl_assembler_name_hash (name
),
207 gcc_assert (*aslot
!= node
);
208 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
210 ((symtab_node
*)*aslot
)->previous_sharing_asm_name
= node
;
213 /* Update also possible inline clones sharing a decl. */
214 cnode
= dyn_cast
<cgraph_node
*> (node
);
215 if (cnode
&& cnode
->clones
&& with_clones
)
216 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
217 if (cnode
->decl
== decl
)
218 insert_to_assembler_name_hash (cnode
, true);
223 /* Remove NODE from assembler name hash. */
226 unlink_from_assembler_name_hash (symtab_node
*node
, bool with_clones
)
228 if (assembler_name_hash
)
230 struct cgraph_node
*cnode
;
231 tree decl
= node
->decl
;
233 if (node
->next_sharing_asm_name
)
234 node
->next_sharing_asm_name
->previous_sharing_asm_name
235 = node
->previous_sharing_asm_name
;
236 if (node
->previous_sharing_asm_name
)
238 node
->previous_sharing_asm_name
->next_sharing_asm_name
239 = node
->next_sharing_asm_name
;
243 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
245 slot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
246 decl_assembler_name_hash (name
),
248 gcc_assert (*slot
== node
);
249 if (!node
->next_sharing_asm_name
)
250 htab_clear_slot (assembler_name_hash
, slot
);
252 *slot
= node
->next_sharing_asm_name
;
254 node
->next_sharing_asm_name
= NULL
;
255 node
->previous_sharing_asm_name
= NULL
;
257 /* Update also possible inline clones sharing a decl. */
258 cnode
= dyn_cast
<cgraph_node
*> (node
);
259 if (cnode
&& cnode
->clones
&& with_clones
)
260 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
261 if (cnode
->decl
== decl
)
262 unlink_from_assembler_name_hash (cnode
, true);
266 /* Arrange node to be first in its entry of assembler_name_hash. */
269 symtab_prevail_in_asm_name_hash (symtab_node
*node
)
271 unlink_from_assembler_name_hash (node
, false);
272 insert_to_assembler_name_hash (node
, false);
276 /* Add node into symbol table. This function is not used directly, but via
277 cgraph/varpool node creation routines. */
280 symtab_register_node (symtab_node
*node
)
282 node
->next
= symtab_nodes
;
283 node
->previous
= NULL
;
285 symtab_nodes
->previous
= node
;
288 if (!node
->decl
->decl_with_vis
.symtab_node
)
289 node
->decl
->decl_with_vis
.symtab_node
= node
;
291 node
->ref_list
.clear ();
293 node
->order
= symtab_order
++;
295 /* Be sure to do this last; C++ FE might create new nodes via
296 DECL_ASSEMBLER_NAME langhook! */
297 insert_to_assembler_name_hash (node
, false);
300 /* Remove NODE from same comdat group. */
303 symtab_remove_from_same_comdat_group (symtab_node
*node
)
305 if (node
->same_comdat_group
)
308 for (prev
= node
->same_comdat_group
;
309 prev
->same_comdat_group
!= node
;
310 prev
= prev
->same_comdat_group
)
312 if (node
->same_comdat_group
== prev
)
313 prev
->same_comdat_group
= NULL
;
315 prev
->same_comdat_group
= node
->same_comdat_group
;
316 node
->same_comdat_group
= NULL
;
317 node
->set_comdat_group (NULL_TREE
);
321 /* Remove node from symbol table. This function is not used directly, but via
322 cgraph/varpool node removal routines. */
325 symtab_unregister_node (symtab_node
*node
)
327 node
->remove_all_references ();
328 node
->remove_all_referring ();
330 /* Remove reference to section. */
331 node
->set_section_for_node (NULL
);
333 symtab_remove_from_same_comdat_group (node
);
336 node
->previous
->next
= node
->next
;
338 symtab_nodes
= node
->next
;
340 node
->next
->previous
= node
->previous
;
342 node
->previous
= NULL
;
344 /* During LTO symtab merging we temporarily corrupt decl to symtab node
346 gcc_assert (node
->decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
347 if (node
->decl
->decl_with_vis
.symtab_node
== node
)
349 symtab_node
*replacement_node
= NULL
;
350 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
351 replacement_node
= cgraph_find_replacement_node (cnode
);
352 node
->decl
->decl_with_vis
.symtab_node
= replacement_node
;
354 if (!is_a
<varpool_node
*> (node
) || !DECL_HARD_REGISTER (node
->decl
))
355 unlink_from_assembler_name_hash (node
, false);
356 if (node
->in_init_priority_hash
)
358 struct symbol_priority_map in
;
362 slot
= htab_find_slot (init_priority_hash
, &in
, NO_INSERT
);
364 htab_clear_slot (init_priority_hash
, slot
);
369 /* Remove symtab NODE from the symbol table. */
372 symtab_remove_node (symtab_node
*node
)
374 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
375 cgraph_remove_node (cnode
);
376 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
377 varpool_remove_node (vnode
);
380 /* Initalize asm name hash unless. */
383 symtab_initialize_asm_name_hash (void)
386 if (!assembler_name_hash
)
388 assembler_name_hash
=
389 htab_create_ggc (10, hash_node_by_assembler_name
, eq_assembler_name
,
391 FOR_EACH_SYMBOL (node
)
392 insert_to_assembler_name_hash (node
, false);
396 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
397 Return NULL if there's no such node. */
400 symtab_node_for_asm (const_tree asmname
)
405 symtab_initialize_asm_name_hash ();
406 slot
= htab_find_slot_with_hash (assembler_name_hash
, asmname
,
407 decl_assembler_name_hash (asmname
),
412 node
= (symtab_node
*) *slot
;
418 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
421 change_decl_assembler_name (tree decl
, tree name
)
423 symtab_node
*node
= NULL
;
425 /* We can have user ASM names on things, like global register variables, that
426 are not in the symbol table. */
427 if ((TREE_CODE (decl
) == VAR_DECL
428 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
429 || TREE_CODE (decl
) == FUNCTION_DECL
)
430 node
= symtab_get_node (decl
);
431 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
433 SET_DECL_ASSEMBLER_NAME (decl
, name
);
435 insert_to_assembler_name_hash (node
, true);
439 if (name
== DECL_ASSEMBLER_NAME (decl
))
442 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
443 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
446 unlink_from_assembler_name_hash (node
, true);
447 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
448 && DECL_RTL_SET_P (decl
))
449 warning (0, "%D renamed after being referenced in assembly", decl
);
451 SET_DECL_ASSEMBLER_NAME (decl
, name
);
454 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
455 TREE_CHAIN (name
) = alias
;
458 insert_to_assembler_name_hash (node
, true);
462 /* Add NEW_ to the same comdat group that OLD is in. */
465 symtab_add_to_same_comdat_group (symtab_node
*new_node
,
466 symtab_node
*old_node
)
468 gcc_assert (old_node
->get_comdat_group ());
469 gcc_assert (!new_node
->same_comdat_group
);
470 gcc_assert (new_node
!= old_node
);
472 new_node
->set_comdat_group (old_node
->get_comdat_group ());
473 new_node
->same_comdat_group
= old_node
;
474 if (!old_node
->same_comdat_group
)
475 old_node
->same_comdat_group
= new_node
;
479 for (n
= old_node
->same_comdat_group
;
480 n
->same_comdat_group
!= old_node
;
481 n
= n
->same_comdat_group
)
483 n
->same_comdat_group
= new_node
;
487 /* Dissolve the same_comdat_group list in which NODE resides. */
490 symtab_dissolve_same_comdat_group_list (symtab_node
*node
)
492 symtab_node
*n
= node
;
495 if (!node
->same_comdat_group
)
499 next
= n
->same_comdat_group
;
500 n
->same_comdat_group
= NULL
;
501 /* Clear comdat_group for comdat locals, since
502 make_decl_local doesn't. */
503 if (!TREE_PUBLIC (n
->decl
))
504 n
->set_comdat_group (NULL
);
510 /* Return printable assembler name of NODE.
511 This function is used only for debugging. When assembler name
512 is unknown go with identifier name. */
515 symtab_node::asm_name () const
517 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
518 return lang_hooks
.decl_printable_name (decl
, 2);
519 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
522 /* Return printable identifier name. */
525 symtab_node::name () const
527 return lang_hooks
.decl_printable_name (decl
, 2);
530 /* Return ipa reference from this symtab_node to
531 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
535 symtab_node::add_reference (symtab_node
*referred_node
,
536 enum ipa_ref_use use_type
)
538 return add_reference (referred_node
, use_type
, NULL
);
542 /* Return ipa reference from this symtab_node to
543 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
544 of the use and STMT the statement (if it exists). */
547 symtab_node::add_reference (symtab_node
*referred_node
,
548 enum ipa_ref_use use_type
, gimple stmt
)
550 struct ipa_ref
*ref
= NULL
, *ref2
= NULL
;
551 struct ipa_ref_list
*list
, *list2
;
552 ipa_ref_t
*old_references
;
554 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
555 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
558 old_references
= vec_safe_address (list
->references
);
559 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
560 ref
= &list
->references
->last ();
562 list2
= &referred_node
->ref_list
;
564 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
565 if(use_type
== IPA_REF_ALIAS
)
567 list2
->referring
.safe_insert (0, ref
);
568 ref
->referred_index
= 0;
570 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
571 list2
->referring
[i
]->referred_index
= i
;
575 list2
->referring
.safe_push (ref
);
576 ref
->referred_index
= list2
->referring
.length () - 1;
579 ref
->referring
= this;
580 ref
->referred
= referred_node
;
582 ref
->lto_stmt_uid
= 0;
584 ref
->speculative
= 0;
586 /* If vector was moved in memory, update pointers. */
587 if (old_references
!= list
->references
->address ())
590 for (i
= 0; iterate_reference(i
, ref2
); i
++)
591 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
596 /* If VAL is a reference to a function or a variable, add a reference from
597 this symtab_node to the corresponding symbol table node. USE_TYPE specify
598 type of the use and STMT the statement (if it exists). Return the new
599 reference or NULL if none was created. */
602 symtab_node::maybe_add_reference (tree val
, enum ipa_ref_use use_type
,
606 if (TREE_CODE (val
) != ADDR_EXPR
)
608 val
= get_base_var (val
);
609 if (val
&& (TREE_CODE (val
) == FUNCTION_DECL
610 || TREE_CODE (val
) == VAR_DECL
))
612 symtab_node
*referred
= symtab_get_node (val
);
613 gcc_checking_assert (referred
);
614 return add_reference (referred
, use_type
, stmt
);
619 /* Clone all references from symtab NODE to this symtab_node. */
622 symtab_node::clone_references (struct symtab_node
*node
)
624 struct ipa_ref
*ref
= NULL
, *ref2
= NULL
;
626 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
628 bool speculative
= ref
->speculative
;
629 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
631 ref2
= add_reference (ref
->referred
, ref
->use
, ref
->stmt
);
632 ref2
->speculative
= speculative
;
633 ref2
->lto_stmt_uid
= stmt_uid
;
637 /* Clone all referring from symtab NODE to this symtab_node. */
640 symtab_node::clone_referring (struct symtab_node
*node
)
642 struct ipa_ref
*ref
= NULL
, *ref2
= NULL
;
644 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
646 bool speculative
= ref
->speculative
;
647 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
649 ref2
= ref
->referring
->add_reference (this, ref
->use
, ref
->stmt
);
650 ref2
->speculative
= speculative
;
651 ref2
->lto_stmt_uid
= stmt_uid
;
655 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
658 symtab_node::clone_reference (struct ipa_ref
*ref
, gimple stmt
)
660 bool speculative
= ref
->speculative
;
661 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
662 struct ipa_ref
*ref2
;
664 ref2
= add_reference (ref
->referred
, ref
->use
, stmt
);
665 ref2
->speculative
= speculative
;
666 ref2
->lto_stmt_uid
= stmt_uid
;
670 /* Find the structure describing a reference to REFERRED_NODE
671 and associated with statement STMT. */
674 symtab_node::find_reference (symtab_node
*referred_node
,
675 gimple stmt
, unsigned int lto_stmt_uid
)
677 struct ipa_ref
*r
= NULL
;
680 for (i
= 0; iterate_reference (i
, r
); i
++)
681 if (r
->referred
== referred_node
683 && ((stmt
&& r
->stmt
== stmt
)
684 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
685 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
690 /* Remove all references that are associated with statement STMT. */
693 symtab_node::remove_stmt_references (gimple stmt
)
695 struct ipa_ref
*r
= NULL
;
698 while (iterate_reference (i
, r
))
700 r
->remove_reference ();
705 /* Remove all stmt references in non-speculative references.
706 Those are not maintained during inlining & clonning.
707 The exception are speculative references that are updated along
708 with callgraph edges associated with them. */
711 symtab_node::clear_stmts_in_references (void)
713 struct ipa_ref
*r
= NULL
;
716 for (i
= 0; iterate_reference (i
, r
); i
++)
724 /* Remove all references in ref list. */
727 symtab_node::remove_all_references (void)
729 while (vec_safe_length (ref_list
.references
))
730 ref_list
.references
->last ().remove_reference ();
731 vec_free (ref_list
.references
);
734 /* Remove all referring items in ref list. */
737 symtab_node::remove_all_referring (void)
739 while (ref_list
.referring
.length ())
740 ref_list
.referring
.last ()->remove_reference ();
741 ref_list
.referring
.release ();
744 /* Dump references in ref list to FILE. */
747 symtab_node::dump_references (FILE *file
)
749 struct ipa_ref
*ref
= NULL
;
751 for (i
= 0; iterate_reference (i
, ref
); i
++)
753 fprintf (file
, "%s/%i (%s)",
754 ref
->referred
->asm_name (),
755 ref
->referred
->order
,
756 ipa_ref_use_name
[ref
->use
]);
757 if (ref
->speculative
)
758 fprintf (file
, " (speculative)");
760 fprintf (file
, "\n");
763 /* Dump referring in list to FILE. */
766 symtab_node::dump_referring (FILE *file
)
768 struct ipa_ref
*ref
= NULL
;
770 for (i
= 0; iterate_referring(i
, ref
); i
++)
772 fprintf (file
, "%s/%i (%s)",
773 ref
->referring
->asm_name (),
774 ref
->referring
->order
,
775 ipa_ref_use_name
[ref
->use
]);
776 if (ref
->speculative
)
777 fprintf (file
, " (speculative)");
779 fprintf (file
, "\n");
782 /* Return true if list contains an alias. */
784 symtab_node::has_aliases_p (void)
786 struct ipa_ref
*ref
= NULL
;
789 for (i
= 0; iterate_referring (i
, ref
); i
++)
790 if (ref
->use
== IPA_REF_ALIAS
)
795 /* Iterates I-th reference in the list, REF is also set. */
798 symtab_node::iterate_reference (unsigned i
, struct ipa_ref
*&ref
)
800 vec_safe_iterate (ref_list
.references
, i
, &ref
);
805 /* Iterates I-th referring item in the list, REF is also set. */
808 symtab_node::iterate_referring (unsigned i
, struct ipa_ref
*&ref
)
810 ref_list
.referring
.iterate (i
, &ref
);
815 /* Iterates I-th referring alias item in the list, REF is also set. */
818 symtab_node::iterate_direct_aliases (unsigned i
, struct ipa_ref
*&ref
)
820 ref_list
.referring
.iterate (i
, &ref
);
822 if (ref
&& ref
->use
!= IPA_REF_ALIAS
)
829 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
831 /* Dump base fields of symtab nodes. Not to be used directly. */
834 dump_symtab_base (FILE *f
, symtab_node
*node
)
836 static const char * const visibility_types
[] = {
837 "default", "protected", "hidden", "internal"
840 fprintf (f
, "%s/%i (%s)",
844 dump_addr (f
, " @", (void *)node
);
845 fprintf (f
, "\n Type: %s", symtab_type_names
[node
->type
]);
847 if (node
->definition
)
848 fprintf (f
, " definition");
850 fprintf (f
, " analyzed");
852 fprintf (f
, " alias");
854 fprintf (f
, " weakref");
855 if (node
->cpp_implicit_alias
)
856 fprintf (f
, " cpp_implicit_alias");
857 if (node
->alias_target
)
858 fprintf (f
, " target:%s",
859 DECL_P (node
->alias_target
)
860 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
861 (node
->alias_target
))
862 : IDENTIFIER_POINTER (node
->alias_target
));
863 if (node
->body_removed
)
864 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
865 fprintf (f
, "\n Visibility:");
866 if (node
->in_other_partition
)
867 fprintf (f
, " in_other_partition");
868 if (node
->used_from_other_partition
)
869 fprintf (f
, " used_from_other_partition");
870 if (node
->force_output
)
871 fprintf (f
, " force_output");
872 if (node
->forced_by_abi
)
873 fprintf (f
, " forced_by_abi");
874 if (node
->externally_visible
)
875 fprintf (f
, " externally_visible");
876 if (node
->resolution
!= LDPR_UNKNOWN
)
878 ld_plugin_symbol_resolution_names
[(int)node
->resolution
]);
879 if (TREE_ASM_WRITTEN (node
->decl
))
880 fprintf (f
, " asm_written");
881 if (DECL_EXTERNAL (node
->decl
))
882 fprintf (f
, " external");
883 if (TREE_PUBLIC (node
->decl
))
884 fprintf (f
, " public");
885 if (DECL_COMMON (node
->decl
))
886 fprintf (f
, " common");
887 if (DECL_WEAK (node
->decl
))
888 fprintf (f
, " weak");
889 if (DECL_DLLIMPORT_P (node
->decl
))
890 fprintf (f
, " dll_import");
891 if (DECL_COMDAT (node
->decl
))
892 fprintf (f
, " comdat");
893 if (node
->get_comdat_group ())
894 fprintf (f
, " comdat_group:%s",
895 IDENTIFIER_POINTER (node
->get_comdat_group_id ()));
896 if (DECL_ONE_ONLY (node
->decl
))
897 fprintf (f
, " one_only");
898 if (node
->get_section ())
899 fprintf (f
, " section:%s",
900 node
->get_section ());
901 if (node
->implicit_section
)
902 fprintf (f
," (implicit_section)");
903 if (DECL_VISIBILITY_SPECIFIED (node
->decl
))
904 fprintf (f
, " visibility_specified");
905 if (DECL_VISIBILITY (node
->decl
))
906 fprintf (f
, " visibility:%s",
907 visibility_types
[DECL_VISIBILITY (node
->decl
)]);
908 if (DECL_VIRTUAL_P (node
->decl
))
909 fprintf (f
, " virtual");
910 if (DECL_ARTIFICIAL (node
->decl
))
911 fprintf (f
, " artificial");
912 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
914 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
915 fprintf (f
, " constructor");
916 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
917 fprintf (f
, " destructor");
921 if (node
->same_comdat_group
)
922 fprintf (f
, " Same comdat group as: %s/%i\n",
923 node
->same_comdat_group
->asm_name (),
924 node
->same_comdat_group
->order
);
925 if (node
->next_sharing_asm_name
)
926 fprintf (f
, " next sharing asm name: %i\n",
927 node
->next_sharing_asm_name
->order
);
928 if (node
->previous_sharing_asm_name
)
929 fprintf (f
, " previous sharing asm name: %i\n",
930 node
->previous_sharing_asm_name
->order
);
932 if (node
->address_taken
)
933 fprintf (f
, " Address is taken.\n");
936 fprintf (f
, " Aux:");
937 dump_addr (f
, " @", (void *)node
->aux
);
940 fprintf (f
, " References: ");
941 node
->dump_references (f
);
942 fprintf (f
, " Referring: ");
943 node
->dump_referring (f
);
944 if (node
->lto_file_data
)
945 fprintf (f
, " Read from file: %s\n",
946 node
->lto_file_data
->file_name
);
949 /* Dump symtab node. */
952 dump_symtab_node (FILE *f
, symtab_node
*node
)
954 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
955 dump_cgraph_node (f
, cnode
);
956 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
957 dump_varpool_node (f
, vnode
);
960 /* Dump symbol table. */
963 dump_symtab (FILE *f
)
966 fprintf (f
, "Symbol table:\n\n");
967 FOR_EACH_SYMBOL (node
)
968 dump_symtab_node (f
, node
);
971 /* Dump symtab node NODE to stderr. */
974 debug_symtab_node (symtab_node
*node
)
976 dump_symtab_node (stderr
, node
);
979 /* Dump symbol table to stderr. */
984 dump_symtab (stderr
);
987 /* Verify common part of symtab nodes. */
990 verify_symtab_base (symtab_node
*node
)
992 bool error_found
= false;
993 symtab_node
*hashed_node
;
995 if (is_a
<cgraph_node
*> (node
))
997 if (TREE_CODE (node
->decl
) != FUNCTION_DECL
)
999 error ("function symbol is not function");
1003 else if (is_a
<varpool_node
*> (node
))
1005 if (TREE_CODE (node
->decl
) != VAR_DECL
)
1007 error ("variable symbol is not variable");
1013 error ("node has unknown type");
1017 if (cgraph_state
!= CGRAPH_LTO_STREAMING
)
1019 hashed_node
= symtab_get_node (node
->decl
);
1022 error ("node not found node->decl->decl_with_vis.symtab_node");
1025 if (hashed_node
!= node
1026 && (!is_a
<cgraph_node
*> (node
)
1027 || !dyn_cast
<cgraph_node
*> (node
)->clone_of
1028 || dyn_cast
<cgraph_node
*> (node
)->clone_of
->decl
1031 error ("node differs from node->decl->decl_with_vis.symtab_node");
1035 if (assembler_name_hash
)
1037 hashed_node
= symtab_node_for_asm (DECL_ASSEMBLER_NAME (node
->decl
));
1038 if (hashed_node
&& hashed_node
->previous_sharing_asm_name
)
1040 error ("assembler name hash list corrupted");
1045 if (hashed_node
== node
)
1047 hashed_node
= hashed_node
->next_sharing_asm_name
;
1050 && !(is_a
<varpool_node
*> (node
)
1051 || DECL_HARD_REGISTER (node
->decl
)))
1053 error ("node not found in symtab assembler name hash");
1057 if (node
->previous_sharing_asm_name
1058 && node
->previous_sharing_asm_name
->next_sharing_asm_name
!= node
)
1060 error ("double linked list of assembler names corrupted");
1063 if (node
->analyzed
&& !node
->definition
)
1065 error ("node is analyzed byt it is not a definition");
1068 if (node
->cpp_implicit_alias
&& !node
->alias
)
1070 error ("node is alias but not implicit alias");
1073 if (node
->alias
&& !node
->definition
1076 error ("node is alias but not definition");
1079 if (node
->weakref
&& !node
->alias
)
1081 error ("node is weakref but not an alias");
1084 if (node
->same_comdat_group
)
1086 symtab_node
*n
= node
->same_comdat_group
;
1088 if (!n
->get_comdat_group ())
1090 error ("node is in same_comdat_group list but has no comdat_group");
1093 if (n
->get_comdat_group () != node
->get_comdat_group ())
1095 error ("same_comdat_group list across different groups");
1100 error ("Node has same_comdat_group but it is not a definition");
1103 if (n
->type
!= node
->type
)
1105 error ("mixing different types of symbol in same comdat groups is not supported");
1110 error ("node is alone in a comdat group");
1115 if (!n
->same_comdat_group
)
1117 error ("same_comdat_group is not a circular list");
1121 n
= n
->same_comdat_group
;
1124 if (symtab_comdat_local_p (node
))
1126 struct ipa_ref
*ref
= NULL
;
1128 for (int i
= 0; node
->iterate_referring (i
, ref
); ++i
)
1130 if (!symtab_in_same_comdat_p (ref
->referring
, node
))
1132 error ("comdat-local symbol referred to by %s outside its "
1134 identifier_to_locale (ref
->referring
->name()));
1140 if (node
->implicit_section
&& !node
->get_section ())
1142 error ("implicit_section flag is set but section isn't");
1145 if (node
->get_section () && node
->get_comdat_group ()
1146 && !node
->implicit_section
)
1148 error ("Both section and comdat group is set");
1151 /* TODO: Add string table for sections, so we do not keep holding duplicated
1153 if (node
->alias
&& node
->definition
1154 && node
->get_section () != symtab_alias_target (node
)->get_section ()
1155 && (!node
->get_section()
1156 || !symtab_alias_target (node
)->get_section ()
1157 || strcmp (node
->get_section(),
1158 symtab_alias_target (node
)->get_section ())))
1160 error ("Alias and target's section differs");
1161 dump_symtab_node (stderr
, symtab_alias_target (node
));
1164 if (node
->alias
&& node
->definition
1165 && node
->get_comdat_group () != symtab_alias_target (node
)->get_comdat_group ())
1167 error ("Alias and target's comdat groups differs");
1168 dump_symtab_node (stderr
, symtab_alias_target (node
));
1175 /* Verify consistency of NODE. */
1178 verify_symtab_node (symtab_node
*node
)
1183 timevar_push (TV_CGRAPH_VERIFY
);
1184 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1185 verify_cgraph_node (cnode
);
1187 if (verify_symtab_base (node
))
1189 dump_symtab_node (stderr
, node
);
1190 internal_error ("verify_symtab_node failed");
1192 timevar_pop (TV_CGRAPH_VERIFY
);
1195 /* Verify symbol table for internal consistency. */
1198 verify_symtab (void)
1201 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1203 FOR_EACH_SYMBOL (node
)
1205 verify_symtab_node (node
);
1206 if (node
->get_comdat_group ())
1208 symtab_node
**entry
, *s
;
1211 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1216 for (s
= (*entry
)->same_comdat_group
; s
!= NULL
&& s
!= node
; s
= s
->same_comdat_group
)
1217 if (!s
|| s
== *entry
)
1219 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1220 dump_symtab_node (stderr
, *entry
);
1221 dump_symtab_node (stderr
, node
);
1222 internal_error ("verify_symtab failed");
1228 /* Return true when RESOLUTION indicate that linker will use
1229 the symbol from non-LTO object files. */
1232 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
1234 return (resolution
== LDPR_PREVAILING_DEF
1235 || resolution
== LDPR_PREEMPTED_REG
1236 || resolution
== LDPR_RESOLVED_EXEC
1237 || resolution
== LDPR_RESOLVED_DYN
);
1240 /* Return true when NODE is known to be used from other (non-LTO) object file.
1241 Known only when doing LTO via linker plugin. */
1244 symtab_used_from_object_file_p (symtab_node
*node
)
1246 if (!TREE_PUBLIC (node
->decl
) || DECL_EXTERNAL (node
->decl
))
1248 if (resolution_used_from_other_file_p (node
->resolution
))
1253 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1254 but other code such as notice_global_symbol generates rtl. */
1257 symtab_make_decl_local (tree decl
)
1261 /* Avoid clearing comdat_groups on comdat-local decls. */
1262 if (TREE_PUBLIC (decl
) == 0)
1265 if (TREE_CODE (decl
) == VAR_DECL
)
1266 DECL_COMMON (decl
) = 0;
1267 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1269 DECL_COMDAT (decl
) = 0;
1270 DECL_WEAK (decl
) = 0;
1271 DECL_EXTERNAL (decl
) = 0;
1272 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1273 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1274 TREE_PUBLIC (decl
) = 0;
1275 if (!DECL_RTL_SET_P (decl
))
1278 /* Update rtl flags. */
1279 make_decl_rtl (decl
);
1281 rtl
= DECL_RTL (decl
);
1285 symbol
= XEXP (rtl
, 0);
1286 if (GET_CODE (symbol
) != SYMBOL_REF
)
1289 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1292 /* Return availability of NODE. */
1295 symtab_node_availability (symtab_node
*node
)
1297 if (is_a
<cgraph_node
*> (node
))
1298 return cgraph_function_body_availability (cgraph (node
));
1300 return cgraph_variable_initializer_availability (varpool (node
));
1303 /* Given NODE, walk the alias chain to return the symbol NODE is alias of.
1304 If NODE is not an alias, return NODE.
1305 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1308 symtab_alias_ultimate_target (symtab_node
*node
, enum availability
*availability
)
1310 bool weakref_p
= false;
1315 *availability
= symtab_node_availability (node
);
1319 /* To determine visibility of the target, we follow ELF semantic of aliases.
1320 Here alias is an alternative assembler name of a given definition. Its
1321 availability prevails the availability of its target (i.e. static alias of
1322 weak definition is available.
1324 Weakref is a different animal (and not part of ELF per se). It is just
1325 alternative name of a given symbol used within one complation unit
1326 and is translated prior hitting the object file. It inherits the
1327 visibility of its target (i.e. weakref of non-overwritable definition
1328 is non-overwritable, while weakref of weak definition is weak).
1330 If we ever get into supporting targets with different semantics, a target
1331 hook will be needed here. */
1335 weakref_p
= node
->weakref
;
1337 *availability
= symtab_node_availability (node
);
1339 *availability
= AVAIL_LOCAL
;
1343 if (node
->alias
&& node
->analyzed
)
1344 node
= symtab_alias_target (node
);
1349 else if (node
->analyzed
)
1353 enum availability a
= symtab_node_availability (node
);
1354 if (a
< *availability
)
1359 *availability
= AVAIL_NOT_AVAILABLE
;
1362 if (node
&& availability
&& weakref_p
)
1364 enum availability a
= symtab_node_availability (node
);
1365 if (a
< *availability
)
1367 weakref_p
= node
->weakref
;
1371 *availability
= AVAIL_NOT_AVAILABLE
;
1375 /* C++ FE sometimes change linkage flags after producing same body aliases.
1377 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1378 are obviously equivalent. The way it is doing so is however somewhat
1379 kludgy and interferes with the visibility code. As a result we need to
1380 copy the visibility from the target to get things right. */
1383 fixup_same_cpp_alias_visibility (symtab_node
*node
, symtab_node
*target
)
1385 if (is_a
<cgraph_node
*> (node
))
1387 DECL_DECLARED_INLINE_P (node
->decl
)
1388 = DECL_DECLARED_INLINE_P (target
->decl
);
1389 DECL_DISREGARD_INLINE_LIMITS (node
->decl
)
1390 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1392 /* FIXME: It is not really clear why those flags should not be copied for
1396 DECL_WEAK (node
->decl
) = DECL_WEAK (target
->decl
);
1397 DECL_EXTERNAL (node
->decl
) = DECL_EXTERNAL (target
->decl
);
1398 DECL_VISIBILITY (node
->decl
) = DECL_VISIBILITY (target
->decl
);
1400 DECL_VIRTUAL_P (node
->decl
) = DECL_VIRTUAL_P (target
->decl
);
1401 if (TREE_PUBLIC (node
->decl
))
1405 DECL_EXTERNAL (node
->decl
) = DECL_EXTERNAL (target
->decl
);
1406 DECL_COMDAT (node
->decl
) = DECL_COMDAT (target
->decl
);
1407 group
= target
->get_comdat_group ();
1408 node
->set_comdat_group (group
);
1410 && !node
->same_comdat_group
)
1411 symtab_add_to_same_comdat_group (node
, target
);
1413 node
->externally_visible
= target
->externally_visible
;
1416 /* Hash sections by their names. */
1419 hash_section_hash_entry (const void *p
)
1421 const section_hash_entry
*n
= (const section_hash_entry
*) p
;
1422 return htab_hash_string (n
->name
);
1425 /* Return true if section P1 name equals to P2. */
1428 eq_sections (const void *p1
, const void *p2
)
1430 const section_hash_entry
*n1
= (const section_hash_entry
*) p1
;
1431 const char *name
= (const char *)p2
;
1432 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
1435 /* Set section, do not recurse into aliases.
1436 When one wants to change section of symbol and its aliases,
1440 symtab_node::set_section_for_node (const char *section
)
1442 const char *current
= get_section ();
1445 if (current
== section
1446 || (current
&& section
1447 && !strcmp (current
, section
)))
1452 x_section
->ref_count
--;
1453 if (!x_section
->ref_count
)
1455 slot
= htab_find_slot_with_hash (section_hash
, x_section
->name
,
1456 htab_hash_string (x_section
->name
),
1458 ggc_free (x_section
);
1459 htab_clear_slot (section_hash
, slot
);
1465 implicit_section
= false;
1469 section_hash
= htab_create_ggc (10, hash_section_hash_entry
,
1471 slot
= htab_find_slot_with_hash (section_hash
, section
,
1472 htab_hash_string (section
),
1475 x_section
= (section_hash_entry
*)*slot
;
1478 int len
= strlen (section
);
1479 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1480 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1481 memcpy (x_section
->name
, section
, len
+ 1);
1483 x_section
->ref_count
++;
1486 /* Worker for set_section. */
1489 set_section_1 (struct symtab_node
*n
, void *s
)
1491 n
->set_section_for_node ((char *)s
);
1495 /* Set section of symbol and its aliases. */
1498 symtab_node::set_section (const char *section
)
1500 gcc_assert (!this->alias
);
1501 symtab_for_node_and_aliases (this, set_section_1
, const_cast<char *>(section
), true);
1504 /* Return the initialization priority. */
1507 symtab_node::get_init_priority ()
1509 struct symbol_priority_map
*h
;
1510 struct symbol_priority_map in
;
1512 if (!this->in_init_priority_hash
)
1513 return DEFAULT_INIT_PRIORITY
;
1515 h
= (struct symbol_priority_map
*) htab_find (init_priority_hash
, &in
);
1516 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1519 /* Return the finalization priority. */
1522 cgraph_node::get_fini_priority ()
1524 struct symbol_priority_map
*h
;
1525 struct symbol_priority_map in
;
1527 if (!this->in_init_priority_hash
)
1528 return DEFAULT_INIT_PRIORITY
;
1530 h
= (struct symbol_priority_map
*) htab_find (init_priority_hash
, &in
);
1531 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1534 /* Return true if the from tree in both priority maps are equal. */
1537 symbol_priority_map_eq (const void *va
, const void *vb
)
1539 const struct symbol_priority_map
*const a
= (const struct symbol_priority_map
*) va
,
1540 *const b
= (const struct symbol_priority_map
*) vb
;
1541 return (a
->symbol
== b
->symbol
);
1544 /* Hash a from symbol in a symbol_priority_map. */
1547 symbol_priority_map_hash (const void *item
)
1549 return htab_hash_pointer (((const struct symbol_priority_map
*)item
)->symbol
);
1552 /* Return the initialization and finalization priority information for
1553 DECL. If there is no previous priority information, a freshly
1554 allocated structure is returned. */
1556 static struct symbol_priority_map
*
1557 symbol_priority_info (struct symtab_node
*symbol
)
1559 struct symbol_priority_map in
;
1560 struct symbol_priority_map
*h
;
1564 if (!init_priority_hash
)
1565 init_priority_hash
= htab_create_ggc (512, symbol_priority_map_hash
,
1566 symbol_priority_map_eq
, 0);
1568 loc
= htab_find_slot (init_priority_hash
, &in
, INSERT
);
1569 h
= (struct symbol_priority_map
*) *loc
;
1572 h
= ggc_cleared_alloc
<symbol_priority_map
> ();
1575 h
->init
= DEFAULT_INIT_PRIORITY
;
1576 h
->fini
= DEFAULT_INIT_PRIORITY
;
1577 symbol
->in_init_priority_hash
= true;
1583 /* Set initialization priority to PRIORITY. */
1586 symtab_node::set_init_priority (priority_type priority
)
1588 struct symbol_priority_map
*h
;
1590 if (is_a
<cgraph_node
*> (this))
1591 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1593 if (priority
== DEFAULT_INIT_PRIORITY
)
1595 gcc_assert (get_init_priority() == priority
);
1598 h
= symbol_priority_info (this);
1602 /* Set fialization priority to PRIORITY. */
1605 cgraph_node::set_fini_priority (priority_type priority
)
1607 struct symbol_priority_map
*h
;
1609 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1611 if (priority
== DEFAULT_INIT_PRIORITY
)
1613 gcc_assert (get_fini_priority() == priority
);
1616 h
= symbol_priority_info (this);
1620 /* Worker for symtab_resolve_alias. */
1623 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
1625 n
->implicit_section
= true;
1629 /* Add reference recording that NODE is alias of TARGET.
1630 The function can fail in the case of aliasing cycles; in this case
1631 it returns false. */
1634 symtab_resolve_alias (symtab_node
*node
, symtab_node
*target
)
1638 gcc_assert (!node
->analyzed
1639 && !vec_safe_length (node
->ref_list
.references
));
1641 /* Never let cycles to creep into the symbol table alias references;
1642 those will make alias walkers to be infinite. */
1643 for (n
= target
; n
&& n
->alias
;
1644 n
= n
->analyzed
? symtab_alias_target (n
) : NULL
)
1647 if (is_a
<cgraph_node
*> (node
))
1648 error ("function %q+D part of alias cycle", node
->decl
);
1649 else if (is_a
<varpool_node
*> (node
))
1650 error ("variable %q+D part of alias cycle", node
->decl
);
1653 node
->alias
= false;
1657 /* "analyze" the node - i.e. mark the reference. */
1658 node
->definition
= true;
1660 node
->analyzed
= true;
1661 node
->add_reference (target
, IPA_REF_ALIAS
, NULL
);
1663 /* Add alias into the comdat group of its target unless it is already there. */
1664 if (node
->same_comdat_group
)
1665 symtab_remove_from_same_comdat_group (node
);
1666 node
->set_comdat_group (NULL
);
1667 if (target
->get_comdat_group ())
1668 symtab_add_to_same_comdat_group (node
, target
);
1670 if ((node
->get_section () != target
->get_section ()
1671 || target
->get_comdat_group ())
1672 && node
->get_section () && !node
->implicit_section
)
1674 error ("section of alias %q+D must match section of its target",
1677 symtab_for_node_and_aliases (node
, set_section_1
,
1678 const_cast<char *>(target
->get_section ()), true);
1679 if (target
->implicit_section
)
1680 symtab_for_node_and_aliases (node
,
1681 set_implicit_section
, NULL
, true);
1683 /* Alias targets become redundant after alias is resolved into an reference.
1684 We do not want to keep it around or we would have to mind updating them
1685 when renaming symbols. */
1686 node
->alias_target
= NULL
;
1688 if (node
->cpp_implicit_alias
&& cgraph_state
>= CGRAPH_STATE_CONSTRUCTION
)
1689 fixup_same_cpp_alias_visibility (node
, target
);
1691 /* If alias has address taken, so does the target. */
1692 if (node
->address_taken
)
1693 symtab_alias_ultimate_target (target
, NULL
)->address_taken
= true;
1697 /* Call calback on NODE and aliases associated to NODE.
1698 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1702 symtab_for_node_and_aliases (symtab_node
*node
,
1703 bool (*callback
) (symtab_node
*, void *),
1705 bool include_overwritable
)
1708 struct ipa_ref
*ref
;
1710 if (callback (node
, data
))
1712 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
1713 if (ref
->use
== IPA_REF_ALIAS
)
1715 symtab_node
*alias
= ref
->referring
;
1716 if (include_overwritable
1717 || symtab_node_availability (alias
) > AVAIL_OVERWRITABLE
)
1718 if (symtab_for_node_and_aliases (alias
, callback
, data
,
1719 include_overwritable
))
1725 /* Worker searching nonoverwritable alias. */
1728 symtab_nonoverwritable_alias_1 (symtab_node
*node
, void *data
)
1730 if (decl_binds_to_current_def_p (node
->decl
))
1732 symtab_node
*fn
= symtab_alias_ultimate_target (node
);
1734 /* Ensure that the alias is well formed this may not be the case
1735 of user defined aliases and currently it is not always the case
1736 of C++ same body aliases (that is a bug). */
1737 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
1738 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
1739 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
1740 && flags_from_decl_or_type (node
->decl
)
1741 != flags_from_decl_or_type (fn
->decl
))
1742 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
1745 *(symtab_node
**)data
= node
;
1751 /* If NODE can not be overwriten by static or dynamic linker to point to different
1752 definition, return NODE. Otherwise look for alias with such property and if
1753 none exists, introduce new one. */
1756 symtab_nonoverwritable_alias (symtab_node
*node
)
1759 symtab_node
*new_node
= NULL
;
1761 /* First try to look up existing alias or base object
1762 (if that is already non-overwritable). */
1763 node
= symtab_alias_ultimate_target (node
, NULL
);
1764 gcc_assert (!node
->alias
&& !node
->weakref
);
1765 symtab_for_node_and_aliases (node
, symtab_nonoverwritable_alias_1
,
1766 (void *)&new_node
, true);
1769 #ifndef ASM_OUTPUT_DEF
1770 /* If aliases aren't supported by the assembler, fail. */
1774 /* Otherwise create a new one. */
1775 new_decl
= copy_node (node
->decl
);
1776 DECL_NAME (new_decl
) = clone_function_name (node
->decl
, "localalias");
1777 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1778 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1779 DECL_INITIAL (new_decl
) = NULL
;
1780 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1781 SET_DECL_RTL (new_decl
, NULL
);
1783 /* Update the properties. */
1784 DECL_EXTERNAL (new_decl
) = 0;
1785 TREE_PUBLIC (new_decl
) = 0;
1786 DECL_COMDAT (new_decl
) = 0;
1787 DECL_WEAK (new_decl
) = 0;
1789 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1790 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1791 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1793 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1794 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1795 new_node
= cgraph_create_function_alias
1796 (new_decl
, node
->decl
);
1800 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
1801 DECL_INITIAL (new_decl
) = error_mark_node
;
1802 new_node
= varpool_create_variable_alias (new_decl
, node
->decl
);
1804 symtab_resolve_alias (new_node
, node
);
1805 gcc_assert (decl_binds_to_current_def_p (new_decl
)
1806 && targetm
.binds_local_p (new_decl
));
1810 /* Return true if A and B represents semantically equivalent symbols. */
1813 symtab_semantically_equivalent_p (symtab_node
*a
,
1816 enum availability avail
;
1820 /* Equivalent functions are equivalent. */
1821 if (a
->decl
== b
->decl
)
1824 /* If symbol is not overwritable by different implementation,
1825 walk to the base object it defines. */
1826 ba
= symtab_alias_ultimate_target (a
, &avail
);
1827 if (avail
>= AVAIL_AVAILABLE
)
1834 bb
= symtab_alias_ultimate_target (b
, &avail
);
1835 if (avail
>= AVAIL_AVAILABLE
)
1845 /* Classify symbol NODE for partitioning. */
1847 enum symbol_partitioning_class
1848 symtab_get_symbol_partitioning_class (symtab_node
*node
)
1850 /* Inline clones are always duplicated.
1851 This include external delcarations. */
1852 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1854 if (DECL_ABSTRACT (node
->decl
))
1855 return SYMBOL_EXTERNAL
;
1857 if (cnode
&& cnode
->global
.inlined_to
)
1858 return SYMBOL_DUPLICATE
;
1860 /* Weakref aliases are always duplicated. */
1862 return SYMBOL_DUPLICATE
;
1864 /* External declarations are external. */
1865 if (DECL_EXTERNAL (node
->decl
))
1866 return SYMBOL_EXTERNAL
;
1868 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
1870 /* Constant pool references use local symbol names that can not
1871 be promoted global. We should never put into a constant pool
1872 objects that can not be duplicated across partitions. */
1873 if (DECL_IN_CONSTANT_POOL (node
->decl
))
1874 return SYMBOL_DUPLICATE
;
1875 gcc_checking_assert (vnode
->definition
);
1877 /* Functions that are cloned may stay in callgraph even if they are unused.
1878 Handle them as external; compute_ltrans_boundary take care to make
1879 proper things to happen (i.e. to make them appear in the boundary but
1880 with body streamed, so clone can me materialized). */
1881 else if (!cgraph (node
)->definition
)
1882 return SYMBOL_EXTERNAL
;
1884 /* Linker discardable symbols are duplicated to every use unless they are
1886 if (DECL_ONE_ONLY (node
->decl
)
1887 && !node
->force_output
1888 && !node
->forced_by_abi
1889 && !symtab_used_from_object_file_p (node
))
1890 return SYMBOL_DUPLICATE
;
1892 return SYMBOL_PARTITION
;
1895 /* Return true when symbol is known to be non-zero. */
1898 symtab_node::nonzero_address ()
1900 /* Weakrefs may be NULL when their target is not defined. */
1901 if (this->alias
&& this->weakref
)
1905 symtab_node
*target
= symtab_alias_ultimate_target (this);
1907 if (target
->alias
&& target
->weakref
)
1909 /* We can not recurse to target::nonzero. It is possible that the
1910 target is used only via the alias.
1911 We may walk references and look for strong use, but we do not know
1912 if this strong use will survive to final binary, so be
1914 ??? Maybe we could do the lookup during late optimization that
1915 could be useful to eliminate the NULL pointer checks in LTO
1917 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
1919 if (target
->resolution
!= LDPR_UNKNOWN
1920 && target
->resolution
!= LDPR_UNDEF
1921 && flag_delete_null_pointer_checks
)
1929 /* With !flag_delete_null_pointer_checks we assume that symbols may
1930 bind to NULL. This is on by default on embedded targets only.
1932 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1933 linking fails. Important case of WEAK we want to do well are comdats.
1934 Those are handled by later check for definition.
1936 When parsing, beware the cases when WEAK attribute is added later. */
1937 if (!DECL_WEAK (this->decl
)
1938 && flag_delete_null_pointer_checks
1939 && cgraph_state
> CGRAPH_STATE_PARSING
)
1942 /* If target is defined and not extern, we know it will be output and thus
1943 it will bind to non-NULL.
1944 Play safe for flag_delete_null_pointer_checks where weak definition maye
1945 be re-defined by NULL. */
1946 if (this->definition
&& !DECL_EXTERNAL (this->decl
)
1947 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (this->decl
)))
1950 /* As the last resort, check the resolution info. */
1951 if (this->resolution
!= LDPR_UNKNOWN
1952 && this->resolution
!= LDPR_UNDEF
1953 && flag_delete_null_pointer_checks
)
1957 #include "gt-symtab.h"