2 Copyright (C) 2012-2021 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
31 #include "lto-streamer.h"
32 #include "print-tree.h"
34 #include "langhooks.h"
36 #include "ipa-utils.h"
38 #include "stringpool.h"
42 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias"};
44 const char * const ld_plugin_symbol_resolution_names
[]=
49 "prevailing_def_ironly",
55 "prevailing_def_ironly_exp"
58 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at ALIAS
59 until we find an identifier that is not itself a transparent alias. */
62 ultimate_transparent_alias_target (tree alias
)
66 while (IDENTIFIER_TRANSPARENT_ALIAS (target
))
68 gcc_checking_assert (TREE_CHAIN (target
));
69 target
= TREE_CHAIN (target
);
71 gcc_checking_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
72 && ! TREE_CHAIN (target
));
78 /* Hash asmnames ignoring the user specified marks. */
81 symbol_table::decl_assembler_name_hash (const_tree asmname
)
83 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
85 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
86 size_t ulp_len
= strlen (user_label_prefix
);
90 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
93 return htab_hash_string (decl_str
);
96 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
99 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
103 symbol_table::assembler_names_equal_p (const char *name1
, const char *name2
)
109 size_t ulp_len
= strlen (user_label_prefix
);
115 else if (strncmp (name1
, user_label_prefix
, ulp_len
) == 0)
122 size_t ulp_len
= strlen (user_label_prefix
);
128 else if (strncmp (name2
, user_label_prefix
, ulp_len
) == 0)
133 return !strcmp (name1
, name2
);
138 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
141 symbol_table::decl_assembler_name_equal (tree decl
, const_tree asmname
)
143 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
144 const char *decl_str
;
145 const char *asmname_str
;
147 if (decl_asmname
== asmname
)
150 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
151 asmname_str
= IDENTIFIER_POINTER (asmname
);
152 return assembler_names_equal_p (decl_str
, asmname_str
);
156 /* Returns nonzero if P1 and P2 are equal. */
158 /* Insert NODE to assembler name hash. */
161 symbol_table::insert_to_assembler_name_hash (symtab_node
*node
,
164 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
166 gcc_checking_assert (!node
->previous_sharing_asm_name
167 && !node
->next_sharing_asm_name
);
168 if (assembler_name_hash
)
172 tree decl
= node
->decl
;
174 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
176 /* C++ FE can produce decls without associated assembler name and insert
177 them to symtab to hold section or TLS information. */
181 hashval_t hash
= decl_assembler_name_hash (name
);
182 aslot
= assembler_name_hash
->find_slot_with_hash (name
, hash
, INSERT
);
183 gcc_assert (*aslot
!= node
);
184 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
186 (*aslot
)->previous_sharing_asm_name
= node
;
189 /* Update also possible inline clones sharing a decl. */
190 cnode
= dyn_cast
<cgraph_node
*> (node
);
191 if (cnode
&& cnode
->clones
&& with_clones
)
192 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
193 if (cnode
->decl
== decl
)
194 insert_to_assembler_name_hash (cnode
, true);
199 /* Remove NODE from assembler name hash. */
202 symbol_table::unlink_from_assembler_name_hash (symtab_node
*node
,
205 if (assembler_name_hash
)
208 tree decl
= node
->decl
;
210 if (node
->next_sharing_asm_name
)
211 node
->next_sharing_asm_name
->previous_sharing_asm_name
212 = node
->previous_sharing_asm_name
;
213 if (node
->previous_sharing_asm_name
)
215 node
->previous_sharing_asm_name
->next_sharing_asm_name
216 = node
->next_sharing_asm_name
;
220 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
226 hashval_t hash
= decl_assembler_name_hash (name
);
227 slot
= assembler_name_hash
->find_slot_with_hash (name
, hash
,
229 gcc_assert (*slot
== node
);
230 if (!node
->next_sharing_asm_name
)
231 assembler_name_hash
->clear_slot (slot
);
233 *slot
= node
->next_sharing_asm_name
;
235 node
->next_sharing_asm_name
= NULL
;
236 node
->previous_sharing_asm_name
= NULL
;
238 /* Update also possible inline clones sharing a decl. */
239 cnode
= dyn_cast
<cgraph_node
*> (node
);
240 if (cnode
&& cnode
->clones
&& with_clones
)
241 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
242 if (cnode
->decl
== decl
)
243 unlink_from_assembler_name_hash (cnode
, true);
247 /* Arrange node to be first in its entry of assembler_name_hash. */
250 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node
*node
)
252 unlink_from_assembler_name_hash (node
, false);
253 insert_to_assembler_name_hash (node
, false);
256 /* Initialize asm name hash unless. */
259 symbol_table::symtab_initialize_asm_name_hash (void)
262 if (!assembler_name_hash
)
264 assembler_name_hash
= hash_table
<asmname_hasher
>::create_ggc (10);
265 FOR_EACH_SYMBOL (node
)
266 insert_to_assembler_name_hash (node
, false);
270 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
273 symbol_table::change_decl_assembler_name (tree decl
, tree name
)
275 symtab_node
*node
= NULL
;
277 /* We can have user ASM names on things, like global register variables, that
278 are not in the symbol table. */
279 if ((VAR_P (decl
) && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
280 || TREE_CODE (decl
) == FUNCTION_DECL
)
281 node
= symtab_node::get (decl
);
282 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
284 SET_DECL_ASSEMBLER_NAME (decl
, name
);
286 insert_to_assembler_name_hash (node
, true);
290 if (name
== DECL_ASSEMBLER_NAME (decl
))
293 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
294 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
297 unlink_from_assembler_name_hash (node
, true);
299 const char *old_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
300 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
301 && DECL_RTL_SET_P (decl
))
302 warning (0, "%qD renamed after being referenced in assembly", decl
);
304 SET_DECL_ASSEMBLER_NAME (decl
, name
);
307 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
308 TREE_CHAIN (name
) = alias
;
310 /* If we change assembler name, also all transparent aliases must
311 be updated. There are three kinds - those having same assembler name,
312 those being renamed in varasm.c and weakref being renamed by the
316 insert_to_assembler_name_hash (node
, true);
318 for (unsigned i
= 0; node
->iterate_direct_aliases (i
, ref
); i
++)
320 struct symtab_node
*alias
= ref
->referring
;
321 if (alias
->transparent_alias
&& !alias
->weakref
322 && symbol_table::assembler_names_equal_p
323 (old_name
, IDENTIFIER_POINTER (
324 DECL_ASSEMBLER_NAME (alias
->decl
))))
325 change_decl_assembler_name (alias
->decl
, name
);
326 else if (alias
->transparent_alias
327 && IDENTIFIER_TRANSPARENT_ALIAS (alias
->decl
))
329 gcc_assert (TREE_CHAIN (DECL_ASSEMBLER_NAME (alias
->decl
))
330 && IDENTIFIER_TRANSPARENT_ALIAS
331 (DECL_ASSEMBLER_NAME (alias
->decl
)));
333 TREE_CHAIN (DECL_ASSEMBLER_NAME (alias
->decl
)) =
334 ultimate_transparent_alias_target
335 (DECL_ASSEMBLER_NAME (node
->decl
));
337 #ifdef ASM_OUTPUT_WEAKREF
338 else gcc_assert (!alias
->transparent_alias
|| alias
->weakref
);
340 else gcc_assert (!alias
->transparent_alias
);
343 gcc_assert (!node
->transparent_alias
|| !node
->definition
345 || TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
346 || symbol_table::assembler_names_equal_p
347 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
350 (node
->get_alias_target ()->decl
))));
355 /* Hash sections by their names. */
358 section_name_hasher::hash (section_hash_entry
*n
)
360 return htab_hash_string (n
->name
);
363 /* Return true if section P1 name equals to P2. */
366 section_name_hasher::equal (section_hash_entry
*n1
, const char *name
)
368 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
371 /* Bump the reference count on ENTRY so that it is retained. */
373 static section_hash_entry
*
374 retain_section_hash_entry (section_hash_entry
*entry
)
380 /* Drop the reference count on ENTRY and remove it if the reference
381 count drops to zero. */
384 release_section_hash_entry (section_hash_entry
*entry
)
389 if (!entry
->ref_count
)
391 hashval_t hash
= htab_hash_string (entry
->name
);
392 section_hash_entry
**slot
393 = symtab
->section_hash
->find_slot_with_hash (entry
->name
,
396 symtab
->section_hash
->clear_slot (slot
);
401 /* Add node into symbol table. This function is not used directly, but via
402 cgraph/varpool node creation routines. */
405 symtab_node::register_symbol (void)
407 symtab
->register_symbol (this);
409 if (!decl
->decl_with_vis
.symtab_node
)
410 decl
->decl_with_vis
.symtab_node
= this;
414 /* Be sure to do this last; C++ FE might create new nodes via
415 DECL_ASSEMBLER_NAME langhook! */
416 symtab
->insert_to_assembler_name_hash (this, false);
419 /* Remove NODE from same comdat group. */
422 symtab_node::remove_from_same_comdat_group (void)
424 if (same_comdat_group
)
427 for (prev
= same_comdat_group
;
428 prev
->same_comdat_group
!= this;
429 prev
= prev
->same_comdat_group
)
431 if (same_comdat_group
== prev
)
432 prev
->same_comdat_group
= NULL
;
434 prev
->same_comdat_group
= same_comdat_group
;
435 same_comdat_group
= NULL
;
436 set_comdat_group (NULL
);
440 /* Remove node from symbol table. This function is not used directly, but via
441 cgraph/varpool node removal routines.
442 INFO is a clone info to attach to new root of clone tree (if any). */
445 symtab_node::unregister (clone_info
*info
)
447 remove_all_references ();
448 remove_all_referring ();
450 /* Remove reference to section. */
451 set_section_for_node (NULL
);
453 remove_from_same_comdat_group ();
455 symtab
->unregister (this);
457 /* During LTO symtab merging we temporarily corrupt decl to symtab node
459 gcc_assert (decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
460 if (decl
->decl_with_vis
.symtab_node
== this)
462 symtab_node
*replacement_node
= NULL
;
463 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
464 replacement_node
= cnode
->find_replacement (info
);
465 decl
->decl_with_vis
.symtab_node
= replacement_node
;
467 if (!is_a
<varpool_node
*> (this) || !DECL_HARD_REGISTER (decl
))
468 symtab
->unlink_from_assembler_name_hash (this, false);
469 if (in_init_priority_hash
)
470 symtab
->init_priority_hash
->remove (this);
474 /* Remove symbol from symbol table. */
477 symtab_node::remove (void)
479 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
481 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
485 /* Add NEW_ to the same comdat group that OLD is in. */
488 symtab_node::add_to_same_comdat_group (symtab_node
*old_node
)
490 gcc_assert (old_node
->get_comdat_group ());
491 gcc_assert (!same_comdat_group
);
492 gcc_assert (this != old_node
);
494 set_comdat_group (old_node
->get_comdat_group ());
495 same_comdat_group
= old_node
;
496 if (!old_node
->same_comdat_group
)
497 old_node
->same_comdat_group
= this;
501 for (n
= old_node
->same_comdat_group
;
502 n
->same_comdat_group
!= old_node
;
503 n
= n
->same_comdat_group
)
505 n
->same_comdat_group
= this;
509 if (comdat_local_p ()
510 && (n
= dyn_cast
<cgraph_node
*> (this)) != NULL
)
512 for (cgraph_edge
*e
= n
->callers
; e
; e
= e
->next_caller
)
513 if (e
->caller
->inlined_to
)
514 e
->caller
->inlined_to
->calls_comdat_local
= true;
516 e
->caller
->calls_comdat_local
= true;
520 /* Dissolve the same_comdat_group list in which NODE resides. */
523 symtab_node::dissolve_same_comdat_group_list (void)
525 symtab_node
*n
= this;
528 if (!same_comdat_group
)
532 next
= n
->same_comdat_group
;
533 n
->same_comdat_group
= NULL
;
534 if (dyn_cast
<cgraph_node
*> (n
))
535 dyn_cast
<cgraph_node
*> (n
)->calls_comdat_local
= false;
536 /* Clear comdat_group for comdat locals, since
537 make_decl_local doesn't. */
538 if (!TREE_PUBLIC (n
->decl
))
539 n
->set_comdat_group (NULL
);
545 /* Return printable assembler name of NODE.
546 This function is used only for debugging. When assembler name
547 is unknown go with identifier name. */
550 symtab_node::asm_name () const
552 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
554 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
557 /* Return printable identifier name. */
560 symtab_node::name () const
562 if (!DECL_NAME (decl
))
564 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
569 return lang_hooks
.decl_printable_name (decl
, 2);
573 symtab_node::get_dump_name (bool asm_name_p
) const
576 const char *fname
= asm_name_p
? asm_name () : name ();
577 unsigned l
= strlen (fname
);
579 char *s
= (char *)ggc_internal_cleared_alloc (l
+ EXTRA
);
580 snprintf (s
, l
+ EXTRA
, "%s/%d", fname
, order
);
586 symtab_node::dump_name () const
588 return get_dump_name (false);
592 symtab_node::dump_asm_name () const
594 return get_dump_name (true);
597 /* Return ipa reference from this symtab_node to
598 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
602 symtab_node::create_reference (symtab_node
*referred_node
,
603 enum ipa_ref_use use_type
)
605 return create_reference (referred_node
, use_type
, NULL
);
609 /* Return ipa reference from this symtab_node to
610 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
611 of the use and STMT the statement (if it exists). */
614 symtab_node::create_reference (symtab_node
*referred_node
,
615 enum ipa_ref_use use_type
, gimple
*stmt
)
617 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
618 ipa_ref_list
*list
, *list2
;
619 ipa_ref_t
*old_references
;
621 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
622 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
625 old_references
= list
->references
.address ();
626 list
->references
.safe_grow (list
->references
.length () + 1, false);
627 ref
= &list
->references
.last ();
629 list2
= &referred_node
->ref_list
;
631 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
632 if(use_type
== IPA_REF_ALIAS
)
634 list2
->referring
.safe_insert (0, ref
);
635 ref
->referred_index
= 0;
637 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
638 list2
->referring
[i
]->referred_index
= i
;
642 list2
->referring
.safe_push (ref
);
643 ref
->referred_index
= list2
->referring
.length () - 1;
646 ref
->referring
= this;
647 ref
->referred
= referred_node
;
649 ref
->lto_stmt_uid
= 0;
650 ref
->speculative_id
= 0;
652 ref
->speculative
= 0;
654 /* If vector was moved in memory, update pointers. */
655 if (old_references
!= list
->references
.address ())
658 for (i
= 0; iterate_reference(i
, ref2
); i
++)
659 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
665 symtab_node::maybe_create_reference (tree val
, gimple
*stmt
)
668 ipa_ref_use use_type
;
670 switch (TREE_CODE (val
))
673 use_type
= IPA_REF_LOAD
;
676 use_type
= IPA_REF_ADDR
;
679 gcc_assert (!handled_component_p (val
));
683 val
= get_base_var (val
);
684 if (val
&& VAR_OR_FUNCTION_DECL_P (val
))
686 symtab_node
*referred
= symtab_node::get (val
);
687 gcc_checking_assert (referred
);
688 return create_reference (referred
, use_type
, stmt
);
693 /* Clone all references from symtab NODE to this symtab_node. */
696 symtab_node::clone_references (symtab_node
*node
)
698 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
700 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
702 bool speculative
= ref
->speculative
;
703 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
704 unsigned int spec_id
= ref
->speculative_id
;
706 ref2
= create_reference (ref
->referred
, ref
->use
, ref
->stmt
);
707 ref2
->speculative
= speculative
;
708 ref2
->lto_stmt_uid
= stmt_uid
;
709 ref2
->speculative_id
= spec_id
;
713 /* Clone all referring from symtab NODE to this symtab_node. */
716 symtab_node::clone_referring (symtab_node
*node
)
718 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
720 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
722 bool speculative
= ref
->speculative
;
723 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
724 unsigned int spec_id
= ref
->speculative_id
;
726 ref2
= ref
->referring
->create_reference (this, ref
->use
, ref
->stmt
);
727 ref2
->speculative
= speculative
;
728 ref2
->lto_stmt_uid
= stmt_uid
;
729 ref2
->speculative_id
= spec_id
;
733 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
736 symtab_node::clone_reference (ipa_ref
*ref
, gimple
*stmt
)
738 bool speculative
= ref
->speculative
;
739 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
740 unsigned int spec_id
= ref
->speculative_id
;
743 ref2
= create_reference (ref
->referred
, ref
->use
, stmt
);
744 ref2
->speculative
= speculative
;
745 ref2
->lto_stmt_uid
= stmt_uid
;
746 ref2
->speculative_id
= spec_id
;
750 /* Find the structure describing a reference to REFERRED_NODE
751 and associated with statement STMT. */
754 symtab_node::find_reference (symtab_node
*referred_node
,
755 gimple
*stmt
, unsigned int lto_stmt_uid
)
760 for (i
= 0; iterate_reference (i
, r
); i
++)
761 if (r
->referred
== referred_node
763 && ((stmt
&& r
->stmt
== stmt
)
764 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
765 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
770 /* Remove all references that are associated with statement STMT. */
773 symtab_node::remove_stmt_references (gimple
*stmt
)
778 while (iterate_reference (i
, r
))
780 r
->remove_reference ();
785 /* Remove all stmt references in non-speculative references in THIS
787 Those are not maintained during inlining & cloning.
788 The exception are speculative references that are updated along
789 with callgraph edges associated with them. */
792 symtab_node::clear_stmts_in_references (void)
797 for (i
= 0; iterate_reference (i
, r
); i
++)
802 r
->speculative_id
= 0;
804 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
808 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
809 cnode
->clear_stmts_in_references ();
813 /* Remove all references in ref list. */
816 symtab_node::remove_all_references (void)
818 while (ref_list
.references
.length ())
819 ref_list
.references
.last ().remove_reference ();
820 ref_list
.references
.release ();
823 /* Remove all referring items in ref list. */
826 symtab_node::remove_all_referring (void)
828 while (ref_list
.referring
.length ())
829 ref_list
.referring
.last ()->remove_reference ();
830 ref_list
.referring
.release ();
833 /* Dump references in ref list to FILE. */
836 symtab_node::dump_references (FILE *file
)
840 for (i
= 0; iterate_reference (i
, ref
); i
++)
842 fprintf (file
, "%s (%s) ", ref
->referred
->dump_asm_name (),
843 ipa_ref_use_name
[ref
->use
]);
844 if (ref
->speculative
)
845 fprintf (file
, "(speculative) ");
847 fprintf (file
, "\n");
850 /* Dump referring in list to FILE. */
853 symtab_node::dump_referring (FILE *file
)
857 for (i
= 0; iterate_referring(i
, ref
); i
++)
859 fprintf (file
, "%s (%s) ", ref
->referring
->dump_asm_name (),
860 ipa_ref_use_name
[ref
->use
]);
861 if (ref
->speculative
)
862 fprintf (file
, "(speculative) ");
864 fprintf (file
, "\n");
867 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
869 /* Dump the visibility of the symbol. */
872 symtab_node::get_visibility_string () const
874 static const char * const visibility_types
[]
875 = { "default", "protected", "hidden", "internal" };
876 return visibility_types
[DECL_VISIBILITY (decl
)];
879 /* Dump the type_name of the symbol. */
881 symtab_node::get_symtab_type_string () const
883 return symtab_type_names
[type
];
886 /* Dump base fields of symtab nodes to F. Not to be used directly. */
889 symtab_node::dump_base (FILE *f
)
891 static const char * const visibility_types
[] = {
892 "default", "protected", "hidden", "internal"
895 fprintf (f
, "%s (%s)", dump_asm_name (), name ());
896 dump_addr (f
, " @", (void *)this);
897 fprintf (f
, "\n Type: %s", symtab_type_names
[type
]);
900 fprintf (f
, " definition");
902 fprintf (f
, " analyzed");
904 fprintf (f
, " alias");
905 if (transparent_alias
)
906 fprintf (f
, " transparent_alias");
908 fprintf (f
, " weakref");
910 fprintf (f
, " symver");
911 if (cpp_implicit_alias
)
912 fprintf (f
, " cpp_implicit_alias");
914 fprintf (f
, " target:%s",
915 DECL_P (alias_target
)
916 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
918 : IDENTIFIER_POINTER (alias_target
));
920 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
921 fprintf (f
, "\n Visibility:");
922 if (in_other_partition
)
923 fprintf (f
, " in_other_partition");
924 if (used_from_other_partition
)
925 fprintf (f
, " used_from_other_partition");
927 fprintf (f
, " force_output");
929 fprintf (f
, " forced_by_abi");
930 if (externally_visible
)
931 fprintf (f
, " externally_visible");
932 if (semantic_interposition
)
933 fprintf (f
, " semantic_interposition");
935 fprintf (f
, " no_reorder");
936 if (resolution
!= LDPR_UNKNOWN
)
938 ld_plugin_symbol_resolution_names
[(int)resolution
]);
939 if (TREE_ASM_WRITTEN (decl
))
940 fprintf (f
, " asm_written");
941 if (DECL_EXTERNAL (decl
))
942 fprintf (f
, " external");
943 if (TREE_PUBLIC (decl
))
944 fprintf (f
, " public");
945 if (DECL_COMMON (decl
))
946 fprintf (f
, " common");
947 if (DECL_WEAK (decl
))
948 fprintf (f
, " weak");
949 if (DECL_DLLIMPORT_P (decl
))
950 fprintf (f
, " dll_import");
951 if (DECL_COMDAT (decl
))
952 fprintf (f
, " comdat");
953 if (get_comdat_group ())
954 fprintf (f
, " comdat_group:%s",
955 IDENTIFIER_POINTER (get_comdat_group_id ()));
956 if (DECL_ONE_ONLY (decl
))
957 fprintf (f
, " one_only");
959 fprintf (f
, " section:%s",
961 if (implicit_section
)
962 fprintf (f
," (implicit_section)");
963 if (DECL_VISIBILITY_SPECIFIED (decl
))
964 fprintf (f
, " visibility_specified");
965 if (DECL_VISIBILITY (decl
))
966 fprintf (f
, " visibility:%s",
967 visibility_types
[DECL_VISIBILITY (decl
)]);
968 if (DECL_VIRTUAL_P (decl
))
969 fprintf (f
, " virtual");
970 if (DECL_ARTIFICIAL (decl
))
971 fprintf (f
, " artificial");
972 if (TREE_CODE (decl
) == FUNCTION_DECL
)
974 if (DECL_STATIC_CONSTRUCTOR (decl
))
975 fprintf (f
, " constructor");
976 if (DECL_STATIC_DESTRUCTOR (decl
))
977 fprintf (f
, " destructor");
980 fprintf (f
, " ifunc_resolver");
983 if (same_comdat_group
)
984 fprintf (f
, " Same comdat group as: %s\n",
985 same_comdat_group
->dump_asm_name ());
986 if (next_sharing_asm_name
)
987 fprintf (f
, " next sharing asm name: %i\n",
988 next_sharing_asm_name
->order
);
989 if (previous_sharing_asm_name
)
990 fprintf (f
, " previous sharing asm name: %i\n",
991 previous_sharing_asm_name
->order
);
994 fprintf (f
, " Address is taken.\n");
997 fprintf (f
, " Aux:");
998 dump_addr (f
, " @", (void *)aux
);
1002 fprintf (f
, " References: ");
1003 dump_references (f
);
1004 fprintf (f
, " Referring: ");
1007 fprintf (f
, " Read from file: %s\n",
1008 lto_file_data
->file_name
);
1011 /* Dump symtab node to F. */
1014 symtab_node::dump (FILE *f
)
1016 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
1018 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
1023 symtab_node::dump_graphviz (FILE *f
)
1025 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
1026 cnode
->dump_graphviz (f
);
1030 symbol_table::dump (FILE *f
)
1033 fprintf (f
, "Symbol table:\n\n");
1034 FOR_EACH_SYMBOL (node
)
1039 symbol_table::dump_graphviz (FILE *f
)
1042 fprintf (f
, "digraph symtab {\n");
1043 FOR_EACH_SYMBOL (node
)
1044 node
->dump_graphviz (f
);
1049 symbol_table::debug (void)
1054 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1055 Return NULL if there's no such node. */
1058 symtab_node::get_for_asmname (const_tree asmname
)
1062 symtab
->symtab_initialize_asm_name_hash ();
1063 hashval_t hash
= symtab
->decl_assembler_name_hash (asmname
);
1065 = symtab
->assembler_name_hash
->find_slot_with_hash (asmname
, hash
,
1076 /* Dump symtab node NODE to stderr. */
1079 symtab_node::debug (void)
1084 /* Verify common part of symtab nodes. */
1087 /* Disable warnings about missing quoting in GCC diagnostics for
1088 the verification errors. Their format strings don't follow GCC
1089 diagnostic conventions and the calls are ultimately followed by
1090 one to internal_error. */
1091 # pragma GCC diagnostic push
1092 # pragma GCC diagnostic ignored "-Wformat-diag"
1096 symtab_node::verify_base (void)
1098 bool error_found
= false;
1099 symtab_node
*hashed_node
;
1101 if (is_a
<cgraph_node
*> (this))
1103 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1105 error ("function symbol is not function");
1108 else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
))
1110 != dyn_cast
<cgraph_node
*> (this)->ifunc_resolver
)
1112 error ("inconsistent %<ifunc%> attribute");
1116 else if (is_a
<varpool_node
*> (this))
1120 error ("variable symbol is not variable");
1126 error ("node has unknown type");
1129 if (order
< 0 || order
>= symtab
->order
)
1131 error ("node has invalid order %i", order
);
1135 if (symtab
->state
!= LTO_STREAMING
)
1137 hashed_node
= symtab_node::get (decl
);
1140 error ("node not found node->decl->decl_with_vis.symtab_node");
1143 if (hashed_node
!= this
1144 && (!is_a
<cgraph_node
*> (this)
1145 || !dyn_cast
<cgraph_node
*> (this)->clone_of
1146 || dyn_cast
<cgraph_node
*> (this)->clone_of
->decl
!= decl
))
1148 error ("node differs from node->decl->decl_with_vis.symtab_node");
1152 if (symtab
->assembler_name_hash
)
1154 hashed_node
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
1157 if (hashed_node
->previous_sharing_asm_name
)
1159 error ("assembler name hash list corrupted");
1162 else if (previous_sharing_asm_name
== NULL
)
1164 if (hashed_node
!= this)
1166 error ("assembler name hash list corrupted");
1170 else if (!(is_a
<varpool_node
*> (this) && DECL_HARD_REGISTER (decl
)))
1172 if (!asmname_hasher::equal (previous_sharing_asm_name
,
1173 DECL_ASSEMBLER_NAME (decl
)))
1175 error ("node not found in symtab assembler name hash");
1181 if (previous_sharing_asm_name
1182 && previous_sharing_asm_name
->next_sharing_asm_name
!= this)
1184 error ("double linked list of assembler names corrupted");
1187 if (body_removed
&& definition
)
1189 error ("node has body_removed but is definition");
1192 if (analyzed
&& !definition
)
1194 error ("node is analyzed but it is not a definition");
1197 if (cpp_implicit_alias
&& !alias
)
1199 error ("node is alias but not implicit alias");
1202 if (alias
&& !definition
&& !weakref
)
1204 error ("node is alias but not definition");
1207 if (weakref
&& !transparent_alias
)
1209 error ("node is weakref but not an transparent_alias");
1212 if (transparent_alias
&& !alias
)
1214 error ("node is transparent_alias but not an alias");
1217 if (symver
&& !alias
)
1219 error ("node is symver but not alias");
1222 /* Limitation of gas requires us to output targets of symver aliases as
1223 global symbols. This is binutils PR 25295. */
1225 && (!TREE_PUBLIC (get_alias_target ()->decl
)
1226 || DECL_VISIBILITY (get_alias_target ()->decl
) != VISIBILITY_DEFAULT
))
1228 error ("symver target is not exported with default visibility");
1232 && (!TREE_PUBLIC (decl
)
1233 || DECL_VISIBILITY (decl
) != VISIBILITY_DEFAULT
))
1235 error ("symver is not exported with default visibility");
1238 if (same_comdat_group
)
1240 symtab_node
*n
= same_comdat_group
;
1242 if (!n
->get_comdat_group ())
1244 error ("node is in same_comdat_group list but has no comdat_group");
1247 if (n
->get_comdat_group () != get_comdat_group ())
1249 error ("same_comdat_group list across different groups");
1252 if (n
->type
!= type
)
1254 error ("mixing different types of symbol in same comdat groups is not supported");
1259 error ("node is alone in a comdat group");
1264 if (!n
->same_comdat_group
)
1266 error ("same_comdat_group is not a circular list");
1270 n
= n
->same_comdat_group
;
1273 if (comdat_local_p ())
1275 ipa_ref
*ref
= NULL
;
1277 for (int i
= 0; iterate_referring (i
, ref
); ++i
)
1279 if (!in_same_comdat_group_p (ref
->referring
))
1281 error ("comdat-local symbol referred to by %s outside its "
1283 identifier_to_locale (ref
->referring
->name()));
1289 if (implicit_section
&& !get_section ())
1291 error ("implicit_section flag is set but section isn%'t");
1294 if (get_section () && get_comdat_group ()
1295 && !implicit_section
1296 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl
)))
1298 error ("Both section and comdat group is set");
1301 /* TODO: Add string table for sections, so we do not keep holding duplicated
1303 if (alias
&& definition
1304 && get_section () != get_alias_target ()->get_section ()
1306 || !get_alias_target ()->get_section ()
1307 || strcmp (get_section(),
1308 get_alias_target ()->get_section ())))
1310 error ("Alias and target%'s section differs");
1311 get_alias_target ()->dump (stderr
);
1314 if (alias
&& definition
1315 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1317 error ("Alias and target%'s comdat groups differs");
1318 get_alias_target ()->dump (stderr
);
1321 if (transparent_alias
&& definition
&& !weakref
)
1323 symtab_node
*to
= get_alias_target ();
1325 = IDENTIFIER_POINTER (
1326 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl
)));
1328 = IDENTIFIER_POINTER (
1329 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to
->decl
)));
1330 if (!symbol_table::assembler_names_equal_p (name1
, name2
))
1332 error ("Transparent alias and target%'s assembler names differs");
1333 get_alias_target ()->dump (stderr
);
1337 if (transparent_alias
&& definition
1338 && get_alias_target()->transparent_alias
&& get_alias_target()->analyzed
)
1340 error ("Chained transparent aliases");
1341 get_alias_target ()->dump (stderr
);
1348 /* Verify consistency of NODE. */
1351 symtab_node::verify (void)
1356 timevar_push (TV_CGRAPH_VERIFY
);
1357 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (this))
1358 node
->verify_node ();
1363 internal_error ("symtab_node::verify failed");
1365 timevar_pop (TV_CGRAPH_VERIFY
);
1368 /* Verify symbol table for internal consistency. */
1371 symtab_node::verify_symtab_nodes (void)
1374 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1377 for (anode
= symtab
->first_asm_symbol (); anode
; anode
= anode
->next
)
1378 if (anode
->order
< 0 || anode
->order
>= symtab
->order
)
1380 error ("invalid order in asm node %i", anode
->order
);
1381 internal_error ("symtab_node::verify failed");
1384 FOR_EACH_SYMBOL (node
)
1387 if (node
->get_comdat_group ())
1389 symtab_node
**entry
, *s
;
1392 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1396 else if (!DECL_EXTERNAL (node
->decl
))
1398 for (s
= (*entry
)->same_comdat_group
;
1399 s
!= NULL
&& s
!= node
&& s
!= *entry
;
1400 s
= s
->same_comdat_group
)
1402 if (!s
|| s
== *entry
)
1404 error ("Two symbols with same comdat_group are not linked by "
1405 "the same_comdat_group list.");
1408 internal_error ("symtab_node::verify failed");
1416 # pragma GCC diagnostic pop
1419 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1420 but other code such as notice_global_symbol generates rtl. */
1423 symtab_node::make_decl_local (void)
1430 IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
)) = 0;
1431 TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
)) = NULL_TREE
;
1432 symtab
->change_decl_assembler_name
1433 (decl
, DECL_ASSEMBLER_NAME (get_alias_target ()->decl
));
1434 DECL_ATTRIBUTES (decl
) = remove_attribute ("weakref",
1435 DECL_ATTRIBUTES (decl
));
1437 /* Avoid clearing comdat_groups on comdat-local decls. */
1438 else if (TREE_PUBLIC (decl
) == 0)
1441 /* Localizing a symbol also make all its transparent aliases local. */
1443 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
); i
++)
1445 struct symtab_node
*alias
= ref
->referring
;
1446 if (alias
->transparent_alias
)
1447 alias
->make_decl_local ();
1452 DECL_COMMON (decl
) = 0;
1453 /* ADDRESSABLE flag is not defined for public symbols. */
1454 TREE_ADDRESSABLE (decl
) = 1;
1455 TREE_STATIC (decl
) = 1;
1458 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1460 DECL_COMDAT (decl
) = 0;
1461 DECL_WEAK (decl
) = 0;
1462 DECL_EXTERNAL (decl
) = 0;
1463 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1464 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1465 TREE_PUBLIC (decl
) = 0;
1466 DECL_DLLIMPORT_P (decl
) = 0;
1467 if (!DECL_RTL_SET_P (decl
))
1470 /* Update rtl flags. */
1471 make_decl_rtl (decl
);
1473 rtl
= DECL_RTL (decl
);
1477 symbol
= XEXP (rtl
, 0);
1478 if (GET_CODE (symbol
) != SYMBOL_REF
)
1481 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1484 /* Copy visibility from N.
1485 This is useful when THIS becomes a transparent alias of N. */
1488 symtab_node::copy_visibility_from (symtab_node
*n
)
1490 gcc_checking_assert (n
->weakref
== weakref
);
1493 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
); i
++)
1495 struct symtab_node
*alias
= ref
->referring
;
1496 if (alias
->transparent_alias
)
1497 alias
->copy_visibility_from (n
);
1502 DECL_COMMON (decl
) = DECL_COMMON (n
->decl
);
1503 /* ADDRESSABLE flag is not defined for public symbols. */
1504 if (TREE_PUBLIC (decl
) && !TREE_PUBLIC (n
->decl
))
1505 TREE_ADDRESSABLE (decl
) = 1;
1506 TREE_STATIC (decl
) = TREE_STATIC (n
->decl
);
1508 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1510 DECL_COMDAT (decl
) = DECL_COMDAT (n
->decl
);
1511 DECL_WEAK (decl
) = DECL_WEAK (n
->decl
);
1512 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (n
->decl
);
1513 DECL_VISIBILITY_SPECIFIED (decl
) = DECL_VISIBILITY_SPECIFIED (n
->decl
);
1514 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (n
->decl
);
1515 TREE_PUBLIC (decl
) = TREE_PUBLIC (n
->decl
);
1516 DECL_DLLIMPORT_P (decl
) = DECL_DLLIMPORT_P (n
->decl
);
1517 resolution
= n
->resolution
;
1518 set_comdat_group (n
->get_comdat_group ());
1520 externally_visible
= n
->externally_visible
;
1521 if (!DECL_RTL_SET_P (decl
))
1524 /* Update rtl flags. */
1525 make_decl_rtl (decl
);
1527 rtx rtl
= DECL_RTL (decl
);
1531 rtx symbol
= XEXP (rtl
, 0);
1532 if (GET_CODE (symbol
) != SYMBOL_REF
)
1535 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1538 /* Walk the alias chain to return the symbol NODE is alias of.
1539 If NODE is not an alias, return NODE.
1540 Assumes NODE is known to be alias. */
1543 symtab_node::ultimate_alias_target_1 (enum availability
*availability
,
1546 bool transparent_p
= false;
1548 /* To determine visibility of the target, we follow ELF semantic of aliases.
1549 Here alias is an alternative assembler name of a given definition. Its
1550 availability prevails the availability of its target (i.e. static alias of
1551 weak definition is available.
1553 Transparent alias is just alternative name of a given symbol used within
1554 one compilation unit and is translated prior hitting the object file. It
1555 inherits the visibility of its target.
1556 Weakref is a different animal (and noweak definition is weak).
1558 If we ever get into supporting targets with different semantics, a target
1559 hook will be needed here. */
1563 transparent_p
= transparent_alias
;
1565 *availability
= get_availability (ref
);
1567 *availability
= AVAIL_NOT_AVAILABLE
;
1570 symtab_node
*node
= this;
1573 if (node
->alias
&& node
->analyzed
)
1574 node
= node
->get_alias_target ();
1577 if (!availability
|| (!transparent_p
&& node
->analyzed
))
1579 else if (node
->analyzed
&& !node
->transparent_alias
)
1580 *availability
= node
->get_availability (ref
);
1582 *availability
= AVAIL_NOT_AVAILABLE
;
1585 if (node
&& availability
&& transparent_p
1586 && node
->transparent_alias
)
1588 *availability
= node
->get_availability (ref
);
1589 transparent_p
= false;
1593 *availability
= AVAIL_NOT_AVAILABLE
;
1597 /* C++ FE sometimes change linkage flags after producing same body aliases.
1599 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1600 are obviously equivalent. The way it is doing so is however somewhat
1601 kludgy and interferes with the visibility code. As a result we need to
1602 copy the visibility from the target to get things right. */
1605 symtab_node::fixup_same_cpp_alias_visibility (symtab_node
*target
)
1607 if (is_a
<cgraph_node
*> (this))
1609 DECL_DECLARED_INLINE_P (decl
)
1610 = DECL_DECLARED_INLINE_P (target
->decl
);
1611 DECL_DISREGARD_INLINE_LIMITS (decl
)
1612 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1614 /* FIXME: It is not really clear why those flags should not be copied for
1618 DECL_WEAK (decl
) = DECL_WEAK (target
->decl
);
1619 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1620 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (target
->decl
);
1622 if (TREE_PUBLIC (decl
))
1626 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1627 DECL_COMDAT (decl
) = DECL_COMDAT (target
->decl
);
1628 group
= target
->get_comdat_group ();
1629 set_comdat_group (group
);
1630 if (group
&& !same_comdat_group
)
1631 add_to_same_comdat_group (target
);
1633 externally_visible
= target
->externally_visible
;
1636 /* Set section, do not recurse into aliases.
1637 When one wants to change section of a symbol and its aliases,
1641 symtab_node::set_section_for_node (const char *section
)
1643 const char *current
= get_section ();
1645 if (current
== section
1646 || (current
&& section
1647 && !strcmp (current
, section
)))
1650 release_section_hash_entry (x_section
);
1654 implicit_section
= false;
1657 if (!symtab
->section_hash
)
1658 symtab
->section_hash
= hash_table
<section_name_hasher
>::create_ggc (10);
1659 section_hash_entry
**slot
= symtab
->section_hash
->find_slot_with_hash
1660 (section
, htab_hash_string (section
), INSERT
);
1662 x_section
= retain_section_hash_entry (*slot
);
1665 int len
= strlen (section
);
1666 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1667 x_section
->ref_count
= 1;
1668 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1669 memcpy (x_section
->name
, section
, len
+ 1);
1673 /* Set the section of node THIS to be the same as the section
1674 of node OTHER. Keep reference counts of the sections
1675 up-to-date as needed. */
1678 symtab_node::set_section_for_node (const symtab_node
&other
)
1680 if (x_section
== other
.x_section
)
1682 if (get_section () && other
.get_section ())
1683 gcc_checking_assert (strcmp (get_section (), other
.get_section ()) != 0);
1684 release_section_hash_entry (x_section
);
1685 if (other
.x_section
)
1686 x_section
= retain_section_hash_entry (other
.x_section
);
1690 implicit_section
= false;
1694 /* Workers for set_section. */
1697 symtab_node::set_section_from_string (symtab_node
*n
, void *s
)
1699 n
->set_section_for_node ((char *)s
);
1703 /* Set the section of node N to be the same as the section
1707 symtab_node::set_section_from_node (symtab_node
*n
, void *o
)
1709 const symtab_node
&other
= *static_cast<const symtab_node
*> (o
);
1710 n
->set_section_for_node (other
);
1714 /* Set section of symbol and its aliases. */
1717 symtab_node::set_section (const char *section
)
1719 gcc_assert (!this->alias
|| !this->analyzed
);
1720 call_for_symbol_and_aliases
1721 (symtab_node::set_section_from_string
, const_cast<char *>(section
), true);
1725 symtab_node::set_section (const symtab_node
&other
)
1727 call_for_symbol_and_aliases
1728 (symtab_node::set_section_from_node
, const_cast<symtab_node
*>(&other
), true);
1731 /* Return the initialization priority. */
1734 symtab_node::get_init_priority ()
1736 if (!this->in_init_priority_hash
)
1737 return DEFAULT_INIT_PRIORITY
;
1739 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1740 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1743 /* Return the finalization priority. */
1746 cgraph_node::get_fini_priority ()
1748 if (!this->in_init_priority_hash
)
1749 return DEFAULT_INIT_PRIORITY
;
1750 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1751 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1754 /* Return the initialization and finalization priority information for
1755 DECL. If there is no previous priority information, a freshly
1756 allocated structure is returned. */
1758 symbol_priority_map
*
1759 symtab_node::priority_info (void)
1761 if (!symtab
->init_priority_hash
)
1762 symtab
->init_priority_hash
= hash_map
<symtab_node
*, symbol_priority_map
>::create_ggc (13);
1765 symbol_priority_map
*h
1766 = &symtab
->init_priority_hash
->get_or_insert (this, &existed
);
1769 h
->init
= DEFAULT_INIT_PRIORITY
;
1770 h
->fini
= DEFAULT_INIT_PRIORITY
;
1771 in_init_priority_hash
= true;
1777 /* Set initialization priority to PRIORITY. */
1780 symtab_node::set_init_priority (priority_type priority
)
1782 symbol_priority_map
*h
;
1784 if (is_a
<cgraph_node
*> (this))
1785 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1787 if (priority
== DEFAULT_INIT_PRIORITY
)
1789 gcc_assert (get_init_priority() == priority
);
1792 h
= priority_info ();
1796 /* Set finalization priority to PRIORITY. */
1799 cgraph_node::set_fini_priority (priority_type priority
)
1801 symbol_priority_map
*h
;
1803 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1805 if (priority
== DEFAULT_INIT_PRIORITY
)
1807 gcc_assert (get_fini_priority() == priority
);
1810 h
= priority_info ();
1814 /* Worker for symtab_resolve_alias. */
1817 symtab_node::set_implicit_section (symtab_node
*n
,
1818 void *data ATTRIBUTE_UNUSED
)
1820 n
->implicit_section
= true;
1824 /* Add reference recording that symtab node is alias of TARGET.
1825 The function can fail in the case of aliasing cycles; in this case
1826 it returns false. */
1829 symtab_node::resolve_alias (symtab_node
*target
, bool transparent
)
1833 gcc_assert (!analyzed
&& !ref_list
.references
.length ());
1835 /* Never let cycles to creep into the symbol table alias references;
1836 those will make alias walkers to be infinite. */
1837 for (n
= target
; n
&& n
->alias
;
1838 n
= n
->analyzed
? n
->get_alias_target () : NULL
)
1841 if (is_a
<cgraph_node
*> (this))
1842 error ("function %q+D part of alias cycle", decl
);
1843 else if (is_a
<varpool_node
*> (this))
1844 error ("variable %q+D part of alias cycle", decl
);
1851 /* "analyze" the node - i.e. mark the reference. */
1855 transparent
|= transparent_alias
;
1856 transparent_alias
= transparent
;
1858 while (target
->transparent_alias
&& target
->analyzed
)
1859 target
= target
->get_alias_target ();
1860 create_reference (target
, IPA_REF_ALIAS
, NULL
);
1862 /* Add alias into the comdat group of its target unless it is already there. */
1863 if (same_comdat_group
)
1864 remove_from_same_comdat_group ();
1865 set_comdat_group (NULL
);
1866 if (target
->get_comdat_group ())
1867 add_to_same_comdat_group (target
);
1869 if ((get_section () != target
->get_section ()
1870 || target
->get_comdat_group ()) && get_section () && !implicit_section
)
1872 error ("section of alias %q+D must match section of its target", decl
);
1874 set_section (*target
);
1875 if (target
->implicit_section
)
1876 call_for_symbol_and_aliases (set_implicit_section
, NULL
, true);
1878 /* Alias targets become redundant after alias is resolved into an reference.
1879 We do not want to keep it around or we would have to mind updating them
1880 when renaming symbols. */
1881 alias_target
= NULL
;
1883 if (!transparent
&& cpp_implicit_alias
&& symtab
->state
>= CONSTRUCTION
)
1884 fixup_same_cpp_alias_visibility (target
);
1886 /* If alias has address taken, so does the target. */
1888 target
->ultimate_alias_target ()->address_taken
= true;
1890 /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
1891 If alias is transparent, also all transparent aliases of THIS are now
1893 Also merge same comdat group lists. */
1895 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
);)
1897 struct symtab_node
*alias_alias
= ref
->referring
;
1898 if (alias_alias
->get_comdat_group ())
1900 alias_alias
->remove_from_same_comdat_group ();
1901 alias_alias
->set_comdat_group (NULL
);
1902 if (target
->get_comdat_group ())
1903 alias_alias
->add_to_same_comdat_group (target
);
1905 if ((!alias_alias
->transparent_alias
1906 && !alias_alias
->symver
)
1909 alias_alias
->remove_all_references ();
1910 alias_alias
->create_reference (target
, IPA_REF_ALIAS
, NULL
);
1917 /* Worker searching noninterposable alias. */
1920 symtab_node::noninterposable_alias (symtab_node
*node
, void *data
)
1922 if (!node
->transparent_alias
&& decl_binds_to_current_def_p (node
->decl
))
1924 symtab_node
*fn
= node
->ultimate_alias_target ();
1926 /* Ensure that the alias is well formed this may not be the case
1927 of user defined aliases and currently it is not always the case
1928 of C++ same body aliases (that is a bug). */
1929 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
1930 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
1931 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
1932 && flags_from_decl_or_type (node
->decl
)
1933 != flags_from_decl_or_type (fn
->decl
))
1934 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
1936 *(symtab_node
**)data
= node
;
1942 /* If node cannot be overwriten by static or dynamic linker to point to
1943 different definition, return NODE. Otherwise look for alias with such
1944 property and if none exists, introduce new one. */
1947 symtab_node::noninterposable_alias (void)
1950 symtab_node
*new_node
= NULL
;
1952 /* First try to look up existing alias or base object
1953 (if that is already non-overwritable). */
1954 symtab_node
*node
= ultimate_alias_target ();
1955 gcc_assert (!node
->alias
&& !node
->weakref
);
1956 node
->call_for_symbol_and_aliases (symtab_node::noninterposable_alias
,
1957 (void *)&new_node
, true);
1961 /* If aliases aren't supported by the assembler, fail. */
1962 if (!TARGET_SUPPORTS_ALIASES
)
1964 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node
->decl
)))
1967 /* Otherwise create a new one. */
1968 new_decl
= copy_node (node
->decl
);
1969 DECL_DLLIMPORT_P (new_decl
) = 0;
1970 tree name
= clone_function_name (node
->decl
, "localalias");
1973 unsigned long num
= 0;
1974 /* In the rare case we already have a localalias, but the above
1975 node->call_for_symbol_and_aliases call didn't find any suitable,
1976 iterate until we find one not used yet. */
1977 while (symtab_node::get_for_asmname (name
))
1978 name
= clone_function_name (node
->decl
, "localalias", num
++);
1980 DECL_NAME (new_decl
) = name
;
1981 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1982 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1983 DECL_INITIAL (new_decl
) = NULL
;
1984 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1985 SET_DECL_RTL (new_decl
, NULL
);
1987 /* Update the properties. */
1988 DECL_EXTERNAL (new_decl
) = 0;
1989 TREE_PUBLIC (new_decl
) = 0;
1990 DECL_COMDAT (new_decl
) = 0;
1991 DECL_WEAK (new_decl
) = 0;
1993 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1994 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1995 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1997 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1998 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1999 new_node
= cgraph_node::create_alias (new_decl
, node
->decl
);
2001 cgraph_node
*new_cnode
= dyn_cast
<cgraph_node
*> (new_node
),
2002 *cnode
= dyn_cast
<cgraph_node
*> (node
);
2004 new_cnode
->unit_id
= cnode
->unit_id
;
2005 new_cnode
->merged_comdat
= cnode
->merged_comdat
;
2006 new_cnode
->merged_extern_inline
= cnode
->merged_extern_inline
;
2010 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
2011 DECL_INITIAL (new_decl
) = error_mark_node
;
2012 new_node
= varpool_node::create_alias (new_decl
, node
->decl
);
2014 new_node
->resolve_alias (node
);
2015 gcc_assert (decl_binds_to_current_def_p (new_decl
)
2016 && targetm
.binds_local_p (new_decl
));
2020 /* Return true if symtab node and TARGET represents
2021 semantically equivalent symbols. */
2024 symtab_node::semantically_equivalent_p (symtab_node
*target
)
2026 enum availability avail
;
2030 /* Equivalent functions are equivalent. */
2031 if (decl
== target
->decl
)
2034 /* If symbol is not overwritable by different implementation,
2035 walk to the base object it defines. */
2036 ba
= ultimate_alias_target (&avail
);
2037 if (avail
>= AVAIL_AVAILABLE
)
2044 bb
= target
->ultimate_alias_target (&avail
);
2045 if (avail
>= AVAIL_AVAILABLE
)
2055 /* Classify symbol symtab node for partitioning. */
2057 enum symbol_partitioning_class
2058 symtab_node::get_partitioning_class (void)
2060 /* Inline clones are always duplicated.
2061 This include external declarations. */
2062 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2064 if (DECL_ABSTRACT_P (decl
))
2065 return SYMBOL_EXTERNAL
;
2067 if (cnode
&& (cnode
->inlined_to
|| cnode
->declare_variant_alt
))
2068 return SYMBOL_DUPLICATE
;
2070 /* Transparent aliases are always duplicated. */
2071 if (transparent_alias
)
2072 return definition
? SYMBOL_DUPLICATE
: SYMBOL_EXTERNAL
;
2074 /* External declarations are external. */
2075 if (DECL_EXTERNAL (decl
))
2076 return SYMBOL_EXTERNAL
;
2078 /* Even static aliases of external functions as external. Those can happen
2079 when COMDAT got resolved to non-IL implementation. */
2080 if (alias
&& DECL_EXTERNAL (ultimate_alias_target ()->decl
))
2081 return SYMBOL_EXTERNAL
;
2083 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
2085 if (alias
&& definition
&& !ultimate_alias_target ()->definition
)
2086 return SYMBOL_EXTERNAL
;
2087 /* Constant pool references use local symbol names that cannot
2088 be promoted global. We should never put into a constant pool
2089 objects that cannot be duplicated across partitions. */
2090 if (DECL_IN_CONSTANT_POOL (decl
))
2091 return SYMBOL_DUPLICATE
;
2092 if (DECL_HARD_REGISTER (decl
))
2093 return SYMBOL_DUPLICATE
;
2094 gcc_checking_assert (vnode
->definition
);
2096 /* Functions that are cloned may stay in callgraph even if they are unused.
2097 Handle them as external; compute_ltrans_boundary take care to make
2098 proper things to happen (i.e. to make them appear in the boundary but
2099 with body streamed, so clone can me materialized). */
2100 else if (!dyn_cast
<cgraph_node
*> (this)->function_symbol ()->definition
)
2101 return SYMBOL_EXTERNAL
;
2103 /* Linker discardable symbols are duplicated to every use unless they are
2105 if (DECL_ONE_ONLY (decl
)
2108 && !used_from_object_file_p ())
2109 return SYMBOL_DUPLICATE
;
2111 return SYMBOL_PARTITION
;
2114 /* Return true when symbol is known to be non-zero. */
2117 symtab_node::nonzero_address ()
2119 /* Weakrefs may be NULL when their target is not defined. */
2120 if (alias
&& weakref
)
2124 symtab_node
*target
= ultimate_alias_target ();
2126 if (target
->alias
&& target
->weakref
)
2128 /* We cannot recurse to target::nonzero. It is possible that the
2129 target is used only via the alias.
2130 We may walk references and look for strong use, but we do not know
2131 if this strong use will survive to final binary, so be
2133 ??? Maybe we could do the lookup during late optimization that
2134 could be useful to eliminate the NULL pointer checks in LTO
2136 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
2138 if (target
->resolution
!= LDPR_UNKNOWN
2139 && target
->resolution
!= LDPR_UNDEF
2140 && !target
->can_be_discarded_p ()
2141 && flag_delete_null_pointer_checks
)
2149 /* With !flag_delete_null_pointer_checks we assume that symbols may
2150 bind to NULL. This is on by default on embedded targets only.
2152 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
2153 linking fails. Important case of WEAK we want to do well are comdats,
2154 which also must be defined somewhere.
2156 When parsing, beware the cases when WEAK attribute is added later. */
2157 if ((!DECL_WEAK (decl
) || DECL_COMDAT (decl
))
2158 && flag_delete_null_pointer_checks
)
2160 refuse_visibility_changes
= true;
2164 /* If target is defined and not extern, we know it will be
2165 output and thus it will bind to non-NULL.
2166 Play safe for flag_delete_null_pointer_checks where weak definition may
2167 be re-defined by NULL. */
2168 if (definition
&& !DECL_EXTERNAL (decl
)
2169 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (decl
)))
2171 if (!DECL_WEAK (decl
))
2172 refuse_visibility_changes
= true;
2176 /* As the last resort, check the resolution info. */
2177 if (resolution
!= LDPR_UNKNOWN
2178 && resolution
!= LDPR_UNDEF
2179 && !can_be_discarded_p ()
2180 && flag_delete_null_pointer_checks
)
2185 /* Return 0 if symbol is known to have different address than S2,
2186 Return 1 if symbol is known to have same address as S2,
2187 return -1 otherwise.
2189 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
2190 and S2 is going to be accessed. This eliminates the situations when
2191 either THIS or S2 is NULL and is useful for comparing bases when deciding
2192 about memory aliasing. */
2194 symtab_node::equal_address_to (symtab_node
*s2
, bool memory_accessed
)
2196 enum availability avail1
, avail2
;
2198 /* A Shortcut: equivalent symbols are always equivalent. */
2202 /* Unwind transparent aliases first; those are always equal to their
2204 if (this->transparent_alias
&& this->analyzed
)
2205 return this->get_alias_target ()->equal_address_to (s2
);
2206 while (s2
->transparent_alias
&& s2
->analyzed
)
2207 s2
= s2
->get_alias_target();
2212 /* For non-interposable aliases, lookup and compare their actual definitions.
2213 Also check if the symbol needs to bind to given definition. */
2214 symtab_node
*rs1
= ultimate_alias_target (&avail1
);
2215 symtab_node
*rs2
= s2
->ultimate_alias_target (&avail2
);
2216 bool binds_local1
= rs1
->analyzed
&& decl_binds_to_current_def_p (this->decl
);
2217 bool binds_local2
= rs2
->analyzed
&& decl_binds_to_current_def_p (s2
->decl
);
2218 bool really_binds_local1
= binds_local1
;
2219 bool really_binds_local2
= binds_local2
;
2221 /* Addresses of vtables and virtual functions cannot be used by user
2222 code and are used only within speculation. In this case we may make
2223 symbol equivalent to its alias even if interposition may break this
2224 rule. Doing so will allow us to turn speculative inlining into
2225 non-speculative more aggressively. */
2226 if (DECL_VIRTUAL_P (this->decl
) && avail1
>= AVAIL_AVAILABLE
)
2227 binds_local1
= true;
2228 if (DECL_VIRTUAL_P (s2
->decl
) && avail2
>= AVAIL_AVAILABLE
)
2229 binds_local2
= true;
2231 /* If both definitions are available we know that even if they are bound
2232 to other unit they must be defined same way and therefore we can use
2233 equivalence test. */
2234 if (rs1
!= rs2
&& avail1
>= AVAIL_AVAILABLE
&& avail2
>= AVAIL_AVAILABLE
)
2235 binds_local1
= binds_local2
= true;
2237 if (binds_local1
&& binds_local2
&& rs1
== rs2
)
2239 /* We made use of the fact that alias is not weak. */
2241 refuse_visibility_changes
= true;
2243 s2
->refuse_visibility_changes
= true;
2247 /* If both symbols may resolve to NULL, we cannot really prove them
2249 if (!memory_accessed
&& !nonzero_address () && !s2
->nonzero_address ())
2252 /* Except for NULL, functions and variables never overlap. */
2253 if (TREE_CODE (decl
) != TREE_CODE (s2
->decl
))
2256 /* If one of the symbols is unresolved alias, punt. */
2257 if (rs1
->alias
|| rs2
->alias
)
2260 /* If we have a non-interposale definition of at least one of the symbols
2261 and the other symbol is different, we know other unit cannot interpose
2262 it to the first symbol; all aliases of the definition needs to be
2263 present in the current unit. */
2264 if (((really_binds_local1
|| really_binds_local2
)
2265 /* If we have both definitions and they are different, we know they
2266 will be different even in units they binds to. */
2267 || (binds_local1
&& binds_local2
))
2270 /* We make use of the fact that one symbol is not alias of the other
2271 and that the definition is non-interposable. */
2272 refuse_visibility_changes
= true;
2273 s2
->refuse_visibility_changes
= true;
2274 rs1
->refuse_visibility_changes
= true;
2275 rs2
->refuse_visibility_changes
= true;
2279 /* TODO: Alias oracle basically assume that addresses of global variables
2280 are different unless they are declared as alias of one to another while
2281 the code folding comparisons doesn't.
2282 We probably should be consistent and use this fact here, too, but for
2283 the moment return false only when we are called from the alias oracle. */
2285 return memory_accessed
&& rs1
!= rs2
? 0 : -1;
2288 /* Worker for call_for_symbol_and_aliases. */
2291 symtab_node::call_for_symbol_and_aliases_1 (bool (*callback
) (symtab_node
*,
2294 bool include_overwritable
)
2297 FOR_EACH_ALIAS (this, ref
)
2299 symtab_node
*alias
= ref
->referring
;
2300 if (include_overwritable
2301 || alias
->get_availability () > AVAIL_INTERPOSABLE
)
2302 if (alias
->call_for_symbol_and_aliases (callback
, data
,
2303 include_overwritable
))
2309 /* Return true if address of N is possibly compared. */
2312 address_matters_1 (symtab_node
*n
, void *)
2314 struct ipa_ref
*ref
;
2316 if (!n
->address_can_be_compared_p ())
2318 if (n
->externally_visible
|| n
->force_output
)
2321 for (unsigned int i
= 0; n
->iterate_referring (i
, ref
); i
++)
2322 if (ref
->address_matters_p ())
2327 /* Return true if symbol's address may possibly be compared to other
2328 symbol's address. */
2331 symtab_node::address_matters_p ()
2333 gcc_assert (!alias
);
2334 return call_for_symbol_and_aliases (address_matters_1
, NULL
, true);
2337 /* Return true if symbol's alignment may be increased. */
2340 symtab_node::can_increase_alignment_p (void)
2342 symtab_node
*target
= ultimate_alias_target ();
2344 /* For now support only variables. */
2348 /* With -fno-toplevel-reorder we may have already output the constant. */
2349 if (TREE_ASM_WRITTEN (target
->decl
))
2352 /* If target is already placed in an anchor, we cannot touch its
2354 if (DECL_RTL_SET_P (target
->decl
)
2355 && MEM_P (DECL_RTL (target
->decl
))
2356 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target
->decl
), 0)))
2359 /* Constant pool entries may be shared. */
2360 if (DECL_IN_CONSTANT_POOL (target
->decl
))
2363 /* We cannot change alignment of symbols that may bind to symbols
2364 in other translation unit that may contain a definition with lower
2366 if (!decl_binds_to_current_def_p (decl
))
2369 /* When compiling partition, be sure the symbol is not output by other
2372 && (target
->in_other_partition
2373 || target
->get_partitioning_class () == SYMBOL_DUPLICATE
))
2376 /* Do not override the alignment as specified by the ABI when the used
2377 attribute is set. */
2378 if (DECL_PRESERVE_P (decl
) || DECL_PRESERVE_P (target
->decl
))
2381 /* Do not override explicit alignment set by the user when an explicit
2382 section name is also used. This is a common idiom used by many
2383 software projects. */
2384 if (DECL_SECTION_NAME (target
->decl
) != NULL
&& !target
->implicit_section
)
2390 /* Worker for symtab_node::increase_alignment. */
2393 increase_alignment_1 (symtab_node
*n
, void *v
)
2395 unsigned int align
= (size_t)v
;
2396 if (DECL_ALIGN (n
->decl
) < align
2397 && n
->can_increase_alignment_p ())
2399 SET_DECL_ALIGN (n
->decl
, align
);
2400 DECL_USER_ALIGN (n
->decl
) = 1;
2405 /* Increase alignment of THIS to ALIGN. */
2408 symtab_node::increase_alignment (unsigned int align
)
2410 gcc_assert (can_increase_alignment_p () && align
<= MAX_OFILE_ALIGNMENT
);
2411 ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1
,
2412 (void *)(size_t) align
,
2414 gcc_assert (DECL_ALIGN (decl
) >= align
);
2417 /* Helper for symtab_node::definition_alignment. */
2420 get_alignment_1 (symtab_node
*n
, void *v
)
2422 *((unsigned int *)v
) = MAX (*((unsigned int *)v
), DECL_ALIGN (n
->decl
));
2426 /* Return desired alignment of the definition. This is NOT alignment useful
2427 to access THIS, because THIS may be interposable and DECL_ALIGN should
2428 be used instead. It however must be guaranteed when output definition
2432 symtab_node::definition_alignment ()
2434 unsigned int align
= 0;
2435 gcc_assert (!alias
);
2436 call_for_symbol_and_aliases (get_alignment_1
, &align
, true);
2440 /* Return symbol used to separate symbol name from suffix. */
2443 symbol_table::symbol_suffix_separator ()
2445 #ifndef NO_DOT_IN_LABEL
2447 #elif !defined NO_DOLLAR_IN_LABEL
2454 /* Return true when references to this symbol from REF must bind to current
2455 definition in final executable. */
2458 symtab_node::binds_to_current_def_p (symtab_node
*ref
)
2460 if (!definition
&& !in_other_partition
)
2462 if (transparent_alias
)
2464 && get_alias_target()->binds_to_current_def_p (ref
);
2465 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2466 if (cnode
&& cnode
->ifunc_resolver
)
2468 if (decl_binds_to_current_def_p (decl
))
2471 /* Inline clones always binds locally. */
2472 if (cnode
&& cnode
->inlined_to
)
2475 if (DECL_EXTERNAL (decl
))
2478 gcc_assert (externally_visible
);
2482 cgraph_node
*cref
= dyn_cast
<cgraph_node
*> (ref
);
2484 ref
= cref
->inlined_to
;
2487 /* If this is a reference from symbol itself and there are no aliases, we
2488 may be sure that the symbol was not interposed by something else because
2489 the symbol itself would be unreachable otherwise. This is important
2490 to optimize recursive functions well.
2492 This assumption may be broken by inlining: if symbol is interposable
2493 but the body is available (i.e. declared inline), inliner may make
2494 the body reachable even with interposition. */
2495 if (this == ref
&& !has_aliases_p ()
2497 || symtab
->state
>= IPA_SSA_AFTER_INLINING
2498 || get_availability () >= AVAIL_INTERPOSABLE
))
2502 /* References within one comdat group are always bound in a group. */
2504 && symtab
->state
>= IPA_SSA_AFTER_INLINING
2505 && get_comdat_group ()
2506 && get_comdat_group () == ref
->get_comdat_group ())
2512 /* Return true if symbol should be output to the symbol table. */
2515 symtab_node::output_to_lto_symbol_table_p (void)
2517 /* Only externally visible symbols matter. */
2518 if (!TREE_PUBLIC (decl
))
2520 if (!real_symbol_p ())
2522 /* FIXME: variables probably should not be considered as real symbols at
2524 if (VAR_P (decl
) && DECL_HARD_REGISTER (decl
))
2526 if (TREE_CODE (decl
) == FUNCTION_DECL
&& !definition
2527 && fndecl_built_in_p (decl
))
2529 /* Builtins like those for most math functions have actual implementations
2530 in libraries so make sure to output references into the symbol table to
2531 make those libraries referenced. Note this is incomplete handling for
2532 now and only covers math functions. */
2533 return builtin_with_linkage_p (decl
);
2536 /* We have real symbol that should be in symbol table. However try to trim
2537 down the references to libraries bit more because linker will otherwise
2538 bring unnecessary object files into the final link.
2539 FIXME: The following checks can easily be confused i.e. by self recursive
2540 function or self-referring variable. */
2542 /* We keep external functions in symtab for sake of inlining
2543 and devirtualization. We do not want to see them in symbol table as
2544 references unless they are really used. */
2545 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2546 if (cnode
&& (!definition
|| DECL_EXTERNAL (decl
))
2550 /* Ignore all references from external vars initializers - they are not really
2551 part of the compilation unit until they are used by folding. Some symbols,
2552 like references to external construction vtables cannot be referred to at
2553 all. We decide this at can_refer_decl_in_current_unit_p. */
2554 if (!definition
|| DECL_EXTERNAL (decl
))
2557 struct ipa_ref
*ref
;
2558 for (i
= 0; iterate_referring (i
, ref
); i
++)
2560 if (ref
->use
== IPA_REF_ALIAS
)
2562 if (is_a
<cgraph_node
*> (ref
->referring
))
2564 if (!DECL_EXTERNAL (ref
->referring
->decl
))