Mercurial > hg > CbC > CbC_gcc
comparison gcc/symtab.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Symbol table. | 1 /* Symbol table. |
2 Copyright (C) 2012-2018 Free Software Foundation, Inc. | 2 Copyright (C) 2012-2020 Free Software Foundation, Inc. |
3 Contributed by Jan Hubicka | 3 Contributed by Jan Hubicka |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify it under | 7 GCC is free software; you can redistribute it and/or modify it under |
251 { | 251 { |
252 unlink_from_assembler_name_hash (node, false); | 252 unlink_from_assembler_name_hash (node, false); |
253 insert_to_assembler_name_hash (node, false); | 253 insert_to_assembler_name_hash (node, false); |
254 } | 254 } |
255 | 255 |
256 /* Initalize asm name hash unless. */ | 256 /* Initialize asm name hash unless. */ |
257 | 257 |
258 void | 258 void |
259 symbol_table::symtab_initialize_asm_name_hash (void) | 259 symbol_table::symtab_initialize_asm_name_hash (void) |
260 { | 260 { |
261 symtab_node *node; | 261 symtab_node *node; |
487 return; | 487 return; |
488 do | 488 do |
489 { | 489 { |
490 next = n->same_comdat_group; | 490 next = n->same_comdat_group; |
491 n->same_comdat_group = NULL; | 491 n->same_comdat_group = NULL; |
492 if (dyn_cast <cgraph_node *> (n)) | |
493 dyn_cast <cgraph_node *> (n)->calls_comdat_local = false; | |
492 /* Clear comdat_group for comdat locals, since | 494 /* Clear comdat_group for comdat locals, since |
493 make_decl_local doesn't. */ | 495 make_decl_local doesn't. */ |
494 if (!TREE_PUBLIC (n->decl)) | 496 if (!TREE_PUBLIC (n->decl)) |
495 n->set_comdat_group (NULL); | 497 n->set_comdat_group (NULL); |
496 n = next; | 498 n = next; |
549 { | 551 { |
550 return get_dump_name (true); | 552 return get_dump_name (true); |
551 } | 553 } |
552 | 554 |
553 /* Return ipa reference from this symtab_node to | 555 /* Return ipa reference from this symtab_node to |
554 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type | 556 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type |
555 of the use. */ | 557 of the use. */ |
556 | 558 |
557 ipa_ref * | 559 ipa_ref * |
558 symtab_node::create_reference (symtab_node *referred_node, | 560 symtab_node::create_reference (symtab_node *referred_node, |
559 enum ipa_ref_use use_type) | 561 enum ipa_ref_use use_type) |
561 return create_reference (referred_node, use_type, NULL); | 563 return create_reference (referred_node, use_type, NULL); |
562 } | 564 } |
563 | 565 |
564 | 566 |
565 /* Return ipa reference from this symtab_node to | 567 /* Return ipa reference from this symtab_node to |
566 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type | 568 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type |
567 of the use and STMT the statement (if it exists). */ | 569 of the use and STMT the statement (if it exists). */ |
568 | 570 |
569 ipa_ref * | 571 ipa_ref * |
570 symtab_node::create_reference (symtab_node *referred_node, | 572 symtab_node::create_reference (symtab_node *referred_node, |
571 enum ipa_ref_use use_type, gimple *stmt) | 573 enum ipa_ref_use use_type, gimple *stmt) |
601 | 603 |
602 ref->referring = this; | 604 ref->referring = this; |
603 ref->referred = referred_node; | 605 ref->referred = referred_node; |
604 ref->stmt = stmt; | 606 ref->stmt = stmt; |
605 ref->lto_stmt_uid = 0; | 607 ref->lto_stmt_uid = 0; |
608 ref->speculative_id = 0; | |
606 ref->use = use_type; | 609 ref->use = use_type; |
607 ref->speculative = 0; | 610 ref->speculative = 0; |
608 | 611 |
609 /* If vector was moved in memory, update pointers. */ | 612 /* If vector was moved in memory, update pointers. */ |
610 if (old_references != list->references->address ()) | 613 if (old_references != list->references->address ()) |
658 unsigned int stmt_uid = ref->lto_stmt_uid; | 661 unsigned int stmt_uid = ref->lto_stmt_uid; |
659 | 662 |
660 ref2 = create_reference (ref->referred, ref->use, ref->stmt); | 663 ref2 = create_reference (ref->referred, ref->use, ref->stmt); |
661 ref2->speculative = speculative; | 664 ref2->speculative = speculative; |
662 ref2->lto_stmt_uid = stmt_uid; | 665 ref2->lto_stmt_uid = stmt_uid; |
666 ref2->speculative_id = ref->speculative_id; | |
663 } | 667 } |
664 } | 668 } |
665 | 669 |
666 /* Clone all referring from symtab NODE to this symtab_node. */ | 670 /* Clone all referring from symtab NODE to this symtab_node. */ |
667 | 671 |
676 unsigned int stmt_uid = ref->lto_stmt_uid; | 680 unsigned int stmt_uid = ref->lto_stmt_uid; |
677 | 681 |
678 ref2 = ref->referring->create_reference (this, ref->use, ref->stmt); | 682 ref2 = ref->referring->create_reference (this, ref->use, ref->stmt); |
679 ref2->speculative = speculative; | 683 ref2->speculative = speculative; |
680 ref2->lto_stmt_uid = stmt_uid; | 684 ref2->lto_stmt_uid = stmt_uid; |
685 ref2->speculative_id = ref->speculative_id; | |
681 } | 686 } |
682 } | 687 } |
683 | 688 |
684 /* Clone reference REF to this symtab_node and set its stmt to STMT. */ | 689 /* Clone reference REF to this symtab_node and set its stmt to STMT. */ |
685 | 690 |
691 ipa_ref *ref2; | 696 ipa_ref *ref2; |
692 | 697 |
693 ref2 = create_reference (ref->referred, ref->use, stmt); | 698 ref2 = create_reference (ref->referred, ref->use, stmt); |
694 ref2->speculative = speculative; | 699 ref2->speculative = speculative; |
695 ref2->lto_stmt_uid = stmt_uid; | 700 ref2->lto_stmt_uid = stmt_uid; |
701 ref2->speculative_id = ref->speculative_id; | |
696 return ref2; | 702 return ref2; |
697 } | 703 } |
698 | 704 |
699 /* Find the structure describing a reference to REFERRED_NODE | 705 /* Find the structure describing a reference to REFERRED_NODE |
700 and associated with statement STMT. */ | 706 and associated with statement STMT. */ |
730 else | 736 else |
731 i++; | 737 i++; |
732 } | 738 } |
733 | 739 |
734 /* Remove all stmt references in non-speculative references. | 740 /* Remove all stmt references in non-speculative references. |
735 Those are not maintained during inlining & clonning. | 741 Those are not maintained during inlining & cloning. |
736 The exception are speculative references that are updated along | 742 The exception are speculative references that are updated along |
737 with callgraph edges associated with them. */ | 743 with callgraph edges associated with them. */ |
738 | 744 |
739 void | 745 void |
740 symtab_node::clear_stmts_in_references (void) | 746 symtab_node::clear_stmts_in_references (void) |
745 for (i = 0; iterate_reference (i, r); i++) | 751 for (i = 0; iterate_reference (i, r); i++) |
746 if (!r->speculative) | 752 if (!r->speculative) |
747 { | 753 { |
748 r->stmt = NULL; | 754 r->stmt = NULL; |
749 r->lto_stmt_uid = 0; | 755 r->lto_stmt_uid = 0; |
756 r->speculative_id = 0; | |
750 } | 757 } |
751 } | 758 } |
752 | 759 |
753 /* Remove all references in ref list. */ | 760 /* Remove all references in ref list. */ |
754 | 761 |
805 } | 812 } |
806 fprintf (file, "\n"); | 813 fprintf (file, "\n"); |
807 } | 814 } |
808 | 815 |
809 static const char * const symtab_type_names[] = {"symbol", "function", "variable"}; | 816 static const char * const symtab_type_names[] = {"symbol", "function", "variable"}; |
817 | |
818 /* Dump the visibility of the symbol. */ | |
819 | |
820 const char * | |
821 symtab_node::get_visibility_string () const | |
822 { | |
823 static const char * const visibility_types[] | |
824 = { "default", "protected", "hidden", "internal" }; | |
825 return visibility_types[DECL_VISIBILITY (decl)]; | |
826 } | |
827 | |
828 /* Dump the type_name of the symbol. */ | |
829 const char * | |
830 symtab_node::get_symtab_type_string () const | |
831 { | |
832 return symtab_type_names[type]; | |
833 } | |
810 | 834 |
811 /* Dump base fields of symtab nodes to F. Not to be used directly. */ | 835 /* Dump base fields of symtab nodes to F. Not to be used directly. */ |
812 | 836 |
813 void | 837 void |
814 symtab_node::dump_base (FILE *f) | 838 symtab_node::dump_base (FILE *f) |
829 fprintf (f, " alias"); | 853 fprintf (f, " alias"); |
830 if (transparent_alias) | 854 if (transparent_alias) |
831 fprintf (f, " transparent_alias"); | 855 fprintf (f, " transparent_alias"); |
832 if (weakref) | 856 if (weakref) |
833 fprintf (f, " weakref"); | 857 fprintf (f, " weakref"); |
858 if (symver) | |
859 fprintf (f, " symver"); | |
834 if (cpp_implicit_alias) | 860 if (cpp_implicit_alias) |
835 fprintf (f, " cpp_implicit_alias"); | 861 fprintf (f, " cpp_implicit_alias"); |
836 if (alias_target) | 862 if (alias_target) |
837 fprintf (f, " target:%s", | 863 fprintf (f, " target:%s", |
838 DECL_P (alias_target) | 864 DECL_P (alias_target) |
895 if (DECL_STATIC_CONSTRUCTOR (decl)) | 921 if (DECL_STATIC_CONSTRUCTOR (decl)) |
896 fprintf (f, " constructor"); | 922 fprintf (f, " constructor"); |
897 if (DECL_STATIC_DESTRUCTOR (decl)) | 923 if (DECL_STATIC_DESTRUCTOR (decl)) |
898 fprintf (f, " destructor"); | 924 fprintf (f, " destructor"); |
899 } | 925 } |
926 if (ifunc_resolver) | |
927 fprintf (f, " ifunc_resolver"); | |
900 fprintf (f, "\n"); | 928 fprintf (f, "\n"); |
901 | 929 |
902 if (same_comdat_group) | 930 if (same_comdat_group) |
903 fprintf (f, " Same comdat group as: %s\n", | 931 fprintf (f, " Same comdat group as: %s\n", |
904 same_comdat_group->dump_asm_name ()); | 932 same_comdat_group->dump_asm_name ()); |
905 if (next_sharing_asm_name) | 933 if (next_sharing_asm_name) |
906 fprintf (f, " next sharing asm name: %i\n", | 934 fprintf (f, " next sharing asm name: %i\n", |
937 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) | 965 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) |
938 vnode->dump (f); | 966 vnode->dump (f); |
939 } | 967 } |
940 | 968 |
941 void | 969 void |
970 symtab_node::dump_graphviz (FILE *f) | |
971 { | |
972 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this)) | |
973 cnode->dump_graphviz (f); | |
974 } | |
975 | |
976 void | |
942 symbol_table::dump (FILE *f) | 977 symbol_table::dump (FILE *f) |
943 { | 978 { |
944 symtab_node *node; | 979 symtab_node *node; |
945 fprintf (f, "Symbol table:\n\n"); | 980 fprintf (f, "Symbol table:\n\n"); |
946 FOR_EACH_SYMBOL (node) | 981 FOR_EACH_SYMBOL (node) |
947 node->dump (f); | 982 node->dump (f); |
983 } | |
984 | |
985 void | |
986 symbol_table::dump_graphviz (FILE *f) | |
987 { | |
988 symtab_node *node; | |
989 fprintf (f, "digraph symtab {\n"); | |
990 FOR_EACH_SYMBOL (node) | |
991 node->dump_graphviz (f); | |
992 fprintf (f, "}\n"); | |
948 } | 993 } |
949 | 994 |
950 DEBUG_FUNCTION void | 995 DEBUG_FUNCTION void |
951 symbol_table::debug (void) | 996 symbol_table::debug (void) |
952 { | 997 { |
983 dump (stderr); | 1028 dump (stderr); |
984 } | 1029 } |
985 | 1030 |
986 /* Verify common part of symtab nodes. */ | 1031 /* Verify common part of symtab nodes. */ |
987 | 1032 |
1033 #if __GNUC__ >= 10 | |
1034 /* Disable warnings about missing quoting in GCC diagnostics for | |
1035 the verification errors. Their format strings don't follow GCC | |
1036 diagnostic conventions and the calls are ultimately followed by | |
1037 one to internal_error. */ | |
1038 # pragma GCC diagnostic push | |
1039 # pragma GCC diagnostic ignored "-Wformat-diag" | |
1040 #endif | |
1041 | |
988 DEBUG_FUNCTION bool | 1042 DEBUG_FUNCTION bool |
989 symtab_node::verify_base (void) | 1043 symtab_node::verify_base (void) |
990 { | 1044 { |
991 bool error_found = false; | 1045 bool error_found = false; |
992 symtab_node *hashed_node; | 1046 symtab_node *hashed_node; |
1000 } | 1054 } |
1001 else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)) | 1055 else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)) |
1002 != NULL) | 1056 != NULL) |
1003 != dyn_cast <cgraph_node *> (this)->ifunc_resolver) | 1057 != dyn_cast <cgraph_node *> (this)->ifunc_resolver) |
1004 { | 1058 { |
1005 error ("inconsistent `ifunc' attribute"); | 1059 error ("inconsistent %<ifunc%> attribute"); |
1006 error_found = true; | 1060 error_found = true; |
1007 } | 1061 } |
1008 } | 1062 } |
1009 else if (is_a <varpool_node *> (this)) | 1063 else if (is_a <varpool_node *> (this)) |
1010 { | 1064 { |
1038 } | 1092 } |
1039 } | 1093 } |
1040 if (symtab->assembler_name_hash) | 1094 if (symtab->assembler_name_hash) |
1041 { | 1095 { |
1042 hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl)); | 1096 hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl)); |
1043 if (hashed_node && hashed_node->previous_sharing_asm_name) | 1097 if (hashed_node) |
1044 { | 1098 { |
1045 error ("assembler name hash list corrupted"); | 1099 if (hashed_node->previous_sharing_asm_name) |
1046 error_found = true; | 1100 { |
1047 } | 1101 error ("assembler name hash list corrupted"); |
1048 while (hashed_node) | 1102 error_found = true; |
1049 { | 1103 } |
1050 if (hashed_node == this) | 1104 else if (previous_sharing_asm_name == NULL) |
1051 break; | 1105 { |
1052 hashed_node = hashed_node->next_sharing_asm_name; | 1106 if (hashed_node != this) |
1053 } | 1107 { |
1054 if (!hashed_node | 1108 error ("assembler name hash list corrupted"); |
1055 && !(is_a <varpool_node *> (this) | 1109 error_found = true; |
1056 && DECL_HARD_REGISTER (decl))) | 1110 } |
1057 { | 1111 } |
1058 error ("node not found in symtab assembler name hash"); | 1112 else if (!(is_a <varpool_node *> (this) && DECL_HARD_REGISTER (decl))) |
1059 error_found = true; | 1113 { |
1114 if (!asmname_hasher::equal (previous_sharing_asm_name, | |
1115 DECL_ASSEMBLER_NAME (decl))) | |
1116 { | |
1117 error ("node not found in symtab assembler name hash"); | |
1118 error_found = true; | |
1119 } | |
1120 } | |
1060 } | 1121 } |
1061 } | 1122 } |
1062 if (previous_sharing_asm_name | 1123 if (previous_sharing_asm_name |
1063 && previous_sharing_asm_name->next_sharing_asm_name != this) | 1124 && previous_sharing_asm_name->next_sharing_asm_name != this) |
1064 { | 1125 { |
1091 error_found = true; | 1152 error_found = true; |
1092 } | 1153 } |
1093 if (transparent_alias && !alias) | 1154 if (transparent_alias && !alias) |
1094 { | 1155 { |
1095 error ("node is transparent_alias but not an alias"); | 1156 error ("node is transparent_alias but not an alias"); |
1157 error_found = true; | |
1158 } | |
1159 if (symver && !alias) | |
1160 { | |
1161 error ("node is symver but not alias"); | |
1162 error_found = true; | |
1163 } | |
1164 /* Limitation of gas requires us to output targets of symver aliases as | |
1165 global symbols. This is binutils PR 25295. */ | |
1166 if (symver | |
1167 && (!TREE_PUBLIC (get_alias_target ()->decl) | |
1168 || DECL_VISIBILITY (get_alias_target ()->decl) != VISIBILITY_DEFAULT)) | |
1169 { | |
1170 error ("symver target is not exported with default visibility"); | |
1171 error_found = true; | |
1172 } | |
1173 if (symver | |
1174 && (!TREE_PUBLIC (decl) | |
1175 || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT)) | |
1176 { | |
1177 error ("symver is not exported with default visibility"); | |
1096 error_found = true; | 1178 error_found = true; |
1097 } | 1179 } |
1098 if (same_comdat_group) | 1180 if (same_comdat_group) |
1099 { | 1181 { |
1100 symtab_node *n = same_comdat_group; | 1182 symtab_node *n = same_comdat_group; |
1146 } | 1228 } |
1147 } | 1229 } |
1148 } | 1230 } |
1149 if (implicit_section && !get_section ()) | 1231 if (implicit_section && !get_section ()) |
1150 { | 1232 { |
1151 error ("implicit_section flag is set but section isn't"); | 1233 error ("implicit_section flag is set but section isn%'t"); |
1152 error_found = true; | 1234 error_found = true; |
1153 } | 1235 } |
1154 if (get_section () && get_comdat_group () | 1236 if (get_section () && get_comdat_group () |
1155 && !implicit_section | 1237 && !implicit_section |
1156 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl))) | 1238 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl))) |
1165 && (!get_section() | 1247 && (!get_section() |
1166 || !get_alias_target ()->get_section () | 1248 || !get_alias_target ()->get_section () |
1167 || strcmp (get_section(), | 1249 || strcmp (get_section(), |
1168 get_alias_target ()->get_section ()))) | 1250 get_alias_target ()->get_section ()))) |
1169 { | 1251 { |
1170 error ("Alias and target's section differs"); | 1252 error ("Alias and target%'s section differs"); |
1171 get_alias_target ()->dump (stderr); | 1253 get_alias_target ()->dump (stderr); |
1172 error_found = true; | 1254 error_found = true; |
1173 } | 1255 } |
1174 if (alias && definition | 1256 if (alias && definition |
1175 && get_comdat_group () != get_alias_target ()->get_comdat_group ()) | 1257 && get_comdat_group () != get_alias_target ()->get_comdat_group ()) |
1176 { | 1258 { |
1177 error ("Alias and target's comdat groups differs"); | 1259 error ("Alias and target%'s comdat groups differs"); |
1178 get_alias_target ()->dump (stderr); | 1260 get_alias_target ()->dump (stderr); |
1179 error_found = true; | 1261 error_found = true; |
1180 } | 1262 } |
1181 if (transparent_alias && definition && !weakref) | 1263 if (transparent_alias && definition && !weakref) |
1182 { | 1264 { |
1187 const char *name2 | 1269 const char *name2 |
1188 = IDENTIFIER_POINTER ( | 1270 = IDENTIFIER_POINTER ( |
1189 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to->decl))); | 1271 ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to->decl))); |
1190 if (!symbol_table::assembler_names_equal_p (name1, name2)) | 1272 if (!symbol_table::assembler_names_equal_p (name1, name2)) |
1191 { | 1273 { |
1192 error ("Transparent alias and target's assembler names differs"); | 1274 error ("Transparent alias and target%'s assembler names differs"); |
1193 get_alias_target ()->dump (stderr); | 1275 get_alias_target ()->dump (stderr); |
1194 error_found = true; | 1276 error_found = true; |
1195 } | 1277 } |
1196 } | 1278 } |
1197 if (transparent_alias && definition | 1279 if (transparent_alias && definition |
1262 } | 1344 } |
1263 } | 1345 } |
1264 } | 1346 } |
1265 } | 1347 } |
1266 | 1348 |
1349 #if __GNUC__ >= 10 | |
1350 # pragma GCC diagnostic pop | |
1351 #endif | |
1352 | |
1267 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early, | 1353 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early, |
1268 but other code such as notice_global_symbol generates rtl. */ | 1354 but other code such as notice_global_symbol generates rtl. */ |
1269 | 1355 |
1270 void | 1356 void |
1271 symtab_node::make_decl_local (void) | 1357 symtab_node::make_decl_local (void) |
1397 /* To determine visibility of the target, we follow ELF semantic of aliases. | 1483 /* To determine visibility of the target, we follow ELF semantic of aliases. |
1398 Here alias is an alternative assembler name of a given definition. Its | 1484 Here alias is an alternative assembler name of a given definition. Its |
1399 availability prevails the availability of its target (i.e. static alias of | 1485 availability prevails the availability of its target (i.e. static alias of |
1400 weak definition is available. | 1486 weak definition is available. |
1401 | 1487 |
1402 Transaparent alias is just alternative anme of a given symbol used within | 1488 Transparent alias is just alternative name of a given symbol used within |
1403 one compilation unit and is translated prior hitting the object file. It | 1489 one compilation unit and is translated prior hitting the object file. It |
1404 inherits the visibility of its target. | 1490 inherits the visibility of its target. |
1405 Weakref is a different animal (and noweak definition is weak). | 1491 Weakref is a different animal (and noweak definition is weak). |
1406 | 1492 |
1407 If we ever get into supporting targets with different semantics, a target | 1493 If we ever get into supporting targets with different semantics, a target |
1544 /* Set section of symbol and its aliases. */ | 1630 /* Set section of symbol and its aliases. */ |
1545 | 1631 |
1546 void | 1632 void |
1547 symtab_node::set_section (const char *section) | 1633 symtab_node::set_section (const char *section) |
1548 { | 1634 { |
1549 gcc_assert (!this->alias); | 1635 gcc_assert (!this->alias || !this->analyzed); |
1550 call_for_symbol_and_aliases | 1636 call_for_symbol_and_aliases |
1551 (symtab_node::set_section, const_cast<char *>(section), true); | 1637 (symtab_node::set_section, const_cast<char *>(section), true); |
1552 } | 1638 } |
1553 | 1639 |
1554 /* Return the initialization priority. */ | 1640 /* Return the initialization priority. */ |
1614 } | 1700 } |
1615 h = priority_info (); | 1701 h = priority_info (); |
1616 h->init = priority; | 1702 h->init = priority; |
1617 } | 1703 } |
1618 | 1704 |
1619 /* Set fialization priority to PRIORITY. */ | 1705 /* Set finalization priority to PRIORITY. */ |
1620 | 1706 |
1621 void | 1707 void |
1622 cgraph_node::set_fini_priority (priority_type priority) | 1708 cgraph_node::set_fini_priority (priority_type priority) |
1623 { | 1709 { |
1624 symbol_priority_map *h; | 1710 symbol_priority_map *h; |
1724 alias_alias->remove_from_same_comdat_group (); | 1810 alias_alias->remove_from_same_comdat_group (); |
1725 alias_alias->set_comdat_group (NULL); | 1811 alias_alias->set_comdat_group (NULL); |
1726 if (target->get_comdat_group ()) | 1812 if (target->get_comdat_group ()) |
1727 alias_alias->add_to_same_comdat_group (target); | 1813 alias_alias->add_to_same_comdat_group (target); |
1728 } | 1814 } |
1729 if (!alias_alias->transparent_alias || transparent) | 1815 if ((!alias_alias->transparent_alias |
1816 && !alias_alias->symver) | |
1817 || transparent) | |
1730 { | 1818 { |
1731 alias_alias->remove_all_references (); | 1819 alias_alias->remove_all_references (); |
1732 alias_alias->create_reference (target, IPA_REF_ALIAS, NULL); | 1820 alias_alias->create_reference (target, IPA_REF_ALIAS, NULL); |
1733 } | 1821 } |
1734 else i++; | 1822 else i++; |
1759 return true; | 1847 return true; |
1760 } | 1848 } |
1761 return false; | 1849 return false; |
1762 } | 1850 } |
1763 | 1851 |
1764 /* If node can not be overwriten by static or dynamic linker to point to | 1852 /* If node cannot be overwriten by static or dynamic linker to point to |
1765 different definition, return NODE. Otherwise look for alias with such | 1853 different definition, return NODE. Otherwise look for alias with such |
1766 property and if none exists, introduce new one. */ | 1854 property and if none exists, introduce new one. */ |
1767 | 1855 |
1768 symtab_node * | 1856 symtab_node * |
1769 symtab_node::noninterposable_alias (void) | 1857 symtab_node::noninterposable_alias (void) |
1774 /* First try to look up existing alias or base object | 1862 /* First try to look up existing alias or base object |
1775 (if that is already non-overwritable). */ | 1863 (if that is already non-overwritable). */ |
1776 symtab_node *node = ultimate_alias_target (); | 1864 symtab_node *node = ultimate_alias_target (); |
1777 gcc_assert (!node->alias && !node->weakref); | 1865 gcc_assert (!node->alias && !node->weakref); |
1778 node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias, | 1866 node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias, |
1779 (void *)&new_node, true); | 1867 (void *)&new_node, true); |
1780 if (new_node) | 1868 if (new_node) |
1781 return new_node; | 1869 return new_node; |
1782 | 1870 |
1783 /* If aliases aren't supported by the assembler, fail. */ | 1871 /* If aliases aren't supported by the assembler, fail. */ |
1784 if (!TARGET_SUPPORTS_ALIASES) | 1872 if (!TARGET_SUPPORTS_ALIASES) |
1785 return NULL; | 1873 return NULL; |
1786 | 1874 |
1787 /* Otherwise create a new one. */ | 1875 /* Otherwise create a new one. */ |
1788 new_decl = copy_node (node->decl); | 1876 new_decl = copy_node (node->decl); |
1789 DECL_DLLIMPORT_P (new_decl) = 0; | 1877 DECL_DLLIMPORT_P (new_decl) = 0; |
1790 DECL_NAME (new_decl) = clone_function_name (node->decl, "localalias"); | 1878 tree name = clone_function_name (node->decl, "localalias"); |
1879 if (!flag_wpa) | |
1880 { | |
1881 unsigned long num = 0; | |
1882 /* In the rare case we already have a localalias, but the above | |
1883 node->call_for_symbol_and_aliases call didn't find any suitable, | |
1884 iterate until we find one not used yet. */ | |
1885 while (symtab_node::get_for_asmname (name)) | |
1886 name = clone_function_name (node->decl, "localalias", num++); | |
1887 } | |
1888 DECL_NAME (new_decl) = name; | |
1791 if (TREE_CODE (new_decl) == FUNCTION_DECL) | 1889 if (TREE_CODE (new_decl) == FUNCTION_DECL) |
1792 DECL_STRUCT_FUNCTION (new_decl) = NULL; | 1890 DECL_STRUCT_FUNCTION (new_decl) = NULL; |
1793 DECL_INITIAL (new_decl) = NULL; | 1891 DECL_INITIAL (new_decl) = NULL; |
1794 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl)); | 1892 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl)); |
1795 SET_DECL_RTL (new_decl, NULL); | 1893 SET_DECL_RTL (new_decl, NULL); |
1805 if (TREE_CODE (new_decl) == FUNCTION_DECL) | 1903 if (TREE_CODE (new_decl) == FUNCTION_DECL) |
1806 { | 1904 { |
1807 DECL_STATIC_CONSTRUCTOR (new_decl) = 0; | 1905 DECL_STATIC_CONSTRUCTOR (new_decl) = 0; |
1808 DECL_STATIC_DESTRUCTOR (new_decl) = 0; | 1906 DECL_STATIC_DESTRUCTOR (new_decl) = 0; |
1809 new_node = cgraph_node::create_alias (new_decl, node->decl); | 1907 new_node = cgraph_node::create_alias (new_decl, node->decl); |
1908 | |
1909 cgraph_node *new_cnode = dyn_cast <cgraph_node *> (new_node), | |
1910 *cnode = dyn_cast <cgraph_node *> (node); | |
1911 | |
1912 new_cnode->unit_id = cnode->unit_id; | |
1913 new_cnode->merged_comdat = cnode->merged_comdat; | |
1914 new_cnode->merged_extern_inline = cnode->merged_extern_inline; | |
1810 } | 1915 } |
1811 else | 1916 else |
1812 { | 1917 { |
1813 TREE_READONLY (new_decl) = TREE_READONLY (node->decl); | 1918 TREE_READONLY (new_decl) = TREE_READONLY (node->decl); |
1814 DECL_INITIAL (new_decl) = error_mark_node; | 1919 DECL_INITIAL (new_decl) = error_mark_node; |
1859 | 1964 |
1860 enum symbol_partitioning_class | 1965 enum symbol_partitioning_class |
1861 symtab_node::get_partitioning_class (void) | 1966 symtab_node::get_partitioning_class (void) |
1862 { | 1967 { |
1863 /* Inline clones are always duplicated. | 1968 /* Inline clones are always duplicated. |
1864 This include external delcarations. */ | 1969 This include external declarations. */ |
1865 cgraph_node *cnode = dyn_cast <cgraph_node *> (this); | 1970 cgraph_node *cnode = dyn_cast <cgraph_node *> (this); |
1866 | 1971 |
1867 if (DECL_ABSTRACT_P (decl)) | 1972 if (DECL_ABSTRACT_P (decl)) |
1868 return SYMBOL_EXTERNAL; | 1973 return SYMBOL_EXTERNAL; |
1869 | 1974 |
1870 if (cnode && cnode->global.inlined_to) | 1975 if (cnode && cnode->inlined_to) |
1871 return SYMBOL_DUPLICATE; | 1976 return SYMBOL_DUPLICATE; |
1872 | 1977 |
1873 /* Transparent aliases are always duplicated. */ | 1978 /* Transparent aliases are always duplicated. */ |
1874 if (transparent_alias) | 1979 if (transparent_alias) |
1875 return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL; | 1980 return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL; |
1876 | 1981 |
1877 /* External declarations are external. */ | 1982 /* External declarations are external. */ |
1878 if (DECL_EXTERNAL (decl)) | 1983 if (DECL_EXTERNAL (decl)) |
1879 return SYMBOL_EXTERNAL; | 1984 return SYMBOL_EXTERNAL; |
1880 | 1985 |
1986 /* Even static aliases of external functions as external. Those can happen | |
1987 when COMDAT got resolved to non-IL implementation. */ | |
1988 if (alias && DECL_EXTERNAL (ultimate_alias_target ()->decl)) | |
1989 return SYMBOL_EXTERNAL; | |
1990 | |
1881 if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) | 1991 if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) |
1882 { | 1992 { |
1883 if (alias && definition && !ultimate_alias_target ()->definition) | 1993 if (alias && definition && !ultimate_alias_target ()->definition) |
1884 return SYMBOL_EXTERNAL; | 1994 return SYMBOL_EXTERNAL; |
1885 /* Constant pool references use local symbol names that can not | 1995 /* Constant pool references use local symbol names that cannot |
1886 be promoted global. We should never put into a constant pool | 1996 be promoted global. We should never put into a constant pool |
1887 objects that can not be duplicated across partitions. */ | 1997 objects that cannot be duplicated across partitions. */ |
1888 if (DECL_IN_CONSTANT_POOL (decl)) | 1998 if (DECL_IN_CONSTANT_POOL (decl)) |
1889 return SYMBOL_DUPLICATE; | 1999 return SYMBOL_DUPLICATE; |
1890 if (DECL_HARD_REGISTER (decl)) | 2000 if (DECL_HARD_REGISTER (decl)) |
1891 return SYMBOL_DUPLICATE; | 2001 return SYMBOL_DUPLICATE; |
1892 gcc_checking_assert (vnode->definition); | 2002 gcc_checking_assert (vnode->definition); |
1921 { | 2031 { |
1922 symtab_node *target = ultimate_alias_target (); | 2032 symtab_node *target = ultimate_alias_target (); |
1923 | 2033 |
1924 if (target->alias && target->weakref) | 2034 if (target->alias && target->weakref) |
1925 return false; | 2035 return false; |
1926 /* We can not recurse to target::nonzero. It is possible that the | 2036 /* We cannot recurse to target::nonzero. It is possible that the |
1927 target is used only via the alias. | 2037 target is used only via the alias. |
1928 We may walk references and look for strong use, but we do not know | 2038 We may walk references and look for strong use, but we do not know |
1929 if this strong use will survive to final binary, so be | 2039 if this strong use will survive to final binary, so be |
1930 conservative here. | 2040 conservative here. |
1931 ??? Maybe we could do the lookup during late optimization that | 2041 ??? Maybe we could do the lookup during late optimization that |
1946 | 2056 |
1947 /* With !flag_delete_null_pointer_checks we assume that symbols may | 2057 /* With !flag_delete_null_pointer_checks we assume that symbols may |
1948 bind to NULL. This is on by default on embedded targets only. | 2058 bind to NULL. This is on by default on embedded targets only. |
1949 | 2059 |
1950 Otherwise all non-WEAK symbols must be defined and thus non-NULL or | 2060 Otherwise all non-WEAK symbols must be defined and thus non-NULL or |
1951 linking fails. Important case of WEAK we want to do well are comdats. | 2061 linking fails. Important case of WEAK we want to do well are comdats, |
1952 Those are handled by later check for definition. | 2062 which also must be defined somewhere. |
1953 | 2063 |
1954 When parsing, beware the cases when WEAK attribute is added later. */ | 2064 When parsing, beware the cases when WEAK attribute is added later. */ |
1955 if (!DECL_WEAK (decl) | 2065 if ((!DECL_WEAK (decl) || DECL_COMDAT (decl)) |
1956 && flag_delete_null_pointer_checks) | 2066 && flag_delete_null_pointer_checks) |
1957 { | 2067 { |
1958 refuse_visibility_changes = true; | 2068 refuse_visibility_changes = true; |
1959 return true; | 2069 return true; |
1960 } | 2070 } |
1961 | 2071 |
1962 /* If target is defined and either comdat or not extern, we know it will be | 2072 /* If target is defined and not extern, we know it will be |
1963 output and thus it will bind to non-NULL. | 2073 output and thus it will bind to non-NULL. |
1964 Play safe for flag_delete_null_pointer_checks where weak definition may | 2074 Play safe for flag_delete_null_pointer_checks where weak definition may |
1965 be re-defined by NULL. */ | 2075 be re-defined by NULL. */ |
1966 if (definition && (!DECL_EXTERNAL (decl) || DECL_COMDAT (decl)) | 2076 if (definition && !DECL_EXTERNAL (decl) |
1967 && (flag_delete_null_pointer_checks || !DECL_WEAK (decl))) | 2077 && (flag_delete_null_pointer_checks || !DECL_WEAK (decl))) |
1968 { | 2078 { |
1969 if (!DECL_WEAK (decl)) | 2079 if (!DECL_WEAK (decl)) |
1970 refuse_visibility_changes = true; | 2080 refuse_visibility_changes = true; |
1971 return true; | 2081 return true; |
1984 Return 1 if symbol is known to have same address as S2, | 2094 Return 1 if symbol is known to have same address as S2, |
1985 return -1 otherwise. | 2095 return -1 otherwise. |
1986 | 2096 |
1987 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS | 2097 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS |
1988 and S2 is going to be accessed. This eliminates the situations when | 2098 and S2 is going to be accessed. This eliminates the situations when |
1989 either THIS or S2 is NULL and is seful for comparing bases when deciding | 2099 either THIS or S2 is NULL and is useful for comparing bases when deciding |
1990 about memory aliasing. */ | 2100 about memory aliasing. */ |
1991 int | 2101 int |
1992 symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed) | 2102 symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed) |
1993 { | 2103 { |
1994 enum availability avail1, avail2; | 2104 enum availability avail1, avail2; |
2014 bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl); | 2124 bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl); |
2015 bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl); | 2125 bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl); |
2016 bool really_binds_local1 = binds_local1; | 2126 bool really_binds_local1 = binds_local1; |
2017 bool really_binds_local2 = binds_local2; | 2127 bool really_binds_local2 = binds_local2; |
2018 | 2128 |
2019 /* Addresses of vtables and virtual functions can not be used by user | 2129 /* Addresses of vtables and virtual functions cannot be used by user |
2020 code and are used only within speculation. In this case we may make | 2130 code and are used only within speculation. In this case we may make |
2021 symbol equivalent to its alias even if interposition may break this | 2131 symbol equivalent to its alias even if interposition may break this |
2022 rule. Doing so will allow us to turn speculative inlining into | 2132 rule. Doing so will allow us to turn speculative inlining into |
2023 non-speculative more agressively. */ | 2133 non-speculative more aggressively. */ |
2024 if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE) | 2134 if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE) |
2025 binds_local1 = true; | 2135 binds_local1 = true; |
2026 if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE) | 2136 if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE) |
2027 binds_local2 = true; | 2137 binds_local2 = true; |
2028 | 2138 |
2040 if (rs2 != s2) | 2150 if (rs2 != s2) |
2041 s2->refuse_visibility_changes = true; | 2151 s2->refuse_visibility_changes = true; |
2042 return 1; | 2152 return 1; |
2043 } | 2153 } |
2044 | 2154 |
2045 /* If both symbols may resolve to NULL, we can not really prove them | 2155 /* If both symbols may resolve to NULL, we cannot really prove them |
2046 different. */ | 2156 different. */ |
2047 if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ()) | 2157 if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ()) |
2048 return -1; | 2158 return -1; |
2049 | 2159 |
2050 /* Except for NULL, functions and variables never overlap. */ | 2160 /* Except for NULL, functions and variables never overlap. */ |
2054 /* If one of the symbols is unresolved alias, punt. */ | 2164 /* If one of the symbols is unresolved alias, punt. */ |
2055 if (rs1->alias || rs2->alias) | 2165 if (rs1->alias || rs2->alias) |
2056 return -1; | 2166 return -1; |
2057 | 2167 |
2058 /* If we have a non-interposale definition of at least one of the symbols | 2168 /* If we have a non-interposale definition of at least one of the symbols |
2059 and the other symbol is different, we know other unit can not interpose | 2169 and the other symbol is different, we know other unit cannot interpose |
2060 it to the first symbol; all aliases of the definition needs to be | 2170 it to the first symbol; all aliases of the definition needs to be |
2061 present in the current unit. */ | 2171 present in the current unit. */ |
2062 if (((really_binds_local1 || really_binds_local2) | 2172 if (((really_binds_local1 || really_binds_local2) |
2063 /* If we have both definitions and they are different, we know they | 2173 /* If we have both definitions and they are different, we know they |
2064 will be different even in units they binds to. */ | 2174 will be different even in units they binds to. */ |
2074 return 0; | 2184 return 0; |
2075 } | 2185 } |
2076 | 2186 |
2077 /* TODO: Alias oracle basically assume that addresses of global variables | 2187 /* TODO: Alias oracle basically assume that addresses of global variables |
2078 are different unless they are declared as alias of one to another while | 2188 are different unless they are declared as alias of one to another while |
2079 the code folding comparsions doesn't. | 2189 the code folding comparisons doesn't. |
2080 We probably should be consistent and use this fact here, too, but for | 2190 We probably should be consistent and use this fact here, too, but for |
2081 the moment return false only when we are called from the alias oracle. */ | 2191 the moment return false only when we are called from the alias oracle. */ |
2082 | 2192 |
2083 return memory_accessed && rs1 != rs2 ? 0 : -1; | 2193 return memory_accessed && rs1 != rs2 ? 0 : -1; |
2084 } | 2194 } |
2145 | 2255 |
2146 /* With -fno-toplevel-reorder we may have already output the constant. */ | 2256 /* With -fno-toplevel-reorder we may have already output the constant. */ |
2147 if (TREE_ASM_WRITTEN (target->decl)) | 2257 if (TREE_ASM_WRITTEN (target->decl)) |
2148 return false; | 2258 return false; |
2149 | 2259 |
2150 /* If target is already placed in an anchor, we can not touch its | 2260 /* If target is already placed in an anchor, we cannot touch its |
2151 alignment. */ | 2261 alignment. */ |
2152 if (DECL_RTL_SET_P (target->decl) | 2262 if (DECL_RTL_SET_P (target->decl) |
2153 && MEM_P (DECL_RTL (target->decl)) | 2263 && MEM_P (DECL_RTL (target->decl)) |
2154 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0))) | 2264 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0))) |
2155 return false; | 2265 return false; |
2265 return false; | 2375 return false; |
2266 if (decl_binds_to_current_def_p (decl)) | 2376 if (decl_binds_to_current_def_p (decl)) |
2267 return true; | 2377 return true; |
2268 | 2378 |
2269 /* Inline clones always binds locally. */ | 2379 /* Inline clones always binds locally. */ |
2270 if (cnode && cnode->global.inlined_to) | 2380 if (cnode && cnode->inlined_to) |
2271 return true; | 2381 return true; |
2272 | 2382 |
2273 if (DECL_EXTERNAL (decl)) | 2383 if (DECL_EXTERNAL (decl)) |
2274 return false; | 2384 return false; |
2275 | 2385 |
2277 | 2387 |
2278 if (ref) | 2388 if (ref) |
2279 { | 2389 { |
2280 cgraph_node *cref = dyn_cast <cgraph_node *> (ref); | 2390 cgraph_node *cref = dyn_cast <cgraph_node *> (ref); |
2281 if (cref) | 2391 if (cref) |
2282 ref = cref->global.inlined_to; | 2392 ref = cref->inlined_to; |
2283 } | 2393 } |
2284 | 2394 |
2285 /* If this is a reference from symbol itself and there are no aliases, we | 2395 /* If this is a reference from symbol itself and there are no aliases, we |
2286 may be sure that the symbol was not interposed by something else because | 2396 may be sure that the symbol was not interposed by something else because |
2287 the symbol itself would be unreachable otherwise. This is important | 2397 the symbol itself would be unreachable otherwise. This is important |
2319 return false; | 2429 return false; |
2320 /* FIXME: variables probably should not be considered as real symbols at | 2430 /* FIXME: variables probably should not be considered as real symbols at |
2321 first place. */ | 2431 first place. */ |
2322 if (VAR_P (decl) && DECL_HARD_REGISTER (decl)) | 2432 if (VAR_P (decl) && DECL_HARD_REGISTER (decl)) |
2323 return false; | 2433 return false; |
2324 /* FIXME: Builtins corresponding to real functions probably should have | 2434 if (TREE_CODE (decl) == FUNCTION_DECL && !definition |
2325 symbol table entries. */ | 2435 && fndecl_built_in_p (decl)) |
2326 if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl)) | 2436 { |
2327 return false; | 2437 /* Builtins like those for most math functions have actual implementations |
2438 in libraries so make sure to output references into the symbol table to | |
2439 make those libraries referenced. Note this is incomplete handling for | |
2440 now and only covers math functions. */ | |
2441 if (builtin_with_linkage_p (decl)) | |
2442 return true; | |
2443 else | |
2444 return false; | |
2445 } | |
2328 | 2446 |
2329 /* We have real symbol that should be in symbol table. However try to trim | 2447 /* We have real symbol that should be in symbol table. However try to trim |
2330 down the refernces to libraries bit more because linker will otherwise | 2448 down the references to libraries bit more because linker will otherwise |
2331 bring unnecesary object files into the final link. | 2449 bring unnecessary object files into the final link. |
2332 FIXME: The following checks can easily be confused i.e. by self recursive | 2450 FIXME: The following checks can easily be confused i.e. by self recursive |
2333 function or self-referring variable. */ | 2451 function or self-referring variable. */ |
2334 | 2452 |
2335 /* We keep external functions in symtab for sake of inlining | 2453 /* We keep external functions in symtab for sake of inlining |
2336 and devirtualization. We do not want to see them in symbol table as | 2454 and devirtualization. We do not want to see them in symbol table as |
2340 && cnode->callers) | 2458 && cnode->callers) |
2341 return true; | 2459 return true; |
2342 | 2460 |
2343 /* Ignore all references from external vars initializers - they are not really | 2461 /* Ignore all references from external vars initializers - they are not really |
2344 part of the compilation unit until they are used by folding. Some symbols, | 2462 part of the compilation unit until they are used by folding. Some symbols, |
2345 like references to external construction vtables can not be referred to at | 2463 like references to external construction vtables cannot be referred to at |
2346 all. We decide this at can_refer_decl_in_current_unit_p. */ | 2464 all. We decide this at can_refer_decl_in_current_unit_p. */ |
2347 if (!definition || DECL_EXTERNAL (decl)) | 2465 if (!definition || DECL_EXTERNAL (decl)) |
2348 { | 2466 { |
2349 int i; | 2467 int i; |
2350 struct ipa_ref *ref; | 2468 struct ipa_ref *ref; |