2 Copyright (C) 2012-2013 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"
26 #include "tree-inline.h"
27 #include "langhooks.h"
31 #include "diagnostic.h"
33 #include "lto-streamer.h"
36 const char * const ld_plugin_symbol_resolution_names
[]=
41 "prevailing_def_ironly",
47 "prevailing_def_ironly_exp"
50 /* Hash table used to convert declarations into nodes. */
51 static GTY((param_is (union symtab_node_def
))) htab_t symtab_hash
;
52 /* Hash table used to convert assembler names into nodes. */
53 static GTY((param_is (union symtab_node_def
))) htab_t assembler_name_hash
;
55 /* Linked list of symbol table nodes. */
56 symtab_node symtab_nodes
;
58 /* The order index of the next symtab node to be created. This is
59 used so that we can sort the cgraph nodes in order by when we saw
60 them, to support -fno-toplevel-reorder. */
63 /* Returns a hash code for P. */
66 hash_node (const void *p
)
68 const_symtab_node n
= (const_symtab_node
) p
;
69 return (hashval_t
) DECL_UID (n
->symbol
.decl
);
73 /* Returns nonzero if P1 and P2 are equal. */
76 eq_node (const void *p1
, const void *p2
)
78 const_symtab_node n1
= (const_symtab_node
) p1
;
79 const_symtab_node n2
= (const_symtab_node
) p2
;
80 return DECL_UID (n1
->symbol
.decl
) == DECL_UID (n2
->symbol
.decl
);
83 /* Returns a hash code for P. */
86 hash_node_by_assembler_name (const void *p
)
88 const_symtab_node n
= (const_symtab_node
) p
;
89 return (hashval_t
) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n
->symbol
.decl
));
92 /* Returns nonzero if P1 and P2 are equal. */
95 eq_assembler_name (const void *p1
, const void *p2
)
97 const_symtab_node n1
= (const_symtab_node
) p1
;
98 const_tree name
= (const_tree
)p2
;
99 return (decl_assembler_name_equal (n1
->symbol
.decl
, name
));
102 /* Insert NODE to assembler name hash. */
105 insert_to_assembler_name_hash (symtab_node node
, bool with_clones
)
107 if (is_a
<varpool_node
> (node
) && DECL_HARD_REGISTER (node
->symbol
.decl
))
109 gcc_checking_assert (!node
->symbol
.previous_sharing_asm_name
110 && !node
->symbol
.next_sharing_asm_name
);
111 if (assembler_name_hash
)
114 struct cgraph_node
*cnode
;
115 tree decl
= node
->symbol
.decl
;
117 tree name
= DECL_ASSEMBLER_NAME (node
->symbol
.decl
);
119 aslot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
120 decl_assembler_name_hash (name
),
122 gcc_assert (*aslot
!= node
);
123 node
->symbol
.next_sharing_asm_name
= (symtab_node
)*aslot
;
125 ((symtab_node
)*aslot
)->symbol
.previous_sharing_asm_name
= node
;
128 /* Update also possible inline clones sharing a decl. */
129 cnode
= dyn_cast
<cgraph_node
> (node
);
130 if (cnode
&& cnode
->clones
&& with_clones
)
131 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
132 if (cnode
->symbol
.decl
== decl
)
133 insert_to_assembler_name_hash ((symtab_node
) cnode
, true);
138 /* Remove NODE from assembler name hash. */
141 unlink_from_assembler_name_hash (symtab_node node
, bool with_clones
)
143 if (assembler_name_hash
)
145 struct cgraph_node
*cnode
;
146 tree decl
= node
->symbol
.decl
;
148 if (node
->symbol
.next_sharing_asm_name
)
149 node
->symbol
.next_sharing_asm_name
->symbol
.previous_sharing_asm_name
150 = node
->symbol
.previous_sharing_asm_name
;
151 if (node
->symbol
.previous_sharing_asm_name
)
153 node
->symbol
.previous_sharing_asm_name
->symbol
.next_sharing_asm_name
154 = node
->symbol
.next_sharing_asm_name
;
158 tree name
= DECL_ASSEMBLER_NAME (node
->symbol
.decl
);
160 slot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
161 decl_assembler_name_hash (name
),
163 gcc_assert (*slot
== node
);
164 if (!node
->symbol
.next_sharing_asm_name
)
165 htab_clear_slot (assembler_name_hash
, slot
);
167 *slot
= node
->symbol
.next_sharing_asm_name
;
169 node
->symbol
.next_sharing_asm_name
= NULL
;
170 node
->symbol
.previous_sharing_asm_name
= NULL
;
172 /* Update also possible inline clones sharing a decl. */
173 cnode
= dyn_cast
<cgraph_node
> (node
);
174 if (cnode
&& cnode
->clones
&& with_clones
)
175 for (cnode
= cnode
->clones
; cnode
; cnode
= cnode
->next_sibling_clone
)
176 if (cnode
->symbol
.decl
== decl
)
177 unlink_from_assembler_name_hash ((symtab_node
) cnode
, true);
181 /* Arrange node to be first in its entry of assembler_name_hash. */
184 symtab_prevail_in_asm_name_hash (symtab_node node
)
186 unlink_from_assembler_name_hash (node
, false);
187 insert_to_assembler_name_hash (node
, false);
191 /* Add node into symbol table. This function is not used directly, but via
192 cgraph/varpool node creation routines. */
195 symtab_register_node (symtab_node node
)
197 struct symtab_node_base key
;
200 node
->symbol
.next
= symtab_nodes
;
201 node
->symbol
.previous
= NULL
;
203 symtab_nodes
->symbol
.previous
= node
;
207 symtab_hash
= htab_create_ggc (10, hash_node
, eq_node
, NULL
);
208 key
.decl
= node
->symbol
.decl
;
209 slot
= (symtab_node
*) htab_find_slot (symtab_hash
, &key
, INSERT
);
213 ipa_empty_ref_list (&node
->symbol
.ref_list
);
215 node
->symbol
.order
= symtab_order
++;
217 /* Be sure to do this last; C++ FE might create new nodes via
218 DECL_ASSEMBLER_NAME langhook! */
219 insert_to_assembler_name_hash (node
, false);
222 /* Make NODE to be the one symtab hash is pointing to. Used when reshaping tree
226 symtab_insert_node_to_hashtable (symtab_node node
)
228 struct symtab_node_base key
;
232 symtab_hash
= htab_create_ggc (10, hash_node
, eq_node
, NULL
);
233 key
.decl
= node
->symbol
.decl
;
234 slot
= (symtab_node
*) htab_find_slot (symtab_hash
, &key
, INSERT
);
238 /* Remove node from symbol table. This function is not used directly, but via
239 cgraph/varpool node removal routines. */
242 symtab_unregister_node (symtab_node node
)
245 ipa_remove_all_references (&node
->symbol
.ref_list
);
246 ipa_remove_all_referring (&node
->symbol
.ref_list
);
248 if (node
->symbol
.same_comdat_group
)
251 for (prev
= node
->symbol
.same_comdat_group
;
252 prev
->symbol
.same_comdat_group
!= node
;
253 prev
= prev
->symbol
.same_comdat_group
)
255 if (node
->symbol
.same_comdat_group
== prev
)
256 prev
->symbol
.same_comdat_group
= NULL
;
258 prev
->symbol
.same_comdat_group
= node
->symbol
.same_comdat_group
;
259 node
->symbol
.same_comdat_group
= NULL
;
262 if (node
->symbol
.previous
)
263 node
->symbol
.previous
->symbol
.next
= node
->symbol
.next
;
265 symtab_nodes
= node
->symbol
.next
;
266 if (node
->symbol
.next
)
267 node
->symbol
.next
->symbol
.previous
= node
->symbol
.previous
;
268 node
->symbol
.next
= NULL
;
269 node
->symbol
.previous
= NULL
;
271 slot
= htab_find_slot (symtab_hash
, node
, NO_INSERT
);
274 symtab_node replacement_node
= NULL
;
275 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
276 replacement_node
= (symtab_node
)cgraph_find_replacement_node (cnode
);
277 if (!replacement_node
)
278 htab_clear_slot (symtab_hash
, slot
);
280 *slot
= replacement_node
;
282 unlink_from_assembler_name_hash (node
, false);
285 /* Return symbol table node associated with DECL, if any,
286 and NULL otherwise. */
289 symtab_get_node (const_tree decl
)
292 struct symtab_node_base key
;
294 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
295 || (TREE_CODE (decl
) == VAR_DECL
296 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
302 key
.decl
= CONST_CAST2 (tree
, const_tree
, decl
);
304 slot
= (symtab_node
*) htab_find_slot (symtab_hash
, &key
,
312 /* Remove symtab NODE from the symbol table. */
315 symtab_remove_node (symtab_node node
)
317 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
318 cgraph_remove_node (cnode
);
319 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
))
320 varpool_remove_node (vnode
);
323 /* Initalize asm name hash unless. */
326 symtab_initialize_asm_name_hash (void)
329 if (!assembler_name_hash
)
331 assembler_name_hash
=
332 htab_create_ggc (10, hash_node_by_assembler_name
, eq_assembler_name
,
334 FOR_EACH_SYMBOL (node
)
335 insert_to_assembler_name_hash (node
, false);
339 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
340 Return NULL if there's no such node. */
343 symtab_node_for_asm (const_tree asmname
)
348 symtab_initialize_asm_name_hash ();
349 slot
= htab_find_slot_with_hash (assembler_name_hash
, asmname
,
350 decl_assembler_name_hash (asmname
),
355 node
= (symtab_node
) *slot
;
361 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
364 change_decl_assembler_name (tree decl
, tree name
)
366 symtab_node node
= NULL
;
368 /* We can have user ASM names on things, like global register variables, that
369 are not in the symbol table. */
370 if ((TREE_CODE (decl
) == VAR_DECL
371 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
372 || TREE_CODE (decl
) == FUNCTION_DECL
)
373 node
= symtab_get_node (decl
);
374 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
376 SET_DECL_ASSEMBLER_NAME (decl
, name
);
378 insert_to_assembler_name_hash (node
, true);
382 if (name
== DECL_ASSEMBLER_NAME (decl
))
386 unlink_from_assembler_name_hash (node
, true);
387 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
388 && DECL_RTL_SET_P (decl
))
389 warning (0, "%D renamed after being referenced in assembly", decl
);
391 SET_DECL_ASSEMBLER_NAME (decl
, name
);
393 insert_to_assembler_name_hash (node
, true);
397 /* Add NEW_ to the same comdat group that OLD is in. */
400 symtab_add_to_same_comdat_group (symtab_node new_node
,
401 symtab_node old_node
)
403 gcc_assert (DECL_ONE_ONLY (old_node
->symbol
.decl
));
404 gcc_assert (!new_node
->symbol
.same_comdat_group
);
405 gcc_assert (new_node
!= old_node
);
407 DECL_COMDAT_GROUP (new_node
->symbol
.decl
) = DECL_COMDAT_GROUP (old_node
->symbol
.decl
);
408 new_node
->symbol
.same_comdat_group
= old_node
;
409 if (!old_node
->symbol
.same_comdat_group
)
410 old_node
->symbol
.same_comdat_group
= new_node
;
414 for (n
= old_node
->symbol
.same_comdat_group
;
415 n
->symbol
.same_comdat_group
!= old_node
;
416 n
= n
->symbol
.same_comdat_group
)
418 n
->symbol
.same_comdat_group
= new_node
;
422 /* Dissolve the same_comdat_group list in which NODE resides. */
425 symtab_dissolve_same_comdat_group_list (symtab_node node
)
427 symtab_node n
= node
, next
;
429 if (!node
->symbol
.same_comdat_group
)
433 next
= n
->symbol
.same_comdat_group
;
434 n
->symbol
.same_comdat_group
= NULL
;
440 /* Return printable assembler name of NODE.
441 This function is used only for debugging. When assembler name
442 is unknown go with identifier name. */
445 symtab_node_asm_name (symtab_node node
)
447 if (!DECL_ASSEMBLER_NAME_SET_P (node
->symbol
.decl
))
448 return lang_hooks
.decl_printable_name (node
->symbol
.decl
, 2);
449 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->symbol
.decl
));
452 /* Return printable identifier name. */
455 symtab_node_name (symtab_node node
)
457 return lang_hooks
.decl_printable_name (node
->symbol
.decl
, 2);
460 static const char * const symtab_type_names
[] = {"symbol", "function", "variable"};
462 /* Dump base fields of symtab nodes. Not to be used directly. */
465 dump_symtab_base (FILE *f
, symtab_node node
)
467 static const char * const visibility_types
[] = {
468 "default", "protected", "hidden", "internal"
471 fprintf (f
, "%s/%i (%s)",
472 symtab_node_asm_name (node
),
474 symtab_node_name (node
));
475 dump_addr (f
, " @", (void *)node
);
476 fprintf (f
, "\n Type: %s", symtab_type_names
[node
->symbol
.type
]);
478 if (node
->symbol
.definition
)
479 fprintf (f
, " definition");
480 if (node
->symbol
.analyzed
)
481 fprintf (f
, " analyzed");
482 if (node
->symbol
.alias
)
483 fprintf (f
, " alias");
484 if (node
->symbol
.cpp_implicit_alias
)
485 fprintf (f
, " cpp_implicit_alias");
486 if (node
->symbol
.alias_target
)
487 fprintf (f
, " target:%s",
488 DECL_P (node
->symbol
.alias_target
)
489 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
490 (node
->symbol
.alias_target
))
491 : IDENTIFIER_POINTER (node
->symbol
.alias_target
));
492 fprintf (f
, "\n Visibility:");
493 if (node
->symbol
.in_other_partition
)
494 fprintf (f
, " in_other_partition");
495 if (node
->symbol
.used_from_other_partition
)
496 fprintf (f
, " used_from_other_partition");
497 if (node
->symbol
.force_output
)
498 fprintf (f
, " force_output");
499 if (node
->symbol
.resolution
!= LDPR_UNKNOWN
)
501 ld_plugin_symbol_resolution_names
[(int)node
->symbol
.resolution
]);
502 if (TREE_ASM_WRITTEN (node
->symbol
.decl
))
503 fprintf (f
, " asm_written");
504 if (DECL_EXTERNAL (node
->symbol
.decl
))
505 fprintf (f
, " external");
506 if (TREE_PUBLIC (node
->symbol
.decl
))
507 fprintf (f
, " public");
508 if (DECL_COMMON (node
->symbol
.decl
))
509 fprintf (f
, " common");
510 if (DECL_WEAK (node
->symbol
.decl
))
511 fprintf (f
, " weak");
512 if (DECL_DLLIMPORT_P (node
->symbol
.decl
))
513 fprintf (f
, " dll_import");
514 if (DECL_COMDAT (node
->symbol
.decl
))
515 fprintf (f
, " comdat");
516 if (DECL_COMDAT_GROUP (node
->symbol
.decl
))
517 fprintf (f
, " comdat_group:%s",
518 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (node
->symbol
.decl
)));
519 if (DECL_ONE_ONLY (node
->symbol
.decl
))
520 fprintf (f
, " one_only");
521 if (DECL_SECTION_NAME (node
->symbol
.decl
))
522 fprintf (f
, " section_name:%s",
523 TREE_STRING_POINTER (DECL_SECTION_NAME (node
->symbol
.decl
)));
524 if (DECL_VISIBILITY_SPECIFIED (node
->symbol
.decl
))
525 fprintf (f
, " visibility_specified");
526 if (DECL_VISIBILITY (node
->symbol
.decl
))
527 fprintf (f
, " visibility:%s",
528 visibility_types
[DECL_VISIBILITY (node
->symbol
.decl
)]);
529 if (DECL_VIRTUAL_P (node
->symbol
.decl
))
530 fprintf (f
, " virtual");
531 if (DECL_ARTIFICIAL (node
->symbol
.decl
))
532 fprintf (f
, " artificial");
533 if (TREE_CODE (node
->symbol
.decl
) == FUNCTION_DECL
)
535 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
))
536 fprintf (f
, " constructor");
537 if (DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
538 fprintf (f
, " destructor");
542 if (node
->symbol
.same_comdat_group
)
543 fprintf (f
, " Same comdat group as: %s/%i\n",
544 symtab_node_asm_name (node
->symbol
.same_comdat_group
),
545 node
->symbol
.same_comdat_group
->symbol
.order
);
546 if (node
->symbol
.next_sharing_asm_name
)
547 fprintf (f
, " next sharing asm name: %i\n",
548 node
->symbol
.next_sharing_asm_name
->symbol
.order
);
549 if (node
->symbol
.previous_sharing_asm_name
)
550 fprintf (f
, " previous sharing asm name: %i\n",
551 node
->symbol
.previous_sharing_asm_name
->symbol
.order
);
553 if (node
->symbol
.address_taken
)
554 fprintf (f
, " Address is taken.\n");
555 if (node
->symbol
.aux
)
557 fprintf (f
, " Aux:");
558 dump_addr (f
, " @", (void *)node
->symbol
.aux
);
561 fprintf (f
, " References: ");
562 ipa_dump_references (f
, &node
->symbol
.ref_list
);
563 fprintf (f
, " Referring: ");
564 ipa_dump_referring (f
, &node
->symbol
.ref_list
);
565 if (node
->symbol
.lto_file_data
)
566 fprintf (f
, " Read from file: %s\n",
567 node
->symbol
.lto_file_data
->file_name
);
570 /* Dump symtab node. */
573 dump_symtab_node (FILE *f
, symtab_node node
)
575 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
576 dump_cgraph_node (f
, cnode
);
577 else if (varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
))
578 dump_varpool_node (f
, vnode
);
581 /* Dump symbol table. */
584 dump_symtab (FILE *f
)
587 fprintf (f
, "Symbol table:\n\n");
588 FOR_EACH_SYMBOL (node
)
589 dump_symtab_node (f
, node
);
592 /* Dump symtab node NODE to stderr. */
595 debug_symtab_node (symtab_node node
)
597 dump_symtab_node (stderr
, node
);
600 /* Dump symbol table to stderr. */
605 dump_symtab (stderr
);
608 /* Verify common part of symtab nodes. */
611 verify_symtab_base (symtab_node node
)
613 bool error_found
= false;
614 symtab_node hashed_node
;
616 if (is_a
<cgraph_node
> (node
))
618 if (TREE_CODE (node
->symbol
.decl
) != FUNCTION_DECL
)
620 error ("function symbol is not function");
624 else if (is_a
<varpool_node
> (node
))
626 if (TREE_CODE (node
->symbol
.decl
) != VAR_DECL
)
628 error ("variable symbol is not variable");
634 error ("node has unknown type");
638 hashed_node
= symtab_get_node (node
->symbol
.decl
);
641 error ("node not found in symtab decl hashtable");
644 if (assembler_name_hash
)
646 hashed_node
= symtab_node_for_asm (DECL_ASSEMBLER_NAME (node
->symbol
.decl
));
647 if (hashed_node
&& hashed_node
->symbol
.previous_sharing_asm_name
)
649 error ("assembler name hash list corrupted");
654 if (hashed_node
== node
)
656 hashed_node
= hashed_node
->symbol
.next_sharing_asm_name
;
659 && !(is_a
<varpool_node
> (node
)
660 || DECL_HARD_REGISTER (node
->symbol
.decl
)))
662 error ("node not found in symtab assembler name hash");
666 if (node
->symbol
.previous_sharing_asm_name
667 && node
->symbol
.previous_sharing_asm_name
->symbol
.next_sharing_asm_name
!= node
)
669 error ("double linked list of assembler names corrupted");
672 if (node
->symbol
.analyzed
&& !node
->symbol
.definition
)
674 error ("node is analyzed byt it is not a definition");
677 if (node
->symbol
.cpp_implicit_alias
&& !node
->symbol
.alias
)
679 error ("node is alias but not implicit alias");
682 if (node
->symbol
.alias
&& !node
->symbol
.definition
683 && !lookup_attribute ("weakref", DECL_ATTRIBUTES (node
->symbol
.decl
)))
685 error ("node is alias but not definition");
688 if (node
->symbol
.same_comdat_group
)
690 symtab_node n
= node
->symbol
.same_comdat_group
;
692 if (!DECL_ONE_ONLY (n
->symbol
.decl
))
694 error ("non-DECL_ONE_ONLY node in a same_comdat_group list");
697 if (n
->symbol
.type
!= node
->symbol
.type
)
699 error ("mixing different types of symbol in same comdat groups is not supported");
704 error ("node is alone in a comdat group");
709 if (!n
->symbol
.same_comdat_group
)
711 error ("same_comdat_group is not a circular list");
715 n
= n
->symbol
.same_comdat_group
;
722 /* Verify consistency of NODE. */
725 verify_symtab_node (symtab_node node
)
730 timevar_push (TV_CGRAPH_VERIFY
);
731 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
732 verify_cgraph_node (cnode
);
734 if (verify_symtab_base (node
))
736 dump_symtab_node (stderr
, node
);
737 internal_error ("verify_symtab_node failed");
739 timevar_pop (TV_CGRAPH_VERIFY
);
742 /* Verify symbol table for internal consistency. */
748 FOR_EACH_SYMBOL (node
)
749 verify_symtab_node (node
);
752 /* Return true when RESOLUTION indicate that linker will use
753 the symbol from non-LTO object files. */
756 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
758 return (resolution
== LDPR_PREVAILING_DEF
759 || resolution
== LDPR_PREEMPTED_REG
760 || resolution
== LDPR_RESOLVED_EXEC
761 || resolution
== LDPR_RESOLVED_DYN
);
764 /* Return true when NODE is known to be used from other (non-LTO) object file.
765 Known only when doing LTO via linker plugin. */
768 symtab_used_from_object_file_p (symtab_node node
)
770 if (!TREE_PUBLIC (node
->symbol
.decl
) || DECL_EXTERNAL (node
->symbol
.decl
))
772 if (resolution_used_from_other_file_p (node
->symbol
.resolution
))
777 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
778 but other code such as notice_global_symbol generates rtl. */
781 symtab_make_decl_local (tree decl
)
785 if (TREE_CODE (decl
) == VAR_DECL
)
786 DECL_COMMON (decl
) = 0;
787 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
789 if (DECL_ONE_ONLY (decl
) || DECL_COMDAT (decl
))
791 DECL_SECTION_NAME (decl
) = 0;
792 DECL_COMDAT (decl
) = 0;
794 DECL_COMDAT_GROUP (decl
) = 0;
795 DECL_WEAK (decl
) = 0;
796 DECL_EXTERNAL (decl
) = 0;
797 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
798 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
799 TREE_PUBLIC (decl
) = 0;
800 DECL_VISIBILITY_SPECIFIED (decl
) = 0;
801 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
802 if (!DECL_RTL_SET_P (decl
))
805 /* Update rtl flags. */
806 make_decl_rtl (decl
);
808 rtl
= DECL_RTL (decl
);
812 symbol
= XEXP (rtl
, 0);
813 if (GET_CODE (symbol
) != SYMBOL_REF
)
816 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
819 /* Return availability of NODE. */
822 symtab_node_availability (symtab_node node
)
824 if (is_a
<cgraph_node
> (node
))
825 return cgraph_function_body_availability (cgraph (node
));
827 return cgraph_variable_initializer_availability (varpool (node
));
830 /* Given NODE, walk the alias chain to return the symbol NODE is alias of.
831 If NODE is not an alias, return NODE.
832 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
835 symtab_alias_ultimate_target (symtab_node node
, enum availability
*availability
)
837 bool weakref_p
= false;
839 if (!node
->symbol
.alias
)
842 *availability
= symtab_node_availability (node
);
846 /* To determine visibility of the target, we follow ELF semantic of aliases.
847 Here alias is an alternative assembler name of a given definition. Its
848 availablity prevails the availablity of its target (i.e. static alias of
849 weak definition is available.
851 Weakref is a different animal (and not part of ELF per se). It is just
852 alternative name of a given symbol used within one complation unit
853 and is translated prior hitting the object file. It inherits the
854 visibility of its target (i.e. weakref of non-overwritable definition
855 is non-overwritable, while weakref of weak definition is weak).
857 If we ever get into supporting targets with different semantics, a target
858 hook will be needed here. */
862 weakref_p
= DECL_EXTERNAL (node
->symbol
.decl
) && node
->symbol
.alias
;
864 *availability
= symtab_node_availability (node
);
866 *availability
= AVAIL_LOCAL
;
870 if (node
->symbol
.alias
&& node
->symbol
.analyzed
)
871 node
= symtab_alias_target (node
);
876 else if (node
->symbol
.analyzed
)
880 enum availability a
= symtab_node_availability (node
);
881 if (a
< *availability
)
886 *availability
= AVAIL_NOT_AVAILABLE
;
889 if (node
&& availability
&& weakref_p
)
891 enum availability a
= symtab_node_availability (node
);
892 if (a
< *availability
)
894 weakref_p
= DECL_EXTERNAL (node
->symbol
.decl
) && node
->symbol
.alias
;
898 *availability
= AVAIL_NOT_AVAILABLE
;
902 /* C++ FE sometimes change linkage flags after producing same body aliases.
904 FIXME: C++ produce implicit aliases for virtual functions and vtables that
905 are obviously equivalent. The way it is doing so is however somewhat
906 kludgy and interferes with the visibility code. As a result we need to
907 copy the visibility from the target to get things right. */
910 fixup_same_cpp_alias_visibility (symtab_node node
, symtab_node target
)
912 if (is_a
<cgraph_node
> (node
))
914 DECL_DECLARED_INLINE_P (node
->symbol
.decl
)
915 = DECL_DECLARED_INLINE_P (target
->symbol
.decl
);
916 DECL_DISREGARD_INLINE_LIMITS (node
->symbol
.decl
)
917 = DECL_DISREGARD_INLINE_LIMITS (target
->symbol
.decl
);
919 /* FIXME: It is not really clear why those flags should not be copied for
923 DECL_WEAK (node
->symbol
.decl
) = DECL_WEAK (target
->symbol
.decl
);
924 DECL_EXTERNAL (node
->symbol
.decl
) = DECL_EXTERNAL (target
->symbol
.decl
);
925 DECL_VISIBILITY (node
->symbol
.decl
) = DECL_VISIBILITY (target
->symbol
.decl
);
927 DECL_VIRTUAL_P (node
->symbol
.decl
) = DECL_VIRTUAL_P (target
->symbol
.decl
);
928 if (TREE_PUBLIC (node
->symbol
.decl
))
930 DECL_EXTERNAL (node
->symbol
.decl
) = DECL_EXTERNAL (target
->symbol
.decl
);
931 DECL_COMDAT (node
->symbol
.decl
) = DECL_COMDAT (target
->symbol
.decl
);
932 DECL_COMDAT_GROUP (node
->symbol
.decl
)
933 = DECL_COMDAT_GROUP (target
->symbol
.decl
);
934 if (DECL_ONE_ONLY (target
->symbol
.decl
)
935 && !node
->symbol
.same_comdat_group
)
936 symtab_add_to_same_comdat_group ((symtab_node
)node
, (symtab_node
)target
);
938 node
->symbol
.externally_visible
= target
->symbol
.externally_visible
;
941 /* Add reference recording that NODE is alias of TARGET.
942 The function can fail in the case of aliasing cycles; in this case
946 symtab_resolve_alias (symtab_node node
, symtab_node target
)
950 gcc_assert (!node
->symbol
.analyzed
951 && !vec_safe_length (node
->symbol
.ref_list
.references
));
953 /* Never let cycles to creep into the symbol table alias references;
954 those will make alias walkers to be infinite. */
955 for (n
= target
; n
&& n
->symbol
.alias
;
956 n
= n
->symbol
.analyzed
? symtab_alias_target (n
) : NULL
)
959 if (is_a
<cgraph_node
> (node
))
960 error ("function %q+D part of alias cycle", node
->symbol
.decl
);
961 else if (is_a
<varpool_node
> (node
))
962 error ("variable %q+D part of alias cycle", node
->symbol
.decl
);
965 node
->symbol
.alias
= false;
969 /* "analyze" the node - i.e. mark the reference. */
970 node
->symbol
.definition
= true;
971 node
->symbol
.alias
= true;
972 node
->symbol
.analyzed
= true;
973 ipa_record_reference (node
, target
, IPA_REF_ALIAS
, NULL
);
975 /* Alias targets become reudndant after alias is resolved into an reference.
976 We do not want to keep it around or we would have to mind updating them
977 when renaming symbols. */
978 node
->symbol
.alias_target
= NULL
;
979 DECL_ATTRIBUTES (node
->symbol
.decl
)
980 = remove_attribute ("alias", DECL_ATTRIBUTES (node
->symbol
.decl
));
982 if (node
->symbol
.cpp_implicit_alias
&& cgraph_state
>= CGRAPH_STATE_CONSTRUCTION
)
983 fixup_same_cpp_alias_visibility (node
, target
);
985 /* If alias has address taken, so does the target. */
986 if (node
->symbol
.address_taken
)
987 symtab_alias_ultimate_target (target
, NULL
)->symbol
.address_taken
= true;
990 #include "gt-symtab.h"