2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "print-tree.h"
33 #include "hard-reg-set.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
41 #include "gimple-expr.h"
44 #include "tree-inline.h"
45 #include "langhooks.h"
47 #include "diagnostic.h"
49 #include "lto-streamer.h"
51 #include "ipa-utils.h"
54 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias"};
56 const char * const ld_plugin_symbol_resolution_names
[]=
61 "prevailing_def_ironly",
67 "prevailing_def_ironly_exp"
70 /* Hash asmnames ignoring the user specified marks. */
73 symbol_table::decl_assembler_name_hash (const_tree asmname
)
75 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
77 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
78 size_t ulp_len
= strlen (user_label_prefix
);
82 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
85 return htab_hash_string (decl_str
);
88 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
92 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
95 symbol_table::decl_assembler_name_equal (tree decl
, const_tree asmname
)
97 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
99 const char *asmname_str
;
102 if (decl_asmname
== asmname
)
105 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
106 asmname_str
= IDENTIFIER_POINTER (asmname
);
109 /* If the target assembler name was set by the user, things are trickier.
110 We have a leading '*' to begin with. After that, it's arguable what
111 is the correct thing to do with -fleading-underscore. Arguably, we've
112 historically been doing the wrong thing in assemble_alias by always
113 printing the leading underscore. Since we're not changing that, make
114 sure user_label_prefix follows the '*' before matching. */
115 if (decl_str
[0] == '*')
117 size_t ulp_len
= strlen (user_label_prefix
);
123 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
124 decl_str
+= ulp_len
, test
=true;
128 if (asmname_str
[0] == '*')
130 size_t ulp_len
= strlen (user_label_prefix
);
136 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
137 asmname_str
+= ulp_len
, test
=true;
144 return strcmp (decl_str
, asmname_str
) == 0;
148 /* Returns nonzero if P1 and P2 are equal. */
150 /* Insert NODE to assembler name hash. */
153 symbol_table::insert_to_assembler_name_hash (symtab_node
*node
,
156 if (is_a
<varpool_node
*> (node
) && DECL_HARD_REGISTER (node
->decl
))
158 gcc_checking_assert (!node
->previous_sharing_asm_name
159 && !node
->next_sharing_asm_name
);
160 if (assembler_name_hash
)
164 tree decl
= node
->decl
;
166 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
168 hashval_t hash
= decl_assembler_name_hash (name
);
169 aslot
= assembler_name_hash
->find_slot_with_hash (name
, hash
, INSERT
);
170 gcc_assert (*aslot
!= node
);
171 node
->next_sharing_asm_name
= (symtab_node
*)*aslot
;
173 (*aslot
)->previous_sharing_asm_name
= node
;
176 /* Update also possible inline clones sharing a decl. */
177 cnode
= dyn_cast
<cgraph_node
*> (node
);
178 if (cnode
&& cnode
->clones
&& with_clones
)
179 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
180 if (cnode
->decl
== decl
)
181 insert_to_assembler_name_hash (cnode
, true);
186 /* Remove NODE from assembler name hash. */
189 symbol_table::unlink_from_assembler_name_hash (symtab_node
*node
,
192 if (assembler_name_hash
)
195 tree decl
= node
->decl
;
197 if (node
->next_sharing_asm_name
)
198 node
->next_sharing_asm_name
->previous_sharing_asm_name
199 = node
->previous_sharing_asm_name
;
200 if (node
->previous_sharing_asm_name
)
202 node
->previous_sharing_asm_name
->next_sharing_asm_name
203 = node
->next_sharing_asm_name
;
207 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
209 hashval_t hash
= decl_assembler_name_hash (name
);
210 slot
= assembler_name_hash
->find_slot_with_hash (name
, hash
,
212 gcc_assert (*slot
== node
);
213 if (!node
->next_sharing_asm_name
)
214 assembler_name_hash
->clear_slot (slot
);
216 *slot
= node
->next_sharing_asm_name
;
218 node
->next_sharing_asm_name
= NULL
;
219 node
->previous_sharing_asm_name
= NULL
;
221 /* Update also possible inline clones sharing a decl. */
222 cnode
= dyn_cast
<cgraph_node
*> (node
);
223 if (cnode
&& cnode
->clones
&& with_clones
)
224 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
225 if (cnode
->decl
== decl
)
226 unlink_from_assembler_name_hash (cnode
, true);
230 /* Arrange node to be first in its entry of assembler_name_hash. */
233 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node
*node
)
235 unlink_from_assembler_name_hash (node
, false);
236 insert_to_assembler_name_hash (node
, false);
239 /* Initalize asm name hash unless. */
242 symbol_table::symtab_initialize_asm_name_hash (void)
245 if (!assembler_name_hash
)
247 assembler_name_hash
= hash_table
<asmname_hasher
>::create_ggc (10);
248 FOR_EACH_SYMBOL (node
)
249 insert_to_assembler_name_hash (node
, false);
253 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
256 symbol_table::change_decl_assembler_name (tree decl
, tree name
)
258 symtab_node
*node
= NULL
;
260 /* We can have user ASM names on things, like global register variables, that
261 are not in the symbol table. */
262 if ((TREE_CODE (decl
) == VAR_DECL
263 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
264 || TREE_CODE (decl
) == FUNCTION_DECL
)
265 node
= symtab_node::get (decl
);
266 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
268 SET_DECL_ASSEMBLER_NAME (decl
, name
);
270 insert_to_assembler_name_hash (node
, true);
274 if (name
== DECL_ASSEMBLER_NAME (decl
))
277 tree alias
= (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl
))
278 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl
))
281 unlink_from_assembler_name_hash (node
, true);
282 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
283 && DECL_RTL_SET_P (decl
))
284 warning (0, "%D renamed after being referenced in assembly", decl
);
286 SET_DECL_ASSEMBLER_NAME (decl
, name
);
289 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
290 TREE_CHAIN (name
) = alias
;
293 insert_to_assembler_name_hash (node
, true);
297 /* Return true when RESOLUTION indicate that linker will use
298 the symbol from non-LTO object files. */
301 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
303 return (resolution
== LDPR_PREVAILING_DEF
304 || resolution
== LDPR_PREEMPTED_REG
305 || resolution
== LDPR_RESOLVED_EXEC
306 || resolution
== LDPR_RESOLVED_DYN
);
309 /* Hash sections by their names. */
312 section_name_hasher::hash (section_hash_entry
*n
)
314 return htab_hash_string (n
->name
);
317 /* Return true if section P1 name equals to P2. */
320 section_name_hasher::equal (section_hash_entry
*n1
, const char *name
)
322 return n1
->name
== name
|| !strcmp (n1
->name
, name
);
325 /* Add node into symbol table. This function is not used directly, but via
326 cgraph/varpool node creation routines. */
329 symtab_node::register_symbol (void)
331 symtab
->register_symbol (this);
333 if (!decl
->decl_with_vis
.symtab_node
)
334 decl
->decl_with_vis
.symtab_node
= this;
338 /* Be sure to do this last; C++ FE might create new nodes via
339 DECL_ASSEMBLER_NAME langhook! */
340 symtab
->insert_to_assembler_name_hash (this, false);
343 /* Remove NODE from same comdat group. */
346 symtab_node::remove_from_same_comdat_group (void)
348 if (same_comdat_group
)
351 for (prev
= same_comdat_group
;
352 prev
->same_comdat_group
!= this;
353 prev
= prev
->same_comdat_group
)
355 if (same_comdat_group
== prev
)
356 prev
->same_comdat_group
= NULL
;
358 prev
->same_comdat_group
= same_comdat_group
;
359 same_comdat_group
= NULL
;
360 set_comdat_group (NULL
);
364 /* Remove node from symbol table. This function is not used directly, but via
365 cgraph/varpool node removal routines. */
368 symtab_node::unregister (void)
370 remove_all_references ();
371 remove_all_referring ();
373 /* Remove reference to section. */
374 set_section_for_node (NULL
);
376 remove_from_same_comdat_group ();
378 symtab
->unregister (this);
380 /* During LTO symtab merging we temporarily corrupt decl to symtab node
382 gcc_assert (decl
->decl_with_vis
.symtab_node
|| in_lto_p
);
383 if (decl
->decl_with_vis
.symtab_node
== this)
385 symtab_node
*replacement_node
= NULL
;
386 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
387 replacement_node
= cnode
->find_replacement ();
388 decl
->decl_with_vis
.symtab_node
= replacement_node
;
390 if (!is_a
<varpool_node
*> (this) || !DECL_HARD_REGISTER (decl
))
391 symtab
->unlink_from_assembler_name_hash (this, false);
392 if (in_init_priority_hash
)
393 symtab
->init_priority_hash
->remove (this);
397 /* Remove symbol from symbol table. */
400 symtab_node::remove (void)
402 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
404 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
408 /* Add NEW_ to the same comdat group that OLD is in. */
411 symtab_node::add_to_same_comdat_group (symtab_node
*old_node
)
413 gcc_assert (old_node
->get_comdat_group ());
414 gcc_assert (!same_comdat_group
);
415 gcc_assert (this != old_node
);
417 set_comdat_group (old_node
->get_comdat_group ());
418 same_comdat_group
= old_node
;
419 if (!old_node
->same_comdat_group
)
420 old_node
->same_comdat_group
= this;
424 for (n
= old_node
->same_comdat_group
;
425 n
->same_comdat_group
!= old_node
;
426 n
= n
->same_comdat_group
)
428 n
->same_comdat_group
= this;
432 /* Dissolve the same_comdat_group list in which NODE resides. */
435 symtab_node::dissolve_same_comdat_group_list (void)
437 symtab_node
*n
= this;
440 if (!same_comdat_group
)
444 next
= n
->same_comdat_group
;
445 n
->same_comdat_group
= NULL
;
446 /* Clear comdat_group for comdat locals, since
447 make_decl_local doesn't. */
448 if (!TREE_PUBLIC (n
->decl
))
449 n
->set_comdat_group (NULL
);
455 /* Return printable assembler name of NODE.
456 This function is used only for debugging. When assembler name
457 is unknown go with identifier name. */
460 symtab_node::asm_name () const
462 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
463 return lang_hooks
.decl_printable_name (decl
, 2);
464 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
467 /* Return printable identifier name. */
470 symtab_node::name () const
472 return lang_hooks
.decl_printable_name (decl
, 2);
475 /* Return ipa reference from this symtab_node to
476 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
480 symtab_node::create_reference (symtab_node
*referred_node
,
481 enum ipa_ref_use use_type
)
483 return create_reference (referred_node
, use_type
, NULL
);
487 /* Return ipa reference from this symtab_node to
488 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
489 of the use and STMT the statement (if it exists). */
492 symtab_node::create_reference (symtab_node
*referred_node
,
493 enum ipa_ref_use use_type
, gimple stmt
)
495 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
496 ipa_ref_list
*list
, *list2
;
497 ipa_ref_t
*old_references
;
499 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
*> (this));
500 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
503 old_references
= vec_safe_address (list
->references
);
504 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
505 ref
= &list
->references
->last ();
507 list2
= &referred_node
->ref_list
;
509 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
510 if(use_type
== IPA_REF_ALIAS
)
512 list2
->referring
.safe_insert (0, ref
);
513 ref
->referred_index
= 0;
515 for (unsigned int i
= 1; i
< list2
->referring
.length (); i
++)
516 list2
->referring
[i
]->referred_index
= i
;
520 list2
->referring
.safe_push (ref
);
521 ref
->referred_index
= list2
->referring
.length () - 1;
524 ref
->referring
= this;
525 ref
->referred
= referred_node
;
527 ref
->lto_stmt_uid
= 0;
529 ref
->speculative
= 0;
531 /* If vector was moved in memory, update pointers. */
532 if (old_references
!= list
->references
->address ())
535 for (i
= 0; iterate_reference(i
, ref2
); i
++)
536 ref2
->referred_ref_list ()->referring
[ref2
->referred_index
] = ref2
;
541 /* If VAL is a reference to a function or a variable, add a reference from
542 this symtab_node to the corresponding symbol table node. USE_TYPE specify
543 type of the use and STMT the statement (if it exists). Return the new
544 reference or NULL if none was created. */
547 symtab_node::maybe_create_reference (tree val
, enum ipa_ref_use use_type
,
551 if (TREE_CODE (val
) != ADDR_EXPR
)
553 val
= get_base_var (val
);
554 if (val
&& (TREE_CODE (val
) == FUNCTION_DECL
555 || TREE_CODE (val
) == VAR_DECL
))
557 symtab_node
*referred
= symtab_node::get (val
);
558 gcc_checking_assert (referred
);
559 return create_reference (referred
, use_type
, stmt
);
564 /* Clone all references from symtab NODE to this symtab_node. */
567 symtab_node::clone_references (symtab_node
*node
)
569 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
571 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
573 bool speculative
= ref
->speculative
;
574 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
576 ref2
= create_reference (ref
->referred
, ref
->use
, ref
->stmt
);
577 ref2
->speculative
= speculative
;
578 ref2
->lto_stmt_uid
= stmt_uid
;
582 /* Clone all referring from symtab NODE to this symtab_node. */
585 symtab_node::clone_referring (symtab_node
*node
)
587 ipa_ref
*ref
= NULL
, *ref2
= NULL
;
589 for (i
= 0; node
->iterate_referring(i
, ref
); i
++)
591 bool speculative
= ref
->speculative
;
592 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
594 ref2
= ref
->referring
->create_reference (this, ref
->use
, ref
->stmt
);
595 ref2
->speculative
= speculative
;
596 ref2
->lto_stmt_uid
= stmt_uid
;
600 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
603 symtab_node::clone_reference (ipa_ref
*ref
, gimple stmt
)
605 bool speculative
= ref
->speculative
;
606 unsigned int stmt_uid
= ref
->lto_stmt_uid
;
609 ref2
= create_reference (ref
->referred
, ref
->use
, stmt
);
610 ref2
->speculative
= speculative
;
611 ref2
->lto_stmt_uid
= stmt_uid
;
615 /* Find the structure describing a reference to REFERRED_NODE
616 and associated with statement STMT. */
619 symtab_node::find_reference (symtab_node
*referred_node
,
620 gimple stmt
, unsigned int lto_stmt_uid
)
625 for (i
= 0; iterate_reference (i
, r
); i
++)
626 if (r
->referred
== referred_node
628 && ((stmt
&& r
->stmt
== stmt
)
629 || (lto_stmt_uid
&& r
->lto_stmt_uid
== lto_stmt_uid
)
630 || (!stmt
&& !lto_stmt_uid
&& !r
->stmt
&& !r
->lto_stmt_uid
)))
635 /* Remove all references that are associated with statement STMT. */
638 symtab_node::remove_stmt_references (gimple stmt
)
643 while (iterate_reference (i
, r
))
645 r
->remove_reference ();
650 /* Remove all stmt references in non-speculative references.
651 Those are not maintained during inlining & clonning.
652 The exception are speculative references that are updated along
653 with callgraph edges associated with them. */
656 symtab_node::clear_stmts_in_references (void)
661 for (i
= 0; iterate_reference (i
, r
); i
++)
669 /* Remove all references in ref list. */
672 symtab_node::remove_all_references (void)
674 while (vec_safe_length (ref_list
.references
))
675 ref_list
.references
->last ().remove_reference ();
676 vec_free (ref_list
.references
);
679 /* Remove all referring items in ref list. */
682 symtab_node::remove_all_referring (void)
684 while (ref_list
.referring
.length ())
685 ref_list
.referring
.last ()->remove_reference ();
686 ref_list
.referring
.release ();
689 /* Dump references in ref list to FILE. */
692 symtab_node::dump_references (FILE *file
)
696 for (i
= 0; iterate_reference (i
, ref
); i
++)
698 fprintf (file
, "%s/%i (%s)",
699 ref
->referred
->asm_name (),
700 ref
->referred
->order
,
701 ipa_ref_use_name
[ref
->use
]);
702 if (ref
->speculative
)
703 fprintf (file
, " (speculative)");
705 fprintf (file
, "\n");
708 /* Dump referring in list to FILE. */
711 symtab_node::dump_referring (FILE *file
)
715 for (i
= 0; iterate_referring(i
, ref
); i
++)
717 fprintf (file
, "%s/%i (%s)",
718 ref
->referring
->asm_name (),
719 ref
->referring
->order
,
720 ipa_ref_use_name
[ref
->use
]);
721 if (ref
->speculative
)
722 fprintf (file
, " (speculative)");
724 fprintf (file
, "\n");
727 /* Return true if list contains an alias. */
729 symtab_node::has_aliases_p (void)
734 for (i
= 0; iterate_referring (i
, ref
); i
++)
735 if (ref
->use
== IPA_REF_ALIAS
)
740 /* Iterates I-th reference in the list, REF is also set. */
743 symtab_node::iterate_reference (unsigned i
, ipa_ref
*&ref
)
745 vec_safe_iterate (ref_list
.references
, i
, &ref
);
750 /* Iterates I-th referring item in the list, REF is also set. */
753 symtab_node::iterate_referring (unsigned i
, ipa_ref
*&ref
)
755 ref_list
.referring
.iterate (i
, &ref
);
760 /* Iterates I-th referring alias item in the list, REF is also set. */
763 symtab_node::iterate_direct_aliases (unsigned i
, ipa_ref
*&ref
)
765 ref_list
.referring
.iterate (i
, &ref
);
767 if (ref
&& ref
->use
!= IPA_REF_ALIAS
)
773 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
775 /* Dump base fields of symtab nodes to F. Not to be used directly. */
778 symtab_node::dump_base (FILE *f
)
780 static const char * const visibility_types
[] = {
781 "default", "protected", "hidden", "internal"
784 fprintf (f
, "%s/%i (%s)", asm_name (), order
, name ());
785 dump_addr (f
, " @", (void *)this);
786 fprintf (f
, "\n Type: %s", symtab_type_names
[type
]);
789 fprintf (f
, " definition");
791 fprintf (f
, " analyzed");
793 fprintf (f
, " alias");
795 fprintf (f
, " weakref");
796 if (cpp_implicit_alias
)
797 fprintf (f
, " cpp_implicit_alias");
799 fprintf (f
, " target:%s",
800 DECL_P (alias_target
)
801 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
803 : IDENTIFIER_POINTER (alias_target
));
805 fprintf (f
, "\n Body removed by symtab_remove_unreachable_nodes");
806 fprintf (f
, "\n Visibility:");
807 if (in_other_partition
)
808 fprintf (f
, " in_other_partition");
809 if (used_from_other_partition
)
810 fprintf (f
, " used_from_other_partition");
812 fprintf (f
, " force_output");
814 fprintf (f
, " forced_by_abi");
815 if (externally_visible
)
816 fprintf (f
, " externally_visible");
818 fprintf (f
, " no_reorder");
819 if (resolution
!= LDPR_UNKNOWN
)
821 ld_plugin_symbol_resolution_names
[(int)resolution
]);
822 if (TREE_ASM_WRITTEN (decl
))
823 fprintf (f
, " asm_written");
824 if (DECL_EXTERNAL (decl
))
825 fprintf (f
, " external");
826 if (TREE_PUBLIC (decl
))
827 fprintf (f
, " public");
828 if (DECL_COMMON (decl
))
829 fprintf (f
, " common");
830 if (DECL_WEAK (decl
))
831 fprintf (f
, " weak");
832 if (DECL_DLLIMPORT_P (decl
))
833 fprintf (f
, " dll_import");
834 if (DECL_COMDAT (decl
))
835 fprintf (f
, " comdat");
836 if (get_comdat_group ())
837 fprintf (f
, " comdat_group:%s",
838 IDENTIFIER_POINTER (get_comdat_group_id ()));
839 if (DECL_ONE_ONLY (decl
))
840 fprintf (f
, " one_only");
842 fprintf (f
, " section:%s",
844 if (implicit_section
)
845 fprintf (f
," (implicit_section)");
846 if (DECL_VISIBILITY_SPECIFIED (decl
))
847 fprintf (f
, " visibility_specified");
848 if (DECL_VISIBILITY (decl
))
849 fprintf (f
, " visibility:%s",
850 visibility_types
[DECL_VISIBILITY (decl
)]);
851 if (DECL_VIRTUAL_P (decl
))
852 fprintf (f
, " virtual");
853 if (DECL_ARTIFICIAL (decl
))
854 fprintf (f
, " artificial");
855 if (TREE_CODE (decl
) == FUNCTION_DECL
)
857 if (DECL_STATIC_CONSTRUCTOR (decl
))
858 fprintf (f
, " constructor");
859 if (DECL_STATIC_DESTRUCTOR (decl
))
860 fprintf (f
, " destructor");
864 if (same_comdat_group
)
865 fprintf (f
, " Same comdat group as: %s/%i\n",
866 same_comdat_group
->asm_name (),
867 same_comdat_group
->order
);
868 if (next_sharing_asm_name
)
869 fprintf (f
, " next sharing asm name: %i\n",
870 next_sharing_asm_name
->order
);
871 if (previous_sharing_asm_name
)
872 fprintf (f
, " previous sharing asm name: %i\n",
873 previous_sharing_asm_name
->order
);
876 fprintf (f
, " Address is taken.\n");
879 fprintf (f
, " Aux:");
880 dump_addr (f
, " @", (void *)aux
);
883 fprintf (f
, " References: ");
885 fprintf (f
, " Referring: ");
888 fprintf (f
, " Read from file: %s\n",
889 lto_file_data
->file_name
);
892 /* Dump symtab node to F. */
895 symtab_node::dump (FILE *f
)
897 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this))
899 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
903 /* Dump symbol table to F. */
906 symtab_node::dump_table (FILE *f
)
909 fprintf (f
, "Symbol table:\n\n");
910 FOR_EACH_SYMBOL (node
)
915 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
916 Return NULL if there's no such node. */
919 symtab_node::get_for_asmname (const_tree asmname
)
923 symtab
->symtab_initialize_asm_name_hash ();
924 hashval_t hash
= symtab
->decl_assembler_name_hash (asmname
);
926 = symtab
->assembler_name_hash
->find_slot_with_hash (asmname
, hash
,
937 /* Dump symtab node NODE to stderr. */
940 symtab_node::debug (void)
945 /* Verify common part of symtab nodes. */
948 symtab_node::verify_base (void)
950 bool error_found
= false;
951 symtab_node
*hashed_node
;
953 if (is_a
<cgraph_node
*> (this))
955 if (TREE_CODE (decl
) != FUNCTION_DECL
)
957 error ("function symbol is not function");
961 else if (is_a
<varpool_node
*> (this))
963 if (TREE_CODE (decl
) != VAR_DECL
)
965 error ("variable symbol is not variable");
971 error ("node has unknown type");
975 if (symtab
->state
!= LTO_STREAMING
)
977 hashed_node
= symtab_node::get (decl
);
980 error ("node not found node->decl->decl_with_vis.symtab_node");
983 if (hashed_node
!= this
984 && (!is_a
<cgraph_node
*> (this)
985 || !dyn_cast
<cgraph_node
*> (this)->clone_of
986 || dyn_cast
<cgraph_node
*> (this)->clone_of
->decl
!= decl
))
988 error ("node differs from node->decl->decl_with_vis.symtab_node");
992 if (symtab
->assembler_name_hash
)
994 hashed_node
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
995 if (hashed_node
&& hashed_node
->previous_sharing_asm_name
)
997 error ("assembler name hash list corrupted");
1002 if (hashed_node
== this)
1004 hashed_node
= hashed_node
->next_sharing_asm_name
;
1007 && !(is_a
<varpool_node
*> (this)
1008 || DECL_HARD_REGISTER (decl
)))
1010 error ("node not found in symtab assembler name hash");
1014 if (previous_sharing_asm_name
1015 && previous_sharing_asm_name
->next_sharing_asm_name
!= this)
1017 error ("double linked list of assembler names corrupted");
1020 if (analyzed
&& !definition
)
1022 error ("node is analyzed byt it is not a definition");
1025 if (cpp_implicit_alias
&& !alias
)
1027 error ("node is alias but not implicit alias");
1030 if (alias
&& !definition
&& !weakref
)
1032 error ("node is alias but not definition");
1035 if (weakref
&& !alias
)
1037 error ("node is weakref but not an alias");
1040 if (same_comdat_group
)
1042 symtab_node
*n
= same_comdat_group
;
1044 if (!n
->get_comdat_group ())
1046 error ("node is in same_comdat_group list but has no comdat_group");
1049 if (n
->get_comdat_group () != get_comdat_group ())
1051 error ("same_comdat_group list across different groups");
1056 error ("Node has same_comdat_group but it is not a definition");
1059 if (n
->type
!= type
)
1061 error ("mixing different types of symbol in same comdat groups is not supported");
1066 error ("node is alone in a comdat group");
1071 if (!n
->same_comdat_group
)
1073 error ("same_comdat_group is not a circular list");
1077 n
= n
->same_comdat_group
;
1080 if (comdat_local_p ())
1082 ipa_ref
*ref
= NULL
;
1084 for (int i
= 0; iterate_referring (i
, ref
); ++i
)
1086 if (!in_same_comdat_group_p (ref
->referring
))
1088 error ("comdat-local symbol referred to by %s outside its "
1090 identifier_to_locale (ref
->referring
->name()));
1096 if (implicit_section
&& !get_section ())
1098 error ("implicit_section flag is set but section isn't");
1101 if (get_section () && get_comdat_group ()
1102 && !implicit_section
)
1104 error ("Both section and comdat group is set");
1107 /* TODO: Add string table for sections, so we do not keep holding duplicated
1109 if (alias
&& definition
1110 && get_section () != get_alias_target ()->get_section ()
1112 || !get_alias_target ()->get_section ()
1113 || strcmp (get_section(),
1114 get_alias_target ()->get_section ())))
1116 error ("Alias and target's section differs");
1117 get_alias_target ()->dump (stderr
);
1120 if (alias
&& definition
1121 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1123 error ("Alias and target's comdat groups differs");
1124 get_alias_target ()->dump (stderr
);
1131 /* Verify consistency of NODE. */
1134 symtab_node::verify (void)
1139 timevar_push (TV_CGRAPH_VERIFY
);
1140 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (this))
1141 node
->verify_node ();
1146 internal_error ("symtab_node::verify failed");
1148 timevar_pop (TV_CGRAPH_VERIFY
);
1151 /* Verify symbol table for internal consistency. */
1154 symtab_node::verify_symtab_nodes (void)
1157 hash_map
<tree
, symtab_node
*> comdat_head_map (251);
1159 FOR_EACH_SYMBOL (node
)
1162 if (node
->get_comdat_group ())
1164 symtab_node
**entry
, *s
;
1167 entry
= &comdat_head_map
.get_or_insert (node
->get_comdat_group (),
1172 for (s
= (*entry
)->same_comdat_group
; s
!= NULL
&& s
!= node
; s
= s
->same_comdat_group
)
1173 if (!s
|| s
== *entry
)
1175 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1178 internal_error ("symtab_node::verify failed");
1184 /* Return true when NODE is known to be used from other (non-LTO)
1185 object file. Known only when doing LTO via linker plugin. */
1188 symtab_node::used_from_object_file_p_worker (symtab_node
*node
)
1190 if (!TREE_PUBLIC (node
->decl
) || DECL_EXTERNAL (node
->decl
))
1192 if (resolution_used_from_other_file_p (node
->resolution
))
1198 /* Return true when symtab_node is known to be used from other (non-LTO)
1199 object file. Known only when doing LTO via linker plugin. */
1202 symtab_node::used_from_object_file_p (void)
1204 return symtab_node::used_from_object_file_p_worker (this);
1207 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1208 but other code such as notice_global_symbol generates rtl. */
1211 symtab_node::make_decl_local (void)
1215 /* Avoid clearing comdat_groups on comdat-local decls. */
1216 if (TREE_PUBLIC (decl
) == 0)
1219 if (TREE_CODE (decl
) == VAR_DECL
)
1220 DECL_COMMON (decl
) = 0;
1221 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1223 DECL_COMDAT (decl
) = 0;
1224 DECL_WEAK (decl
) = 0;
1225 DECL_EXTERNAL (decl
) = 0;
1226 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
1227 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
1228 TREE_PUBLIC (decl
) = 0;
1229 if (!DECL_RTL_SET_P (decl
))
1232 /* Update rtl flags. */
1233 make_decl_rtl (decl
);
1235 rtl
= DECL_RTL (decl
);
1239 symbol
= XEXP (rtl
, 0);
1240 if (GET_CODE (symbol
) != SYMBOL_REF
)
1243 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
1246 /* Walk the alias chain to return the symbol NODE is alias of.
1247 If NODE is not an alias, return NODE.
1248 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1251 symtab_node::ultimate_alias_target (enum availability
*availability
)
1253 bool weakref_p
= false;
1258 *availability
= get_availability ();
1262 /* To determine visibility of the target, we follow ELF semantic of aliases.
1263 Here alias is an alternative assembler name of a given definition. Its
1264 availability prevails the availability of its target (i.e. static alias of
1265 weak definition is available.
1267 Weakref is a different animal (and not part of ELF per se). It is just
1268 alternative name of a given symbol used within one complation unit
1269 and is translated prior hitting the object file. It inherits the
1270 visibility of its target (i.e. weakref of non-overwritable definition
1271 is non-overwritable, while weakref of weak definition is weak).
1273 If we ever get into supporting targets with different semantics, a target
1274 hook will be needed here. */
1278 weakref_p
= weakref
;
1280 *availability
= get_availability ();
1282 *availability
= AVAIL_LOCAL
;
1285 symtab_node
*node
= this;
1288 if (node
->alias
&& node
->analyzed
)
1289 node
= node
->get_alias_target ();
1294 else if (node
->analyzed
)
1298 enum availability a
= node
->get_availability ();
1299 if (a
< *availability
)
1304 *availability
= AVAIL_NOT_AVAILABLE
;
1307 if (node
&& availability
&& weakref_p
)
1309 enum availability a
= node
->get_availability ();
1310 if (a
< *availability
)
1312 weakref_p
= node
->weakref
;
1316 *availability
= AVAIL_NOT_AVAILABLE
;
1320 /* C++ FE sometimes change linkage flags after producing same body aliases.
1322 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1323 are obviously equivalent. The way it is doing so is however somewhat
1324 kludgy and interferes with the visibility code. As a result we need to
1325 copy the visibility from the target to get things right. */
1328 symtab_node::fixup_same_cpp_alias_visibility (symtab_node
*target
)
1330 if (is_a
<cgraph_node
*> (this))
1332 DECL_DECLARED_INLINE_P (decl
)
1333 = DECL_DECLARED_INLINE_P (target
->decl
);
1334 DECL_DISREGARD_INLINE_LIMITS (decl
)
1335 = DECL_DISREGARD_INLINE_LIMITS (target
->decl
);
1337 /* FIXME: It is not really clear why those flags should not be copied for
1341 DECL_WEAK (decl
) = DECL_WEAK (target
->decl
);
1342 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1343 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (target
->decl
);
1345 DECL_VIRTUAL_P (decl
) = DECL_VIRTUAL_P (target
->decl
);
1346 if (TREE_PUBLIC (decl
))
1350 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (target
->decl
);
1351 DECL_COMDAT (decl
) = DECL_COMDAT (target
->decl
);
1352 group
= target
->get_comdat_group ();
1353 set_comdat_group (group
);
1354 if (group
&& !same_comdat_group
)
1355 add_to_same_comdat_group (target
);
1357 externally_visible
= target
->externally_visible
;
1360 /* Set section, do not recurse into aliases.
1361 When one wants to change section of symbol and its aliases,
1365 symtab_node::set_section_for_node (const char *section
)
1367 const char *current
= get_section ();
1368 section_hash_entry
**slot
;
1370 if (current
== section
1371 || (current
&& section
1372 && !strcmp (current
, section
)))
1377 x_section
->ref_count
--;
1378 if (!x_section
->ref_count
)
1380 hashval_t hash
= htab_hash_string (x_section
->name
);
1381 slot
= symtab
->section_hash
->find_slot_with_hash (x_section
->name
,
1383 ggc_free (x_section
);
1384 symtab
->section_hash
->clear_slot (slot
);
1390 implicit_section
= false;
1393 if (!symtab
->section_hash
)
1394 symtab
->section_hash
= hash_table
<section_name_hasher
>::create_ggc (10);
1395 slot
= symtab
->section_hash
->find_slot_with_hash (section
,
1396 htab_hash_string (section
),
1399 x_section
= (section_hash_entry
*)*slot
;
1402 int len
= strlen (section
);
1403 *slot
= x_section
= ggc_cleared_alloc
<section_hash_entry
> ();
1404 x_section
->name
= ggc_vec_alloc
<char> (len
+ 1);
1405 memcpy (x_section
->name
, section
, len
+ 1);
1407 x_section
->ref_count
++;
1410 /* Worker for set_section. */
1413 symtab_node::set_section (symtab_node
*n
, void *s
)
1415 n
->set_section_for_node ((char *)s
);
1419 /* Set section of symbol and its aliases. */
1422 symtab_node::set_section (const char *section
)
1424 gcc_assert (!this->alias
);
1425 call_for_symbol_and_aliases
1426 (symtab_node::set_section
, const_cast<char *>(section
), true);
1429 /* Return the initialization priority. */
1432 symtab_node::get_init_priority ()
1434 if (!this->in_init_priority_hash
)
1435 return DEFAULT_INIT_PRIORITY
;
1437 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1438 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
1441 /* Return availability of NODE. */
1442 enum availability
symtab_node::get_availability (void)
1444 if (is_a
<cgraph_node
*> (this))
1445 return dyn_cast
<cgraph_node
*> (this)->get_availability ();
1447 return dyn_cast
<varpool_node
*> (this)->get_availability ();;
1451 /* Return the finalization priority. */
1454 cgraph_node::get_fini_priority ()
1456 if (!this->in_init_priority_hash
)
1457 return DEFAULT_INIT_PRIORITY
;
1458 symbol_priority_map
*h
= symtab
->init_priority_hash
->get (this);
1459 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
1462 /* Return the initialization and finalization priority information for
1463 DECL. If there is no previous priority information, a freshly
1464 allocated structure is returned. */
1466 symbol_priority_map
*
1467 symtab_node::priority_info (void)
1469 if (!symtab
->init_priority_hash
)
1470 symtab
->init_priority_hash
= hash_map
<symtab_node
*, symbol_priority_map
>::create_ggc (13);
1473 symbol_priority_map
*h
1474 = &symtab
->init_priority_hash
->get_or_insert (this, &existed
);
1477 h
->init
= DEFAULT_INIT_PRIORITY
;
1478 h
->fini
= DEFAULT_INIT_PRIORITY
;
1479 in_init_priority_hash
= true;
1485 /* Set initialization priority to PRIORITY. */
1488 symtab_node::set_init_priority (priority_type priority
)
1490 symbol_priority_map
*h
;
1492 if (is_a
<cgraph_node
*> (this))
1493 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl
));
1495 if (priority
== DEFAULT_INIT_PRIORITY
)
1497 gcc_assert (get_init_priority() == priority
);
1500 h
= priority_info ();
1504 /* Set fialization priority to PRIORITY. */
1507 cgraph_node::set_fini_priority (priority_type priority
)
1509 symbol_priority_map
*h
;
1511 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl
));
1513 if (priority
== DEFAULT_INIT_PRIORITY
)
1515 gcc_assert (get_fini_priority() == priority
);
1518 h
= priority_info ();
1522 /* Worker for symtab_resolve_alias. */
1525 symtab_node::set_implicit_section (symtab_node
*n
,
1526 void *data ATTRIBUTE_UNUSED
)
1528 n
->implicit_section
= true;
1532 /* Add reference recording that symtab node is alias of TARGET.
1533 The function can fail in the case of aliasing cycles; in this case
1534 it returns false. */
1537 symtab_node::resolve_alias (symtab_node
*target
)
1541 gcc_assert (!analyzed
&& !vec_safe_length (ref_list
.references
));
1543 /* Never let cycles to creep into the symbol table alias references;
1544 those will make alias walkers to be infinite. */
1545 for (n
= target
; n
&& n
->alias
;
1546 n
= n
->analyzed
? n
->get_alias_target () : NULL
)
1549 if (is_a
<cgraph_node
*> (this))
1550 error ("function %q+D part of alias cycle", decl
);
1551 else if (is_a
<varpool_node
*> (this))
1552 error ("variable %q+D part of alias cycle", decl
);
1559 /* "analyze" the node - i.e. mark the reference. */
1563 create_reference (target
, IPA_REF_ALIAS
, NULL
);
1565 /* Add alias into the comdat group of its target unless it is already there. */
1566 if (same_comdat_group
)
1567 remove_from_same_comdat_group ();
1568 set_comdat_group (NULL
);
1569 if (target
->get_comdat_group ())
1570 add_to_same_comdat_group (target
);
1572 if ((get_section () != target
->get_section ()
1573 || target
->get_comdat_group ()) && get_section () && !implicit_section
)
1575 error ("section of alias %q+D must match section of its target", decl
);
1577 call_for_symbol_and_aliases (symtab_node::set_section
,
1578 const_cast<char *>(target
->get_section ()), true);
1579 if (target
->implicit_section
)
1580 call_for_symbol_and_aliases (set_implicit_section
, NULL
, true);
1582 /* Alias targets become redundant after alias is resolved into an reference.
1583 We do not want to keep it around or we would have to mind updating them
1584 when renaming symbols. */
1585 alias_target
= NULL
;
1587 if (cpp_implicit_alias
&& symtab
->state
>= CONSTRUCTION
)
1588 fixup_same_cpp_alias_visibility (target
);
1590 /* If alias has address taken, so does the target. */
1592 target
->ultimate_alias_target ()->address_taken
= true;
1596 /* Call calback on symtab node and aliases associated to this node.
1597 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1601 symtab_node::call_for_symbol_and_aliases (bool (*callback
) (symtab_node
*,
1603 void *data
, bool include_overwritable
)
1608 if (callback (this, data
))
1610 for (i
= 0; iterate_referring (i
, ref
); i
++)
1611 if (ref
->use
== IPA_REF_ALIAS
)
1613 symtab_node
*alias
= ref
->referring
;
1614 if (include_overwritable
1615 || alias
->get_availability () > AVAIL_INTERPOSABLE
)
1616 if (alias
->call_for_symbol_and_aliases (callback
, data
,
1617 include_overwritable
))
1623 /* Worker searching noninterposable alias. */
1626 symtab_node::noninterposable_alias (symtab_node
*node
, void *data
)
1628 if (decl_binds_to_current_def_p (node
->decl
))
1630 symtab_node
*fn
= node
->ultimate_alias_target ();
1632 /* Ensure that the alias is well formed this may not be the case
1633 of user defined aliases and currently it is not always the case
1634 of C++ same body aliases (that is a bug). */
1635 if (TREE_TYPE (node
->decl
) != TREE_TYPE (fn
->decl
)
1636 || DECL_CONTEXT (node
->decl
) != DECL_CONTEXT (fn
->decl
)
1637 || (TREE_CODE (node
->decl
) == FUNCTION_DECL
1638 && flags_from_decl_or_type (node
->decl
)
1639 != flags_from_decl_or_type (fn
->decl
))
1640 || DECL_ATTRIBUTES (node
->decl
) != DECL_ATTRIBUTES (fn
->decl
))
1643 *(symtab_node
**)data
= node
;
1649 /* If node can not be overwriten by static or dynamic linker to point to
1650 different definition, return NODE. Otherwise look for alias with such
1651 property and if none exists, introduce new one. */
1654 symtab_node::noninterposable_alias (void)
1657 symtab_node
*new_node
= NULL
;
1659 /* First try to look up existing alias or base object
1660 (if that is already non-overwritable). */
1661 symtab_node
*node
= ultimate_alias_target ();
1662 gcc_assert (!node
->alias
&& !node
->weakref
);
1663 node
->call_for_symbol_and_aliases (symtab_node::noninterposable_alias
,
1664 (void *)&new_node
, true);
1667 #ifndef ASM_OUTPUT_DEF
1668 /* If aliases aren't supported by the assembler, fail. */
1672 /* Otherwise create a new one. */
1673 new_decl
= copy_node (node
->decl
);
1674 DECL_NAME (new_decl
) = clone_function_name (node
->decl
, "localalias");
1675 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1676 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
1677 DECL_INITIAL (new_decl
) = NULL
;
1678 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
1679 SET_DECL_RTL (new_decl
, NULL
);
1681 /* Update the properties. */
1682 DECL_EXTERNAL (new_decl
) = 0;
1683 TREE_PUBLIC (new_decl
) = 0;
1684 DECL_COMDAT (new_decl
) = 0;
1685 DECL_WEAK (new_decl
) = 0;
1687 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1688 DECL_VIRTUAL_P (new_decl
) = DECL_VIRTUAL_P (node
->decl
);
1689 if (TREE_CODE (new_decl
) == FUNCTION_DECL
)
1691 DECL_STATIC_CONSTRUCTOR (new_decl
) = 0;
1692 DECL_STATIC_DESTRUCTOR (new_decl
) = 0;
1693 new_node
= cgraph_node::create_alias (new_decl
, node
->decl
);
1697 TREE_READONLY (new_decl
) = TREE_READONLY (node
->decl
);
1698 DECL_INITIAL (new_decl
) = error_mark_node
;
1699 new_node
= varpool_node::create_alias (new_decl
, node
->decl
);
1701 new_node
->resolve_alias (node
);
1702 gcc_assert (decl_binds_to_current_def_p (new_decl
)
1703 && targetm
.binds_local_p (new_decl
));
1707 /* Return true if symtab node and TARGET represents
1708 semantically equivalent symbols. */
1711 symtab_node::semantically_equivalent_p (symtab_node
*target
)
1713 enum availability avail
;
1717 /* Equivalent functions are equivalent. */
1718 if (decl
== target
->decl
)
1721 /* If symbol is not overwritable by different implementation,
1722 walk to the base object it defines. */
1723 ba
= ultimate_alias_target (&avail
);
1724 if (avail
>= AVAIL_AVAILABLE
)
1731 bb
= target
->ultimate_alias_target (&avail
);
1732 if (avail
>= AVAIL_AVAILABLE
)
1742 /* Classify symbol symtab node for partitioning. */
1744 enum symbol_partitioning_class
1745 symtab_node::get_partitioning_class (void)
1747 /* Inline clones are always duplicated.
1748 This include external delcarations. */
1749 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (this);
1751 if (DECL_ABSTRACT_P (decl
))
1752 return SYMBOL_EXTERNAL
;
1754 if (cnode
&& cnode
->global
.inlined_to
)
1755 return SYMBOL_DUPLICATE
;
1757 /* Weakref aliases are always duplicated. */
1759 return SYMBOL_DUPLICATE
;
1761 /* External declarations are external. */
1762 if (DECL_EXTERNAL (decl
))
1763 return SYMBOL_EXTERNAL
;
1765 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (this))
1767 /* Constant pool references use local symbol names that can not
1768 be promoted global. We should never put into a constant pool
1769 objects that can not be duplicated across partitions. */
1770 if (DECL_IN_CONSTANT_POOL (decl
))
1771 return SYMBOL_DUPLICATE
;
1772 gcc_checking_assert (vnode
->definition
);
1774 /* Functions that are cloned may stay in callgraph even if they are unused.
1775 Handle them as external; compute_ltrans_boundary take care to make
1776 proper things to happen (i.e. to make them appear in the boundary but
1777 with body streamed, so clone can me materialized). */
1778 else if (!dyn_cast
<cgraph_node
*> (this)->definition
)
1779 return SYMBOL_EXTERNAL
;
1781 /* Linker discardable symbols are duplicated to every use unless they are
1783 if (DECL_ONE_ONLY (decl
)
1786 && !used_from_object_file_p ())
1787 return SYMBOL_DUPLICATE
;
1789 return SYMBOL_PARTITION
;
1792 /* Return true when symbol is known to be non-zero. */
1795 symtab_node::nonzero_address ()
1797 /* Weakrefs may be NULL when their target is not defined. */
1798 if (alias
&& weakref
)
1802 symtab_node
*target
= ultimate_alias_target ();
1804 if (target
->alias
&& target
->weakref
)
1806 /* We can not recurse to target::nonzero. It is possible that the
1807 target is used only via the alias.
1808 We may walk references and look for strong use, but we do not know
1809 if this strong use will survive to final binary, so be
1811 ??? Maybe we could do the lookup during late optimization that
1812 could be useful to eliminate the NULL pointer checks in LTO
1814 if (target
->definition
&& !DECL_EXTERNAL (target
->decl
))
1816 if (target
->resolution
!= LDPR_UNKNOWN
1817 && target
->resolution
!= LDPR_UNDEF
1818 && flag_delete_null_pointer_checks
)
1826 /* With !flag_delete_null_pointer_checks we assume that symbols may
1827 bind to NULL. This is on by default on embedded targets only.
1829 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1830 linking fails. Important case of WEAK we want to do well are comdats.
1831 Those are handled by later check for definition.
1833 When parsing, beware the cases when WEAK attribute is added later. */
1834 if (!DECL_WEAK (decl
)
1835 && flag_delete_null_pointer_checks
)
1837 refuse_visibility_changes
= true;
1841 /* If target is defined and not extern, we know it will be output and thus
1842 it will bind to non-NULL.
1843 Play safe for flag_delete_null_pointer_checks where weak definition maye
1844 be re-defined by NULL. */
1845 if (definition
&& !DECL_EXTERNAL (decl
)
1846 && (flag_delete_null_pointer_checks
|| !DECL_WEAK (decl
)))
1848 if (!DECL_WEAK (decl
))
1849 refuse_visibility_changes
= true;
1853 /* As the last resort, check the resolution info. */
1854 if (resolution
!= LDPR_UNKNOWN
1855 && resolution
!= LDPR_UNDEF
1856 && flag_delete_null_pointer_checks
)