2 Copyright (C) 2012-2024 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"
41 #include "fold-const.h"
43 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias"};
45 const char * const ld_plugin_symbol_resolution_names
[]=
50 "prevailing_def_ironly",
56 "prevailing_def_ironly_exp"
59 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at ALIAS
60 until we find an identifier that is not itself a transparent alias. */
63 ultimate_transparent_alias_target (tree alias
)
67 while (IDENTIFIER_TRANSPARENT_ALIAS (target
))
69 gcc_checking_assert (TREE_CHAIN (target
));
70 target
= TREE_CHAIN (target
);
72 gcc_checking_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
73 && ! TREE_CHAIN (target
));
79 /* Hash asmnames ignoring the user specified marks. */
82 symbol_table::decl_assembler_name_hash (const_tree asmname
)
84 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
86 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
87 size_t ulp_len
= strlen (user_label_prefix
);
91 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
94 return htab_hash_string (decl_str
);
97 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
100 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
104 symbol_table::assembler_names_equal_p (const char *name1
, const char *name2
)
110 size_t ulp_len
= strlen (user_label_prefix
);
116 else if (strncmp (name1
, user_label_prefix
, ulp_len
) == 0)
123 size_t ulp_len
= strlen (user_label_prefix
);
129 else if (strncmp (name2
, user_label_prefix
, ulp_len
) == 0)
134 return !strcmp (name1
, name2
);
139 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
142 symbol_table::decl_assembler_name_equal (tree decl
, const_tree asmname
)
144 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
145 const char *decl_str
;
146 const char *asmname_str
;
148 if (decl_asmname
== asmname
)
151 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
152 asmname_str
= IDENTIFIER_POINTER (asmname
);
153 return assembler_names_equal_p (decl_str
, asmname_str
);
157 /* Returns nonzero if P1 and P2 are equal. */
159 /* Insert NODE to assembler name hash. */
162 symbol_table::insert_to_assembler_name_hash (symtab_node
*node
,
165 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
167 gcc_checking_assert (!node
->previous_sharing_asm_name
168 && !node
->next_sharing_asm_name
);
169 if (assembler_name_hash
)
173 tree decl
= node
->decl
;
175 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
177 /* C++ FE can produce decls without associated assembler name and insert
178 them to symtab to hold section or TLS information. */
182 hashval_t hash
= decl_assembler_name_hash (name
);
183 aslot
= assembler_name_hash
->find_slot_with_hash (name
, hash
, INSERT
);
184 gcc_assert (*aslot
!= node
);
185 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
187 (*aslot
)->previous_sharing_asm_name
= node
;
190 /* Update also possible inline clones sharing a decl. */
191 cnode
= dyn_cast
<cgraph_node
*> (node
);
192 if (cnode
&& cnode
->clones
&& with_clones
)
193 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
194 if (cnode
->decl
== decl
)
195 insert_to_assembler_name_hash (cnode
, true);
200 /* Remove NODE from assembler name hash. */
203 symbol_table::unlink_from_assembler_name_hash (symtab_node
*node
,
206 if (assembler_name_hash
)
209 tree decl
= node
->decl
;
211 if (node
->next_sharing_asm_name
)
212 node
->next_sharing_asm_name
->previous_sharing_asm_name
213 = node
->previous_sharing_asm_name
;
214 if (node
->previous_sharing_asm_name
)
216 node
->previous_sharing_asm_name
->next_sharing_asm_name
217 = node
->next_sharing_asm_name
;
221 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
227 hashval_t hash
= decl_assembler_name_hash (name
);
228 slot
= assembler_name_hash
->find_slot_with_hash (name
, hash
,
230 gcc_assert (*slot
== node
);
231 if (!node
->next_sharing_asm_name
)
232 assembler_name_hash
->clear_slot (slot
);
234 *slot
= node
->next_sharing_asm_name
;
236 node
->next_sharing_asm_name
= NULL
;
237 node
->previous_sharing_asm_name
= NULL
;
239 /* Update also possible inline clones sharing a decl. */
240 cnode
= dyn_cast
<cgraph_node
*> (node
);
241 if (cnode
&& cnode
->clones
&& with_clones
)
242 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
243 if (cnode
->decl
== decl
)
244 unlink_from_assembler_name_hash (cnode
, true);
248 /* Arrange node to be first in its entry of assembler_name_hash. */
251 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node
*node
)
253 unlink_from_assembler_name_hash (node
, false);
254 insert_to_assembler_name_hash (node
, false);
257 /* Initialize asm name hash unless. */
260 symbol_table::symtab_initialize_asm_name_hash (void)
263 if (!assembler_name_hash
)
265 assembler_name_hash
= hash_table
<asmname_hasher
>::create_ggc (10);
266 FOR_EACH_SYMBOL (node
)
267 insert_to_assembler_name_hash (node
, false);
271 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
274 symbol_table::change_decl_assembler_name (tree decl
, tree name
)
276 symtab_node
*node
= NULL
;
278 /* We can have user ASM names on things, like global register variables, that
279 are not in the symbol table. */
280 if ((VAR_P (decl
) && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
281 || TREE_CODE (decl
) == FUNCTION_DECL
)
282 node
= symtab_node::get (decl
);
283 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
285 SET_DECL_ASSEMBLER_NAME (decl
, name
);
287 insert_to_assembler_name_hash (node
, true);
291 if (name
== DECL_ASSEMBLER_NAME (decl
))
294 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
295 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
298 unlink_from_assembler_name_hash (node
, true);
300 const char *old_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
301 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
302 && DECL_RTL_SET_P (decl
))
303 warning (0, "%qD renamed after being referenced in assembly", decl
);
305 SET_DECL_ASSEMBLER_NAME (decl
, name
);
308 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
309 TREE_CHAIN (name
) = alias
;
311 /* If we change assembler name, also all transparent aliases must
312 be updated. There are three kinds - those having same assembler name,
313 those being renamed in varasm.cc and weakref being renamed by the
317 insert_to_assembler_name_hash (node
, true);
319 for (unsigned i
= 0; node
->iterate_direct_aliases (i
, ref
); i
++)
321 struct symtab_node
*alias
= ref
->referring
;
322 if (alias
->transparent_alias
&& !alias
->weakref
323 && symbol_table::assembler_names_equal_p
324 (old_name
, IDENTIFIER_POINTER (
325 DECL_ASSEMBLER_NAME (alias
->decl
))))
326 change_decl_assembler_name (alias
->decl
, name
);
327 else if (alias
->transparent_alias
328 && IDENTIFIER_TRANSPARENT_ALIAS (alias
->decl
))
330 gcc_assert (TREE_CHAIN (DECL_ASSEMBLER_NAME (alias
->decl
))
331 && IDENTIFIER_TRANSPARENT_ALIAS
332 (DECL_ASSEMBLER_NAME (alias
->decl
)));
334 TREE_CHAIN (DECL_ASSEMBLER_NAME (alias
->decl
)) =
335 ultimate_transparent_alias_target
336 (DECL_ASSEMBLER_NAME (node
->decl
));
338 #ifdef ASM_OUTPUT_WEAKREF
339 else gcc_assert (!alias
->transparent_alias
|| alias
->weakref
);
341 else gcc_assert (!alias
->transparent_alias
);
344 gcc_assert (!node
->transparent_alias
|| !node
->definition
346 || TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
347 || symbol_table::assembler_names_equal_p
348 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
351 (node
->get_alias_target ()->decl
))));
356 /* Hash sections by their names. */
359 section_name_hasher::hash (section_hash_entry
*n
)
361 return htab_hash_string (n
->name
);
364 /* Return true if section P1 name equals to P2. */
367 section_name_hasher::equal (section_hash_entry
*n1
, const char *name
)
369 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
372 /* Bump the reference count on ENTRY so that it is retained. */
374 static section_hash_entry
*
375 retain_section_hash_entry (section_hash_entry
*entry
)
381 /* Drop the reference count on ENTRY and remove it if the reference
382 count drops to zero. */
385 release_section_hash_entry (section_hash_entry
*entry
)
390 if (!entry
->ref_count
)
392 hashval_t hash
= htab_hash_string (entry
->name
);
393 section_hash_entry
**slot
394 = symtab
->section_hash
->find_slot_with_hash (entry
->name
,
397 symtab
->section_hash
->clear_slot (slot
);
402 /* Add node into symbol table. This function is not used directly, but via
403 cgraph/varpool node creation routines. */
406 symtab_node::register_symbol (void)
408 symtab
->register_symbol (this);
410 if (!decl
->decl_with_vis
.symtab_node
)
411 decl
->decl_with_vis
.symtab_node
= this;
415 /* Be sure to do this last; C++ FE might create new nodes via
416 DECL_ASSEMBLER_NAME langhook! */
417 symtab
->insert_to_assembler_name_hash (this, false);
420 /* Remove NODE from same comdat group. */
423 symtab_node::remove_from_same_comdat_group (void)
425 if (same_comdat_group
)
428 for (prev
= same_comdat_group
;
429 prev
->same_comdat_group
!= this;
430 prev
= prev
->same_comdat_group
)
432 if (same_comdat_group
== prev
)
433 prev
->same_comdat_group
= NULL
;
435 prev
->same_comdat_group
= same_comdat_group
;
436 same_comdat_group
= NULL
;
437 set_comdat_group (NULL
);
441 /* Remove node from symbol table. This function is not used directly, but via
442 cgraph/varpool node removal routines.
443 INFO is a clone info to attach to new root of clone tree (if any). */
446 symtab_node::unregister (clone_info
*info
)
448 remove_all_references ();
449 remove_all_referring ();
451 /* Remove reference to section. */
452 set_section_for_node (NULL
);
454 remove_from_same_comdat_group ();
456 symtab
->unregister (this);
458 /* During LTO symtab merging we temporarily corrupt decl to symtab node
460 gcc_assert (decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
461 if (decl
->decl_with_vis
.symtab_node
== this)
463 symtab_node
*replacement_node
= NULL
;
464 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
465 replacement_node
= cnode
->find_replacement (info
);
466 decl
->decl_with_vis
.symtab_node
= replacement_node
;
468 if (!is_a
<varpool_node
*> (this) || !DECL_HARD_REGISTER (decl
))
469 symtab
->unlink_from_assembler_name_hash (this, false);
470 if (in_init_priority_hash
)
471 symtab
->init_priority_hash
->remove (this);
475 /* Remove symbol from symbol table. */
478 symtab_node::remove (void)
480 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
482 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
486 /* Add NEW_ to the same comdat group that OLD is in. */
489 symtab_node::add_to_same_comdat_group (symtab_node
*old_node
)
491 gcc_assert (old_node
->get_comdat_group ());
492 gcc_assert (!same_comdat_group
);
493 gcc_assert (this != old_node
);
495 set_comdat_group (old_node
->get_comdat_group ());
496 same_comdat_group
= old_node
;
497 if (!old_node
->same_comdat_group
)
498 old_node
->same_comdat_group
= this;
502 for (n
= old_node
->same_comdat_group
;
503 n
->same_comdat_group
!= old_node
;
504 n
= n
->same_comdat_group
)
506 n
->same_comdat_group
= this;
510 if (comdat_local_p ()
511 && (n
= dyn_cast
<cgraph_node
*> (this)) != NULL
)
513 for (cgraph_edge
*e
= n
->callers
; e
; e
= e
->next_caller
)
514 if (e
->caller
->inlined_to
)
515 e
->caller
->inlined_to
->calls_comdat_local
= true;
517 e
->caller
->calls_comdat_local
= true;
521 /* Dissolve the same_comdat_group list in which NODE resides. */
524 symtab_node::dissolve_same_comdat_group_list (void)
526 symtab_node
*n
= this;
529 if (!same_comdat_group
)
533 next
= n
->same_comdat_group
;
534 n
->same_comdat_group
= NULL
;
535 if (dyn_cast
<cgraph_node
*> (n
))
536 dyn_cast
<cgraph_node
*> (n
)->calls_comdat_local
= false;
537 /* Clear comdat_group for comdat locals, since
538 make_decl_local doesn't. */
539 if (!TREE_PUBLIC (n
->decl
))
540 n
->set_comdat_group (NULL
);
546 /* Return printable assembler name of NODE.
547 This function is used only for debugging. When assembler name
548 is unknown go with identifier name. */
551 symtab_node::asm_name () const
553 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
555 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
558 /* Return printable identifier name. */
561 symtab_node::name () const
563 if (!DECL_NAME (decl
))
565 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
570 return lang_hooks
.decl_printable_name (decl
, 2);
574 symtab_node::get_dump_name (bool asm_name_p
) const
577 const char *fname
= asm_name_p
? asm_name () : name ();
578 unsigned l
= strlen (fname
);
580 char *s
= (char *)ggc_internal_cleared_alloc (l
+ EXTRA
);
581 snprintf (s
, l
+ EXTRA
, "%s/%d", fname
, order
);
587 symtab_node::dump_name () const
589 return get_dump_name (false);
593 symtab_node::dump_asm_name () const
595 return get_dump_name (true);
598 /* Return ipa reference from this symtab_node to
599 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
603 symtab_node::create_reference (symtab_node
*referred_node
,
604 enum ipa_ref_use use_type
)
606 return create_reference (referred_node
, use_type
, NULL
);
610 /* Return ipa reference from this symtab_node to
611 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
612 of the use and STMT the statement (if it exists). */
615 symtab_node::create_reference (symtab_node
*referred_node
,
616 enum ipa_ref_use use_type
, gimple
*stmt
)
618 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
619 ipa_ref_list
*list
, *list2
;
620 ipa_ref_t
*old_references
;
622 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
623 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
626 old_references
= list
->references
.address ();
627 list
->references
.safe_grow (list
->references
.length () + 1, false);
628 ref
= &list
->references
.last ();
630 list2
= &referred_node
->ref_list
;
632 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
633 if(use_type
== IPA_REF_ALIAS
)
635 list2
->referring
.safe_insert (0, ref
);
636 ref
->referred_index
= 0;
638 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
639 list2
->referring
[i
]->referred_index
= i
;
643 list2
->referring
.safe_push (ref
);
644 ref
->referred_index
= list2
->referring
.length () - 1;
647 ref
->referring
= this;
648 ref
->referred
= referred_node
;
650 ref
->lto_stmt_uid
= 0;
651 ref
->speculative_id
= 0;
653 ref
->speculative
= 0;
655 /* If vector was moved in memory, update pointers. */
656 if (old_references
!= list
->references
.address ())
659 for (i
= 0; iterate_reference(i
, ref2
); i
++)
660 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
666 symtab_node::maybe_create_reference (tree val
, gimple
*stmt
)
669 ipa_ref_use use_type
;
671 switch (TREE_CODE (val
))
674 use_type
= IPA_REF_LOAD
;
677 use_type
= IPA_REF_ADDR
;
680 gcc_assert (!handled_component_p (val
));
684 val
= get_base_var (val
);
685 if (val
&& VAR_OR_FUNCTION_DECL_P (val
))
687 symtab_node
*referred
= symtab_node::get (val
);
688 gcc_checking_assert (referred
);
689 return create_reference (referred
, use_type
, stmt
);
694 /* Clone all references from symtab NODE to this symtab_node. */
697 symtab_node::clone_references (symtab_node
*node
)
699 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
701 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
703 bool speculative
= ref
->speculative
;
704 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
705 unsigned int spec_id
= ref
->speculative_id
;
707 ref2
= create_reference (ref
->referred
, ref
->use
, ref
->stmt
);
708 ref2
->speculative
= speculative
;
709 ref2
->lto_stmt_uid
= stmt_uid
;
710 ref2
->speculative_id
= spec_id
;
714 /* Clone all referring from symtab NODE to this symtab_node. */
717 symtab_node::clone_referring (symtab_node
*node
)
719 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
721 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
723 bool speculative
= ref
->speculative
;
724 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
725 unsigned int spec_id
= ref
->speculative_id
;
727 ref2
= ref
->referring
->create_reference (this, ref
->use
, ref
->stmt
);
728 ref2
->speculative
= speculative
;
729 ref2
->lto_stmt_uid
= stmt_uid
;
730 ref2
->speculative_id
= spec_id
;
734 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
737 symtab_node::clone_reference (ipa_ref
*ref
, gimple
*stmt
)
739 bool speculative
= ref
->speculative
;
740 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
741 unsigned int spec_id
= ref
->speculative_id
;
744 ref2
= create_reference (ref
->referred
, ref
->use
, stmt
);
745 ref2
->speculative
= speculative
;
746 ref2
->lto_stmt_uid
= stmt_uid
;
747 ref2
->speculative_id
= spec_id
;
751 /* Find the structure describing a reference to REFERRED_NODE of USE_TYPE and
752 associated with statement STMT or LTO_STMT_UID. */
755 symtab_node::find_reference (symtab_node
*referred_node
,
756 gimple
*stmt
, unsigned int lto_stmt_uid
,
757 enum ipa_ref_use use_type
)
762 for (i
= 0; iterate_reference (i
, r
); i
++)
763 if (r
->referred
== referred_node
765 && r
->use
== use_type
766 && ((stmt
&& r
->stmt
== stmt
)
767 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
768 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
773 /* Remove all references that are associated with statement STMT. */
776 symtab_node::remove_stmt_references (gimple
*stmt
)
781 while (iterate_reference (i
, r
))
783 r
->remove_reference ();
788 /* Remove all stmt references in non-speculative references in THIS
790 Those are not maintained during inlining & cloning.
791 The exception are speculative references that are updated along
792 with callgraph edges associated with them. */
795 symtab_node::clear_stmts_in_references (void)
800 for (i
= 0; iterate_reference (i
, r
); i
++)
805 r
->speculative_id
= 0;
807 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
811 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
812 cnode
->clear_stmts_in_references ();
816 /* Remove all references in ref list. */
819 symtab_node::remove_all_references (void)
821 while (ref_list
.references
.length ())
822 ref_list
.references
.last ().remove_reference ();
823 ref_list
.references
.release ();
826 /* Remove all referring items in ref list. */
829 symtab_node::remove_all_referring (void)
831 while (ref_list
.referring
.length ())
832 ref_list
.referring
.last ()->remove_reference ();
833 ref_list
.referring
.release ();
836 /* Dump references in ref list to FILE. */
839 symtab_node::dump_references (FILE *file
)
843 for (i
= 0; iterate_reference (i
, ref
); i
++)
845 fprintf (file
, "%s (%s) ", ref
->referred
->dump_asm_name (),
846 ipa_ref_use_name
[ref
->use
]);
847 if (ref
->speculative
)
848 fprintf (file
, "(speculative) ");
850 fprintf (file
, "\n");
853 /* Dump referring in list to FILE. */
856 symtab_node::dump_referring (FILE *file
)
860 for (i
= 0; iterate_referring(i
, ref
); i
++)
862 fprintf (file
, "%s (%s) ", ref
->referring
->dump_asm_name (),
863 ipa_ref_use_name
[ref
->use
]);
864 if (ref
->speculative
)
865 fprintf (file
, "(speculative) ");
867 fprintf (file
, "\n");
870 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
872 /* Dump the visibility of the symbol. */
875 symtab_node::get_visibility_string () const
877 static const char * const visibility_types
[]
878 = { "default", "protected", "hidden", "internal" };
879 return visibility_types
[DECL_VISIBILITY (decl
)];
882 /* Dump the type_name of the symbol. */
884 symtab_node::get_symtab_type_string () const
886 return symtab_type_names
[type
];
889 /* Dump base fields of symtab nodes to F. Not to be used directly. */
892 symtab_node::dump_base (FILE *f
)
894 static const char * const visibility_types
[] = {
895 "default", "protected", "hidden", "internal"
898 fprintf (f
, "%s (%s)", dump_asm_name (), name ());
899 if (dump_flags
& TDF_ADDRESS
)
900 dump_addr (f
, " @", (void *)this);
901 fprintf (f
, "\n Type: %s", symtab_type_names
[type
]);
904 fprintf (f
, " definition");
906 fprintf (f
, " analyzed");
908 fprintf (f
, " alias");
909 if (transparent_alias
)
910 fprintf (f
, " transparent_alias");
912 fprintf (f
, " weakref");
914 fprintf (f
, " symver");
915 if (cpp_implicit_alias
)
916 fprintf (f
, " cpp_implicit_alias");
918 fprintf (f
, " target:%s",
919 DECL_P (alias_target
)
920 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
922 : IDENTIFIER_POINTER (alias_target
));
924 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
925 fprintf (f
, "\n Visibility:");
926 if (in_other_partition
)
927 fprintf (f
, " in_other_partition");
928 if (used_from_other_partition
)
929 fprintf (f
, " used_from_other_partition");
931 fprintf (f
, " force_output");
933 fprintf (f
, " forced_by_abi");
934 if (externally_visible
)
935 fprintf (f
, " externally_visible");
936 if (semantic_interposition
)
937 fprintf (f
, " semantic_interposition");
939 fprintf (f
, " no_reorder");
940 if (resolution
!= LDPR_UNKNOWN
)
942 ld_plugin_symbol_resolution_names
[(int)resolution
]);
943 if (TREE_ASM_WRITTEN (decl
))
944 fprintf (f
, " asm_written");
945 if (DECL_EXTERNAL (decl
))
946 fprintf (f
, " external");
947 if (TREE_PUBLIC (decl
))
948 fprintf (f
, " public");
949 if (DECL_COMMON (decl
))
950 fprintf (f
, " common");
951 if (DECL_WEAK (decl
))
952 fprintf (f
, " weak");
953 if (DECL_DLLIMPORT_P (decl
))
954 fprintf (f
, " dll_import");
955 if (DECL_COMDAT (decl
))
956 fprintf (f
, " comdat");
957 if (get_comdat_group ())
958 fprintf (f
, " comdat_group:%s",
959 IDENTIFIER_POINTER (get_comdat_group_id ()));
960 if (DECL_ONE_ONLY (decl
))
961 fprintf (f
, " one_only");
963 fprintf (f
, " section:%s",
965 if (implicit_section
)
966 fprintf (f
," (implicit_section)");
967 if (DECL_VISIBILITY_SPECIFIED (decl
))
968 fprintf (f
, " visibility_specified");
969 if (DECL_VISIBILITY (decl
))
970 fprintf (f
, " visibility:%s",
971 visibility_types
[DECL_VISIBILITY (decl
)]);
972 if (DECL_VIRTUAL_P (decl
))
973 fprintf (f
, " virtual");
974 if (DECL_ARTIFICIAL (decl
))
975 fprintf (f
, " artificial");
976 if (TREE_CODE (decl
) == FUNCTION_DECL
)
978 if (DECL_STATIC_CONSTRUCTOR (decl
))
979 fprintf (f
, " constructor");
980 if (DECL_STATIC_DESTRUCTOR (decl
))
981 fprintf (f
, " destructor");
984 fprintf (f
, " ifunc_resolver");
987 if (same_comdat_group
)
988 fprintf (f
, " Same comdat group as: %s\n",
989 same_comdat_group
->dump_asm_name ());
990 if (next_sharing_asm_name
)
991 fprintf (f
, " next sharing asm name: %i\n",
992 next_sharing_asm_name
->order
);
993 if (previous_sharing_asm_name
)
994 fprintf (f
, " previous sharing asm name: %i\n",
995 previous_sharing_asm_name
->order
);
998 fprintf (f
, " Address is taken.\n");
1001 fprintf (f
, " Aux:");
1002 dump_addr (f
, " @", (void *)aux
);
1006 fprintf (f
, " References: ");
1007 dump_references (f
);
1008 fprintf (f
, " Referring: ");
1011 fprintf (f
, " Read from file: %s\n",
1012 lto_file_data
->file_name
);
1015 /* Dump symtab node to F. */
1018 symtab_node::dump (FILE *f
)
1020 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
1022 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
1027 symtab_node::dump_graphviz (FILE *f
)
1029 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
1030 cnode
->dump_graphviz (f
);
1034 symbol_table::dump (FILE *f
)
1037 fprintf (f
, "Symbol table:\n\n");
1038 FOR_EACH_SYMBOL (node
)
1043 symbol_table::dump_graphviz (FILE *f
)
1046 fprintf (f
, "digraph symtab {\n");
1047 FOR_EACH_SYMBOL (node
)
1048 node
->dump_graphviz (f
);
1053 symbol_table::debug (void)
1058 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1059 Return NULL if there's no such node. */
1062 symtab_node::get_for_asmname (const_tree asmname
)
1066 symtab
->symtab_initialize_asm_name_hash ();
1067 hashval_t hash
= symtab
->decl_assembler_name_hash (asmname
);
1069 = symtab
->assembler_name_hash
->find_slot_with_hash (asmname
, hash
,
1080 /* Dump symtab node NODE to stderr. */
1083 symtab_node::debug (void)
1088 /* Verify common part of symtab nodes. */
1091 /* Disable warnings about missing quoting in GCC diagnostics for
1092 the verification errors. Their format strings don't follow GCC
1093 diagnostic conventions and the calls are ultimately followed by
1094 one to internal_error. */
1095 # pragma GCC diagnostic push
1096 # pragma GCC diagnostic ignored "-Wformat-diag"
1100 symtab_node::verify_base (void)
1102 bool error_found
= false;
1103 symtab_node
*hashed_node
;
1105 if (is_a
<cgraph_node
*> (this))
1107 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1109 error ("function symbol is not function");
1112 else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl
))
1114 != dyn_cast
<cgraph_node
*> (this)->ifunc_resolver
)
1116 error ("inconsistent %<ifunc%> attribute");
1120 else if (is_a
<varpool_node
*> (this))
1124 error ("variable symbol is not variable");
1130 error ("node has unknown type");
1133 if (order
< 0 || order
>= symtab
->order
)
1135 error ("node has invalid order %i", order
);
1139 if (symtab
->state
!= LTO_STREAMING
)
1141 hashed_node
= symtab_node::get (decl
);
1144 error ("node not found node->decl->decl_with_vis.symtab_node");
1147 if (hashed_node
!= this
1148 && (!is_a
<cgraph_node
*> (this)
1149 || !dyn_cast
<cgraph_node
*> (this)->clone_of
1150 || dyn_cast
<cgraph_node
*> (this)->clone_of
->decl
!= decl
))
1152 error ("node differs from node->decl->decl_with_vis.symtab_node");
1156 if (symtab
->assembler_name_hash
)
1158 hashed_node
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
1161 if (hashed_node
->previous_sharing_asm_name
)
1163 error ("assembler name hash list corrupted");
1166 else if (previous_sharing_asm_name
== NULL
)
1168 if (hashed_node
!= this)
1170 error ("assembler name hash list corrupted");
1174 else if (!(is_a
<varpool_node
*> (this) && DECL_HARD_REGISTER (decl
)))
1176 if (!asmname_hasher::equal (previous_sharing_asm_name
,
1177 DECL_ASSEMBLER_NAME (decl
)))
1179 error ("node not found in symtab assembler name hash");
1185 if (previous_sharing_asm_name
1186 && previous_sharing_asm_name
->next_sharing_asm_name
!= this)
1188 error ("double linked list of assembler names corrupted");
1191 if (body_removed
&& definition
)
1193 error ("node has body_removed but is definition");
1196 if (analyzed
&& !definition
)
1198 error ("node is analyzed but it is not a definition");
1201 if (cpp_implicit_alias
&& !alias
)
1203 error ("node is alias but not implicit alias");
1206 if (alias
&& !definition
&& !weakref
)
1208 error ("node is alias but not definition");
1211 if (weakref
&& !transparent_alias
)
1213 error ("node is weakref but not an transparent_alias");
1216 if (transparent_alias
&& !alias
)
1218 error ("node is transparent_alias but not an alias");
1221 if (symver
&& !alias
)
1223 error ("node is symver but not alias");
1226 /* Limitation of gas requires us to output targets of symver aliases as
1227 global symbols. This is binutils PR 25295. */
1229 && (!TREE_PUBLIC (get_alias_target ()->decl
)
1230 || DECL_VISIBILITY (get_alias_target ()->decl
) != VISIBILITY_DEFAULT
))
1232 error ("symver target is not exported with default visibility");
1236 && (!TREE_PUBLIC (decl
)
1237 || DECL_VISIBILITY (decl
) != VISIBILITY_DEFAULT
))
1239 error ("symver is not exported with default visibility");
1242 if (same_comdat_group
)
1244 symtab_node
*n
= same_comdat_group
;
1246 if (!n
->get_comdat_group ())
1248 error ("node is in same_comdat_group list but has no comdat_group");
1251 if (n
->get_comdat_group () != get_comdat_group ())
1253 error ("same_comdat_group list across different groups");
1256 if (n
->type
!= type
)
1258 error ("mixing different types of symbol in same comdat groups is not supported");
1263 error ("node is alone in a comdat group");
1268 if (!n
->same_comdat_group
)
1270 error ("same_comdat_group is not a circular list");
1274 n
= n
->same_comdat_group
;
1277 if (comdat_local_p ())
1279 ipa_ref
*ref
= NULL
;
1281 for (int i
= 0; iterate_referring (i
, ref
); ++i
)
1283 if (!in_same_comdat_group_p (ref
->referring
))
1285 error ("comdat-local symbol referred to by %s outside its "
1287 identifier_to_locale (ref
->referring
->name()));
1293 if (implicit_section
&& !get_section ())
1295 error ("implicit_section flag is set but section isn%'t");
1298 if (get_section () && get_comdat_group ()
1299 && !implicit_section
1300 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl
)))
1302 error ("Both section and comdat group is set");
1305 /* TODO: Add string table for sections, so we do not keep holding duplicated
1307 if (alias
&& definition
1308 && get_section () != get_alias_target ()->get_section ()
1310 || !get_alias_target ()->get_section ()
1311 || strcmp (get_section(),
1312 get_alias_target ()->get_section ())))
1314 error ("Alias and target%'s section differs");
1315 get_alias_target ()->dump (stderr
);
1318 if (alias
&& definition
1319 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1321 error ("Alias and target%'s comdat groups differs");
1322 get_alias_target ()->dump (stderr
);
1325 if (transparent_alias
&& definition
&& !weakref
)
1327 symtab_node
*to
= get_alias_target ();
1329 = IDENTIFIER_POINTER (
1330 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl
)));
1332 = IDENTIFIER_POINTER (
1333 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to
->decl
)));
1334 if (!symbol_table::assembler_names_equal_p (name1
, name2
))
1336 error ("Transparent alias and target%'s assembler names differs");
1337 get_alias_target ()->dump (stderr
);
1341 if (transparent_alias
&& definition
1342 && get_alias_target()->transparent_alias
&& get_alias_target()->analyzed
)
1344 error ("Chained transparent aliases");
1345 get_alias_target ()->dump (stderr
);
1352 /* Verify consistency of NODE. */
1355 symtab_node::verify (void)
1360 timevar_push (TV_CGRAPH_VERIFY
);
1361 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (this))
1362 node
->verify_node ();
1367 internal_error ("symtab_node::verify failed");
1369 timevar_pop (TV_CGRAPH_VERIFY
);
1372 /* Return true and set *DATA to true if NODE is an ifunc resolver. */
1375 check_ifunc_resolver (cgraph_node
*node
, void *data
)
1377 if (node
->ifunc_resolver
)
1379 bool *is_ifunc_resolver
= (bool *) data
;
1380 *is_ifunc_resolver
= true;
1386 static auto_bitmap ifunc_ref_map
;
1388 /* Return true if any caller of NODE is an ifunc resolver. */
1391 is_caller_ifunc_resolver (cgraph_node
*node
)
1393 bool is_ifunc_resolver
= false;
1395 for (cgraph_edge
*e
= node
->callers
; e
; e
= e
->next_caller
)
1397 /* Return true if caller is known to be an IFUNC resolver. */
1398 if (e
->caller
->called_by_ifunc_resolver
)
1401 /* Check for recursive call. */
1402 if (e
->caller
== node
)
1405 /* Skip if it has been visited. */
1406 unsigned int uid
= e
->caller
->get_uid ();
1407 if (bitmap_bit_p (ifunc_ref_map
, uid
))
1409 bitmap_set_bit (ifunc_ref_map
, uid
);
1411 if (is_caller_ifunc_resolver (e
->caller
))
1413 /* Return true if caller is an IFUNC resolver. */
1414 e
->caller
->called_by_ifunc_resolver
= true;
1418 /* Check if caller's alias is an IFUNC resolver. */
1419 e
->caller
->call_for_symbol_and_aliases (check_ifunc_resolver
,
1422 if (is_ifunc_resolver
)
1424 /* Return true if caller's alias is an IFUNC resolver. */
1425 e
->caller
->called_by_ifunc_resolver
= true;
1433 /* Check symbol table for callees of IFUNC resolvers. */
1436 symtab_node::check_ifunc_callee_symtab_nodes (void)
1440 FOR_EACH_SYMBOL (node
)
1442 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1446 unsigned int uid
= cnode
->get_uid ();
1447 if (bitmap_bit_p (ifunc_ref_map
, uid
))
1449 bitmap_set_bit (ifunc_ref_map
, uid
);
1451 bool is_ifunc_resolver
= false;
1452 cnode
->call_for_symbol_and_aliases (check_ifunc_resolver
,
1453 &is_ifunc_resolver
, true);
1454 if (is_ifunc_resolver
|| is_caller_ifunc_resolver (cnode
))
1455 cnode
->called_by_ifunc_resolver
= true;
1458 bitmap_clear (ifunc_ref_map
);
1461 /* Verify symbol table for internal consistency. */
1464 symtab_node::verify_symtab_nodes (void)
1467 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1470 for (anode
= symtab
->first_asm_symbol (); anode
; anode
= anode
->next
)
1471 if (anode
->order
< 0 || anode
->order
>= symtab
->order
)
1473 error ("invalid order in asm node %i", anode
->order
);
1474 internal_error ("symtab_node::verify failed");
1477 FOR_EACH_SYMBOL (node
)
1480 if (node
->get_comdat_group ())
1482 symtab_node
**entry
, *s
;
1485 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1489 else if (!DECL_EXTERNAL (node
->decl
))
1491 for (s
= (*entry
)->same_comdat_group
;
1492 s
!= NULL
&& s
!= node
&& s
!= *entry
;
1493 s
= s
->same_comdat_group
)
1495 if (!s
|| s
== *entry
)
1497 error ("Two symbols with same comdat_group are not linked by "
1498 "the same_comdat_group list.");
1501 internal_error ("symtab_node::verify failed");
1509 # pragma GCC diagnostic pop
1512 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1513 but other code such as notice_global_symbol generates rtl. */
1516 symtab_node::make_decl_local (void)
1523 IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
)) = 0;
1524 TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
)) = NULL_TREE
;
1525 symtab
->change_decl_assembler_name
1526 (decl
, DECL_ASSEMBLER_NAME (get_alias_target ()->decl
));
1527 DECL_ATTRIBUTES (decl
) = remove_attribute ("weakref",
1528 DECL_ATTRIBUTES (decl
));
1530 /* Avoid clearing comdat_groups on comdat-local decls. */
1531 else if (TREE_PUBLIC (decl
) == 0)
1534 /* Localizing a symbol also make all its transparent aliases local. */
1536 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
); i
++)
1538 struct symtab_node
*alias
= ref
->referring
;
1539 if (alias
->transparent_alias
)
1540 alias
->make_decl_local ();
1545 DECL_COMMON (decl
) = 0;
1546 /* ADDRESSABLE flag is not defined for public symbols. */
1547 TREE_ADDRESSABLE (decl
) = 1;
1548 TREE_STATIC (decl
) = 1;
1551 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1553 DECL_COMDAT (decl
) = 0;
1554 DECL_WEAK (decl
) = 0;
1555 DECL_EXTERNAL (decl
) = 0;
1556 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1557 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1558 TREE_PUBLIC (decl
) = 0;
1559 DECL_DLLIMPORT_P (decl
) = 0;
1560 if (!DECL_RTL_SET_P (decl
))
1563 /* Update rtl flags. */
1564 make_decl_rtl (decl
);
1566 rtl
= DECL_RTL (decl
);
1570 symbol
= XEXP (rtl
, 0);
1571 if (GET_CODE (symbol
) != SYMBOL_REF
)
1574 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1577 /* Copy visibility from N.
1578 This is useful when THIS becomes a transparent alias of N. */
1581 symtab_node::copy_visibility_from (symtab_node
*n
)
1583 gcc_checking_assert (n
->weakref
== weakref
);
1586 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
); i
++)
1588 struct symtab_node
*alias
= ref
->referring
;
1589 if (alias
->transparent_alias
)
1590 alias
->copy_visibility_from (n
);
1595 DECL_COMMON (decl
) = DECL_COMMON (n
->decl
);
1596 /* ADDRESSABLE flag is not defined for public symbols. */
1597 if (TREE_PUBLIC (decl
) && !TREE_PUBLIC (n
->decl
))
1598 TREE_ADDRESSABLE (decl
) = 1;
1599 TREE_STATIC (decl
) = TREE_STATIC (n
->decl
);
1601 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1603 DECL_COMDAT (decl
) = DECL_COMDAT (n
->decl
);
1604 DECL_WEAK (decl
) = DECL_WEAK (n
->decl
);
1605 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (n
->decl
);
1606 DECL_VISIBILITY_SPECIFIED (decl
) = DECL_VISIBILITY_SPECIFIED (n
->decl
);
1607 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (n
->decl
);
1608 TREE_PUBLIC (decl
) = TREE_PUBLIC (n
->decl
);
1609 DECL_DLLIMPORT_P (decl
) = DECL_DLLIMPORT_P (n
->decl
);
1610 resolution
= n
->resolution
;
1611 set_comdat_group (n
->get_comdat_group ());
1613 externally_visible
= n
->externally_visible
;
1614 if (!DECL_RTL_SET_P (decl
))
1617 /* Update rtl flags. */
1618 make_decl_rtl (decl
);
1620 rtx rtl
= DECL_RTL (decl
);
1624 rtx symbol
= XEXP (rtl
, 0);
1625 if (GET_CODE (symbol
) != SYMBOL_REF
)
1628 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1631 /* Walk the alias chain to return the symbol NODE is alias of.
1632 If NODE is not an alias, return NODE.
1633 Assumes NODE is known to be alias. */
1636 symtab_node::ultimate_alias_target_1 (enum availability
*availability
,
1639 bool transparent_p
= false;
1641 /* To determine visibility of the target, we follow ELF semantic of aliases.
1642 Here alias is an alternative assembler name of a given definition. Its
1643 availability prevails the availability of its target (i.e. static alias of
1644 weak definition is available.
1646 Transparent alias is just alternative name of a given symbol used within
1647 one compilation unit and is translated prior hitting the object file. It
1648 inherits the visibility of its target.
1649 Weakref is a different animal (and noweak definition is weak).
1651 If we ever get into supporting targets with different semantics, a target
1652 hook will be needed here. */
1656 transparent_p
= transparent_alias
;
1658 *availability
= get_availability (ref
);
1660 *availability
= AVAIL_NOT_AVAILABLE
;
1663 symtab_node
*node
= this;
1666 if (node
->alias
&& node
->analyzed
)
1667 node
= node
->get_alias_target ();
1670 if (!availability
|| (!transparent_p
&& node
->analyzed
))
1672 else if (node
->analyzed
&& !node
->transparent_alias
)
1673 *availability
= node
->get_availability (ref
);
1675 *availability
= AVAIL_NOT_AVAILABLE
;
1678 if (node
&& availability
&& transparent_p
1679 && node
->transparent_alias
)
1681 *availability
= node
->get_availability (ref
);
1682 transparent_p
= false;
1686 *availability
= AVAIL_NOT_AVAILABLE
;
1690 /* C++ FE sometimes change linkage flags after producing same body aliases.
1692 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1693 are obviously equivalent. The way it is doing so is however somewhat
1694 kludgy and interferes with the visibility code. As a result we need to
1695 copy the visibility from the target to get things right. */
1698 symtab_node::fixup_same_cpp_alias_visibility (symtab_node
*target
)
1700 if (is_a
<cgraph_node
*> (this))
1702 DECL_DECLARED_INLINE_P (decl
)
1703 = DECL_DECLARED_INLINE_P (target
->decl
);
1704 DECL_DISREGARD_INLINE_LIMITS (decl
)
1705 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1707 /* FIXME: It is not really clear why those flags should not be copied for
1711 DECL_WEAK (decl
) = DECL_WEAK (target
->decl
);
1712 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1713 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (target
->decl
);
1715 if (TREE_PUBLIC (decl
))
1719 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1720 DECL_COMDAT (decl
) = DECL_COMDAT (target
->decl
);
1721 group
= target
->get_comdat_group ();
1722 set_comdat_group (group
);
1723 if (group
&& !same_comdat_group
)
1724 add_to_same_comdat_group (target
);
1726 externally_visible
= target
->externally_visible
;
1729 /* Set section, do not recurse into aliases.
1730 When one wants to change section of a symbol and its aliases,
1734 symtab_node::set_section_for_node (const char *section
)
1736 const char *current
= get_section ();
1738 if (current
== section
1739 || (current
&& section
1740 && !strcmp (current
, section
)))
1743 release_section_hash_entry (x_section
);
1747 implicit_section
= false;
1750 if (!symtab
->section_hash
)
1751 symtab
->section_hash
= hash_table
<section_name_hasher
>::create_ggc (10);
1752 section_hash_entry
**slot
= symtab
->section_hash
->find_slot_with_hash
1753 (section
, htab_hash_string (section
), INSERT
);
1755 x_section
= retain_section_hash_entry (*slot
);
1758 int len
= strlen (section
);
1759 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1760 x_section
->ref_count
= 1;
1761 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1762 memcpy (x_section
->name
, section
, len
+ 1);
1766 /* Set the section of node THIS to be the same as the section
1767 of node OTHER. Keep reference counts of the sections
1768 up-to-date as needed. */
1771 symtab_node::set_section_for_node (const symtab_node
&other
)
1773 if (x_section
== other
.x_section
)
1775 if (get_section () && other
.get_section ())
1776 gcc_checking_assert (strcmp (get_section (), other
.get_section ()) != 0);
1777 release_section_hash_entry (x_section
);
1778 if (other
.x_section
)
1779 x_section
= retain_section_hash_entry (other
.x_section
);
1783 implicit_section
= false;
1787 /* Workers for set_section. */
1790 symtab_node::set_section_from_string (symtab_node
*n
, void *s
)
1792 n
->set_section_for_node ((char *)s
);
1796 /* Set the section of node N to be the same as the section
1800 symtab_node::set_section_from_node (symtab_node
*n
, void *o
)
1802 const symtab_node
&other
= *static_cast<const symtab_node
*> (o
);
1803 n
->set_section_for_node (other
);
1807 /* Set section of symbol and its aliases. */
1810 symtab_node::set_section (const char *section
)
1812 gcc_assert (!this->alias
|| !this->analyzed
);
1813 call_for_symbol_and_aliases
1814 (symtab_node::set_section_from_string
, const_cast<char *>(section
), true);
1818 symtab_node::set_section (const symtab_node
&other
)
1820 call_for_symbol_and_aliases
1821 (symtab_node::set_section_from_node
, const_cast<symtab_node
*>(&other
), true);
1824 /* Return the initialization priority. */
1827 symtab_node::get_init_priority ()
1829 if (!this->in_init_priority_hash
)
1830 return DEFAULT_INIT_PRIORITY
;
1832 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1833 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1836 /* Return the finalization priority. */
1839 cgraph_node::get_fini_priority ()
1841 if (!this->in_init_priority_hash
)
1842 return DEFAULT_INIT_PRIORITY
;
1843 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1844 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1847 /* Return the initialization and finalization priority information for
1848 DECL. If there is no previous priority information, a freshly
1849 allocated structure is returned. */
1851 symbol_priority_map
*
1852 symtab_node::priority_info (void)
1854 if (!symtab
->init_priority_hash
)
1855 symtab
->init_priority_hash
= hash_map
<symtab_node
*, symbol_priority_map
>::create_ggc (13);
1858 symbol_priority_map
*h
1859 = &symtab
->init_priority_hash
->get_or_insert (this, &existed
);
1862 h
->init
= DEFAULT_INIT_PRIORITY
;
1863 h
->fini
= DEFAULT_INIT_PRIORITY
;
1864 in_init_priority_hash
= true;
1870 /* Set initialization priority to PRIORITY. */
1873 symtab_node::set_init_priority (priority_type priority
)
1875 symbol_priority_map
*h
;
1877 if (is_a
<cgraph_node
*> (this))
1878 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1880 if (priority
== DEFAULT_INIT_PRIORITY
)
1882 gcc_assert (get_init_priority() == priority
);
1885 h
= priority_info ();
1889 /* Set finalization priority to PRIORITY. */
1892 cgraph_node::set_fini_priority (priority_type priority
)
1894 symbol_priority_map
*h
;
1896 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1898 if (priority
== DEFAULT_INIT_PRIORITY
)
1900 gcc_assert (get_fini_priority() == priority
);
1903 h
= priority_info ();
1907 /* Worker for symtab_resolve_alias. */
1910 symtab_node::set_implicit_section (symtab_node
*n
,
1911 void *data ATTRIBUTE_UNUSED
)
1913 n
->implicit_section
= true;
1917 /* Add reference recording that symtab node is alias of TARGET.
1918 The function can fail in the case of aliasing cycles; in this case
1919 it returns false. */
1922 symtab_node::resolve_alias (symtab_node
*target
, bool transparent
)
1926 gcc_assert (!analyzed
&& !ref_list
.references
.length ());
1928 /* Never let cycles to creep into the symbol table alias references;
1929 those will make alias walkers to be infinite. */
1930 for (n
= target
; n
&& n
->alias
;
1931 n
= n
->analyzed
? n
->get_alias_target () : NULL
)
1934 if (is_a
<cgraph_node
*> (this))
1935 error ("function %q+D part of alias cycle", decl
);
1936 else if (is_a
<varpool_node
*> (this))
1937 error ("variable %q+D part of alias cycle", decl
);
1944 /* "analyze" the node - i.e. mark the reference. */
1948 transparent
|= transparent_alias
;
1949 transparent_alias
= transparent
;
1951 while (target
->transparent_alias
&& target
->analyzed
)
1952 target
= target
->get_alias_target ();
1953 create_reference (target
, IPA_REF_ALIAS
, NULL
);
1955 /* Add alias into the comdat group of its target unless it is already there. */
1956 if (same_comdat_group
)
1957 remove_from_same_comdat_group ();
1958 set_comdat_group (NULL
);
1959 if (target
->get_comdat_group ())
1960 add_to_same_comdat_group (target
);
1962 if ((get_section () != target
->get_section ()
1963 || target
->get_comdat_group ()) && get_section () && !implicit_section
)
1965 error ("section of alias %q+D must match section of its target", decl
);
1967 set_section (*target
);
1968 if (target
->implicit_section
)
1969 call_for_symbol_and_aliases (set_implicit_section
, NULL
, true);
1971 /* Alias targets become redundant after alias is resolved into an reference.
1972 We do not want to keep it around or we would have to mind updating them
1973 when renaming symbols. */
1974 alias_target
= NULL
;
1976 if (!transparent
&& cpp_implicit_alias
&& symtab
->state
>= CONSTRUCTION
)
1977 fixup_same_cpp_alias_visibility (target
);
1979 /* If alias has address taken, so does the target. */
1981 target
->ultimate_alias_target ()->address_taken
= true;
1983 /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
1984 If alias is transparent, also all transparent aliases of THIS are now
1986 Also merge same comdat group lists. */
1988 for (unsigned i
= 0; iterate_direct_aliases (i
, ref
);)
1990 struct symtab_node
*alias_alias
= ref
->referring
;
1991 if (alias_alias
->get_comdat_group ())
1993 alias_alias
->remove_from_same_comdat_group ();
1994 alias_alias
->set_comdat_group (NULL
);
1995 if (target
->get_comdat_group ())
1996 alias_alias
->add_to_same_comdat_group (target
);
1998 if ((!alias_alias
->transparent_alias
1999 && !alias_alias
->symver
)
2002 alias_alias
->remove_all_references ();
2003 alias_alias
->create_reference (target
, IPA_REF_ALIAS
, NULL
);
2010 /* Worker searching noninterposable alias. */
2013 symtab_node::noninterposable_alias (symtab_node
*node
, void *data
)
2015 if (!node
->transparent_alias
&& decl_binds_to_current_def_p (node
->decl
))
2017 symtab_node
*fn
= node
->ultimate_alias_target ();
2019 /* Ensure that the alias is well formed this may not be the case
2020 of user defined aliases and currently it is not always the case
2021 of C++ same body aliases (that is a bug). */
2022 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
2023 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
2024 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
2025 && flags_from_decl_or_type (node
->decl
)
2026 != flags_from_decl_or_type (fn
->decl
))
2027 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
2029 *(symtab_node
**)data
= node
;
2035 /* If node cannot be overwriten by static or dynamic linker to point to
2036 different definition, return NODE. Otherwise look for alias with such
2037 property and if none exists, introduce new one. */
2040 symtab_node::noninterposable_alias (void)
2043 symtab_node
*new_node
= NULL
;
2045 /* First try to look up existing alias or base object
2046 (if that is already non-overwritable). */
2047 symtab_node
*node
= ultimate_alias_target ();
2048 gcc_assert (!node
->alias
&& !node
->weakref
);
2049 node
->call_for_symbol_and_aliases (symtab_node::noninterposable_alias
,
2050 (void *)&new_node
, true);
2054 /* If aliases aren't supported by the assembler, fail. */
2055 if (!TARGET_SUPPORTS_ALIASES
)
2057 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node
->decl
)))
2060 /* Otherwise create a new one. */
2061 new_decl
= copy_node (node
->decl
);
2062 DECL_DLLIMPORT_P (new_decl
) = 0;
2063 tree name
= clone_function_name (node
->decl
, "localalias");
2066 unsigned long num
= 0;
2067 /* In the rare case we already have a localalias, but the above
2068 node->call_for_symbol_and_aliases call didn't find any suitable,
2069 iterate until we find one not used yet. */
2070 while (symtab_node::get_for_asmname (name
))
2071 name
= clone_function_name (node
->decl
, "localalias", num
++);
2073 DECL_NAME (new_decl
) = name
;
2074 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
2075 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
2076 DECL_INITIAL (new_decl
) = NULL
;
2077 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
2078 SET_DECL_RTL (new_decl
, NULL
);
2080 /* Update the properties. */
2081 DECL_EXTERNAL (new_decl
) = 0;
2082 TREE_PUBLIC (new_decl
) = 0;
2083 DECL_COMDAT (new_decl
) = 0;
2084 DECL_WEAK (new_decl
) = 0;
2086 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
2087 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
2088 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
2090 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
2091 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
2092 new_node
= cgraph_node::create_alias (new_decl
, node
->decl
);
2094 cgraph_node
*new_cnode
= dyn_cast
<cgraph_node
*> (new_node
),
2095 *cnode
= dyn_cast
<cgraph_node
*> (node
);
2097 new_cnode
->unit_id
= cnode
->unit_id
;
2098 new_cnode
->merged_comdat
= cnode
->merged_comdat
;
2099 new_cnode
->merged_extern_inline
= cnode
->merged_extern_inline
;
2103 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
2104 DECL_INITIAL (new_decl
) = error_mark_node
;
2105 new_node
= varpool_node::create_alias (new_decl
, node
->decl
);
2107 new_node
->resolve_alias (node
);
2108 gcc_assert (decl_binds_to_current_def_p (new_decl
)
2109 && targetm
.binds_local_p (new_decl
));
2113 /* Return true if symtab node and TARGET represents
2114 semantically equivalent symbols. */
2117 symtab_node::semantically_equivalent_p (symtab_node
*target
)
2119 enum availability avail
;
2123 /* Equivalent functions are equivalent. */
2124 if (decl
== target
->decl
)
2127 /* If symbol is not overwritable by different implementation,
2128 walk to the base object it defines. */
2129 ba
= ultimate_alias_target (&avail
);
2130 if (avail
>= AVAIL_AVAILABLE
)
2137 bb
= target
->ultimate_alias_target (&avail
);
2138 if (avail
>= AVAIL_AVAILABLE
)
2148 /* Classify symbol symtab node for partitioning. */
2150 enum symbol_partitioning_class
2151 symtab_node::get_partitioning_class (void)
2153 /* Inline clones are always duplicated.
2154 This include external declarations. */
2155 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2157 if (DECL_ABSTRACT_P (decl
))
2158 return SYMBOL_EXTERNAL
;
2160 if (cnode
&& (cnode
->inlined_to
|| cnode
->declare_variant_alt
))
2161 return SYMBOL_DUPLICATE
;
2163 /* Transparent aliases are always duplicated. */
2164 if (transparent_alias
)
2165 return definition
? SYMBOL_DUPLICATE
: SYMBOL_EXTERNAL
;
2167 /* External declarations are external. */
2168 if (DECL_EXTERNAL (decl
))
2169 return SYMBOL_EXTERNAL
;
2171 /* Even static aliases of external functions as external. Those can happen
2172 when COMDAT got resolved to non-IL implementation. */
2173 if (alias
&& DECL_EXTERNAL (ultimate_alias_target ()->decl
))
2174 return SYMBOL_EXTERNAL
;
2176 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
2178 if (alias
&& definition
&& !ultimate_alias_target ()->definition
)
2179 return SYMBOL_EXTERNAL
;
2180 /* Constant pool references use local symbol names that cannot
2181 be promoted global. We should never put into a constant pool
2182 objects that cannot be duplicated across partitions. */
2183 if (DECL_IN_CONSTANT_POOL (decl
))
2184 return SYMBOL_DUPLICATE
;
2185 if (DECL_HARD_REGISTER (decl
))
2186 return SYMBOL_DUPLICATE
;
2187 gcc_checking_assert (vnode
->definition
);
2189 /* Functions that are cloned may stay in callgraph even if they are unused.
2190 Handle them as external; compute_ltrans_boundary take care to make
2191 proper things to happen (i.e. to make them appear in the boundary but
2192 with body streamed, so clone can me materialized). */
2193 else if (!dyn_cast
<cgraph_node
*> (this)->function_symbol ()->definition
)
2194 return SYMBOL_EXTERNAL
;
2196 /* Linker discardable symbols are duplicated to every use unless they are
2198 if (DECL_ONE_ONLY (decl
)
2201 && !used_from_object_file_p ())
2202 return SYMBOL_DUPLICATE
;
2204 return SYMBOL_PARTITION
;
2207 /* Return true when symbol is known to be non-zero. */
2210 symtab_node::nonzero_address ()
2212 /* Weakrefs may be NULL when their target is not defined. */
2213 if (alias
&& weakref
)
2217 symtab_node
*target
= ultimate_alias_target ();
2219 if (target
->alias
&& target
->weakref
)
2221 /* We cannot recurse to target::nonzero. It is possible that the
2222 target is used only via the alias.
2223 We may walk references and look for strong use, but we do not know
2224 if this strong use will survive to final binary, so be
2226 ??? Maybe we could do the lookup during late optimization that
2227 could be useful to eliminate the NULL pointer checks in LTO
2229 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
2231 if (target
->resolution
!= LDPR_UNKNOWN
2232 && target
->resolution
!= LDPR_UNDEF
2233 && !target
->can_be_discarded_p ()
2234 && flag_delete_null_pointer_checks
)
2242 /* With !flag_delete_null_pointer_checks we assume that symbols may
2243 bind to NULL. This is on by default on embedded targets only.
2245 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
2246 linking fails. Important case of WEAK we want to do well are comdats,
2247 which also must be defined somewhere.
2249 When parsing, beware the cases when WEAK attribute is added later. */
2250 if ((!DECL_WEAK (decl
) || DECL_COMDAT (decl
))
2251 && flag_delete_null_pointer_checks
)
2253 refuse_visibility_changes
= true;
2257 /* If target is defined and not extern, we know it will be
2258 output and thus it will bind to non-NULL.
2259 Play safe for flag_delete_null_pointer_checks where weak definition may
2260 be re-defined by NULL. */
2261 if (definition
&& !DECL_EXTERNAL (decl
)
2262 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (decl
)))
2264 if (!DECL_WEAK (decl
))
2265 refuse_visibility_changes
= true;
2269 /* As the last resort, check the resolution info. */
2270 if (resolution
!= LDPR_UNKNOWN
2271 && resolution
!= LDPR_UNDEF
2272 && !can_be_discarded_p ()
2273 && flag_delete_null_pointer_checks
)
2278 /* Return 0 if symbol is known to have different address than S2,
2279 Return 1 if symbol is known to have same address as S2,
2280 return -1 otherwise.
2282 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
2283 and S2 is going to be accessed. This eliminates the situations when
2284 either THIS or S2 is NULL and is useful for comparing bases when deciding
2285 about memory aliasing. */
2287 symtab_node::equal_address_to (symtab_node
*s2
, bool memory_accessed
)
2289 enum availability avail1
, avail2
;
2291 /* A Shortcut: equivalent symbols are always equivalent. */
2295 /* Unwind transparent aliases first; those are always equal to their
2297 if (this->transparent_alias
&& this->analyzed
)
2298 return this->get_alias_target ()->equal_address_to (s2
);
2299 while (s2
->transparent_alias
&& s2
->analyzed
)
2300 s2
= s2
->get_alias_target();
2305 /* For non-interposable aliases, lookup and compare their actual definitions.
2306 Also check if the symbol needs to bind to given definition. */
2307 symtab_node
*rs1
= ultimate_alias_target (&avail1
);
2308 symtab_node
*rs2
= s2
->ultimate_alias_target (&avail2
);
2309 bool binds_local1
= rs1
->analyzed
&& decl_binds_to_current_def_p (this->decl
);
2310 bool binds_local2
= rs2
->analyzed
&& decl_binds_to_current_def_p (s2
->decl
);
2311 bool really_binds_local1
= binds_local1
;
2312 bool really_binds_local2
= binds_local2
;
2314 /* Addresses of vtables and virtual functions cannot be used by user
2315 code and are used only within speculation. In this case we may make
2316 symbol equivalent to its alias even if interposition may break this
2317 rule. Doing so will allow us to turn speculative inlining into
2318 non-speculative more aggressively. */
2319 if (DECL_VIRTUAL_P (this->decl
) && avail1
>= AVAIL_AVAILABLE
)
2320 binds_local1
= true;
2321 if (DECL_VIRTUAL_P (s2
->decl
) && avail2
>= AVAIL_AVAILABLE
)
2322 binds_local2
= true;
2324 /* If both definitions are available we know that even if they are bound
2325 to other unit they must be defined same way and therefore we can use
2326 equivalence test. */
2327 if (rs1
!= rs2
&& avail1
>= AVAIL_AVAILABLE
&& avail2
>= AVAIL_AVAILABLE
)
2328 binds_local1
= binds_local2
= true;
2330 if (binds_local1
&& binds_local2
&& rs1
== rs2
)
2332 /* We made use of the fact that alias is not weak. */
2334 refuse_visibility_changes
= true;
2336 s2
->refuse_visibility_changes
= true;
2340 /* If both symbols may resolve to NULL, we cannot really prove them
2342 if (!memory_accessed
&& !nonzero_address () && !s2
->nonzero_address ())
2345 /* Except for NULL, functions and variables never overlap. */
2346 if (TREE_CODE (decl
) != TREE_CODE (s2
->decl
))
2349 /* If one of the symbols is unresolved alias, punt. */
2350 if (rs1
->alias
|| rs2
->alias
)
2353 /* If we have a non-interposable definition of at least one of the symbols
2354 and the other symbol is different, we know other unit cannot interpose
2355 it to the first symbol; all aliases of the definition needs to be
2356 present in the current unit. */
2357 if (((really_binds_local1
|| really_binds_local2
)
2358 /* If we have both definitions and they are different, we know they
2359 will be different even in units they binds to. */
2360 || (binds_local1
&& binds_local2
))
2363 /* We make use of the fact that one symbol is not alias of the other
2364 and that the definition is non-interposable. */
2365 refuse_visibility_changes
= true;
2366 s2
->refuse_visibility_changes
= true;
2367 rs1
->refuse_visibility_changes
= true;
2368 rs2
->refuse_visibility_changes
= true;
2375 /* If the FE tells us at least one of the decls will never be aliased nor
2376 overlapping with other vars in some other way, return 0. */
2378 && (lookup_attribute ("non overlapping", DECL_ATTRIBUTES (decl
))
2379 || lookup_attribute ("non overlapping", DECL_ATTRIBUTES (s2
->decl
))))
2382 /* TODO: Alias oracle basically assume that addresses of global variables
2383 are different unless they are declared as alias of one to another while
2384 the code folding comparisons doesn't.
2385 We probably should be consistent and use this fact here, too, but for
2386 the moment return false only when we are called from the alias oracle.
2387 Return 0 in C constant initializers and C++ manifestly constant
2388 expressions, the likelyhood that different vars will be aliases is
2389 small and returning -1 lets us reject too many initializers. */
2390 if (memory_accessed
|| folding_initializer
)
2396 /* Worker for call_for_symbol_and_aliases. */
2399 symtab_node::call_for_symbol_and_aliases_1 (bool (*callback
) (symtab_node
*,
2402 bool include_overwritable
)
2405 FOR_EACH_ALIAS (this, ref
)
2407 symtab_node
*alias
= ref
->referring
;
2408 if (include_overwritable
2409 || alias
->get_availability () > AVAIL_INTERPOSABLE
)
2410 if (alias
->call_for_symbol_and_aliases (callback
, data
,
2411 include_overwritable
))
2417 /* Return true if address of N is possibly compared. */
2420 address_matters_1 (symtab_node
*n
, void *)
2422 struct ipa_ref
*ref
;
2424 if (!n
->address_can_be_compared_p ())
2426 if (n
->externally_visible
|| n
->force_output
)
2429 for (unsigned int i
= 0; n
->iterate_referring (i
, ref
); i
++)
2430 if (ref
->address_matters_p ())
2435 /* Return true if symbol's address may possibly be compared to other
2436 symbol's address. */
2439 symtab_node::address_matters_p ()
2441 gcc_assert (!alias
);
2442 return call_for_symbol_and_aliases (address_matters_1
, NULL
, true);
2445 /* Return true if symbol's alignment may be increased. */
2448 symtab_node::can_increase_alignment_p (void)
2450 symtab_node
*target
= ultimate_alias_target ();
2452 /* For now support only variables. */
2456 /* With -fno-toplevel-reorder we may have already output the constant. */
2457 if (TREE_ASM_WRITTEN (target
->decl
))
2460 /* If target is already placed in an anchor, we cannot touch its
2462 if (DECL_RTL_SET_P (target
->decl
)
2463 && MEM_P (DECL_RTL (target
->decl
))
2464 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target
->decl
), 0)))
2467 /* Constant pool entries may be shared. */
2468 if (DECL_IN_CONSTANT_POOL (target
->decl
))
2471 /* We cannot change alignment of symbols that may bind to symbols
2472 in other translation unit that may contain a definition with lower
2474 if (!decl_binds_to_current_def_p (decl
))
2477 /* When compiling partition, be sure the symbol is not output by other
2480 && (target
->in_other_partition
2481 || target
->get_partitioning_class () == SYMBOL_DUPLICATE
))
2484 /* Do not override the alignment as specified by the ABI when the used
2485 attribute is set. */
2486 if (DECL_PRESERVE_P (decl
) || DECL_PRESERVE_P (target
->decl
))
2489 /* Do not override explicit alignment set by the user when an explicit
2490 section name is also used. This is a common idiom used by many
2491 software projects. */
2492 if (DECL_SECTION_NAME (target
->decl
) != NULL
&& !target
->implicit_section
)
2498 /* Worker for symtab_node::increase_alignment. */
2501 increase_alignment_1 (symtab_node
*n
, void *v
)
2503 unsigned int align
= (size_t)v
;
2504 if (DECL_ALIGN (n
->decl
) < align
2505 && n
->can_increase_alignment_p ())
2507 SET_DECL_ALIGN (n
->decl
, align
);
2508 DECL_USER_ALIGN (n
->decl
) = 1;
2513 /* Increase alignment of THIS to ALIGN. */
2516 symtab_node::increase_alignment (unsigned int align
)
2518 gcc_assert (can_increase_alignment_p () && align
<= MAX_OFILE_ALIGNMENT
);
2519 ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1
,
2520 (void *)(size_t) align
,
2522 gcc_assert (DECL_ALIGN (decl
) >= align
);
2525 /* Helper for symtab_node::definition_alignment. */
2528 get_alignment_1 (symtab_node
*n
, void *v
)
2530 *((unsigned int *)v
) = MAX (*((unsigned int *)v
), DECL_ALIGN (n
->decl
));
2534 /* Return desired alignment of the definition. This is NOT alignment useful
2535 to access THIS, because THIS may be interposable and DECL_ALIGN should
2536 be used instead. It however must be guaranteed when output definition
2540 symtab_node::definition_alignment ()
2542 unsigned int align
= 0;
2543 gcc_assert (!alias
);
2544 call_for_symbol_and_aliases (get_alignment_1
, &align
, true);
2548 /* Return symbol used to separate symbol name from suffix. */
2551 symbol_table::symbol_suffix_separator ()
2553 #ifndef NO_DOT_IN_LABEL
2555 #elif !defined NO_DOLLAR_IN_LABEL
2562 /* Return true when references to this symbol from REF must bind to current
2563 definition in final executable. */
2566 symtab_node::binds_to_current_def_p (symtab_node
*ref
)
2568 if (!definition
&& !in_other_partition
)
2570 if (transparent_alias
)
2572 && get_alias_target()->binds_to_current_def_p (ref
);
2573 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2574 if (cnode
&& cnode
->ifunc_resolver
)
2576 if (decl_binds_to_current_def_p (decl
))
2579 /* Inline clones always binds locally. */
2580 if (cnode
&& cnode
->inlined_to
)
2583 if (DECL_EXTERNAL (decl
))
2586 gcc_assert (externally_visible
);
2590 cgraph_node
*cref
= dyn_cast
<cgraph_node
*> (ref
);
2592 ref
= cref
->inlined_to
;
2595 /* If this is a reference from symbol itself and there are no aliases, we
2596 may be sure that the symbol was not interposed by something else because
2597 the symbol itself would be unreachable otherwise. This is important
2598 to optimize recursive functions well.
2600 This assumption may be broken by inlining: if symbol is interposable
2601 but the body is available (i.e. declared inline), inliner may make
2602 the body reachable even with interposition. */
2603 if (this == ref
&& !has_aliases_p ()
2605 || symtab
->state
>= IPA_SSA_AFTER_INLINING
2606 || get_availability () >= AVAIL_INTERPOSABLE
))
2610 /* References within one comdat group are always bound in a group. */
2612 && symtab
->state
>= IPA_SSA_AFTER_INLINING
2613 && get_comdat_group ()
2614 && get_comdat_group () == ref
->get_comdat_group ())
2620 /* Return true if symbol should be output to the symbol table. */
2623 symtab_node::output_to_lto_symbol_table_p (void)
2625 /* Only externally visible symbols matter. */
2626 if (!TREE_PUBLIC (decl
))
2628 if (!real_symbol_p ())
2630 /* FIXME: variables probably should not be considered as real symbols at
2632 if (VAR_P (decl
) && DECL_HARD_REGISTER (decl
))
2634 if (TREE_CODE (decl
) == FUNCTION_DECL
&& !definition
2635 && fndecl_built_in_p (decl
))
2637 /* Builtins like those for most math functions have actual implementations
2638 in libraries so make sure to output references into the symbol table to
2639 make those libraries referenced. Note this is incomplete handling for
2640 now and only covers math functions. */
2641 return builtin_with_linkage_p (decl
);
2644 /* We have real symbol that should be in symbol table. However try to trim
2645 down the references to libraries bit more because linker will otherwise
2646 bring unnecessary object files into the final link.
2647 FIXME: The following checks can easily be confused i.e. by self recursive
2648 function or self-referring variable. */
2650 /* We keep external functions in symtab for sake of inlining
2651 and devirtualization. We do not want to see them in symbol table as
2652 references unless they are really used. */
2653 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
2654 if (cnode
&& (!definition
|| DECL_EXTERNAL (decl
))
2658 /* Ignore all references from external vars initializers - they are not really
2659 part of the compilation unit until they are used by folding. Some symbols,
2660 like references to external construction vtables cannot be referred to at
2661 all. We decide this at can_refer_decl_in_current_unit_p. */
2662 if (!definition
|| DECL_EXTERNAL (decl
))
2665 struct ipa_ref
*ref
;
2666 for (i
= 0; iterate_referring (i
, ref
); i
++)
2668 if (ref
->use
== IPA_REF_ALIAS
)
2670 if (is_a
<cgraph_node
*> (ref
->referring
))
2672 if (!DECL_EXTERNAL (ref
->referring
->decl
))