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"
47 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias"};
49 const char * const ld_plugin_symbol_resolution_names
[]=
54 "prevailing_def_ironly",
60 "prevailing_def_ironly_exp"
64 /* Hash table used to hold sectoons. */
65 static GTY((param_is (section_hash_entry
))) htab_t section_hash
;
67 /* Hash table used to convert assembler names into nodes. */
68 static GTY((param_is (symtab_node
))) htab_t assembler_name_hash
;
70 /* Map from a symbol to initialization/finalization priorities. */
71 struct GTY(()) symbol_priority_map
{
77 /* Hash table used to hold init priorities. */
78 static GTY ((param_is (struct symbol_priority_map
)))
79 htab_t init_priority_hash
;
81 /* Linked list of symbol table nodes. */
82 symtab_node
*symtab_nodes
;
84 /* The order index of the next symtab node to be created. This is
85 used so that we can sort the cgraph nodes in order by when we saw
86 them, to support -fno-toplevel-reorder. */
89 /* Hash asmnames ignoring the user specified marks. */
92 decl_assembler_name_hash (const_tree asmname
)
94 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
96 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
97 size_t ulp_len
= strlen (user_label_prefix
);
101 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
104 return htab_hash_string (decl_str
);
107 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
111 /* Returns a hash code for P. */
114 hash_node_by_assembler_name (const void *p
)
116 const symtab_node
*n
= (const symtab_node
*) p
;
117 return (hashval_t
) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n
->decl
));
120 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
123 decl_assembler_name_equal (tree decl
, const_tree asmname
)
125 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
126 const char *decl_str
;
127 const char *asmname_str
;
130 if (decl_asmname
== asmname
)
133 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
134 asmname_str
= IDENTIFIER_POINTER (asmname
);
137 /* If the target assembler name was set by the user, things are trickier.
138 We have a leading '*' to begin with. After that, it's arguable what
139 is the correct thing to do with -fleading-underscore. Arguably, we've
140 historically been doing the wrong thing in assemble_alias by always
141 printing the leading underscore. Since we're not changing that, make
142 sure user_label_prefix follows the '*' before matching. */
143 if (decl_str
[0] == '*')
145 size_t ulp_len
= strlen (user_label_prefix
);
151 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
152 decl_str
+= ulp_len
, test
=true;
156 if (asmname_str
[0] == '*')
158 size_t ulp_len
= strlen (user_label_prefix
);
164 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
165 asmname_str
+= ulp_len
, test
=true;
172 return strcmp (decl_str
, asmname_str
) == 0;
176 /* Returns nonzero if P1 and P2 are equal. */
179 eq_assembler_name (const void *p1
, const void *p2
)
181 const symtab_node
*n1
= (const symtab_node
*) p1
;
182 const_tree name
= (const_tree
)p2
;
183 return (decl_assembler_name_equal (n1
->decl
, name
));
186 /* Insert NODE to assembler name hash. */
189 insert_to_assembler_name_hash (symtab_node
*node
, bool with_clones
)
191 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
193 gcc_checking_assert (!node
->previous_sharing_asm_name
194 && !node
->next_sharing_asm_name
);
195 if (assembler_name_hash
)
198 struct cgraph_node
*cnode
;
199 tree decl
= node
->decl
;
201 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
203 aslot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
204 decl_assembler_name_hash (name
),
206 gcc_assert (*aslot
!= node
);
207 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
209 ((symtab_node
*)*aslot
)->previous_sharing_asm_name
= node
;
212 /* Update also possible inline clones sharing a decl. */
213 cnode
= dyn_cast
<cgraph_node
*> (node
);
214 if (cnode
&& cnode
->clones
&& with_clones
)
215 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
216 if (cnode
->decl
== decl
)
217 insert_to_assembler_name_hash (cnode
, true);
222 /* Remove NODE from assembler name hash. */
225 unlink_from_assembler_name_hash (symtab_node
*node
, bool with_clones
)
227 if (assembler_name_hash
)
229 struct cgraph_node
*cnode
;
230 tree decl
= node
->decl
;
232 if (node
->next_sharing_asm_name
)
233 node
->next_sharing_asm_name
->previous_sharing_asm_name
234 = node
->previous_sharing_asm_name
;
235 if (node
->previous_sharing_asm_name
)
237 node
->previous_sharing_asm_name
->next_sharing_asm_name
238 = node
->next_sharing_asm_name
;
242 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
244 slot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
245 decl_assembler_name_hash (name
),
247 gcc_assert (*slot
== node
);
248 if (!node
->next_sharing_asm_name
)
249 htab_clear_slot (assembler_name_hash
, slot
);
251 *slot
= node
->next_sharing_asm_name
;
253 node
->next_sharing_asm_name
= NULL
;
254 node
->previous_sharing_asm_name
= NULL
;
256 /* Update also possible inline clones sharing a decl. */
257 cnode
= dyn_cast
<cgraph_node
*> (node
);
258 if (cnode
&& cnode
->clones
&& with_clones
)
259 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
260 if (cnode
->decl
== decl
)
261 unlink_from_assembler_name_hash (cnode
, true);
265 /* Arrange node to be first in its entry of assembler_name_hash. */
268 symtab_prevail_in_asm_name_hash (symtab_node
*node
)
270 unlink_from_assembler_name_hash (node
, false);
271 insert_to_assembler_name_hash (node
, false);
275 /* Add node into symbol table. This function is not used directly, but via
276 cgraph/varpool node creation routines. */
279 symtab_register_node (symtab_node
*node
)
281 node
->next
= symtab_nodes
;
282 node
->previous
= NULL
;
284 symtab_nodes
->previous
= node
;
287 if (!node
->decl
->decl_with_vis
.symtab_node
)
288 node
->decl
->decl_with_vis
.symtab_node
= node
;
290 node
->ref_list
.clear ();
292 node
->order
= symtab_order
++;
294 /* Be sure to do this last; C++ FE might create new nodes via
295 DECL_ASSEMBLER_NAME langhook! */
296 insert_to_assembler_name_hash (node
, false);
299 /* Remove NODE from same comdat group. */
302 symtab_remove_from_same_comdat_group (symtab_node
*node
)
304 if (node
->same_comdat_group
)
307 for (prev
= node
->same_comdat_group
;
308 prev
->same_comdat_group
!= node
;
309 prev
= prev
->same_comdat_group
)
311 if (node
->same_comdat_group
== prev
)
312 prev
->same_comdat_group
= NULL
;
314 prev
->same_comdat_group
= node
->same_comdat_group
;
315 node
->same_comdat_group
= NULL
;
319 /* Remove node from symbol table. This function is not used directly, but via
320 cgraph/varpool node removal routines. */
323 symtab_unregister_node (symtab_node
*node
)
325 node
->remove_all_references ();
326 node
->remove_all_referring ();
328 /* Remove reference to section. */
329 node
->set_section_for_node (NULL
);
331 symtab_remove_from_same_comdat_group (node
);
334 node
->previous
->next
= node
->next
;
336 symtab_nodes
= node
->next
;
338 node
->next
->previous
= node
->previous
;
340 node
->previous
= NULL
;
342 /* During LTO symtab merging we temporarily corrupt decl to symtab node
344 gcc_assert (node
->decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
345 if (node
->decl
->decl_with_vis
.symtab_node
== node
)
347 symtab_node
*replacement_node
= NULL
;
348 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
349 replacement_node
= cgraph_find_replacement_node (cnode
);
350 node
->decl
->decl_with_vis
.symtab_node
= replacement_node
;
352 if (!is_a
<varpool_node
*> (node
) || !DECL_HARD_REGISTER (node
->decl
))
353 unlink_from_assembler_name_hash (node
, false);
354 if (node
->in_init_priority_hash
)
356 struct symbol_priority_map in
;
360 slot
= htab_find_slot (init_priority_hash
, &in
, NO_INSERT
);
362 htab_clear_slot (init_priority_hash
, slot
);
367 /* Remove symtab NODE from the symbol table. */
370 symtab_remove_node (symtab_node
*node
)
372 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
373 cgraph_remove_node (cnode
);
374 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
375 varpool_remove_node (vnode
);
378 /* Initalize asm name hash unless. */
381 symtab_initialize_asm_name_hash (void)
384 if (!assembler_name_hash
)
386 assembler_name_hash
=
387 htab_create_ggc (10, hash_node_by_assembler_name
, eq_assembler_name
,
389 FOR_EACH_SYMBOL (node
)
390 insert_to_assembler_name_hash (node
, false);
394 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
395 Return NULL if there's no such node. */
398 symtab_node_for_asm (const_tree asmname
)
403 symtab_initialize_asm_name_hash ();
404 slot
= htab_find_slot_with_hash (assembler_name_hash
, asmname
,
405 decl_assembler_name_hash (asmname
),
410 node
= (symtab_node
*) *slot
;
416 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
419 change_decl_assembler_name (tree decl
, tree name
)
421 symtab_node
*node
= NULL
;
423 /* We can have user ASM names on things, like global register variables, that
424 are not in the symbol table. */
425 if ((TREE_CODE (decl
) == VAR_DECL
426 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
427 || TREE_CODE (decl
) == FUNCTION_DECL
)
428 node
= symtab_get_node (decl
);
429 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
431 SET_DECL_ASSEMBLER_NAME (decl
, name
);
433 insert_to_assembler_name_hash (node
, true);
437 if (name
== DECL_ASSEMBLER_NAME (decl
))
440 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
441 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
444 unlink_from_assembler_name_hash (node
, true);
445 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
446 && DECL_RTL_SET_P (decl
))
447 warning (0, "%D renamed after being referenced in assembly", decl
);
449 SET_DECL_ASSEMBLER_NAME (decl
, name
);
452 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
453 TREE_CHAIN (name
) = alias
;
456 insert_to_assembler_name_hash (node
, true);
460 /* Add NEW_ to the same comdat group that OLD is in. */
463 symtab_add_to_same_comdat_group (symtab_node
*new_node
,
464 symtab_node
*old_node
)
466 gcc_assert (old_node
->get_comdat_group ());
467 gcc_assert (!new_node
->same_comdat_group
);
468 gcc_assert (new_node
!= old_node
);
470 new_node
->set_comdat_group (old_node
->get_comdat_group ());
471 new_node
->same_comdat_group
= old_node
;
472 if (!old_node
->same_comdat_group
)
473 old_node
->same_comdat_group
= new_node
;
477 for (n
= old_node
->same_comdat_group
;
478 n
->same_comdat_group
!= old_node
;
479 n
= n
->same_comdat_group
)
481 n
->same_comdat_group
= new_node
;
485 /* Dissolve the same_comdat_group list in which NODE resides. */
488 symtab_dissolve_same_comdat_group_list (symtab_node
*node
)
490 symtab_node
*n
= node
;
493 if (!node
->same_comdat_group
)
497 next
= n
->same_comdat_group
;
498 n
->same_comdat_group
= NULL
;
499 /* Clear comdat_group for comdat locals, since
500 make_decl_local doesn't. */
501 if (!TREE_PUBLIC (n
->decl
))
502 n
->set_comdat_group (NULL
);
508 /* Return printable assembler name of NODE.
509 This function is used only for debugging. When assembler name
510 is unknown go with identifier name. */
513 symtab_node::asm_name () const
515 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
516 return lang_hooks
.decl_printable_name (decl
, 2);
517 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
520 /* Return printable identifier name. */
523 symtab_node::name () const
525 return lang_hooks
.decl_printable_name (decl
, 2);
528 /* Return ipa reference from this symtab_node to
529 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
533 symtab_node::add_reference (symtab_node
*referred_node
,
534 enum ipa_ref_use use_type
)
536 return add_reference (referred_node
, use_type
, NULL
);
540 /* Return ipa reference from this symtab_node to
541 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
542 of the use and STMT the statement (if it exists). */
545 symtab_node::add_reference (symtab_node
*referred_node
,
546 enum ipa_ref_use use_type
, gimple stmt
)
548 struct ipa_ref
*ref
= NULL
, *ref2
= NULL
;
549 struct ipa_ref_list
*list
, *list2
;
550 ipa_ref_t
*old_references
;
552 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
553 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
556 old_references
= vec_safe_address (list
->references
);
557 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
558 ref
= &list
->references
->last ();
560 list2
= &referred_node
->ref_list
;
562 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
563 if(use_type
== IPA_REF_ALIAS
)
565 list2
->referring
.safe_insert (0, ref
);
566 ref
->referred_index
= 0;
568 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
569 list2
->referring
[i
]->referred_index
= i
;
573 list2
->referring
.safe_push (ref
);
574 ref
->referred_index
= list2
->referring
.length () - 1;
577 ref
->referring
= this;
578 ref
->referred
= referred_node
;
580 ref
->lto_stmt_uid
= 0;
582 ref
->speculative
= 0;
584 /* If vector was moved in memory, update pointers. */
585 if (old_references
!= list
->references
->address ())
588 for (i
= 0; iterate_reference(i
, ref2
); i
++)
589 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
594 /* If VAL is a reference to a function or a variable, add a reference from
595 this symtab_node to the corresponding symbol table node. USE_TYPE specify
596 type of the use and STMT the statement (if it exists). Return the new
597 reference or NULL if none was created. */
600 symtab_node::maybe_add_reference (tree val
, enum ipa_ref_use use_type
,
604 if (TREE_CODE (val
) != ADDR_EXPR
)
606 val
= get_base_var (val
);
607 if (val
&& (TREE_CODE (val
) == FUNCTION_DECL
608 || TREE_CODE (val
) == VAR_DECL
))
610 symtab_node
*referred
= symtab_get_node (val
);
611 gcc_checking_assert (referred
);
612 return add_reference (referred
, use_type
, stmt
);
617 /* Clone all references from symtab NODE to this symtab_node. */
620 symtab_node::clone_references (struct symtab_node
*node
)
622 struct ipa_ref
*ref
= NULL
, *ref2
= NULL
;
624 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
626 bool speculative
= ref
->speculative
;
627 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
629 ref2
= add_reference (ref
->referred
, ref
->use
, ref
->stmt
);
630 ref2
->speculative
= speculative
;
631 ref2
->lto_stmt_uid
= stmt_uid
;
635 /* Clone all referring from symtab NODE to this symtab_node. */
638 symtab_node::clone_referring (struct symtab_node
*node
)
640 struct ipa_ref
*ref
= NULL
, *ref2
= NULL
;
642 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
644 bool speculative
= ref
->speculative
;
645 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
647 ref2
= ref
->referring
->add_reference (this, ref
->use
, ref
->stmt
);
648 ref2
->speculative
= speculative
;
649 ref2
->lto_stmt_uid
= stmt_uid
;
653 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
656 symtab_node::clone_reference (struct ipa_ref
*ref
, gimple stmt
)
658 bool speculative
= ref
->speculative
;
659 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
660 struct ipa_ref
*ref2
;
662 ref2
= add_reference (ref
->referred
, ref
->use
, stmt
);
663 ref2
->speculative
= speculative
;
664 ref2
->lto_stmt_uid
= stmt_uid
;
668 /* Find the structure describing a reference to REFERRED_NODE
669 and associated with statement STMT. */
672 symtab_node::find_reference (symtab_node
*referred_node
,
673 gimple stmt
, unsigned int lto_stmt_uid
)
675 struct ipa_ref
*r
= NULL
;
678 for (i
= 0; iterate_reference (i
, r
); i
++)
679 if (r
->referred
== referred_node
681 && ((stmt
&& r
->stmt
== stmt
)
682 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
683 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
688 /* Remove all references that are associated with statement STMT. */
691 symtab_node::remove_stmt_references (gimple stmt
)
693 struct ipa_ref
*r
= NULL
;
696 while (iterate_reference (i
, r
))
698 r
->remove_reference ();
703 /* Remove all stmt references in non-speculative references.
704 Those are not maintained during inlining & clonning.
705 The exception are speculative references that are updated along
706 with callgraph edges associated with them. */
709 symtab_node::clear_stmts_in_references (void)
711 struct ipa_ref
*r
= NULL
;
714 for (i
= 0; iterate_reference (i
, r
); i
++)
722 /* Remove all references in ref list. */
725 symtab_node::remove_all_references (void)
727 while (vec_safe_length (ref_list
.references
))
728 ref_list
.references
->last ().remove_reference ();
729 vec_free (ref_list
.references
);
732 /* Remove all referring items in ref list. */
735 symtab_node::remove_all_referring (void)
737 while (ref_list
.referring
.length ())
738 ref_list
.referring
.last ()->remove_reference ();
739 ref_list
.referring
.release ();
742 /* Dump references in ref list to FILE. */
745 symtab_node::dump_references (FILE *file
)
747 struct ipa_ref
*ref
= NULL
;
749 for (i
= 0; iterate_reference (i
, ref
); i
++)
751 fprintf (file
, "%s/%i (%s)",
752 ref
->referred
->asm_name (),
753 ref
->referred
->order
,
754 ipa_ref_use_name
[ref
->use
]);
755 if (ref
->speculative
)
756 fprintf (file
, " (speculative)");
758 fprintf (file
, "\n");
761 /* Dump referring in list to FILE. */
764 symtab_node::dump_referring (FILE *file
)
766 struct ipa_ref
*ref
= NULL
;
768 for (i
= 0; iterate_referring(i
, ref
); i
++)
770 fprintf (file
, "%s/%i (%s)",
771 ref
->referring
->asm_name (),
772 ref
->referring
->order
,
773 ipa_ref_use_name
[ref
->use
]);
774 if (ref
->speculative
)
775 fprintf (file
, " (speculative)");
777 fprintf (file
, "\n");
780 /* Return true if list contains an alias. */
782 symtab_node::has_aliases_p (void)
784 struct ipa_ref
*ref
= NULL
;
787 for (i
= 0; iterate_referring (i
, ref
); i
++)
788 if (ref
->use
== IPA_REF_ALIAS
)
793 /* Iterates I-th reference in the list, REF is also set. */
796 symtab_node::iterate_reference (unsigned i
, struct ipa_ref
*&ref
)
798 vec_safe_iterate (ref_list
.references
, i
, &ref
);
803 /* Iterates I-th referring item in the list, REF is also set. */
806 symtab_node::iterate_referring (unsigned i
, struct ipa_ref
*&ref
)
808 ref_list
.referring
.iterate (i
, &ref
);
813 /* Iterates I-th referring alias item in the list, REF is also set. */
816 symtab_node::iterate_direct_aliases (unsigned i
, struct ipa_ref
*&ref
)
818 ref_list
.referring
.iterate (i
, &ref
);
820 if (ref
&& ref
->use
!= IPA_REF_ALIAS
)
827 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
829 /* Dump base fields of symtab nodes. Not to be used directly. */
832 dump_symtab_base (FILE *f
, symtab_node
*node
)
834 static const char * const visibility_types
[] = {
835 "default", "protected", "hidden", "internal"
838 fprintf (f
, "%s/%i (%s)",
842 dump_addr (f
, " @", (void *)node
);
843 fprintf (f
, "\n Type: %s", symtab_type_names
[node
->type
]);
845 if (node
->definition
)
846 fprintf (f
, " definition");
848 fprintf (f
, " analyzed");
850 fprintf (f
, " alias");
852 fprintf (f
, " weakref");
853 if (node
->cpp_implicit_alias
)
854 fprintf (f
, " cpp_implicit_alias");
855 if (node
->alias_target
)
856 fprintf (f
, " target:%s",
857 DECL_P (node
->alias_target
)
858 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
859 (node
->alias_target
))
860 : IDENTIFIER_POINTER (node
->alias_target
));
861 if (node
->body_removed
)
862 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
863 fprintf (f
, "\n Visibility:");
864 if (node
->in_other_partition
)
865 fprintf (f
, " in_other_partition");
866 if (node
->used_from_other_partition
)
867 fprintf (f
, " used_from_other_partition");
868 if (node
->force_output
)
869 fprintf (f
, " force_output");
870 if (node
->forced_by_abi
)
871 fprintf (f
, " forced_by_abi");
872 if (node
->externally_visible
)
873 fprintf (f
, " externally_visible");
874 if (node
->resolution
!= LDPR_UNKNOWN
)
876 ld_plugin_symbol_resolution_names
[(int)node
->resolution
]);
877 if (TREE_ASM_WRITTEN (node
->decl
))
878 fprintf (f
, " asm_written");
879 if (DECL_EXTERNAL (node
->decl
))
880 fprintf (f
, " external");
881 if (TREE_PUBLIC (node
->decl
))
882 fprintf (f
, " public");
883 if (DECL_COMMON (node
->decl
))
884 fprintf (f
, " common");
885 if (DECL_WEAK (node
->decl
))
886 fprintf (f
, " weak");
887 if (DECL_DLLIMPORT_P (node
->decl
))
888 fprintf (f
, " dll_import");
889 if (DECL_COMDAT (node
->decl
))
890 fprintf (f
, " comdat");
891 if (node
->get_comdat_group ())
892 fprintf (f
, " comdat_group:%s",
893 IDENTIFIER_POINTER (node
->get_comdat_group_id ()));
894 if (DECL_ONE_ONLY (node
->decl
))
895 fprintf (f
, " one_only");
896 if (node
->get_section ())
897 fprintf (f
, " section:%s",
898 node
->get_section ());
899 if (node
->implicit_section
)
900 fprintf (f
," (implicit_section)");
901 if (DECL_VISIBILITY_SPECIFIED (node
->decl
))
902 fprintf (f
, " visibility_specified");
903 if (DECL_VISIBILITY (node
->decl
))
904 fprintf (f
, " visibility:%s",
905 visibility_types
[DECL_VISIBILITY (node
->decl
)]);
906 if (DECL_VIRTUAL_P (node
->decl
))
907 fprintf (f
, " virtual");
908 if (DECL_ARTIFICIAL (node
->decl
))
909 fprintf (f
, " artificial");
910 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
912 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
913 fprintf (f
, " constructor");
914 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
915 fprintf (f
, " destructor");
919 if (node
->same_comdat_group
)
920 fprintf (f
, " Same comdat group as: %s/%i\n",
921 node
->same_comdat_group
->asm_name (),
922 node
->same_comdat_group
->order
);
923 if (node
->next_sharing_asm_name
)
924 fprintf (f
, " next sharing asm name: %i\n",
925 node
->next_sharing_asm_name
->order
);
926 if (node
->previous_sharing_asm_name
)
927 fprintf (f
, " previous sharing asm name: %i\n",
928 node
->previous_sharing_asm_name
->order
);
930 if (node
->address_taken
)
931 fprintf (f
, " Address is taken.\n");
934 fprintf (f
, " Aux:");
935 dump_addr (f
, " @", (void *)node
->aux
);
938 fprintf (f
, " References: ");
939 node
->dump_references (f
);
940 fprintf (f
, " Referring: ");
941 node
->dump_referring (f
);
942 if (node
->lto_file_data
)
943 fprintf (f
, " Read from file: %s\n",
944 node
->lto_file_data
->file_name
);
947 /* Dump symtab node. */
950 dump_symtab_node (FILE *f
, symtab_node
*node
)
952 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
953 dump_cgraph_node (f
, cnode
);
954 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
955 dump_varpool_node (f
, vnode
);
958 /* Dump symbol table. */
961 dump_symtab (FILE *f
)
964 fprintf (f
, "Symbol table:\n\n");
965 FOR_EACH_SYMBOL (node
)
966 dump_symtab_node (f
, node
);
969 /* Dump symtab node NODE to stderr. */
972 debug_symtab_node (symtab_node
*node
)
974 dump_symtab_node (stderr
, node
);
977 /* Dump symbol table to stderr. */
982 dump_symtab (stderr
);
985 /* Verify common part of symtab nodes. */
988 verify_symtab_base (symtab_node
*node
)
990 bool error_found
= false;
991 symtab_node
*hashed_node
;
993 if (is_a
<cgraph_node
*> (node
))
995 if (TREE_CODE (node
->decl
) != FUNCTION_DECL
)
997 error ("function symbol is not function");
1001 else if (is_a
<varpool_node
*> (node
))
1003 if (TREE_CODE (node
->decl
) != VAR_DECL
)
1005 error ("variable symbol is not variable");
1011 error ("node has unknown type");
1015 if (cgraph_state
!= CGRAPH_LTO_STREAMING
)
1017 hashed_node
= symtab_get_node (node
->decl
);
1020 error ("node not found node->decl->decl_with_vis.symtab_node");
1023 if (hashed_node
!= node
1024 && (!is_a
<cgraph_node
*> (node
)
1025 || !dyn_cast
<cgraph_node
*> (node
)->clone_of
1026 || dyn_cast
<cgraph_node
*> (node
)->clone_of
->decl
1029 error ("node differs from node->decl->decl_with_vis.symtab_node");
1033 if (assembler_name_hash
)
1035 hashed_node
= symtab_node_for_asm (DECL_ASSEMBLER_NAME (node
->decl
));
1036 if (hashed_node
&& hashed_node
->previous_sharing_asm_name
)
1038 error ("assembler name hash list corrupted");
1043 if (hashed_node
== node
)
1045 hashed_node
= hashed_node
->next_sharing_asm_name
;
1048 && !(is_a
<varpool_node
*> (node
)
1049 || DECL_HARD_REGISTER (node
->decl
)))
1051 error ("node not found in symtab assembler name hash");
1055 if (node
->previous_sharing_asm_name
1056 && node
->previous_sharing_asm_name
->next_sharing_asm_name
!= node
)
1058 error ("double linked list of assembler names corrupted");
1061 if (node
->analyzed
&& !node
->definition
)
1063 error ("node is analyzed byt it is not a definition");
1066 if (node
->cpp_implicit_alias
&& !node
->alias
)
1068 error ("node is alias but not implicit alias");
1071 if (node
->alias
&& !node
->definition
1074 error ("node is alias but not definition");
1077 if (node
->weakref
&& !node
->alias
)
1079 error ("node is weakref but not an alias");
1082 if (node
->same_comdat_group
)
1084 symtab_node
*n
= node
->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 () != node
->get_comdat_group ())
1093 error ("same_comdat_group list across different groups");
1098 error ("Node has same_comdat_group but it is not a definition");
1101 if (n
->type
!= node
->type
)
1103 error ("mixing different types of symbol in same comdat groups is not supported");
1108 error ("node is alone in a comdat group");
1113 if (!n
->same_comdat_group
)
1115 error ("same_comdat_group is not a circular list");
1119 n
= n
->same_comdat_group
;
1122 if (symtab_comdat_local_p (node
))
1124 struct ipa_ref
*ref
= NULL
;
1126 for (int i
= 0; node
->iterate_referring (i
, ref
); ++i
)
1128 if (!symtab_in_same_comdat_p (ref
->referring
, node
))
1130 error ("comdat-local symbol referred to by %s outside its "
1132 identifier_to_locale (ref
->referring
->name()));
1138 if (node
->implicit_section
&& !node
->get_section ())
1140 error ("implicit_section flag is set but section isn't");
1143 if (node
->get_section () && node
->get_comdat_group ()
1144 && !node
->implicit_section
)
1146 error ("Both section and comdat group is set");
1149 /* TODO: Add string table for sections, so we do not keep holding duplicated
1151 if (node
->alias
&& node
->definition
1152 && node
->get_section () != symtab_alias_target (node
)->get_section ()
1153 && (!node
->get_section()
1154 || !symtab_alias_target (node
)->get_section ()
1155 || strcmp (node
->get_section(),
1156 symtab_alias_target (node
)->get_section ())))
1158 error ("Alias and target's section differs");
1159 dump_symtab_node (stderr
, symtab_alias_target (node
));
1162 if (node
->alias
&& node
->definition
1163 && node
->get_comdat_group () != symtab_alias_target (node
)->get_comdat_group ())
1165 error ("Alias and target's comdat groups differs");
1166 dump_symtab_node (stderr
, symtab_alias_target (node
));
1173 /* Verify consistency of NODE. */
1176 verify_symtab_node (symtab_node
*node
)
1181 timevar_push (TV_CGRAPH_VERIFY
);
1182 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1183 verify_cgraph_node (cnode
);
1185 if (verify_symtab_base (node
))
1187 dump_symtab_node (stderr
, node
);
1188 internal_error ("verify_symtab_node failed");
1190 timevar_pop (TV_CGRAPH_VERIFY
);
1193 /* Verify symbol table for internal consistency. */
1196 verify_symtab (void)
1199 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1201 FOR_EACH_SYMBOL (node
)
1203 verify_symtab_node (node
);
1204 if (node
->get_comdat_group ())
1206 symtab_node
**entry
, *s
;
1209 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1214 for (s
= (*entry
)->same_comdat_group
; s
!= NULL
&& s
!= node
; s
= s
->same_comdat_group
)
1215 if (!s
|| s
== *entry
)
1217 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1218 dump_symtab_node (stderr
, *entry
);
1219 dump_symtab_node (stderr
, s
);
1220 internal_error ("verify_symtab failed");
1226 /* Return true when RESOLUTION indicate that linker will use
1227 the symbol from non-LTO object files. */
1230 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
1232 return (resolution
== LDPR_PREVAILING_DEF
1233 || resolution
== LDPR_PREEMPTED_REG
1234 || resolution
== LDPR_RESOLVED_EXEC
1235 || resolution
== LDPR_RESOLVED_DYN
);
1238 /* Return true when NODE is known to be used from other (non-LTO) object file.
1239 Known only when doing LTO via linker plugin. */
1242 symtab_used_from_object_file_p (symtab_node
*node
)
1244 if (!TREE_PUBLIC (node
->decl
) || DECL_EXTERNAL (node
->decl
))
1246 if (resolution_used_from_other_file_p (node
->resolution
))
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_make_decl_local (tree decl
)
1259 /* Avoid clearing comdat_groups on comdat-local decls. */
1260 if (TREE_PUBLIC (decl
) == 0)
1263 if (TREE_CODE (decl
) == VAR_DECL
)
1264 DECL_COMMON (decl
) = 0;
1265 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1267 DECL_COMDAT (decl
) = 0;
1268 DECL_WEAK (decl
) = 0;
1269 DECL_EXTERNAL (decl
) = 0;
1270 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1271 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1272 TREE_PUBLIC (decl
) = 0;
1273 if (!DECL_RTL_SET_P (decl
))
1276 /* Update rtl flags. */
1277 make_decl_rtl (decl
);
1279 rtl
= DECL_RTL (decl
);
1283 symbol
= XEXP (rtl
, 0);
1284 if (GET_CODE (symbol
) != SYMBOL_REF
)
1287 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1290 /* Return availability of NODE. */
1293 symtab_node_availability (symtab_node
*node
)
1295 if (is_a
<cgraph_node
*> (node
))
1296 return cgraph_function_body_availability (cgraph (node
));
1298 return cgraph_variable_initializer_availability (varpool (node
));
1301 /* Given NODE, walk the alias chain to return the symbol NODE is alias of.
1302 If NODE is not an alias, return NODE.
1303 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1306 symtab_alias_ultimate_target (symtab_node
*node
, enum availability
*availability
)
1308 bool weakref_p
= false;
1313 *availability
= symtab_node_availability (node
);
1317 /* To determine visibility of the target, we follow ELF semantic of aliases.
1318 Here alias is an alternative assembler name of a given definition. Its
1319 availability prevails the availability of its target (i.e. static alias of
1320 weak definition is available.
1322 Weakref is a different animal (and not part of ELF per se). It is just
1323 alternative name of a given symbol used within one complation unit
1324 and is translated prior hitting the object file. It inherits the
1325 visibility of its target (i.e. weakref of non-overwritable definition
1326 is non-overwritable, while weakref of weak definition is weak).
1328 If we ever get into supporting targets with different semantics, a target
1329 hook will be needed here. */
1333 weakref_p
= node
->weakref
;
1335 *availability
= symtab_node_availability (node
);
1337 *availability
= AVAIL_LOCAL
;
1341 if (node
->alias
&& node
->analyzed
)
1342 node
= symtab_alias_target (node
);
1347 else if (node
->analyzed
)
1351 enum availability a
= symtab_node_availability (node
);
1352 if (a
< *availability
)
1357 *availability
= AVAIL_NOT_AVAILABLE
;
1360 if (node
&& availability
&& weakref_p
)
1362 enum availability a
= symtab_node_availability (node
);
1363 if (a
< *availability
)
1365 weakref_p
= node
->weakref
;
1369 *availability
= AVAIL_NOT_AVAILABLE
;
1373 /* C++ FE sometimes change linkage flags after producing same body aliases.
1375 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1376 are obviously equivalent. The way it is doing so is however somewhat
1377 kludgy and interferes with the visibility code. As a result we need to
1378 copy the visibility from the target to get things right. */
1381 fixup_same_cpp_alias_visibility (symtab_node
*node
, symtab_node
*target
)
1383 if (is_a
<cgraph_node
*> (node
))
1385 DECL_DECLARED_INLINE_P (node
->decl
)
1386 = DECL_DECLARED_INLINE_P (target
->decl
);
1387 DECL_DISREGARD_INLINE_LIMITS (node
->decl
)
1388 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1390 /* FIXME: It is not really clear why those flags should not be copied for
1394 DECL_WEAK (node
->decl
) = DECL_WEAK (target
->decl
);
1395 DECL_EXTERNAL (node
->decl
) = DECL_EXTERNAL (target
->decl
);
1396 DECL_VISIBILITY (node
->decl
) = DECL_VISIBILITY (target
->decl
);
1398 DECL_VIRTUAL_P (node
->decl
) = DECL_VIRTUAL_P (target
->decl
);
1399 if (TREE_PUBLIC (node
->decl
))
1403 DECL_EXTERNAL (node
->decl
) = DECL_EXTERNAL (target
->decl
);
1404 DECL_COMDAT (node
->decl
) = DECL_COMDAT (target
->decl
);
1405 group
= target
->get_comdat_group ();
1406 node
->set_comdat_group (group
);
1408 && !node
->same_comdat_group
)
1409 symtab_add_to_same_comdat_group (node
, target
);
1411 node
->externally_visible
= target
->externally_visible
;
1414 /* Hash sections by their names. */
1417 hash_section_hash_entry (const void *p
)
1419 const section_hash_entry
*n
= (const section_hash_entry
*) p
;
1420 return htab_hash_string (n
->name
);
1423 /* Return true if section P1 name equals to P2. */
1426 eq_sections (const void *p1
, const void *p2
)
1428 const section_hash_entry
*n1
= (const section_hash_entry
*) p1
;
1429 const char *name
= (const char *)p2
;
1430 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
1433 /* Set section, do not recurse into aliases.
1434 When one wants to change section of symbol and its aliases,
1438 symtab_node::set_section_for_node (const char *section
)
1440 const char *current
= get_section ();
1443 if (current
== section
1444 || (current
&& section
1445 && !strcmp (current
, section
)))
1450 x_section
->ref_count
--;
1451 if (!x_section
->ref_count
)
1453 slot
= htab_find_slot_with_hash (section_hash
, x_section
->name
,
1454 htab_hash_string (x_section
->name
),
1456 ggc_free (x_section
);
1457 htab_clear_slot (section_hash
, slot
);
1463 implicit_section
= false;
1467 section_hash
= htab_create_ggc (10, hash_section_hash_entry
,
1469 slot
= htab_find_slot_with_hash (section_hash
, section
,
1470 htab_hash_string (section
),
1473 x_section
= (section_hash_entry
*)*slot
;
1476 int len
= strlen (section
);
1477 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1478 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1479 memcpy (x_section
->name
, section
, len
+ 1);
1481 x_section
->ref_count
++;
1484 /* Worker for set_section. */
1487 set_section_1 (struct symtab_node
*n
, void *s
)
1489 n
->set_section_for_node ((char *)s
);
1493 /* Set section of symbol and its aliases. */
1496 symtab_node::set_section (const char *section
)
1498 gcc_assert (!this->alias
);
1499 symtab_for_node_and_aliases (this, set_section_1
, const_cast<char *>(section
), true);
1502 /* Return the initialization priority. */
1505 symtab_node::get_init_priority ()
1507 struct symbol_priority_map
*h
;
1508 struct symbol_priority_map in
;
1510 if (!this->in_init_priority_hash
)
1511 return DEFAULT_INIT_PRIORITY
;
1513 h
= (struct symbol_priority_map
*) htab_find (init_priority_hash
, &in
);
1514 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1517 /* Return the finalization priority. */
1520 cgraph_node::get_fini_priority ()
1522 struct symbol_priority_map
*h
;
1523 struct symbol_priority_map in
;
1525 if (!this->in_init_priority_hash
)
1526 return DEFAULT_INIT_PRIORITY
;
1528 h
= (struct symbol_priority_map
*) htab_find (init_priority_hash
, &in
);
1529 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1532 /* Return true if the from tree in both priority maps are equal. */
1535 symbol_priority_map_eq (const void *va
, const void *vb
)
1537 const struct symbol_priority_map
*const a
= (const struct symbol_priority_map
*) va
,
1538 *const b
= (const struct symbol_priority_map
*) vb
;
1539 return (a
->symbol
== b
->symbol
);
1542 /* Hash a from symbol in a symbol_priority_map. */
1545 symbol_priority_map_hash (const void *item
)
1547 return htab_hash_pointer (((const struct symbol_priority_map
*)item
)->symbol
);
1550 /* Return the initialization and finalization priority information for
1551 DECL. If there is no previous priority information, a freshly
1552 allocated structure is returned. */
1554 static struct symbol_priority_map
*
1555 symbol_priority_info (struct symtab_node
*symbol
)
1557 struct symbol_priority_map in
;
1558 struct symbol_priority_map
*h
;
1562 if (!init_priority_hash
)
1563 init_priority_hash
= htab_create_ggc (512, symbol_priority_map_hash
,
1564 symbol_priority_map_eq
, 0);
1566 loc
= htab_find_slot (init_priority_hash
, &in
, INSERT
);
1567 h
= (struct symbol_priority_map
*) *loc
;
1570 h
= ggc_cleared_alloc
<symbol_priority_map
> ();
1573 h
->init
= DEFAULT_INIT_PRIORITY
;
1574 h
->fini
= DEFAULT_INIT_PRIORITY
;
1575 symbol
->in_init_priority_hash
= true;
1581 /* Set initialization priority to PRIORITY. */
1584 symtab_node::set_init_priority (priority_type priority
)
1586 struct symbol_priority_map
*h
;
1588 if (is_a
<cgraph_node
*> (this))
1589 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1591 if (priority
== DEFAULT_INIT_PRIORITY
)
1593 gcc_assert (get_init_priority() == priority
);
1596 h
= symbol_priority_info (this);
1600 /* Set fialization priority to PRIORITY. */
1603 cgraph_node::set_fini_priority (priority_type priority
)
1605 struct symbol_priority_map
*h
;
1607 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1609 if (priority
== DEFAULT_INIT_PRIORITY
)
1611 gcc_assert (get_fini_priority() == priority
);
1614 h
= symbol_priority_info (this);
1618 /* Worker for symtab_resolve_alias. */
1621 set_implicit_section (struct symtab_node
*n
, void *data ATTRIBUTE_UNUSED
)
1623 n
->implicit_section
= true;
1627 /* Add reference recording that NODE is alias of TARGET.
1628 The function can fail in the case of aliasing cycles; in this case
1629 it returns false. */
1632 symtab_resolve_alias (symtab_node
*node
, symtab_node
*target
)
1636 gcc_assert (!node
->analyzed
1637 && !vec_safe_length (node
->ref_list
.references
));
1639 /* Never let cycles to creep into the symbol table alias references;
1640 those will make alias walkers to be infinite. */
1641 for (n
= target
; n
&& n
->alias
;
1642 n
= n
->analyzed
? symtab_alias_target (n
) : NULL
)
1645 if (is_a
<cgraph_node
*> (node
))
1646 error ("function %q+D part of alias cycle", node
->decl
);
1647 else if (is_a
<varpool_node
*> (node
))
1648 error ("variable %q+D part of alias cycle", node
->decl
);
1651 node
->alias
= false;
1655 /* "analyze" the node - i.e. mark the reference. */
1656 node
->definition
= true;
1658 node
->analyzed
= true;
1659 node
->add_reference (target
, IPA_REF_ALIAS
, NULL
);
1661 /* Add alias into the comdat group of its target unless it is already there. */
1662 if (node
->same_comdat_group
)
1663 symtab_remove_from_same_comdat_group (node
);
1664 node
->set_comdat_group (NULL
);
1665 if (target
->get_comdat_group ())
1666 symtab_add_to_same_comdat_group (node
, target
);
1668 if ((node
->get_section () != target
->get_section ()
1669 || target
->get_comdat_group ())
1670 && node
->get_section () && !node
->implicit_section
)
1672 error ("section of alias %q+D must match section of its target",
1675 symtab_for_node_and_aliases (node
, set_section_1
,
1676 const_cast<char *>(target
->get_section ()), true);
1677 if (target
->implicit_section
)
1678 symtab_for_node_and_aliases (node
,
1679 set_implicit_section
, NULL
, true);
1681 /* Alias targets become redundant after alias is resolved into an reference.
1682 We do not want to keep it around or we would have to mind updating them
1683 when renaming symbols. */
1684 node
->alias_target
= NULL
;
1686 if (node
->cpp_implicit_alias
&& cgraph_state
>= CGRAPH_STATE_CONSTRUCTION
)
1687 fixup_same_cpp_alias_visibility (node
, target
);
1689 /* If alias has address taken, so does the target. */
1690 if (node
->address_taken
)
1691 symtab_alias_ultimate_target (target
, NULL
)->address_taken
= true;
1695 /* Call calback on NODE and aliases associated to NODE.
1696 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1700 symtab_for_node_and_aliases (symtab_node
*node
,
1701 bool (*callback
) (symtab_node
*, void *),
1703 bool include_overwritable
)
1706 struct ipa_ref
*ref
;
1708 if (callback (node
, data
))
1710 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
1711 if (ref
->use
== IPA_REF_ALIAS
)
1713 symtab_node
*alias
= ref
->referring
;
1714 if (include_overwritable
1715 || symtab_node_availability (alias
) > AVAIL_OVERWRITABLE
)
1716 if (symtab_for_node_and_aliases (alias
, callback
, data
,
1717 include_overwritable
))
1723 /* Worker searching nonoverwritable alias. */
1726 symtab_nonoverwritable_alias_1 (symtab_node
*node
, void *data
)
1728 if (decl_binds_to_current_def_p (node
->decl
))
1730 *(symtab_node
**)data
= node
;
1736 /* If NODE can not be overwriten by static or dynamic linker to point to different
1737 definition, return NODE. Otherwise look for alias with such property and if
1738 none exists, introduce new one. */
1741 symtab_nonoverwritable_alias (symtab_node
*node
)
1744 symtab_node
*new_node
= NULL
;
1746 /* First try to look up existing alias or base object
1747 (if that is already non-overwritable). */
1748 node
= symtab_alias_ultimate_target (node
, NULL
);
1749 gcc_assert (!node
->alias
&& !node
->weakref
);
1750 symtab_for_node_and_aliases (node
, symtab_nonoverwritable_alias_1
,
1751 (void *)&new_node
, true);
1754 #ifndef ASM_OUTPUT_DEF
1755 /* If aliases aren't supported by the assembler, fail. */
1759 /* Otherwise create a new one. */
1760 new_decl
= copy_node (node
->decl
);
1761 DECL_NAME (new_decl
) = clone_function_name (node
->decl
, "localalias");
1762 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1763 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1764 DECL_INITIAL (new_decl
) = NULL
;
1765 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1766 SET_DECL_RTL (new_decl
, NULL
);
1768 /* Update the properties. */
1769 DECL_EXTERNAL (new_decl
) = 0;
1770 TREE_PUBLIC (new_decl
) = 0;
1771 DECL_COMDAT (new_decl
) = 0;
1772 DECL_WEAK (new_decl
) = 0;
1774 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1775 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1776 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1778 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1779 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1780 new_node
= cgraph_create_function_alias
1781 (new_decl
, node
->decl
);
1785 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
1786 DECL_INITIAL (new_decl
) = error_mark_node
;
1787 new_node
= varpool_create_variable_alias (new_decl
, node
->decl
);
1789 symtab_resolve_alias (new_node
, node
);
1790 gcc_assert (decl_binds_to_current_def_p (new_decl
)
1791 && targetm
.binds_local_p (new_decl
));
1795 /* Return true if A and B represents semantically equivalent symbols. */
1798 symtab_semantically_equivalent_p (symtab_node
*a
,
1801 enum availability avail
;
1805 /* Equivalent functions are equivalent. */
1806 if (a
->decl
== b
->decl
)
1809 /* If symbol is not overwritable by different implementation,
1810 walk to the base object it defines. */
1811 ba
= symtab_alias_ultimate_target (a
, &avail
);
1812 if (avail
>= AVAIL_AVAILABLE
)
1819 bb
= symtab_alias_ultimate_target (b
, &avail
);
1820 if (avail
>= AVAIL_AVAILABLE
)
1830 /* Classify symbol NODE for partitioning. */
1832 enum symbol_partitioning_class
1833 symtab_get_symbol_partitioning_class (symtab_node
*node
)
1835 /* Inline clones are always duplicated.
1836 This include external delcarations. */
1837 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1839 if (DECL_ABSTRACT (node
->decl
))
1840 return SYMBOL_EXTERNAL
;
1842 if (cnode
&& cnode
->global
.inlined_to
)
1843 return SYMBOL_DUPLICATE
;
1845 /* Weakref aliases are always duplicated. */
1847 return SYMBOL_DUPLICATE
;
1849 /* External declarations are external. */
1850 if (DECL_EXTERNAL (node
->decl
))
1851 return SYMBOL_EXTERNAL
;
1853 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
1855 /* Constant pool references use local symbol names that can not
1856 be promoted global. We should never put into a constant pool
1857 objects that can not be duplicated across partitions. */
1858 if (DECL_IN_CONSTANT_POOL (node
->decl
))
1859 return SYMBOL_DUPLICATE
;
1860 gcc_checking_assert (vnode
->definition
);
1862 /* Functions that are cloned may stay in callgraph even if they are unused.
1863 Handle them as external; compute_ltrans_boundary take care to make
1864 proper things to happen (i.e. to make them appear in the boundary but
1865 with body streamed, so clone can me materialized). */
1866 else if (!cgraph (node
)->definition
)
1867 return SYMBOL_EXTERNAL
;
1869 /* Linker discardable symbols are duplicated to every use unless they are
1871 if (DECL_ONE_ONLY (node
->decl
)
1872 && !node
->force_output
1873 && !node
->forced_by_abi
1874 && !symtab_used_from_object_file_p (node
))
1875 return SYMBOL_DUPLICATE
;
1877 return SYMBOL_PARTITION
;
1879 #include "gt-symtab.h"