LCOV - code coverage report
Current view: top level - gcc - symtab.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.0 % 1243 1056
Test Date: 2026-03-28 14:25:54 Functions: 92.0 % 88 81
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Symbol table.
       2              :    Copyright (C) 2012-2026 Free Software Foundation, Inc.
       3              :    Contributed by Jan Hubicka
       4              : 
       5              : This file is part of GCC.
       6              : 
       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
      10              : version.
      11              : 
      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
      15              : for more details.
      16              : 
      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/>.  */
      20              : 
      21              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "target.h"
      26              : #include "rtl.h"
      27              : #include "tree.h"
      28              : #include "gimple.h"
      29              : #include "timevar.h"
      30              : #include "cgraph.h"
      31              : #include "lto-streamer.h"
      32              : #include "print-tree.h"
      33              : #include "varasm.h"
      34              : #include "langhooks.h"
      35              : #include "output.h"
      36              : #include "ipa-utils.h"
      37              : #include "calls.h"
      38              : #include "stringpool.h"
      39              : #include "attribs.h"
      40              : #include "builtins.h"
      41              : #include "fold-const.h"
      42              : 
      43              : static const char *ipa_ref_use_name[] = {"read","write","addr","alias"};
      44              : 
      45              : const char * const ld_plugin_symbol_resolution_names[]=
      46              : {
      47              :   "",
      48              :   "undef",
      49              :   "prevailing_def",
      50              :   "prevailing_def_ironly",
      51              :   "preempted_reg",
      52              :   "preempted_ir",
      53              :   "resolved_ir",
      54              :   "resolved_exec",
      55              :   "resolved_dyn",
      56              :   "prevailing_def_ironly_exp"
      57              : };
      58              : 
      59              : /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at ALIAS
      60              :    until we find an identifier that is not itself a transparent alias.  */
      61              : 
      62              : static inline tree
      63          186 : ultimate_transparent_alias_target (tree alias)
      64              : {
      65          186 :   tree target = alias;
      66              : 
      67          186 :   while (IDENTIFIER_TRANSPARENT_ALIAS (target))
      68              :     {
      69            0 :       gcc_checking_assert (TREE_CHAIN (target));
      70            0 :       target = TREE_CHAIN (target);
      71              :     }
      72          186 :   gcc_checking_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
      73              :                        && ! TREE_CHAIN (target));
      74              : 
      75          186 :   return target;
      76              : }
      77              : 
      78              : 
      79              : /* Hash asmnames ignoring the user specified marks.  */
      80              : 
      81              : hashval_t
      82    556944533 : symbol_table::decl_assembler_name_hash (const_tree asmname)
      83              : {
      84    556944533 :   if (IDENTIFIER_POINTER (asmname)[0] == '*')
      85              :     {
      86      3262218 :       const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
      87      3262218 :       size_t ulp_len = strlen (user_label_prefix);
      88              : 
      89      3262218 :       if (ulp_len == 0)
      90              :         ;
      91           85 :       else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
      92           85 :         decl_str += ulp_len;
      93              : 
      94      3262218 :       return htab_hash_string (decl_str);
      95              :     }
      96              : 
      97    553682315 :   return htab_hash_string (IDENTIFIER_POINTER (asmname));
      98              : }
      99              : 
     100              : /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
     101              :    name.  */
     102              : 
     103              : bool
     104    482806160 : symbol_table::assembler_names_equal_p (const char *name1, const char *name2)
     105              : {
     106    482806160 :   if (name1 != name2)
     107              :     {
     108    482806061 :       if (name1[0] == '*')
     109              :         {
     110      2792602 :           size_t ulp_len = strlen (user_label_prefix);
     111              : 
     112      2792602 :           name1 ++;
     113              : 
     114      2792602 :           if (ulp_len == 0)
     115              :             ;
     116           30 :           else if (strncmp (name1, user_label_prefix, ulp_len) == 0)
     117           30 :             name1 += ulp_len;
     118              :           else
     119              :             return false;
     120              :         }
     121    482806061 :       if (name2[0] == '*')
     122              :         {
     123      2443219 :           size_t ulp_len = strlen (user_label_prefix);
     124              : 
     125      2443219 :           name2 ++;
     126              : 
     127      2443219 :           if (ulp_len == 0)
     128              :             ;
     129           18 :           else if (strncmp (name2, user_label_prefix, ulp_len) == 0)
     130           18 :             name2 += ulp_len;
     131              :           else
     132              :             return false;
     133              :         }
     134    482806061 :       return !strcmp (name1, name2);
     135              :     }
     136              :   return true;
     137              : }
     138              : 
     139              : /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL.  */
     140              : 
     141              : bool
     142    578009452 : symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
     143              : {
     144    578009452 :   tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
     145    578009452 :   const char *decl_str;
     146    578009452 :   const char *asmname_str;
     147              : 
     148    578009452 :   if (decl_asmname == asmname)
     149              :     return true;
     150              : 
     151    482806061 :   decl_str = IDENTIFIER_POINTER (decl_asmname);
     152    482806061 :   asmname_str = IDENTIFIER_POINTER (asmname);
     153    482806061 :   return assembler_names_equal_p (decl_str, asmname_str);
     154              : }
     155              : 
     156              : 
     157              : /* Returns nonzero if P1 and P2 are equal.  */
     158              : 
     159              : /* Insert NODE to assembler name hash.  */
     160              : 
     161              : void
     162    163963969 : symbol_table::insert_to_assembler_name_hash (symtab_node *node,
     163              :                                              bool with_clones)
     164              : {
     165    207065377 :   if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
     166              :     return;
     167    163963760 :   gcc_checking_assert (!node->previous_sharing_asm_name
     168              :                        && !node->next_sharing_asm_name);
     169    163963760 :   if (assembler_name_hash)
     170              :     {
     171     11692736 :       symtab_node **aslot;
     172     11692736 :       cgraph_node *cnode;
     173     11692736 :       tree decl = node->decl;
     174              : 
     175     11692736 :       tree name = DECL_ASSEMBLER_NAME (node->decl);
     176              : 
     177              :       /* C++ FE can produce decls without associated assembler name and insert
     178              :          them to symtab to hold section or TLS information.  */
     179     11692736 :       if (!name)
     180            0 :         return;
     181              : 
     182     11692736 :       hashval_t hash = decl_assembler_name_hash (name);
     183     11692736 :       aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
     184     11692736 :       gcc_assert (*aslot != node);
     185     11692736 :       node->next_sharing_asm_name = (symtab_node *)*aslot;
     186     11692736 :       if (*aslot != NULL)
     187      3070499 :         (*aslot)->previous_sharing_asm_name = node;
     188     11692736 :       *aslot = node;
     189              : 
     190              :       /* Update also possible inline clones sharing a decl.  */
     191     23385472 :       cnode = dyn_cast <cgraph_node *> (node);
     192      8326417 :       if (cnode && cnode->clones && with_clones)
     193           16 :         for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
     194           10 :           if (cnode->decl == decl)
     195            2 :             insert_to_assembler_name_hash (cnode, true);
     196              :     }
     197              : 
     198              : }
     199              : 
     200              : /* Remove NODE from assembler name hash.  */
     201              : 
     202              : void
     203    148372165 : symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
     204              :                                                bool with_clones)
     205              : {
     206    148372165 :   if (assembler_name_hash)
     207              :     {
     208      4885412 :       cgraph_node *cnode;
     209      4885412 :       tree decl = node->decl;
     210              : 
     211      4885412 :       if (node->next_sharing_asm_name)
     212      2665610 :         node->next_sharing_asm_name->previous_sharing_asm_name
     213      2665610 :           = node->previous_sharing_asm_name;
     214      4885412 :       if (node->previous_sharing_asm_name)
     215              :         {
     216       987491 :           node->previous_sharing_asm_name->next_sharing_asm_name
     217       987491 :             = node->next_sharing_asm_name;
     218              :         }
     219              :       else
     220              :         {
     221      3897921 :           tree name = DECL_ASSEMBLER_NAME (node->decl);
     222      3897921 :           symtab_node **slot;
     223              : 
     224      3897921 :           if (!name)
     225            0 :             return;
     226              : 
     227      3897921 :           hashval_t hash = decl_assembler_name_hash (name);
     228      3897921 :           slot = assembler_name_hash->find_slot_with_hash (name, hash,
     229              :                                                            NO_INSERT);
     230      3897921 :           gcc_assert (*slot == node);
     231      3897921 :           if (!node->next_sharing_asm_name)
     232      1986037 :             assembler_name_hash->clear_slot (slot);
     233              :           else
     234      1911884 :             *slot = node->next_sharing_asm_name;
     235              :         }
     236      4885412 :       node->next_sharing_asm_name = NULL;
     237      4885412 :       node->previous_sharing_asm_name = NULL;
     238              : 
     239              :       /* Update also possible inline clones sharing a decl.  */
     240      4885412 :       cnode = dyn_cast <cgraph_node *> (node);
     241      4782613 :       if (cnode && cnode->clones && with_clones)
     242           16 :         for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
     243           10 :           if (cnode->decl == decl)
     244            2 :             unlink_from_assembler_name_hash (cnode, true);
     245              :     }
     246              : }
     247              : 
     248              : /* Arrange node to be first in its entry of assembler_name_hash.  */
     249              : 
     250              : void
     251         2087 : symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
     252              : {
     253         2087 :   unlink_from_assembler_name_hash (node, false);
     254         2087 :   insert_to_assembler_name_hash (node, false);
     255         2087 : }
     256              : 
     257              : /* Initialize asm name hash unless.  */
     258              : 
     259              : void
     260     83441925 : symbol_table::symtab_initialize_asm_name_hash (void)
     261              : {
     262     83441925 :   symtab_node *node;
     263     83441925 :   if (!assembler_name_hash)
     264              :     {
     265       244350 :       assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
     266      8725132 :       FOR_EACH_SYMBOL (node)
     267      8480782 :         insert_to_assembler_name_hash (node, false);
     268              :     }
     269     83441925 : }
     270              : 
     271              : /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables.  */
     272              : 
     273              : void
     274      2848801 : symbol_table::change_decl_assembler_name (tree decl, tree name)
     275              : {
     276      2848801 :   symtab_node *node = NULL;
     277              : 
     278              :   /* We can have user ASM names on things, like global register variables, that
     279              :      are not in the symbol table.  */
     280        13679 :   if ((VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
     281      2849895 :       || TREE_CODE (decl) == FUNCTION_DECL)
     282      2847707 :     node = symtab_node::get (decl);
     283      2848801 :   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
     284              :     {
     285      1834452 :       SET_DECL_ASSEMBLER_NAME (decl, name);
     286      1834452 :       if (node)
     287           11 :         insert_to_assembler_name_hash (node, true);
     288              :     }
     289              :   else
     290              :     {
     291      1014349 :       if (name == DECL_ASSEMBLER_NAME (decl))
     292              :         return;
     293              : 
     294       156088 :       tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
     295       156088 :                     ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
     296            0 :                     : NULL);
     297       156088 :       if (node)
     298         8189 :         unlink_from_assembler_name_hash (node, true);
     299              : 
     300       156088 :       const char *old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
     301       156088 :       if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
     302       156088 :           && DECL_RTL_SET_P (decl))
     303            0 :         warning (0, "%qD renamed after being referenced in assembly", decl);
     304              : 
     305       156088 :       SET_DECL_ASSEMBLER_NAME (decl, name);
     306       156088 :       if (DECL_RTL_SET_P (decl))
     307              :         {
     308            1 :           SET_DECL_RTL (decl, NULL);
     309            1 :           make_decl_rtl (decl);
     310              :         }
     311       156088 :       if (alias)
     312              :         {
     313            0 :           gcc_assert (!IDENTIFIER_INTERNAL_P (name));
     314            0 :           IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
     315            0 :           TREE_CHAIN (name) = alias;
     316              :         }
     317              :       /* If we change assembler name, also all transparent aliases must
     318              :          be updated.  There are three kinds - those having same assembler name,
     319              :          those being renamed in varasm.cc and weakref being renamed by the
     320              :          assembler.  */
     321       156088 :       if (node)
     322              :         {
     323         8189 :           insert_to_assembler_name_hash (node, true);
     324         8189 :           ipa_ref *ref;
     325         8215 :           for (unsigned i = 0; node->iterate_direct_aliases (i, ref); i++)
     326              :             {
     327           26 :               struct symtab_node *alias = ref->referring;
     328            0 :               if (alias->transparent_alias && !alias->weakref
     329           26 :                   && symbol_table::assembler_names_equal_p
     330            0 :                          (old_name, IDENTIFIER_POINTER (
     331              :                                       DECL_ASSEMBLER_NAME (alias->decl))))
     332            0 :                 change_decl_assembler_name (alias->decl, name);
     333           26 :               else if (alias->transparent_alias
     334           26 :                        && IDENTIFIER_TRANSPARENT_ALIAS (alias->decl))
     335              :                 {
     336            0 :                   gcc_assert (TREE_CHAIN (DECL_ASSEMBLER_NAME (alias->decl))
     337              :                               && IDENTIFIER_TRANSPARENT_ALIAS
     338              :                                      (DECL_ASSEMBLER_NAME (alias->decl)));
     339              : 
     340            0 :                   TREE_CHAIN (DECL_ASSEMBLER_NAME (alias->decl)) =
     341              :                     ultimate_transparent_alias_target
     342            0 :                          (DECL_ASSEMBLER_NAME (node->decl));
     343              :                 }
     344              : #ifdef ASM_OUTPUT_WEAKREF
     345           26 :              else gcc_assert (!alias->transparent_alias || alias->weakref);
     346              : #else
     347              :              else gcc_assert (!alias->transparent_alias);
     348              : #endif
     349              :             }
     350         8189 :           gcc_assert (!node->transparent_alias || !node->definition
     351              :                       || node->weakref
     352              :                       || TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
     353              :                       || symbol_table::assembler_names_equal_p
     354              :                           (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
     355              :                            IDENTIFIER_POINTER
     356              :                              (DECL_ASSEMBLER_NAME
     357              :                                  (node->get_alias_target ()->decl))));
     358              :         }
     359              :     }
     360              : }
     361              : 
     362              : /* Hash sections by their names.  */
     363              : 
     364              : hashval_t
     365     12309052 : section_name_hasher::hash (section_hash_entry *n)
     366              : {
     367     12309052 :   return htab_hash_string (n->name);
     368              : }
     369              : 
     370              : /* Return true if section P1 name equals to P2.  */
     371              : 
     372              : bool
     373     12252757 : section_name_hasher::equal (section_hash_entry *n1, const char *name)
     374              : {
     375     12252757 :   return n1->name == name || !strcmp (n1->name, name);
     376              : }
     377              : 
     378              : /* Bump the reference count on ENTRY so that it is retained.  */
     379              : 
     380              : static section_hash_entry *
     381        47363 : retain_section_hash_entry (section_hash_entry *entry)
     382              : {
     383        47363 :   entry->ref_count++;
     384        47363 :   return entry;
     385              : }
     386              : 
     387              : /* Drop the reference count on ENTRY and remove it if the reference
     388              :    count drops to zero.  */
     389              : 
     390              : static void
     391      1872873 : release_section_hash_entry (section_hash_entry *entry)
     392              : {
     393      1872873 :   if (entry)
     394              :     {
     395        27695 :       entry->ref_count--;
     396        27695 :       if (!entry->ref_count)
     397              :         {
     398        24188 :           hashval_t hash = htab_hash_string (entry->name);
     399        24188 :           section_hash_entry **slot
     400        24188 :             = symtab->section_hash->find_slot_with_hash (entry->name,
     401              :                                                  hash, INSERT);
     402        24188 :           ggc_free (entry);
     403        24188 :           symtab->section_hash->clear_slot (slot);
     404              :         }
     405              :     }
     406      1872873 : }
     407              : 
     408              : /* Add node into symbol table.  This function is not used directly, but via
     409              :    cgraph/varpool node creation routines.  */
     410              : 
     411              : void
     412    155472898 : symtab_node::register_symbol (void)
     413              : {
     414    155472898 :   symtab->register_symbol (this);
     415              : 
     416    155472898 :   if (!decl->decl_with_vis.symtab_node)
     417    152537671 :     decl->decl_with_vis.symtab_node = this;
     418              : 
     419    155472898 :   ref_list.clear ();
     420              : 
     421              :   /* Be sure to do this last; C++ FE might create new nodes via
     422              :      DECL_ASSEMBLER_NAME langhook!  */
     423    155472898 :   symtab->insert_to_assembler_name_hash (this, false);
     424    155472898 : }
     425              : 
     426              : /* Remove NODE from same comdat group.   */
     427              : 
     428              : void
     429    160516004 : symtab_node::remove_from_same_comdat_group (void)
     430              : {
     431    160516004 :   if (same_comdat_group)
     432              :     {
     433              :       symtab_node *prev;
     434              :       for (prev = same_comdat_group;
     435     17724174 :            prev->same_comdat_group != this;
     436              :            prev = prev->same_comdat_group)
     437              :         ;
     438     17072740 :       if (same_comdat_group == prev)
     439     16662470 :         prev->same_comdat_group = NULL;
     440              :       else
     441       410270 :         prev->same_comdat_group = same_comdat_group;
     442     17072740 :       same_comdat_group = NULL;
     443     17072740 :       set_comdat_group (NULL);
     444              :     }
     445    160516004 : }
     446              : 
     447              : /* Remove node from symbol table.  This function is not used directly, but via
     448              :    cgraph/varpool node removal routines.
     449              :    INFO is a clone info to attach to new root of clone tree (if any).  */
     450              : 
     451              : void
     452    148361888 : symtab_node::unregister (clone_info *info)
     453              : {
     454    148361888 :   remove_all_references ();
     455    148361888 :   remove_all_referring ();
     456              : 
     457              :   /* Remove reference to section.  */
     458    148361888 :   set_section_for_node (NULL);
     459              : 
     460    148361888 :   remove_from_same_comdat_group ();
     461              : 
     462    148361888 :   symtab->unregister (this);
     463              : 
     464              :   /* During LTO symtab merging we temporarily corrupt decl to symtab node
     465              :      hash.  */
     466    148361888 :   gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
     467    148361888 :   if (decl->decl_with_vis.symtab_node == this)
     468              :     {
     469    145892318 :       symtab_node *replacement_node = NULL;
     470    145892318 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
     471    109483570 :         replacement_node = cnode->find_replacement (info);
     472    145892318 :       decl->decl_with_vis.symtab_node = replacement_node;
     473              :     }
     474    148361888 :   if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
     475    148361887 :     symtab->unlink_from_assembler_name_hash (this, false);
     476    148361888 :   if (in_init_priority_hash)
     477          109 :     symtab->init_priority_hash->remove (this);
     478    148361888 : }
     479              : 
     480              : 
     481              : /* Remove symbol from symbol table.  */
     482              : 
     483              : void
     484    143489649 : symtab_node::remove (void)
     485              : {
     486    143489649 :   if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
     487    107180050 :     cnode->remove ();
     488     36309599 :   else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
     489     36309599 :     vnode->remove ();
     490    143489649 : }
     491              : 
     492              : /* Add NEW_ to the same comdat group that OLD is in.  */
     493              : 
     494              : void
     495     17146477 : symtab_node::add_to_same_comdat_group (symtab_node *old_node)
     496              : {
     497     17146477 :   gcc_assert (old_node->get_comdat_group ());
     498     17146477 :   gcc_assert (!same_comdat_group);
     499     17146477 :   gcc_assert (this != old_node);
     500              : 
     501     17146477 :   set_comdat_group (old_node->get_comdat_group ());
     502     17146477 :   same_comdat_group = old_node;
     503     17146477 :   if (!old_node->same_comdat_group)
     504     16717949 :     old_node->same_comdat_group = this;
     505              :   else
     506              :     {
     507              :       symtab_node *n;
     508              :       for (n = old_node->same_comdat_group;
     509       774776 :            n->same_comdat_group != old_node;
     510              :            n = n->same_comdat_group)
     511              :         ;
     512       428528 :       n->same_comdat_group = this;
     513              :     }
     514              : 
     515     17146477 :   cgraph_node *n;
     516     17158773 :   if (comdat_local_p ()
     517     17158766 :       && (n = dyn_cast <cgraph_node *> (this)) != NULL)
     518              :     {
     519        27830 :       for (cgraph_edge *e = n->callers; e; e = e->next_caller)
     520        15541 :         if (e->caller->inlined_to)
     521         4338 :           e->caller->inlined_to->calls_comdat_local = true;
     522              :         else
     523        11203 :           e->caller->calls_comdat_local = true;
     524              :     }
     525     17146477 : }
     526              : 
     527              : /* Dissolve the same_comdat_group list in which NODE resides.  */
     528              : 
     529              : void
     530         2061 : symtab_node::dissolve_same_comdat_group_list (void)
     531              : {
     532         2061 :   symtab_node *n = this;
     533         2061 :   symtab_node *next;
     534              : 
     535         2061 :   if (!same_comdat_group)
     536              :     return;
     537         3816 :   do
     538              :     {
     539         3816 :       next = n->same_comdat_group;
     540         3816 :       n->same_comdat_group = NULL;
     541         3816 :       if (dyn_cast <cgraph_node *> (n))
     542         3546 :         dyn_cast <cgraph_node *> (n)->calls_comdat_local = false;
     543              :       /* Clear comdat_group for comdat locals, since
     544              :          make_decl_local doesn't.  */
     545         3816 :       if (!TREE_PUBLIC (n->decl))
     546         2051 :         n->set_comdat_group (NULL);
     547         3816 :       n = next;
     548              :     }
     549         3816 :   while (n != this);
     550              : }
     551              : 
     552              : /* Return printable assembler name of NODE.
     553              :    This function is used only for debugging.  When assembler name
     554              :    is unknown go with identifier name.  */
     555              : 
     556              : const char *
     557        44792 : symtab_node::asm_name () const
     558              : {
     559        44792 :   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
     560          195 :     return name ();
     561        44597 :   return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
     562              : }
     563              : 
     564              : /* Return printable identifier name.  */
     565              : 
     566              : const char *
     567        45420 : symtab_node::name () const
     568              : {
     569        45420 :   if (!DECL_NAME (decl))
     570              :     {
     571            0 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
     572            0 :         return asm_name ();
     573              :       else
     574              :         return "<unnamed>";
     575              :     }
     576        45420 :   return lang_hooks.decl_printable_name (decl, 2);
     577              : }
     578              : 
     579              : const char *
     580        81062 : symtab_node::get_dump_name (bool asm_name_p) const
     581              : {
     582              : #define EXTRA 16
     583        81062 :   const char *fname = asm_name_p ? asm_name () : name ();
     584        81062 :   unsigned l = strlen (fname);
     585              : 
     586        81062 :   char *s = (char *)ggc_internal_cleared_alloc (l + EXTRA);
     587        81062 :   snprintf (s, l + EXTRA, "%s/%d", fname, m_uid);
     588              : 
     589        81062 :   return s;
     590              : }
     591              : 
     592              : const char *
     593        36642 : symtab_node::dump_name () const
     594              : {
     595        36642 :   return get_dump_name (false);
     596              : }
     597              : 
     598              : const char *
     599        44420 : symtab_node::dump_asm_name () const
     600              : {
     601        44420 :   return get_dump_name (true);
     602              : }
     603              : 
     604              : /* Return ipa reference from this symtab_node to
     605              :    REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
     606              :    of the use.  */
     607              : 
     608              : ipa_ref *
     609      6548299 : symtab_node::create_reference (symtab_node *referred_node,
     610              :                                enum ipa_ref_use use_type)
     611              : {
     612      6548299 :   return create_reference (referred_node, use_type, NULL);
     613              : }
     614              : 
     615              : 
     616              : /* Return ipa reference from this symtab_node to
     617              :    REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
     618              :    of the use and STMT the statement (if it exists).  */
     619              : 
     620              : ipa_ref *
     621     42191536 : symtab_node::create_reference (symtab_node *referred_node,
     622              :                                enum ipa_ref_use use_type, gimple *stmt)
     623              : {
     624     42191536 :   ipa_ref *ref = NULL, *ref2 = NULL;
     625     42191536 :   ipa_ref_list *list, *list2;
     626     42191536 :   ipa_ref_t *old_references;
     627              : 
     628     42191536 :   gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
     629     42191536 :   gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
     630              : 
     631     42191536 :   list = &ref_list;
     632     42191536 :   old_references = list->references.address ();
     633     69806459 :   list->references.safe_grow (list->references.length () + 1, false);
     634     42191536 :   ref = &list->references.last ();
     635              : 
     636     42191536 :   list2 = &referred_node->ref_list;
     637              : 
     638              :   /* IPA_REF_ALIAS is always inserted at the beginning of the list.   */
     639     42191536 :   if(use_type == IPA_REF_ALIAS)
     640              :     {
     641      8638429 :       list2->referring.safe_insert (0, ref);
     642      8638429 :       ref->referred_index = 0;
     643              : 
     644      8786757 :       for (unsigned int i = 1; i < list2->referring.length (); i++)
     645       148328 :         list2->referring[i]->referred_index = i;
     646              :     }
     647              :   else
     648              :     {
     649     33553107 :       list2->referring.safe_push (ref);
     650     67106214 :       ref->referred_index = list2->referring.length () - 1;
     651              :     }
     652              : 
     653     42191536 :   ref->referring = this;
     654     42191536 :   ref->referred = referred_node;
     655     42191536 :   ref->stmt = stmt;
     656     42191536 :   ref->lto_stmt_uid = 0;
     657     42191536 :   ref->speculative_id = 0;
     658     42191536 :   ref->use = use_type;
     659     42191536 :   ref->speculative = 0;
     660              : 
     661              :   /* If vector was moved in memory, update pointers.  */
     662     84383072 :   if (old_references != list->references.address ())
     663              :     {
     664              :       int i;
     665     53803164 :       for (i = 0; iterate_reference(i, ref2); i++)
     666     37893461 :         ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
     667              :     }
     668     42191536 :   return ref;
     669              : }
     670              : 
     671              : ipa_ref *
     672        58642 : symtab_node::maybe_create_reference (tree val, gimple *stmt)
     673              : {
     674        58642 :   STRIP_NOPS (val);
     675        58642 :   ipa_ref_use use_type;
     676              : 
     677        58642 :   switch (TREE_CODE (val))
     678              :     {
     679              :     case VAR_DECL:
     680              :       use_type = IPA_REF_LOAD;
     681              :       break;
     682         8345 :     case ADDR_EXPR:
     683         8345 :       use_type = IPA_REF_ADDR;
     684         8345 :       break;
     685        49876 :     default:
     686        49876 :       gcc_assert (!handled_component_p (val));
     687              :       return NULL;
     688              :     }
     689              : 
     690         8766 :   val = get_base_var (val);
     691         8766 :   if (val && VAR_OR_FUNCTION_DECL_P (val))
     692              :     {
     693         4983 :       symtab_node *referred = symtab_node::get (val);
     694         4983 :       gcc_checking_assert (referred);
     695         4983 :       return create_reference (referred, use_type, stmt);
     696              :     }
     697              :   return NULL;
     698              : }
     699              : 
     700              : /* Clone all references from symtab NODE to this symtab_node.  */
     701              : 
     702              : void
     703      3064864 : symtab_node::clone_references (symtab_node *node)
     704              : {
     705      3064864 :   ipa_ref *ref = NULL, *ref2 = NULL;
     706      3064864 :   int i;
     707      3903296 :   for (i = 0; node->iterate_reference (i, ref); i++)
     708              :     {
     709       838432 :       bool speculative = ref->speculative;
     710       838432 :       unsigned int stmt_uid = ref->lto_stmt_uid;
     711       838432 :       unsigned int spec_id = ref->speculative_id;
     712              : 
     713       838432 :       ref2 = create_reference (ref->referred, ref->use, ref->stmt);
     714       838432 :       ref2->speculative = speculative;
     715       838432 :       ref2->lto_stmt_uid = stmt_uid;
     716       838432 :       ref2->speculative_id = spec_id;
     717              :     }
     718      3064864 : }
     719              : 
     720              : /* Clone all referring from symtab NODE to this symtab_node.  */
     721              : 
     722              : void
     723         2683 : symtab_node::clone_referring (symtab_node *node)
     724              : {
     725         2683 :   ipa_ref *ref = NULL, *ref2 = NULL;
     726         2683 :   int i;
     727         4610 :   for (i = 0; node->iterate_referring(i, ref); i++)
     728              :     {
     729         1927 :       bool speculative = ref->speculative;
     730         1927 :       unsigned int stmt_uid = ref->lto_stmt_uid;
     731         1927 :       unsigned int spec_id = ref->speculative_id;
     732              : 
     733         1927 :       ref2 = ref->referring->create_reference (this, ref->use, ref->stmt);
     734         1927 :       ref2->speculative = speculative;
     735         1927 :       ref2->lto_stmt_uid = stmt_uid;
     736         1927 :       ref2->speculative_id = spec_id;
     737              :     }
     738         2683 : }
     739              : 
     740              : /* Clone reference REF to this symtab_node and set its stmt to STMT.  */
     741              : 
     742              : ipa_ref *
     743        27101 : symtab_node::clone_reference (ipa_ref *ref, gimple *stmt)
     744              : {
     745        27101 :   bool speculative = ref->speculative;
     746        27101 :   unsigned int stmt_uid = ref->lto_stmt_uid;
     747        27101 :   unsigned int spec_id = ref->speculative_id;
     748        27101 :   ipa_ref *ref2;
     749              : 
     750        27101 :   ref2 = create_reference (ref->referred, ref->use, stmt);
     751        27101 :   ref2->speculative = speculative;
     752        27101 :   ref2->lto_stmt_uid = stmt_uid;
     753        27101 :   ref2->speculative_id = spec_id;
     754        27101 :   return ref2;
     755              : }
     756              : 
     757              : /* Find the structure describing a reference to REFERRED_NODE of USE_TYPE and
     758              :    associated with statement STMT or LTO_STMT_UID.  */
     759              : 
     760              : ipa_ref *
     761         8944 : symtab_node::find_reference (symtab_node *referred_node,
     762              :                              gimple *stmt, unsigned int lto_stmt_uid,
     763              :                              enum ipa_ref_use use_type)
     764              : {
     765         8944 :   ipa_ref *r = NULL;
     766         8944 :   int i;
     767              : 
     768        55924 :   for (i = 0; iterate_reference (i, r); i++)
     769        55921 :     if (r->referred == referred_node
     770        15501 :         && !r->speculative
     771        15501 :         && r->use == use_type
     772        12321 :         && ((stmt && r->stmt == stmt)
     773         3942 :             || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
     774         3776 :             || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid)))
     775              :       return r;
     776              :   return NULL;
     777              : }
     778              : 
     779              : /* Remove all references that are associated with statement STMT.  */
     780              : 
     781              : void
     782        64290 : symtab_node::remove_stmt_references (gimple *stmt)
     783              : {
     784        64290 :   ipa_ref *r = NULL;
     785        64290 :   int i = 0;
     786              : 
     787        68355 :   while (iterate_reference (i, r))
     788         4065 :     if (r->stmt == stmt)
     789            0 :       r->remove_reference ();
     790              :     else
     791         4065 :       i++;
     792        64290 : }
     793              : 
     794              : /* Remove all stmt references in non-speculative references in THIS
     795              :    and all clones.
     796              :    Those are not maintained during inlining & cloning.
     797              :    The exception are speculative references that are updated along
     798              :    with callgraph edges associated with them.  */
     799              : 
     800              : void
     801      2164467 : symtab_node::clear_stmts_in_references (void)
     802              : {
     803      2164467 :   ipa_ref *r = NULL;
     804      2164467 :   int i;
     805              : 
     806      8698089 :   for (i = 0; iterate_reference (i, r); i++)
     807      6533622 :     if (!r->speculative)
     808              :       {
     809      6518302 :         r->stmt = NULL;
     810      6518302 :         r->lto_stmt_uid = 0;
     811      6518302 :         r->speculative_id = 0;
     812              :       }
     813      2164467 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
     814      2164467 :   if (cnode)
     815              :     {
     816      2164467 :       if (cnode->clones)
     817       684960 :         for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
     818       561677 :           cnode->clear_stmts_in_references ();
     819              :     }
     820      2164467 : }
     821              : 
     822              : /* Remove all references in ref list.  */
     823              : 
     824              : void
     825    289320429 : symtab_node::remove_all_references (void)
     826              : {
     827    327256065 :   while (ref_list.references.length ())
     828     37935636 :     ref_list.references.last ().remove_reference ();
     829    289320429 :   ref_list.references.release ();
     830    289320429 : }
     831              : 
     832              : /* Remove all referring items in ref list.  */
     833              : 
     834              : void
     835    148361888 : symtab_node::remove_all_referring (void)
     836              : {
     837    148446313 :   while (ref_list.referring.length ())
     838        84425 :     ref_list.referring.last ()->remove_reference ();
     839    148361888 :   ref_list.referring.release ();
     840    148361888 : }
     841              : 
     842              : /* Dump references in ref list to FILE.  */
     843              : 
     844              : void
     845         8379 : symtab_node::dump_references (FILE *file)
     846              : {
     847         8379 :   ipa_ref *ref = NULL;
     848         8379 :   int i;
     849        15542 :   for (i = 0; iterate_reference (i, ref); i++)
     850              :     {
     851         7163 :       fprintf (file, "%s (%s) ", ref->referred->dump_asm_name (),
     852         7163 :                ipa_ref_use_name[ref->use]);
     853         7163 :       if (ref->speculative)
     854          113 :         fprintf (file, "(speculative) ");
     855              :     }
     856         8379 :   fprintf (file, "\n");
     857         8379 : }
     858              : 
     859              : /* Dump referring in list to FILE.  */
     860              : 
     861              : void
     862         8379 : symtab_node::dump_referring (FILE *file)
     863              : {
     864         8379 :   ipa_ref *ref = NULL;
     865         8379 :   int i;
     866        13466 :   for (i = 0; iterate_referring(i, ref); i++)
     867              :     {
     868         5087 :       fprintf (file, "%s (%s) ", ref->referring->dump_asm_name (),
     869         5087 :                ipa_ref_use_name[ref->use]);
     870         5087 :       if (ref->speculative)
     871          107 :         fprintf (file, "(speculative) ");
     872              :     }
     873         8379 :   fprintf (file, "\n");
     874         8379 : }
     875              : 
     876              : static const char * const toplevel_type_names[] =
     877              : {
     878              :  "base",
     879              :  "asm",
     880              :  "symbol",
     881              :  "function",
     882              :  "variable",
     883              : };
     884              : 
     885              : static_assert (ARRAY_SIZE(toplevel_type_names) == TOPLEVEL_MAX, "");
     886              : 
     887              : /* Dump the visibility of the symbol.  */
     888              : 
     889              : const char *
     890            0 : symtab_node::get_visibility_string () const
     891              : {
     892            0 :   static const char * const visibility_types[]
     893              :     = { "default", "protected", "hidden", "internal" };
     894            0 :   return visibility_types[DECL_VISIBILITY (decl)];
     895              : }
     896              : 
     897              : /* Dump the type_name of the symbol.  */
     898              : const char *
     899            0 : symtab_node::get_symtab_type_string () const
     900              : {
     901            0 :   return toplevel_type_names[type];
     902              : }
     903              : 
     904              : /* Dump base fields of symtab nodes to F.  Not to be used directly.  */
     905              : 
     906              : void
     907         8379 : symtab_node::dump_base (FILE *f)
     908              : {
     909         8379 :   static const char * const visibility_types[] = {
     910              :     "default", "protected", "hidden", "internal"
     911              :   };
     912              : 
     913         8379 :   fprintf (f, "%s (%s)", dump_asm_name (), name ());
     914         8379 :   if (dump_flags & TDF_ADDRESS)
     915          103 :     dump_addr (f, " @", (void *)this);
     916         8379 :   fprintf (f, "\n  Type: %s", toplevel_type_names[type]);
     917              : 
     918         8379 :   if (definition)
     919         6426 :     fprintf (f, " definition");
     920         8379 :   if (analyzed)
     921         6423 :     fprintf (f, " analyzed");
     922         8379 :   if (alias)
     923          100 :     fprintf (f, " alias");
     924         8379 :   if (transparent_alias)
     925            0 :     fprintf (f, " transparent_alias");
     926         8379 :   if (weakref)
     927            0 :     fprintf (f, " weakref");
     928         8379 :   if (symver)
     929            0 :     fprintf (f, " symver");
     930         8379 :   if (cpp_implicit_alias)
     931           81 :     fprintf (f, " cpp_implicit_alias");
     932         8379 :   if (alias_target)
     933            0 :     fprintf (f, " target:%s",
     934            0 :              DECL_P (alias_target)
     935            0 :              ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
     936              :                                      (alias_target))
     937            0 :              : IDENTIFIER_POINTER (alias_target));
     938         8379 :   if (body_removed)
     939          631 :     fprintf (f, "\n  Body removed by symtab_remove_unreachable_nodes");
     940         8379 :   fprintf (f, "\n  Visibility:");
     941         8379 :   if (in_other_partition)
     942            0 :     fprintf (f, " in_other_partition");
     943         8379 :   if (used_from_other_partition)
     944            0 :     fprintf (f, " used_from_other_partition");
     945         8379 :   if (force_output)
     946          645 :     fprintf (f, " force_output");
     947         8379 :   if (forced_by_abi)
     948          540 :     fprintf (f, " forced_by_abi");
     949         8379 :   if (externally_visible)
     950         3903 :     fprintf (f, " externally_visible");
     951         8379 :   if (semantic_interposition)
     952         7911 :     fprintf (f, " semantic_interposition");
     953         8379 :   if (no_reorder)
     954          557 :     fprintf (f, " no_reorder");
     955         8379 :   if (resolution != LDPR_UNKNOWN)
     956         1091 :     fprintf (f, " %s",
     957         1091 :              ld_plugin_symbol_resolution_names[(int)resolution]);
     958         8379 :   if (TREE_ASM_WRITTEN (decl))
     959          194 :     fprintf (f, " asm_written");
     960         8379 :   if (DECL_EXTERNAL (decl))
     961         1698 :     fprintf (f, " external");
     962         8379 :   if (TREE_PUBLIC (decl))
     963         6477 :     fprintf (f, " public");
     964         8379 :   if (DECL_COMMON (decl))
     965           22 :     fprintf (f, " common");
     966         8379 :   if (DECL_WEAK (decl))
     967         1488 :     fprintf (f, " weak");
     968         8379 :   if (DECL_DLLIMPORT_P (decl))
     969            0 :     fprintf (f, " dll_import");
     970         8379 :   if (DECL_COMDAT (decl))
     971         1452 :     fprintf (f, " comdat");
     972         8379 :   if (get_comdat_group ())
     973         2710 :     fprintf (f, " comdat_group:%s",
     974         1355 :              IDENTIFIER_POINTER (get_comdat_group_id ()));
     975         8379 :   if (DECL_ONE_ONLY (decl))
     976         1401 :     fprintf (f, " one_only");
     977         8379 :   if (get_section ())
     978           38 :     fprintf (f, " section:%s",
     979              :              get_section ());
     980         8379 :   if (implicit_section)
     981           36 :     fprintf (f," (implicit_section)");
     982         8379 :   if (DECL_VISIBILITY_SPECIFIED (decl))
     983          577 :     fprintf (f, " visibility_specified");
     984         8379 :   if (DECL_VISIBILITY (decl))
     985           40 :     fprintf (f, " visibility:%s",
     986           20 :              visibility_types [DECL_VISIBILITY (decl)]);
     987         8379 :   if (DECL_VIRTUAL_P (decl))
     988         1325 :     fprintf (f, " virtual");
     989         8379 :   if (DECL_ARTIFICIAL (decl))
     990         2309 :     fprintf (f, " artificial");
     991         8379 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     992              :     {
     993         5911 :       if (DECL_STATIC_CONSTRUCTOR (decl))
     994           48 :         fprintf (f, " constructor");
     995         5911 :       if (DECL_STATIC_DESTRUCTOR (decl))
     996            7 :         fprintf (f, " destructor");
     997              :     }
     998         8379 :   if (ifunc_resolver)
     999            3 :     fprintf (f, " ifunc_resolver");
    1000         8379 :   fprintf (f, "\n");
    1001              : 
    1002         8379 :   if (same_comdat_group)
    1003          158 :     fprintf (f, "  Same comdat group as: %s\n",
    1004              :              same_comdat_group->dump_asm_name ());
    1005         8379 :   if (next_sharing_asm_name)
    1006          407 :     fprintf (f, "  next sharing asm name: %i\n",
    1007          407 :              next_sharing_asm_name->get_uid ());
    1008         8379 :   if (previous_sharing_asm_name)
    1009          371 :     fprintf (f, "  previous sharing asm name: %i\n",
    1010          371 :              previous_sharing_asm_name->get_uid ());
    1011              : 
    1012         8379 :   if (address_taken)
    1013          878 :     fprintf (f, "  Address is taken.\n");
    1014         8379 :   if (aux)
    1015              :     {
    1016          511 :       fprintf (f, "  Aux:");
    1017          511 :       dump_addr (f, " @", (void *)aux);
    1018          511 :       fprintf (f, "\n");
    1019              :     }
    1020              : 
    1021         8379 :   fprintf (f, "  References: ");
    1022         8379 :   dump_references (f);
    1023         8379 :   fprintf (f, "  Referring: ");
    1024         8379 :   dump_referring (f);
    1025         8379 :   if (lto_file_data)
    1026          255 :     fprintf (f, "  Read from file: %s\n",
    1027              :              lto_file_data->file_name);
    1028         8379 : }
    1029              : 
    1030              : /* Dump symtab node to F.  */
    1031              : 
    1032              : void
    1033         7516 : symtab_node::dump (FILE *f)
    1034              : {
    1035         7516 :   if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
    1036         5048 :     cnode->dump (f);
    1037         2468 :   else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
    1038         2468 :     vnode->dump (f);
    1039         7516 : }
    1040              : 
    1041              : void
    1042            0 : symtab_node::dump_graphviz (FILE *f)
    1043              : {
    1044            0 :   if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
    1045            0 :     cnode->dump_graphviz (f);
    1046            0 : }
    1047              : 
    1048              : void
    1049         1256 : symbol_table::dump (FILE *f)
    1050              : {
    1051         1256 :   symtab_node *node;
    1052         1256 :   fprintf (f, "Symbol table:\n\n");
    1053         8769 :   FOR_EACH_SYMBOL (node)
    1054         7513 :     node->dump (f);
    1055         1256 : }
    1056              : 
    1057              : void
    1058            0 : symbol_table::dump_graphviz (FILE *f)
    1059              : {
    1060            0 :   symtab_node *node;
    1061            0 :   fprintf (f, "digraph symtab {\n");
    1062            0 :   FOR_EACH_SYMBOL (node)
    1063            0 :     node->dump_graphviz (f);
    1064            0 :   fprintf (f, "}\n");
    1065            0 : }
    1066              : 
    1067              : DEBUG_FUNCTION void
    1068            0 : symbol_table::debug (void)
    1069              : {
    1070            0 :   dump (stderr);
    1071            0 : }
    1072              : 
    1073              : /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
    1074              :    Return NULL if there's no such node.  */
    1075              : 
    1076              : symtab_node *
    1077     82953279 : symtab_node::get_for_asmname (const_tree asmname)
    1078              : {
    1079     82953279 :   symtab_node *node;
    1080              : 
    1081     82953279 :   symtab->symtab_initialize_asm_name_hash ();
    1082     82953279 :   hashval_t hash = symtab->decl_assembler_name_hash (asmname);
    1083     82953279 :   symtab_node **slot
    1084     82953279 :     = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
    1085              :                                                         NO_INSERT);
    1086              : 
    1087     82953279 :   if (slot)
    1088              :     {
    1089     82950378 :       node = *slot;
    1090     82950378 :       return node;
    1091              :     }
    1092              :   return NULL;
    1093              : }
    1094              : 
    1095              : /* Dump symtab node NODE to stderr.  */
    1096              : 
    1097              : DEBUG_FUNCTION void
    1098            0 : symtab_node::debug (void)
    1099              : {
    1100            0 :   dump (stderr);
    1101            0 : }
    1102              : 
    1103              : /* Verify common part of symtab nodes.  */
    1104              : 
    1105              : #if __GNUC__ >= 10
    1106              : /* Disable warnings about missing quoting in GCC diagnostics for
    1107              :    the verification errors.  Their format strings don't follow GCC
    1108              :    diagnostic conventions and the calls are ultimately followed by
    1109              :    one to internal_error.  */
    1110              : #  pragma GCC diagnostic push
    1111              : #  pragma GCC diagnostic ignored "-Wformat-diag"
    1112              : #endif
    1113              : 
    1114              : DEBUG_FUNCTION bool
    1115     83432000 : symtab_node::verify_base (void)
    1116              : {
    1117     83432000 :   bool error_found = false;
    1118     83432000 :   symtab_node *hashed_node;
    1119              : 
    1120     83432000 :   if (is_a <cgraph_node *> (this))
    1121              :     {
    1122     51577431 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    1123              :         {
    1124            0 :           error ("function symbol is not function");
    1125            0 :           error_found = true;
    1126              :         }
    1127     51577431 :       else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))
    1128     51577431 :                 != NULL)
    1129     51577431 :                != dyn_cast <cgraph_node *> (this)->ifunc_resolver)
    1130              :         {
    1131            0 :           error ("inconsistent %<ifunc%> attribute");
    1132            0 :           error_found = true;
    1133              :         }
    1134              :     }
    1135     31854569 :   else if (is_a <varpool_node *> (this))
    1136              :     {
    1137     31854569 :       if (!VAR_P (decl))
    1138              :         {
    1139            0 :           error ("variable symbol is not variable");
    1140            0 :           error_found = true;
    1141              :         }
    1142              :     }
    1143              :   else
    1144              :     {
    1145            0 :       error ("node has unknown type");
    1146            0 :       error_found = true;
    1147              :     }
    1148     83432000 :   if (order < 0 || order >= symtab->order)
    1149              :     {
    1150            0 :       error ("node has invalid order %i", order);
    1151            0 :       error_found = true;
    1152              :     }
    1153              : 
    1154     83432000 :   if (symtab->state != LTO_STREAMING)
    1155              :     {
    1156     83276883 :       hashed_node = symtab_node::get (decl);
    1157     83276883 :       if (!hashed_node)
    1158              :         {
    1159            0 :           error ("node not found node->decl->decl_with_vis.symtab_node");
    1160            0 :           error_found = true;
    1161              :         }
    1162     83276883 :       if (hashed_node != this
    1163     88543010 :           && (!is_a <cgraph_node *> (this)
    1164      5266127 :               || !dyn_cast <cgraph_node *> (this)->clone_of
    1165      5266127 :               || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
    1166              :         {
    1167            0 :           error ("node differs from node->decl->decl_with_vis.symtab_node");
    1168            0 :           error_found = true;
    1169              :         }
    1170              :     }
    1171     83432000 :   if (symtab->assembler_name_hash)
    1172              :     {
    1173     82871104 :       hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
    1174     82871104 :       if (hashed_node)
    1175              :         {
    1176     82870299 :           if (hashed_node->previous_sharing_asm_name)
    1177              :             {
    1178            0 :               error ("assembler name hash list corrupted");
    1179            0 :               error_found = true;
    1180              :             }
    1181     82870299 :           else if (previous_sharing_asm_name == NULL)
    1182              :             {
    1183     77577515 :               if (hashed_node != this)
    1184              :                 {
    1185            0 :                   error ("assembler name hash list corrupted");
    1186            0 :                   error_found = true;
    1187              :                 }
    1188              :             }
    1189      5292784 :           else if (!(is_a <varpool_node *> (this) && DECL_HARD_REGISTER (decl)))
    1190              :             {
    1191      5292784 :               if (!asmname_hasher::equal (previous_sharing_asm_name,
    1192      5292784 :                                           DECL_ASSEMBLER_NAME (decl)))
    1193              :                 {
    1194            0 :                   error ("node not found in symtab assembler name hash");
    1195            0 :                   error_found = true;
    1196              :                 }
    1197              :             }
    1198              :         }
    1199              :     }
    1200     83432000 :   if (previous_sharing_asm_name
    1201      5292784 :       && previous_sharing_asm_name->next_sharing_asm_name != this)
    1202              :     {
    1203            0 :       error ("double linked list of assembler names corrupted");
    1204            0 :       error_found = true;
    1205              :     }
    1206     83432000 :   if (body_removed && definition)
    1207              :     {
    1208            0 :       error ("node has body_removed but is definition");
    1209            0 :       error_found = true;
    1210              :     }
    1211     83432000 :   if (analyzed && !definition)
    1212              :     {
    1213            0 :       error ("node is analyzed but it is not a definition");
    1214            0 :       error_found = true;
    1215              :     }
    1216     83432000 :   if (cpp_implicit_alias && !alias)
    1217              :     {
    1218            0 :       error ("node is alias but not implicit alias");
    1219            0 :       error_found = true;
    1220              :     }
    1221     83432000 :   if (alias && !definition && !weakref)
    1222              :     {
    1223            0 :       error ("node is alias but not definition");
    1224            0 :       error_found = true;
    1225              :     }
    1226     83432000 :   if (weakref && !transparent_alias)
    1227              :     {
    1228            0 :       error ("node is weakref but not an transparent_alias");
    1229            0 :       error_found = true;
    1230              :     }
    1231     83432000 :   if (transparent_alias && !alias)
    1232              :     {
    1233            0 :       error ("node is transparent_alias but not an alias");
    1234            0 :       error_found = true;
    1235              :     }
    1236     83432000 :   if (symver && !alias)
    1237              :     {
    1238            0 :       error ("node is symver but not alias");
    1239            0 :       error_found = true;
    1240              :     }
    1241              :   /* Limitation of gas requires us to output targets of symver aliases as
    1242              :      global symbols.  This is binutils PR 25295.  */
    1243     83432000 :   if (symver
    1244     83432000 :       && (!TREE_PUBLIC (get_alias_target ()->decl)
    1245           16 :           || DECL_VISIBILITY (get_alias_target ()->decl) != VISIBILITY_DEFAULT))
    1246              :     {
    1247            0 :       error ("symver target is not exported with default visibility");
    1248            0 :       error_found = true;
    1249              :     }
    1250     83432000 :   if (symver
    1251     83432000 :       && (!TREE_PUBLIC (decl)
    1252           16 :           || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT))
    1253              :     {
    1254            0 :       error ("symver is not exported with default visibility");
    1255            0 :       error_found = true;
    1256              :     }
    1257     83432000 :   if (same_comdat_group)
    1258              :     {
    1259      3181131 :       symtab_node *n = same_comdat_group;
    1260              : 
    1261      3181131 :       if (!n->get_comdat_group ())
    1262              :         {
    1263            0 :           error ("node is in same_comdat_group list but has no comdat_group");
    1264            0 :           error_found = true;
    1265              :         }
    1266      3181131 :       if (n->get_comdat_group () != get_comdat_group ())
    1267              :         {
    1268            0 :           error ("same_comdat_group list across different groups");
    1269            0 :           error_found = true;
    1270              :         }
    1271      3181131 :       if (n->type != type)
    1272              :         {
    1273            0 :           error ("mixing different types of symbol in same comdat groups is not supported");
    1274            0 :           error_found = true;
    1275              :         }
    1276      3181131 :       if (n == this)
    1277              :         {
    1278            0 :           error ("node is alone in a comdat group");
    1279            0 :           error_found = true;
    1280              :         }
    1281      5718231 :       do
    1282              :         {
    1283      5718231 :           if (!n->same_comdat_group)
    1284              :             {
    1285            0 :               error ("same_comdat_group is not a circular list");
    1286            0 :               error_found = true;
    1287            0 :               break;
    1288              :             }
    1289      5718231 :           n = n->same_comdat_group;
    1290              :         }
    1291      5718231 :       while (n != this);
    1292      3181131 :       if (comdat_local_p ())
    1293              :         {
    1294        51750 :           ipa_ref *ref = NULL;
    1295              : 
    1296        53190 :           for (int i = 0; iterate_referring (i, ref); ++i)
    1297              :             {
    1298         1440 :               if (!in_same_comdat_group_p (ref->referring))
    1299              :                 {
    1300            0 :                   error ("comdat-local symbol referred to by %s outside its "
    1301              :                          "comdat",
    1302              :                          identifier_to_locale (ref->referring->name()));
    1303            0 :                   error_found = true;
    1304              :                 }
    1305              :             }
    1306              :         }
    1307              :     }
    1308     98798271 :   if (implicit_section && !get_section ())
    1309              :     {
    1310            0 :       error ("implicit_section flag is set but section isn%'t");
    1311            0 :       error_found = true;
    1312              :     }
    1313     98802500 :   if (get_section () && get_comdat_group ()
    1314      2837602 :       && !implicit_section
    1315     15370764 :       && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
    1316              :     {
    1317            0 :       error ("Both section and comdat group is set");
    1318            0 :       error_found = true;
    1319              :     }
    1320              :   /* TODO: Add string table for sections, so we do not keep holding duplicated
    1321              :      strings.  */
    1322      1449765 :   if (alias && definition
    1323      1508596 :       && get_section () != get_alias_target ()->get_section ()
    1324     83432000 :       && (!get_section()
    1325            0 :           || !get_alias_target ()->get_section ()
    1326            0 :           || strcmp (get_section(),
    1327              :                      get_alias_target ()->get_section ())))
    1328              :     {
    1329            0 :       error ("Alias and target%'s section differs");
    1330            0 :       get_alias_target ()->dump (stderr);
    1331            0 :       error_found = true;
    1332              :     }
    1333      1449765 :   if (alias && definition
    1334     84880515 :       && get_comdat_group () != get_alias_target ()->get_comdat_group ())
    1335              :     {
    1336            0 :       error ("Alias and target%'s comdat groups differs");
    1337            0 :       get_alias_target ()->dump (stderr);
    1338            0 :       error_found = true;
    1339              :     }
    1340     83432000 :   if (transparent_alias && definition && !weakref)
    1341              :     {
    1342           93 :       symtab_node *to = get_alias_target ();
    1343           93 :       const char *name1
    1344           93 :         = IDENTIFIER_POINTER (
    1345              :             ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (decl)));
    1346           93 :       const char *name2
    1347           93 :         = IDENTIFIER_POINTER (
    1348              :             ultimate_transparent_alias_target (DECL_ASSEMBLER_NAME (to->decl)));
    1349           93 :       if (!symbol_table::assembler_names_equal_p (name1, name2))
    1350              :         {
    1351            0 :           error ("Transparent alias and target%'s assembler names differs");
    1352            0 :           get_alias_target ()->dump (stderr);
    1353            0 :           error_found = true;
    1354              :         }
    1355              :     }
    1356         1442 :   if (transparent_alias && definition
    1357     83432192 :       && get_alias_target()->transparent_alias && get_alias_target()->analyzed)
    1358              :     {
    1359            0 :       error ("Chained transparent aliases");
    1360            0 :       get_alias_target ()->dump (stderr);
    1361            0 :       error_found = true;
    1362              :     }
    1363              : 
    1364     83432000 :   return error_found;
    1365              : }
    1366              : 
    1367              : /* Verify consistency of NODE.  */
    1368              : 
    1369              : DEBUG_FUNCTION void
    1370     83434350 : symtab_node::verify (void)
    1371              : {
    1372     83434350 :   if (seen_error ())
    1373              :     return;
    1374              : 
    1375     83432000 :   timevar_push (TV_CGRAPH_VERIFY);
    1376     83432000 :   if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
    1377     51577431 :     node->verify_node ();
    1378              :   else
    1379     31854569 :     if (verify_base ())
    1380              :       {
    1381            0 :         debug ();
    1382            0 :         internal_error ("symtab_node::verify failed");
    1383              :       }
    1384     83432000 :   timevar_pop (TV_CGRAPH_VERIFY);
    1385              : }
    1386              : 
    1387              : /* Return true and set *DATA to true if NODE is an ifunc resolver.  */
    1388              : 
    1389              : static bool
    1390      5497971 : check_ifunc_resolver (cgraph_node *node, void *data)
    1391              : {
    1392      5497971 :   if (node->ifunc_resolver)
    1393              :     {
    1394          428 :       bool *is_ifunc_resolver = (bool *) data;
    1395          428 :       *is_ifunc_resolver = true;
    1396          428 :       return true;
    1397              :     }
    1398              :   return false;
    1399              : }
    1400              : 
    1401              : static bitmap ifunc_ref_map;
    1402              : 
    1403              : /* Return true if any caller of NODE is an ifunc resolver.  */
    1404              : 
    1405              : static bool
    1406      5151967 : is_caller_ifunc_resolver (cgraph_node *node)
    1407              : {
    1408      5151967 :   bool is_ifunc_resolver = false;
    1409              : 
    1410     15215406 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    1411              :     {
    1412              :       /* Return true if caller is known to be an IFUNC resolver.  */
    1413     10063753 :       if (e->caller->called_by_ifunc_resolver)
    1414              :         return true;
    1415              : 
    1416              :       /* Check for recursive call.  */
    1417     10063586 :       if (e->caller == node)
    1418        11345 :         continue;
    1419              : 
    1420              :       /* Skip if it has been visited.  */
    1421     10052241 :       unsigned int uid = e->caller->get_uid ();
    1422     10052241 :       if (!bitmap_set_bit (ifunc_ref_map, uid))
    1423      8146652 :         continue;
    1424              : 
    1425      1905589 :       if (is_caller_ifunc_resolver (e->caller))
    1426              :         {
    1427              :           /* Return true if caller is an IFUNC resolver.  */
    1428           22 :           e->caller->called_by_ifunc_resolver = true;
    1429           22 :           return true;
    1430              :         }
    1431              : 
    1432              :       /* Check if caller's alias is an IFUNC resolver.  */
    1433      1905567 :       e->caller->call_for_symbol_and_aliases (check_ifunc_resolver,
    1434              :                                               &is_ifunc_resolver,
    1435              :                                               true);
    1436      1905567 :       if (is_ifunc_resolver)
    1437              :         {
    1438              :           /* Return true if caller's alias is an IFUNC resolver.  */
    1439          125 :           e->caller->called_by_ifunc_resolver = true;
    1440          125 :           return true;
    1441              :         }
    1442              :     }
    1443              : 
    1444              :   return false;
    1445              : }
    1446              : 
    1447              : /* Check symbol table for callees of IFUNC resolvers.  */
    1448              : 
    1449              : void
    1450       244693 : symtab_node::check_ifunc_callee_symtab_nodes (void)
    1451              : {
    1452       244693 :   symtab_node *node;
    1453              : 
    1454       244693 :   bitmap_obstack_initialize (NULL);
    1455       244693 :   ifunc_ref_map = BITMAP_ALLOC (NULL);
    1456              : 
    1457      8720247 :   FOR_EACH_SYMBOL (node)
    1458              :     {
    1459      8475554 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    1460      8475554 :       if (!cnode)
    1461      5228873 :         continue;
    1462              : 
    1463      5152270 :       unsigned int uid = cnode->get_uid ();
    1464      5152270 :       if (bitmap_bit_p (ifunc_ref_map, uid))
    1465      1905589 :         continue;
    1466      3246681 :       bitmap_set_bit (ifunc_ref_map, uid);
    1467              : 
    1468      3246681 :       bool is_ifunc_resolver = false;
    1469      3246681 :       cnode->call_for_symbol_and_aliases (check_ifunc_resolver,
    1470              :                                           &is_ifunc_resolver, true);
    1471      3246681 :       if (is_ifunc_resolver || is_caller_ifunc_resolver (cnode))
    1472          595 :         cnode->called_by_ifunc_resolver = true;
    1473              :     }
    1474              : 
    1475       244693 :   BITMAP_FREE (ifunc_ref_map);
    1476       244693 :   bitmap_obstack_release (NULL);
    1477       244693 : }
    1478              : 
    1479              : /* Verify symbol table for internal consistency.  */
    1480              : 
    1481              : DEBUG_FUNCTION void
    1482      2186148 : symtab_node::verify_symtab_nodes (void)
    1483              : {
    1484      2186148 :   symtab_node *node;
    1485      2186148 :   hash_map<tree, symtab_node *> comdat_head_map (251);
    1486      2186148 :   asm_node *anode;
    1487              : 
    1488      2186148 :   for (anode = symtab->first_asm_symbol ();
    1489      2303737 :        anode;
    1490       117589 :        anode = safe_as_a<asm_node*>(anode->next))
    1491       117589 :     if (anode->order < 0 || anode->order >= symtab->order)
    1492              :        {
    1493            0 :           error ("invalid order in asm node %i", anode->order);
    1494            0 :           internal_error ("symtab_node::verify failed");
    1495              :        }
    1496              : 
    1497     75142806 :   FOR_EACH_SYMBOL (node)
    1498              :     {
    1499     72956658 :       node->verify ();
    1500     72956658 :       if (node->get_comdat_group ())
    1501              :         {
    1502     10557952 :           symtab_node **entry, *s;
    1503     10557952 :           bool existed;
    1504              : 
    1505     10557952 :           entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
    1506              :                                                   &existed);
    1507     10557952 :           if (!existed)
    1508      9256263 :             *entry = node;
    1509      1301689 :           else if (!DECL_EXTERNAL (node->decl))
    1510              :             {
    1511      1301544 :               for (s = (*entry)->same_comdat_group;
    1512      2441215 :                    s != NULL && s != node && s != *entry;
    1513      1139671 :                    s = s->same_comdat_group)
    1514              :                 ;
    1515      1301544 :               if (!s || s == *entry)
    1516              :                 {
    1517            0 :                   error ("Two symbols with same comdat_group are not linked by "
    1518              :                          "the same_comdat_group list.");
    1519            0 :                   (*entry)->debug ();
    1520            0 :                   node->debug ();
    1521            0 :                   internal_error ("symtab_node::verify failed");
    1522              :                 }
    1523              :             }
    1524              :         }
    1525              :     }
    1526      2186148 : }
    1527              : 
    1528              : #if __GNUC__ >= 10
    1529              : #  pragma GCC diagnostic pop
    1530              : #endif
    1531              : 
    1532              : /* Make DECL local.  FIXME: We shouldn't need to mess with rtl this early,
    1533              :    but other code such as notice_global_symbol generates rtl.  */
    1534              : 
    1535              : void
    1536      3658590 : symtab_node::make_decl_local (void)
    1537              : {
    1538      3658590 :   rtx rtl, symbol;
    1539              : 
    1540      3658590 :   if (weakref)
    1541              :     {
    1542            0 :       weakref = false;
    1543            0 :       IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl)) = 0;
    1544            0 :       TREE_CHAIN (DECL_ASSEMBLER_NAME (decl)) = NULL_TREE;
    1545            0 :       symtab->change_decl_assembler_name
    1546            0 :          (decl, DECL_ASSEMBLER_NAME (get_alias_target ()->decl));
    1547            0 :       DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
    1548            0 :                                                  DECL_ATTRIBUTES (decl));
    1549              :     }
    1550              :   /* Avoid clearing comdat_groups on comdat-local decls.  */
    1551      3658590 :   else if (TREE_PUBLIC (decl) == 0)
    1552      3658576 :     return;
    1553              : 
    1554              :   /* Localizing a symbol also make all its transparent aliases local.  */
    1555              :   ipa_ref *ref;
    1556       102405 :   for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
    1557              :     {
    1558         1789 :       struct symtab_node *alias = ref->referring;
    1559         1789 :       if (alias->transparent_alias)
    1560            5 :         alias->make_decl_local ();
    1561              :     }
    1562              : 
    1563       100616 :   if (VAR_P (decl))
    1564              :     {
    1565        12547 :       DECL_COMMON (decl) = 0;
    1566              :       /* ADDRESSABLE flag is not defined for public symbols.  */
    1567        12547 :       TREE_ADDRESSABLE (decl) = 1;
    1568        12547 :       TREE_STATIC (decl) = 1;
    1569              :     }
    1570              :   else
    1571        88069 :     gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    1572              : 
    1573       100616 :   DECL_COMDAT (decl) = 0;
    1574       100616 :   DECL_WEAK (decl) = 0;
    1575       100616 :   DECL_EXTERNAL (decl) = 0;
    1576       100616 :   DECL_VISIBILITY_SPECIFIED (decl) = 0;
    1577       100616 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    1578       100616 :   TREE_PUBLIC (decl) = 0;
    1579       100616 :   DECL_DLLIMPORT_P (decl) = 0;
    1580       100616 :   if (!DECL_RTL_SET_P (decl))
    1581              :     return;
    1582              : 
    1583              :   /* Update rtl flags.  */
    1584           14 :   make_decl_rtl (decl);
    1585              : 
    1586           14 :   rtl = DECL_RTL (decl);
    1587           14 :   if (!MEM_P (rtl))
    1588              :     return;
    1589              : 
    1590           14 :   symbol = XEXP (rtl, 0);
    1591           14 :   if (GET_CODE (symbol) != SYMBOL_REF)
    1592              :     return;
    1593              : 
    1594           14 :   SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
    1595              : }
    1596              : 
    1597              : /* Copy visibility from N.
    1598              :    This is useful when THIS becomes a transparent alias of N.  */
    1599              : 
    1600              : void
    1601            0 : symtab_node::copy_visibility_from (symtab_node *n)
    1602              : {
    1603            0 :   gcc_checking_assert (n->weakref == weakref);
    1604              : 
    1605              :   ipa_ref *ref;
    1606            0 :   for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
    1607              :     {
    1608            0 :       struct symtab_node *alias = ref->referring;
    1609            0 :       if (alias->transparent_alias)
    1610            0 :         alias->copy_visibility_from (n);
    1611              :     }
    1612              : 
    1613            0 :   if (VAR_P (decl))
    1614              :     {
    1615            0 :       DECL_COMMON (decl) = DECL_COMMON (n->decl);
    1616              :       /* ADDRESSABLE flag is not defined for public symbols.  */
    1617            0 :       if (TREE_PUBLIC (decl) && !TREE_PUBLIC (n->decl))
    1618            0 :         TREE_ADDRESSABLE (decl) = 1;
    1619            0 :       TREE_STATIC (decl) = TREE_STATIC (n->decl);
    1620              :     }
    1621            0 :   else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    1622              : 
    1623            0 :   DECL_COMDAT (decl) = DECL_COMDAT (n->decl);
    1624            0 :   DECL_WEAK (decl) = DECL_WEAK (n->decl);
    1625            0 :   DECL_EXTERNAL (decl) = DECL_EXTERNAL (n->decl);
    1626            0 :   DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (n->decl);
    1627            0 :   DECL_VISIBILITY (decl) = DECL_VISIBILITY (n->decl);
    1628            0 :   TREE_PUBLIC (decl) = TREE_PUBLIC (n->decl);
    1629            0 :   DECL_DLLIMPORT_P (decl) = DECL_DLLIMPORT_P (n->decl);
    1630            0 :   resolution = n->resolution;
    1631            0 :   set_comdat_group (n->get_comdat_group ());
    1632            0 :   set_section (*n);
    1633            0 :   externally_visible = n->externally_visible;
    1634            0 :   if (!DECL_RTL_SET_P (decl))
    1635            0 :     return;
    1636              : 
    1637              :   /* Update rtl flags.  */
    1638            0 :   make_decl_rtl (decl);
    1639              : 
    1640            0 :   rtx rtl = DECL_RTL (decl);
    1641            0 :   if (!MEM_P (rtl))
    1642              :     return;
    1643              : 
    1644            0 :   rtx symbol = XEXP (rtl, 0);
    1645            0 :   if (GET_CODE (symbol) != SYMBOL_REF)
    1646              :     return;
    1647              : 
    1648            0 :   SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
    1649              : }
    1650              : 
    1651              : /* Walk the alias chain to return the symbol NODE is alias of.
    1652              :    If NODE is not an alias, return NODE.
    1653              :    Assumes NODE is known to be alias.  */
    1654              : 
    1655              : symtab_node *
    1656     35934180 : symtab_node::ultimate_alias_target_1 (enum availability *availability,
    1657              :                                       symtab_node *ref)
    1658              : {
    1659     35934180 :   bool transparent_p = false;
    1660              : 
    1661              :   /* To determine visibility of the target, we follow ELF semantic of aliases.
    1662              :      Here alias is an alternative assembler name of a given definition. Its
    1663              :      availability prevails the availability of its target (i.e. static alias of
    1664              :      weak definition is available.
    1665              : 
    1666              :      Transparent alias is just alternative name of a given symbol used within
    1667              :      one compilation unit and is translated prior hitting the object file.  It
    1668              :      inherits the visibility of its target.
    1669              :      Weakref is a different animal (and noweak definition is weak).
    1670              : 
    1671              :      If we ever get into supporting targets with different semantics, a target
    1672              :      hook will be needed here.  */
    1673              : 
    1674     35934180 :   if (availability)
    1675              :     {
    1676     11581308 :       transparent_p = transparent_alias;
    1677     11581308 :       if (!transparent_p)
    1678     11575446 :         *availability = get_availability (ref);
    1679              :       else
    1680         5862 :         *availability = AVAIL_NOT_AVAILABLE;
    1681              :     }
    1682              : 
    1683              :   symtab_node *node = this;
    1684     71859690 :   while (node)
    1685              :     {
    1686     71859690 :       if (node->alias && node->analyzed)
    1687     35925510 :         node = node->get_alias_target ();
    1688              :       else
    1689              :         {
    1690     35934180 :           if (!availability || (!transparent_p && node->analyzed))
    1691              :             ;
    1692        37344 :           else if (node->analyzed && !node->transparent_alias)
    1693          308 :             *availability = node->get_availability (ref);
    1694              :           else
    1695        37036 :             *availability = AVAIL_NOT_AVAILABLE;
    1696     35934180 :           return node;
    1697              :         }
    1698     35925510 :       if (node && availability && transparent_p
    1699          448 :           && node->transparent_alias)
    1700              :         {
    1701           22 :           *availability = node->get_availability (ref);
    1702           22 :           transparent_p = false;
    1703              :         }
    1704              :     }
    1705            0 :   if (availability)
    1706            0 :     *availability = AVAIL_NOT_AVAILABLE;
    1707              :   return NULL;
    1708              : }
    1709              : 
    1710              : /* C++ FE sometimes change linkage flags after producing same body aliases.
    1711              : 
    1712              :    FIXME: C++ produce implicit aliases for virtual functions and vtables that
    1713              :    are obviously equivalent.  The way it is doing so is however somewhat
    1714              :    kludgy and interferes with the visibility code. As a result we need to
    1715              :    copy the visibility from the target to get things right.  */
    1716              : 
    1717              : void
    1718      8927176 : symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
    1719              : {
    1720      8927176 :   if (is_a <cgraph_node *> (this))
    1721              :     {
    1722     26781348 :       DECL_DECLARED_INLINE_P (decl)
    1723      8927116 :          = DECL_DECLARED_INLINE_P (target->decl);
    1724     26781348 :       DECL_DISREGARD_INLINE_LIMITS (decl)
    1725      8927116 :          = DECL_DISREGARD_INLINE_LIMITS (target->decl);
    1726              :     }
    1727              :   /* FIXME: It is not really clear why those flags should not be copied for
    1728              :      functions, too.  */
    1729              :   else
    1730              :     {
    1731           60 :       DECL_WEAK (decl) = DECL_WEAK (target->decl);
    1732           60 :       DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
    1733           60 :       DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
    1734              :     }
    1735      8927176 :   if (TREE_PUBLIC (decl))
    1736              :     {
    1737      8906131 :       tree group;
    1738              : 
    1739      8906131 :       DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
    1740      8906131 :       DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
    1741      8906131 :       group = target->get_comdat_group ();
    1742      8906131 :       set_comdat_group (group);
    1743      8906131 :       if (group && !same_comdat_group)
    1744            0 :         add_to_same_comdat_group (target);
    1745              :     }
    1746      8927176 :   externally_visible = target->externally_visible;
    1747      8927176 : }
    1748              : 
    1749              : /* Set section, do not recurse into aliases.
    1750              :    When one wants to change section of a symbol and its aliases,
    1751              :    use set_section.  */
    1752              : 
    1753              : void
    1754    150209783 : symtab_node::set_section_for_node (const char *section)
    1755              : {
    1756    150209783 :   const char *current = get_section ();
    1757              : 
    1758    150209783 :   if (current == section
    1759      1866055 :       || (current && section
    1760            0 :           && !strcmp (current, section)))
    1761              :     return;
    1762              : 
    1763      1866055 :   release_section_hash_entry (x_section);
    1764      1866055 :   if (!section)
    1765              :     {
    1766        27107 :       x_section = NULL;
    1767        27107 :       implicit_section = false;
    1768        27107 :       return;
    1769              :     }
    1770      1838948 :   if (!symtab->section_hash)
    1771        35719 :     symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
    1772      1838948 :   section_hash_entry **slot = symtab->section_hash->find_slot_with_hash
    1773      1838948 :     (section, htab_hash_string (section), INSERT);
    1774      1838948 :   if (*slot)
    1775        40553 :     x_section = retain_section_hash_entry (*slot);
    1776              :   else
    1777              :     {
    1778      1798395 :       int len = strlen (section);
    1779      1798395 :       *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
    1780      1798395 :       x_section->ref_count = 1;
    1781      1798395 :       x_section->name = ggc_vec_alloc<char> (len + 1);
    1782      1798395 :       memcpy (x_section->name, section, len + 1);
    1783              :     }
    1784              : }
    1785              : 
    1786              : /* Set the section of node THIS to be the same as the section
    1787              :    of node OTHER.  Keep reference counts of the sections
    1788              :    up-to-date as needed.  */
    1789              : 
    1790              : void
    1791     26273308 : symtab_node::set_section_for_node (const symtab_node &other)
    1792              : {
    1793     26273308 :   if (x_section == other.x_section)
    1794              :     return;
    1795         7398 :   if (get_section () && other.get_section ())
    1796          580 :     gcc_checking_assert (strcmp (get_section (), other.get_section ()) != 0);
    1797         6818 :   release_section_hash_entry (x_section);
    1798         6818 :   if (other.x_section)
    1799         6810 :     x_section = retain_section_hash_entry (other.x_section);
    1800              :   else
    1801              :     {
    1802            8 :       x_section = NULL;
    1803            8 :       implicit_section = false;
    1804              :     }
    1805              : }
    1806              : 
    1807              : /* Workers for set_section.  */
    1808              : 
    1809              : bool
    1810      1845393 : symtab_node::set_section_from_string (symtab_node *n, void *s)
    1811              : {
    1812      1845393 :   n->set_section_for_node ((char *)s);
    1813      1845393 :   return false;
    1814              : }
    1815              : 
    1816              : /* Set the section of node N to be the same as the section
    1817              :    of node O.  */
    1818              : 
    1819              : bool
    1820     26273308 : symtab_node::set_section_from_node (symtab_node *n, void *o)
    1821              : {
    1822     26273308 :   const symtab_node &other = *static_cast<const symtab_node *> (o);
    1823     26273308 :   n->set_section_for_node (other);
    1824     26273308 :   return false;
    1825              : }
    1826              : 
    1827              : /* Set section of symbol and its aliases.  */
    1828              : 
    1829              : void
    1830      1803396 : symtab_node::set_section (const char *section)
    1831              : {
    1832      1803396 :   gcc_assert (!this->alias || !this->analyzed);
    1833      1803396 :   call_for_symbol_and_aliases
    1834      1803396 :     (symtab_node::set_section_from_string, const_cast<char *>(section), true);
    1835      1803396 : }
    1836              : 
    1837              : void
    1838     26273059 : symtab_node::set_section (const symtab_node &other)
    1839              : {
    1840     26273059 :   call_for_symbol_and_aliases
    1841     26273059 :     (symtab_node::set_section_from_node, const_cast<symtab_node *>(&other), true);
    1842     26273059 : }
    1843              : 
    1844              : /* Return the initialization priority.  */
    1845              : 
    1846              : priority_type
    1847        46505 : symtab_node::get_init_priority ()
    1848              : {
    1849        46505 :   if (!this->in_init_priority_hash)
    1850              :     return DEFAULT_INIT_PRIORITY;
    1851              : 
    1852         3799 :   symbol_priority_map *h = symtab->init_priority_hash->get (this);
    1853         3799 :   return h ? h->init : DEFAULT_INIT_PRIORITY;
    1854              : }
    1855              : 
    1856              : /* Return the finalization priority.  */
    1857              : 
    1858              : priority_type
    1859         1909 : cgraph_node::get_fini_priority ()
    1860              : {
    1861         1909 :   if (!this->in_init_priority_hash)
    1862              :     return DEFAULT_INIT_PRIORITY;
    1863         1831 :   symbol_priority_map *h = symtab->init_priority_hash->get (this);
    1864         1831 :   return h ? h->fini : DEFAULT_INIT_PRIORITY;
    1865              : }
    1866              : 
    1867              : /* Return the initialization and finalization priority information for
    1868              :    DECL.  If there is no previous priority information, a freshly
    1869              :    allocated structure is returned.  */
    1870              : 
    1871              : symbol_priority_map *
    1872         5227 : symtab_node::priority_info (void)
    1873              : {
    1874         5227 :   if (!symtab->init_priority_hash)
    1875         3447 :     symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
    1876              : 
    1877         5227 :   bool existed;
    1878         5227 :   symbol_priority_map *h
    1879         5227 :     = &symtab->init_priority_hash->get_or_insert (this, &existed);
    1880         5227 :   if (!existed)
    1881              :     {
    1882         5205 :       h->init = DEFAULT_INIT_PRIORITY;
    1883         5205 :       h->fini = DEFAULT_INIT_PRIORITY;
    1884         5205 :       in_init_priority_hash = true;
    1885              :     }
    1886              : 
    1887         5227 :   return h;
    1888              : }
    1889              : 
    1890              : /* Set initialization priority to PRIORITY.  */
    1891              : 
    1892              : void
    1893        25322 : symtab_node::set_init_priority (priority_type priority)
    1894              : {
    1895        25322 :   symbol_priority_map *h;
    1896              : 
    1897        25322 :   if (is_a <cgraph_node *> (this))
    1898        25277 :     gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
    1899              : 
    1900        25322 :   if (priority == DEFAULT_INIT_PRIORITY
    1901        25322 :       && get_init_priority() == priority)
    1902              :     return;
    1903         3601 :   h = priority_info ();
    1904         3601 :   h->init = priority;
    1905              : }
    1906              : 
    1907              : /* Set finalization priority to PRIORITY.  */
    1908              : 
    1909              : void
    1910         1639 : cgraph_node::set_fini_priority (priority_type priority)
    1911              : {
    1912         1639 :   symbol_priority_map *h;
    1913              : 
    1914         1639 :   gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
    1915              : 
    1916         1639 :   if (priority == DEFAULT_INIT_PRIORITY
    1917         1639 :       && get_fini_priority() == priority)
    1918              :     return;
    1919         1626 :   h = priority_info ();
    1920         1626 :   h->fini = priority;
    1921              : }
    1922              : 
    1923              : /* Worker for symtab_resolve_alias.  */
    1924              : 
    1925              : bool
    1926         3140 : symtab_node::set_implicit_section (symtab_node *n,
    1927              :                                    void *data ATTRIBUTE_UNUSED)
    1928              : {
    1929         3140 :   n->implicit_section = true;
    1930         3140 :   return false;
    1931              : }
    1932              : 
    1933              : /* Add reference recording that symtab node is alias of TARGET.
    1934              :    The function can fail in the case of aliasing cycles; in this case
    1935              :    it returns false.  */
    1936              : 
    1937              : bool
    1938      8625976 : symtab_node::resolve_alias (symtab_node *target, bool transparent)
    1939              : {
    1940      8625976 :   symtab_node *n;
    1941              : 
    1942      8625976 :   gcc_assert (!analyzed && !ref_list.references.length ());
    1943              : 
    1944              :   /* Never let cycles to creep into the symbol table alias references;
    1945              :      those will make alias walkers to be infinite.  */
    1946      8630200 :   for (n = target; n && n->alias;
    1947         4438 :        n = n->analyzed ? n->get_alias_target () : NULL)
    1948         4440 :     if (n == this)
    1949              :        {
    1950            2 :          if (is_a <cgraph_node *> (this))
    1951            2 :            error ("function %q+D part of alias cycle", decl);
    1952            0 :          else if (is_a <varpool_node *> (this))
    1953            0 :            error ("variable %q+D part of alias cycle", decl);
    1954              :          else
    1955            0 :            gcc_unreachable ();
    1956            2 :          alias = false;
    1957            2 :          return false;
    1958              :        }
    1959              : 
    1960              :   /* "analyze" the node - i.e. mark the reference.  */
    1961      8625974 :   definition = true;
    1962      8625974 :   alias = true;
    1963      8625974 :   analyzed = true;
    1964      8625974 :   transparent |= transparent_alias;
    1965      8625974 :   transparent_alias = transparent;
    1966      8625974 :   if (transparent)
    1967           54 :     while (target->transparent_alias && target->analyzed)
    1968            0 :       target = target->get_alias_target ();
    1969      8625974 :   create_reference (target, IPA_REF_ALIAS, NULL);
    1970              : 
    1971              :   /* Add alias into the comdat group of its target unless it is already there.  */
    1972      8625974 :   if (same_comdat_group)
    1973      3998331 :     remove_from_same_comdat_group ();
    1974      8625974 :   set_comdat_group (NULL);
    1975      8625974 :   if (target->get_comdat_group ())
    1976      8437259 :     add_to_same_comdat_group (target);
    1977              : 
    1978      8625987 :   if ((get_section () != target->get_section ()
    1979      8625979 :        || target->get_comdat_group ()) && get_section () && !implicit_section)
    1980              :     {
    1981            2 :       error ("section of alias %q+D must match section of its target", decl);
    1982              :     }
    1983      8625974 :   set_section (*target);
    1984      8625974 :   if (target->implicit_section)
    1985         2954 :     call_for_symbol_and_aliases (set_implicit_section, NULL, true);
    1986              : 
    1987              :   /* Alias targets become redundant after alias is resolved into an reference.
    1988              :      We do not want to keep it around or we would have to mind updating them
    1989              :      when renaming symbols.  */
    1990      8625974 :   alias_target = NULL;
    1991              : 
    1992      8625974 :   if (!transparent && cpp_implicit_alias && symtab->state >= CONSTRUCTION)
    1993        17306 :     fixup_same_cpp_alias_visibility (target);
    1994              : 
    1995              :   /* If alias has address taken, so does the target.  */
    1996      8625974 :   if (address_taken)
    1997          973 :     target->ultimate_alias_target ()->address_taken = true;
    1998              : 
    1999              :   /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
    2000              :      If alias is transparent, also all transparent aliases of THIS are now
    2001              :      aliases of TARGET.
    2002              :      Also merge same comdat group lists.  */
    2003              :   ipa_ref *ref;
    2004      8626223 :   for (unsigned i = 0; iterate_direct_aliases (i, ref);)
    2005              :     {
    2006          249 :       struct symtab_node *alias_alias = ref->referring;
    2007          249 :       if (alias_alias->get_comdat_group ())
    2008              :         {
    2009          184 :           alias_alias->remove_from_same_comdat_group ();
    2010          184 :           alias_alias->set_comdat_group (NULL);
    2011          184 :           if (target->get_comdat_group ())
    2012          184 :             alias_alias->add_to_same_comdat_group (target);
    2013              :         }
    2014          249 :       if ((!alias_alias->transparent_alias
    2015          237 :            && !alias_alias->symver)
    2016           12 :           || transparent)
    2017              :         {
    2018          249 :           alias_alias->remove_all_references ();
    2019          249 :           alias_alias->create_reference (target, IPA_REF_ALIAS, NULL);
    2020              :         }
    2021            0 :       else i++;
    2022              :     }
    2023              :   return true;
    2024              : }
    2025              : 
    2026              : /* Worker searching noninterposable alias.  */
    2027              : 
    2028              : bool
    2029        61504 : symtab_node::noninterposable_alias (symtab_node *node, void *data)
    2030              : {
    2031        61504 :   if (!node->transparent_alias && decl_binds_to_current_def_p (node->decl))
    2032              :     {
    2033        59226 :       symtab_node *fn = node->ultimate_alias_target ();
    2034              : 
    2035              :       /* Ensure that the alias is well formed this may not be the case
    2036              :          of user defined aliases and currently it is not always the case
    2037              :          of C++ same body aliases (that is a bug).  */
    2038        59226 :       if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
    2039        59226 :           || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
    2040        59226 :           || (TREE_CODE (node->decl) == FUNCTION_DECL
    2041       118452 :               && flags_from_decl_or_type (node->decl)
    2042        59226 :                  != flags_from_decl_or_type (fn->decl))
    2043       118434 :           || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
    2044           20 :         return false;
    2045        59206 :       *(symtab_node **)data = node;
    2046        59206 :       return true;
    2047              :     }
    2048              :   return false;
    2049              : }
    2050              : 
    2051              : /* If node cannot be overwriten by static or dynamic linker to point to
    2052              :    different definition, return NODE. Otherwise look for alias with such
    2053              :    property and if none exists, introduce new one.  */
    2054              : 
    2055              : symtab_node *
    2056        60205 : symtab_node::noninterposable_alias (void)
    2057              : {
    2058        60205 :   tree new_decl;
    2059        60205 :   symtab_node *new_node = NULL;
    2060              : 
    2061              :   /* First try to look up existing alias or base object
    2062              :      (if that is already non-overwritable).  */
    2063        60205 :   symtab_node *node = ultimate_alias_target ();
    2064        60205 :   gcc_assert (!node->alias && !node->weakref);
    2065        60205 :   node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
    2066              :                                      (void *)&new_node, true);
    2067        60205 :   if (new_node)
    2068              :     return new_node;
    2069              : 
    2070              :   /* If aliases aren't supported by the assembler, fail.  */
    2071          999 :   if (!TARGET_SUPPORTS_ALIASES)
    2072              :     return NULL;
    2073          999 :   else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)))
    2074              :     return NULL;
    2075              : 
    2076              :   /* Otherwise create a new one.  */
    2077          998 :   new_decl = copy_node (node->decl);
    2078          998 :   DECL_DLLIMPORT_P (new_decl) = 0;
    2079          998 :   tree name = clone_function_name (node->decl, "localalias");
    2080          998 :   if (!flag_wpa)
    2081              :     {
    2082              :       unsigned long num = 0;
    2083              :       /* In the rare case we already have a localalias, but the above
    2084              :          node->call_for_symbol_and_aliases call didn't find any suitable,
    2085              :          iterate until we find one not used yet.  */
    2086          992 :       while (symtab_node::get_for_asmname (name))
    2087            0 :         name = clone_function_name (node->decl, "localalias", num++);
    2088              :     }
    2089          998 :   DECL_NAME (new_decl) = name;
    2090          998 :   if (TREE_CODE (new_decl) == FUNCTION_DECL)
    2091          996 :     DECL_STRUCT_FUNCTION (new_decl) = NULL;
    2092          998 :   DECL_INITIAL (new_decl) = NULL;
    2093          998 :   SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
    2094          998 :   SET_DECL_RTL (new_decl, NULL);
    2095              : 
    2096              :   /* Update the properties.  */
    2097          998 :   DECL_EXTERNAL (new_decl) = 0;
    2098          998 :   TREE_PUBLIC (new_decl) = 0;
    2099          998 :   DECL_COMDAT (new_decl) = 0;
    2100          998 :   DECL_WEAK (new_decl) = 0;
    2101              : 
    2102              :   /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag.  */
    2103          998 :   DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
    2104          998 :   if (TREE_CODE (new_decl) == FUNCTION_DECL)
    2105              :     {
    2106          996 :       DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
    2107          996 :       DECL_STATIC_DESTRUCTOR (new_decl) = 0;
    2108          996 :       new_node = cgraph_node::create_alias (new_decl, node->decl);
    2109              : 
    2110         1992 :       cgraph_node *new_cnode = dyn_cast <cgraph_node *> (new_node),
    2111          996 :                    *cnode = dyn_cast <cgraph_node *> (node);
    2112              : 
    2113          996 :       new_cnode->unit_id = cnode->unit_id;
    2114          996 :       new_cnode->merged_comdat = cnode->merged_comdat;
    2115          996 :       new_cnode->merged_extern_inline = cnode->merged_extern_inline;
    2116              :     }
    2117              :   else
    2118              :     {
    2119            2 :       TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
    2120            2 :       DECL_INITIAL (new_decl) = error_mark_node;
    2121            2 :       new_node = varpool_node::create_alias (new_decl, node->decl);
    2122              :     }
    2123          998 :   new_node->resolve_alias (node);
    2124          998 :   gcc_assert (decl_binds_to_current_def_p (new_decl)
    2125              :               && targetm.binds_local_p (new_decl));
    2126          998 :   return new_node;
    2127              : }
    2128              : 
    2129              : /* Return true if symtab node and TARGET represents
    2130              :    semantically equivalent symbols.  */
    2131              : 
    2132              : bool
    2133       348578 : symtab_node::semantically_equivalent_p (symtab_node *target)
    2134              : {
    2135       348578 :   enum availability avail;
    2136       348578 :   symtab_node *ba;
    2137       348578 :   symtab_node *bb;
    2138              : 
    2139              :   /* Equivalent functions are equivalent.  */
    2140       348578 :   if (decl == target->decl)
    2141              :     return true;
    2142              : 
    2143              :   /* If symbol is not overwritable by different implementation,
    2144              :      walk to the base object it defines.  */
    2145       263720 :   ba = ultimate_alias_target (&avail);
    2146       263720 :   if (avail >= AVAIL_AVAILABLE)
    2147              :     {
    2148        49346 :       if (target == ba)
    2149              :         return true;
    2150              :     }
    2151              :   else
    2152              :     ba = this;
    2153       263704 :   bb = target->ultimate_alias_target (&avail);
    2154       263704 :   if (avail >= AVAIL_AVAILABLE)
    2155              :     {
    2156        48789 :       if (this == bb)
    2157              :         return true;
    2158              :     }
    2159              :   else
    2160              :     bb = target;
    2161       263645 :   return bb == ba;
    2162              : }
    2163              : 
    2164              : /* Classify symbol symtab node for partitioning.  */
    2165              : 
    2166              : enum symbol_partitioning_class
    2167      2298137 : symtab_node::get_partitioning_class (void)
    2168              : {
    2169              :   /* Inline clones are always duplicated.
    2170              :      This include external declarations.   */
    2171      2298137 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
    2172              : 
    2173      2298137 :   if (DECL_ABSTRACT_P (decl))
    2174              :     return SYMBOL_EXTERNAL;
    2175              : 
    2176      2298137 :   if (cnode && cnode->inlined_to)
    2177              :     return SYMBOL_DUPLICATE;
    2178              : 
    2179              :   /* Transparent aliases are always duplicated.  */
    2180      2234354 :   if (transparent_alias)
    2181           66 :     return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL;
    2182              : 
    2183              :   /* External declarations are external.  */
    2184      2234288 :   if (DECL_EXTERNAL (decl))
    2185              :     return SYMBOL_EXTERNAL;
    2186              : 
    2187              :   /* Even static aliases of external functions as external.  Those can happen
    2188              :      when COMDAT got resolved to non-IL implementation.  */
    2189      2074669 :   if (alias && DECL_EXTERNAL (ultimate_alias_target ()->decl))
    2190              :     return SYMBOL_EXTERNAL;
    2191              : 
    2192      2074669 :   if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
    2193              :     {
    2194       935713 :       if (alias && definition && !ultimate_alias_target ()->definition)
    2195              :         return SYMBOL_EXTERNAL;
    2196              :       /* Constant pool references use local symbol names that cannot
    2197              :          be promoted global.  We should never put into a constant pool
    2198              :          objects that cannot be duplicated across partitions.  */
    2199       935713 :       if (DECL_IN_CONSTANT_POOL (decl))
    2200              :         return SYMBOL_DUPLICATE;
    2201       935523 :       if (DECL_HARD_REGISTER (decl))
    2202              :         return SYMBOL_DUPLICATE;
    2203       935427 :       gcc_checking_assert (vnode->definition);
    2204              :     }
    2205              :   /* Functions that are cloned may stay in callgraph even if they are unused.
    2206              :      Handle them as external; compute_ltrans_boundary take care to make
    2207              :      proper things to happen (i.e. to make them appear in the boundary but
    2208              :      with body streamed, so clone can me materialized).  */
    2209      1138956 :   else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
    2210              :     return SYMBOL_EXTERNAL;
    2211              : 
    2212              :   /* Linker discardable symbols are duplicated to every use unless they are
    2213              :      keyed.  */
    2214      2084623 :   if (DECL_ONE_ONLY (decl)
    2215        13960 :       && !force_output
    2216        13916 :       && !forced_by_abi
    2217      2082953 :       && !used_from_object_file_p ())
    2218              :     return SYMBOL_DUPLICATE;
    2219              : 
    2220              :   return SYMBOL_PARTITION;
    2221              : }
    2222              : 
    2223              : /* Return true when symbol is known to be non-zero, assume that
    2224              :    flag_delete_null_pointer_checks is equal to delete_null_pointer_checks.  */
    2225              : 
    2226              : bool
    2227     14401733 : symtab_node::nonzero_address (bool delete_null_pointer_checks)
    2228              : {
    2229              :   /* Weakrefs may be NULL when their target is not defined.  */
    2230     14401733 :   if (alias && weakref)
    2231              :     {
    2232         2746 :       if (analyzed)
    2233              :         {
    2234          188 :           symtab_node *target = ultimate_alias_target ();
    2235              : 
    2236          188 :           if (target->alias && target->weakref)
    2237              :             return false;
    2238              :           /* We cannot recurse to target::nonzero.  It is possible that the
    2239              :              target is used only via the alias.
    2240              :              We may walk references and look for strong use, but we do not know
    2241              :              if this strong use will survive to final binary, so be
    2242              :              conservative here.
    2243              :              ??? Maybe we could do the lookup during late optimization that
    2244              :              could be useful to eliminate the NULL pointer checks in LTO
    2245              :              programs.  */
    2246            0 :           if (target->definition && !DECL_EXTERNAL (target->decl))
    2247              :               return true;
    2248            0 :           if (target->resolution != LDPR_UNKNOWN
    2249              :               && target->resolution != LDPR_UNDEF
    2250            0 :               && !target->can_be_discarded_p ()
    2251            0 :               && delete_null_pointer_checks)
    2252              :             return true;
    2253            0 :           return false;
    2254              :         }
    2255              :       else
    2256              :         return false;
    2257              :     }
    2258              : 
    2259              :   /* With !flag_delete_null_pointer_checks we assume that symbols may
    2260              :      bind to NULL. This is on by default on embedded targets only.
    2261              : 
    2262              :      Otherwise all non-WEAK symbols must be defined and thus non-NULL or
    2263              :      linking fails.  Important case of WEAK we want to do well are comdats,
    2264              :      which also must be defined somewhere.
    2265              : 
    2266              :      When parsing, beware the cases when WEAK attribute is added later.  */
    2267     18153054 :   if ((!DECL_WEAK (decl) || DECL_COMDAT (decl))
    2268     15399893 :       && delete_null_pointer_checks)
    2269              :     {
    2270     11635216 :       refuse_visibility_changes = true;
    2271     11635216 :       return true;
    2272              :     }
    2273              : 
    2274              :   /* If target is defined and not extern, we know it will be
    2275              :      output and thus it will bind to non-NULL.
    2276              :      Play safe for flag_delete_null_pointer_checks where weak definition may
    2277              :      be re-defined by NULL.  */
    2278      2738688 :   if (definition && !DECL_EXTERNAL (decl)
    2279      5502458 :       && (delete_null_pointer_checks || !DECL_WEAK (decl)))
    2280              :     {
    2281      2737970 :       if (!DECL_WEAK (decl))
    2282         9110 :         refuse_visibility_changes = true;
    2283      2737970 :       return true;
    2284              :     }
    2285              : 
    2286              :   /* As the last resort, check the resolution info.  */
    2287        25801 :   if (resolution != LDPR_UNKNOWN
    2288              :       && resolution != LDPR_UNDEF
    2289            0 :       && !can_be_discarded_p ()
    2290        25801 :       && delete_null_pointer_checks)
    2291              :     return true;
    2292              :   return false;
    2293              : }
    2294              : 
    2295              : /* Return true when symbol is known to be non-zero.  */
    2296              : 
    2297              : bool
    2298     14400872 : symtab_node::nonzero_address ()
    2299              : {
    2300     14400872 :   return nonzero_address (flag_delete_null_pointer_checks);
    2301              : }
    2302              : 
    2303              : /* Return 0 if symbol is known to have different address than S2,
    2304              :    Return 1 if symbol is known to have same address as S2,
    2305              :    return -1 otherwise.
    2306              : 
    2307              :    If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
    2308              :    and S2 is going to be accessed.  This eliminates the situations when
    2309              :    either THIS or S2 is NULL and is useful for comparing bases when deciding
    2310              :    about memory aliasing.  */
    2311              : int
    2312     85741544 : symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed)
    2313              : {
    2314     85741544 :   enum availability avail1, avail2;
    2315              : 
    2316              :   /* A Shortcut: equivalent symbols are always equivalent.  */
    2317     85741544 :   if (this == s2)
    2318              :     return 1;
    2319              : 
    2320              :   /* Unwind transparent aliases first; those are always equal to their
    2321              :      target.  */
    2322     85213847 :   if (this->transparent_alias && this->analyzed)
    2323            0 :     return this->get_alias_target ()->equal_address_to (s2);
    2324     85213847 :   while (s2->transparent_alias && s2->analyzed)
    2325            0 :     s2 = s2->get_alias_target();
    2326              : 
    2327     85213847 :   if (this == s2)
    2328              :     return 1;
    2329              : 
    2330              :   /* For non-interposable aliases, lookup and compare their actual definitions.
    2331              :      Also check if the symbol needs to bind to given definition.  */
    2332     85213847 :   symtab_node *rs1 = ultimate_alias_target (&avail1);
    2333     85213847 :   symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
    2334     85213847 :   bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
    2335     85213847 :   bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
    2336     85213847 :   bool really_binds_local1 = binds_local1;
    2337     85213847 :   bool really_binds_local2 = binds_local2;
    2338              : 
    2339              :   /* Addresses of vtables and virtual functions cannot be used by user
    2340              :      code and are used only within speculation.  In this case we may make
    2341              :      symbol equivalent to its alias even if interposition may break this
    2342              :      rule.  Doing so will allow us to turn speculative inlining into
    2343              :      non-speculative more aggressively.  */
    2344     85213847 :   if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
    2345              :     binds_local1 = true;
    2346     85213847 :   if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
    2347     85213847 :     binds_local2 = true;
    2348              : 
    2349              :   /* If both definitions are available we know that even if they are bound
    2350              :      to other unit they must be defined same way and therefore we can use
    2351              :      equivalence test.  */
    2352     85213847 :   if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
    2353              :     binds_local1 = binds_local2 = true;
    2354              : 
    2355     85213847 :   if (binds_local1 && binds_local2 && rs1 == rs2)
    2356              :     {
    2357              :       /* We made use of the fact that alias is not weak.  */
    2358          358 :       if (rs1 != this)
    2359          232 :         refuse_visibility_changes = true;
    2360          358 :       if (rs2 != s2)
    2361          126 :         s2->refuse_visibility_changes = true;
    2362          358 :       return 1;
    2363              :     }
    2364              : 
    2365              :   /* If both symbols may resolve to NULL, we cannot really prove them
    2366              :      different.  */
    2367     85213489 :   if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ())
    2368              :     return -1;
    2369              : 
    2370              :   /* Except for NULL, functions and variables never overlap.  */
    2371     85213430 :   if (TREE_CODE (decl) != TREE_CODE (s2->decl))
    2372              :     return 0;
    2373              : 
    2374              :   /* If one of the symbols is unresolved alias, punt.  */
    2375     85042269 :   if (rs1->alias || rs2->alias)
    2376              :     return -1;
    2377              : 
    2378              :   /* If we have a non-interposable definition of at least one of the symbols
    2379              :      and the other symbol is different, we know other unit cannot interpose
    2380              :      it to the first symbol; all aliases of the definition needs to be
    2381              :      present in the current unit.  */
    2382     85042261 :   if (((really_binds_local1 || really_binds_local2)
    2383              :       /* If we have both definitions and they are different, we know they
    2384              :          will be different even in units they binds to.  */
    2385     11543687 :        || (binds_local1 && binds_local2))
    2386     73582972 :       && rs1 != rs2)
    2387              :     {
    2388              :       /* We make use of the fact that one symbol is not alias of the other
    2389              :          and that the definition is non-interposable.  */
    2390     73582879 :       refuse_visibility_changes = true;
    2391     73582879 :       s2->refuse_visibility_changes = true;
    2392     73582879 :       rs1->refuse_visibility_changes = true;
    2393     73582879 :       rs2->refuse_visibility_changes = true;
    2394     73582879 :       return 0;
    2395              :     }
    2396              : 
    2397     11459382 :   if (rs1 == rs2)
    2398              :     return -1;
    2399              : 
    2400              :   /* If the FE tells us at least one of the decls will never be aliased nor
    2401              :      overlapping with other vars in some other way, return 0.  */
    2402     11459289 :   if (VAR_P (decl)
    2403     11459289 :       && (lookup_attribute ("non overlapping", DECL_ATTRIBUTES (decl))
    2404     11455333 :           || lookup_attribute ("non overlapping", DECL_ATTRIBUTES (s2->decl))))
    2405         3929 :     return 0;
    2406              : 
    2407              :   /* TODO: Alias oracle basically assume that addresses of global variables
    2408              :      are different unless they are declared as alias of one to another while
    2409              :      the code folding comparisons doesn't.
    2410              :      We probably should be consistent and use this fact here, too, but for
    2411              :      the moment return false only when we are called from the alias oracle.
    2412              :      Return 0 in C constant initializers and C++ manifestly constant
    2413              :      expressions, the likelyhood that different vars will be aliases is
    2414              :      small and returning -1 lets us reject too many initializers.  */
    2415     11455360 :   if (memory_accessed || folding_initializer)
    2416              :     return 0;
    2417              : 
    2418              :   return -1;
    2419              : }
    2420              : 
    2421              : /* Worker for call_for_symbol_and_aliases.  */
    2422              : 
    2423              : bool
    2424       145053 : symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
    2425              :                                                               void *),
    2426              :                                             void *data,
    2427              :                                             bool include_overwritable)
    2428              : {
    2429       145053 :   ipa_ref *ref;
    2430       314954 :   FOR_EACH_ALIAS (this, ref)
    2431              :     {
    2432       171180 :       symtab_node *alias = ref->referring;
    2433       171180 :       if (include_overwritable
    2434       171180 :           || alias->get_availability () > AVAIL_INTERPOSABLE)
    2435       171180 :         if (alias->call_for_symbol_and_aliases (callback, data,
    2436              :                                               include_overwritable))
    2437              :           return true;
    2438              :     }
    2439              :   return false;
    2440              : }
    2441              : 
    2442              : /* Return true if address of N is possibly compared.  */
    2443              : 
    2444              : static bool
    2445       612081 : address_matters_1 (symtab_node *n, void *)
    2446              : {
    2447       612081 :   struct ipa_ref *ref;
    2448              : 
    2449       612081 :   if (!n->address_can_be_compared_p ())
    2450              :     return false;
    2451       600314 :   if (n->externally_visible || n->force_output || n->ref_by_asm)
    2452              :     return true;
    2453              : 
    2454       506207 :   for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
    2455       447420 :     if (ref->address_matters_p ())
    2456              :       return true;
    2457              :   return false;
    2458              : }
    2459              : 
    2460              : /* Return true if symbol's address may possibly be compared to other
    2461              :    symbol's address.  */
    2462              : 
    2463              : bool
    2464       585382 : symtab_node::address_matters_p ()
    2465              : {
    2466       585382 :   gcc_assert (!alias);
    2467       585382 :   return call_for_symbol_and_aliases (address_matters_1, NULL, true);
    2468              : }
    2469              : 
    2470              : /* Return true if symbol's alignment may be increased.  */
    2471              : 
    2472              : bool
    2473        30061 : symtab_node::can_increase_alignment_p (void)
    2474              : {
    2475        30061 :   symtab_node *target = ultimate_alias_target ();
    2476              : 
    2477              :   /* For now support only variables.  */
    2478        30061 :   if (!VAR_P (decl))
    2479              :     return false;
    2480              : 
    2481              :   /* With -fno-toplevel-reorder we may have already output the constant.  */
    2482        30061 :   if (TREE_ASM_WRITTEN (target->decl))
    2483              :     return false;
    2484              : 
    2485              :   /* If target is already placed in an anchor, we cannot touch its
    2486              :      alignment.  */
    2487        29374 :   if (DECL_RTL_SET_P (target->decl)
    2488        14217 :       && MEM_P (DECL_RTL (target->decl))
    2489        43591 :       && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
    2490              :     return false;
    2491              : 
    2492              :   /* Constant pool entries may be shared.  */
    2493        29374 :   if (DECL_IN_CONSTANT_POOL (target->decl))
    2494              :     return false;
    2495              : 
    2496              :   /* We cannot change alignment of symbols that may bind to symbols
    2497              :      in other translation unit that may contain a definition with lower
    2498              :      alignment.  */
    2499        27252 :   if (!decl_binds_to_current_def_p (decl))
    2500              :     return false;
    2501              : 
    2502              :   /* When compiling partition, be sure the symbol is not output by other
    2503              :      partition.  */
    2504        17143 :   if (flag_ltrans
    2505        17143 :       && (target->in_other_partition
    2506          265 :           || target->get_partitioning_class () == SYMBOL_DUPLICATE))
    2507            0 :     return false;
    2508              : 
    2509              :   /* Do not override the alignment as specified by the ABI when the used
    2510              :      attribute is set.  */
    2511        17143 :   if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl))
    2512              :     return false;
    2513              : 
    2514              :   /* Do not override explicit alignment set by the user when an explicit
    2515              :      section name is also used.  This is a common idiom used by many
    2516              :      software projects.  */
    2517        17143 :   if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section)
    2518              :     return false;
    2519              : 
    2520              :   return true;
    2521              : }
    2522              : 
    2523              : /* Worker for symtab_node::increase_alignment.  */
    2524              : 
    2525              : static bool
    2526         5160 : increase_alignment_1 (symtab_node *n, void *v)
    2527              : {
    2528         5160 :   unsigned int align = (size_t)v;
    2529         5160 :   if (DECL_ALIGN (n->decl) < align
    2530         5160 :       && n->can_increase_alignment_p ())
    2531              :     {
    2532         4006 :       SET_DECL_ALIGN (n->decl, align);
    2533         4006 :       DECL_USER_ALIGN (n->decl) = 1;
    2534              :     }
    2535         5160 :   return false;
    2536              : }
    2537              : 
    2538              : /* Increase alignment of THIS to ALIGN.  */
    2539              : 
    2540              : void
    2541         4612 : symtab_node::increase_alignment (unsigned int align)
    2542              : {
    2543         4612 :   gcc_assert (can_increase_alignment_p () && align <= MAX_OFILE_ALIGNMENT);
    2544         4612 :   ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
    2545         4612 :                                                         (void *)(size_t) align,
    2546              :                                                         true);
    2547         4612 :   gcc_assert (DECL_ALIGN (decl) >= align);
    2548         4612 : }
    2549              : 
    2550              : /* Helper for symtab_node::definition_alignment.  */
    2551              : 
    2552              : static bool
    2553      1699876 : get_alignment_1 (symtab_node *n, void *v)
    2554              : {
    2555      1699876 :   *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
    2556      1699876 :   return false;
    2557              : }
    2558              : 
    2559              : /* Return desired alignment of the definition.  This is NOT alignment useful
    2560              :    to access THIS, because THIS may be interposable and DECL_ALIGN should
    2561              :    be used instead.  It however must be guaranteed when output definition
    2562              :    of THIS.  */
    2563              : 
    2564              : unsigned int
    2565      1640038 : symtab_node::definition_alignment ()
    2566              : {
    2567      1640038 :   unsigned int align = 0;
    2568      1640038 :   gcc_assert (!alias);
    2569      1640038 :   call_for_symbol_and_aliases (get_alignment_1, &align, true);
    2570      1640038 :   return align;
    2571              : }
    2572              : 
    2573              : /* Return symbol used to separate symbol name from suffix.  */
    2574              : 
    2575              : char
    2576       307024 : symbol_table::symbol_suffix_separator ()
    2577              : {
    2578              : #ifndef NO_DOT_IN_LABEL
    2579       307024 :   return '.';
    2580              : #elif !defined NO_DOLLAR_IN_LABEL
    2581              :   return '$';
    2582              : #else
    2583              :   return '_';
    2584              : #endif
    2585              : }
    2586              : 
    2587              : /* Return true when references to this symbol from REF must bind to current
    2588              :    definition in final executable.  */
    2589              : 
    2590              : bool
    2591     95601839 : symtab_node::binds_to_current_def_p (symtab_node *ref)
    2592              : {
    2593     95601839 :   if (!definition && !in_other_partition)
    2594              :     return false;
    2595     47006569 :   if (transparent_alias)
    2596           13 :     return definition
    2597           13 :            && get_alias_target()->binds_to_current_def_p (ref);
    2598     47006556 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
    2599     47006556 :   if (cnode && cnode->ifunc_resolver)
    2600              :     return false;
    2601     47006456 :   if (decl_binds_to_current_def_p (decl))
    2602              :     return true;
    2603              : 
    2604              :   /* Inline clones always binds locally.  */
    2605     22147554 :   if (cnode && cnode->inlined_to)
    2606              :     return true;
    2607              : 
    2608     22122681 :   if (DECL_EXTERNAL (decl))
    2609              :     return false;
    2610              : 
    2611     19684282 :   gcc_assert (externally_visible);
    2612              : 
    2613     19684282 :   if (ref)
    2614              :     {
    2615       139247 :       cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
    2616       139247 :       if (cref)
    2617       139247 :         ref = cref->inlined_to;
    2618              :     }
    2619              : 
    2620              :   /* If this is a reference from symbol itself and there are no aliases, we
    2621              :      may be sure that the symbol was not interposed by something else because
    2622              :      the symbol itself would be unreachable otherwise.  This is important
    2623              :      to optimize recursive functions well.
    2624              : 
    2625              :      This assumption may be broken by inlining: if symbol is interposable
    2626              :      but the body is available (i.e. declared inline), inliner may make
    2627              :      the body reachable even with interposition.  */
    2628          479 :   if (this == ref && !has_aliases_p ()
    2629       139649 :       && (!cnode
    2630          402 :           || symtab->state >= IPA_SSA_AFTER_INLINING
    2631            0 :           || get_availability () >= AVAIL_INTERPOSABLE))
    2632          402 :     return true;
    2633              : 
    2634              : 
    2635              :   /* References within one comdat group are always bound in a group.  */
    2636     19683880 :   if (ref
    2637        70577 :       && symtab->state >= IPA_SSA_AFTER_INLINING
    2638        70577 :       && get_comdat_group ()
    2639     19754453 :       && get_comdat_group () == ref->get_comdat_group ())
    2640              :     return true;
    2641              : 
    2642              :   return false;
    2643              : }
    2644              : 
    2645              : /* Return true if symbol should be output to the symbol table.  */
    2646              : 
    2647              : bool
    2648      1196672 : symtab_node::output_to_lto_symbol_table_p (void)
    2649              : {
    2650              :   /* Only externally visible symbols matter.  */
    2651      1196672 :   if (!TREE_PUBLIC (decl))
    2652              :     return false;
    2653      1126356 :   if (!real_symbol_p ())
    2654              :     return false;
    2655              :   /* FIXME: variables probably should not be considered as real symbols at
    2656              :      first place.  */
    2657      1126356 :   if (VAR_P (decl) && DECL_HARD_REGISTER (decl))
    2658              :     return false;
    2659       658532 :   if (TREE_CODE (decl) == FUNCTION_DECL && !definition
    2660      1591862 :       && fndecl_built_in_p (decl))
    2661              :     {
    2662              :       /* Builtins like those for most math functions have actual implementations
    2663              :          in libraries so make sure to output references into the symbol table to
    2664              :          make those libraries referenced.  Note this is incomplete handling for
    2665              :          now and only covers math functions.  */
    2666        41574 :       return builtin_with_linkage_p (decl);
    2667              :     }
    2668              : 
    2669              :   /* We have real symbol that should be in symbol table.  However try to trim
    2670              :      down the references to libraries bit more because linker will otherwise
    2671              :      bring unnecessary object files into the final link.
    2672              :      FIXME: The following checks can easily be confused i.e. by self recursive
    2673              :      function or self-referring variable.  */
    2674              : 
    2675              :   /* We keep external functions in symtab for sake of inlining
    2676              :      and devirtualization.  We do not want to see them in symbol table as
    2677              :      references unless they are really used.  */
    2678      1084758 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
    2679       616958 :   if (cnode && (!definition || DECL_EXTERNAL (decl))
    2680       424186 :       && cnode->callers)
    2681              :     return true;
    2682              : 
    2683              :  /* Ignore all references from external vars initializers - they are not really
    2684              :     part of the compilation unit until they are used by folding.  Some symbols,
    2685              :     like references to external construction vtables cannot be referred to at
    2686              :     all.  We decide this at can_refer_decl_in_current_unit_p.  */
    2687      1062480 :  if (!definition || DECL_EXTERNAL (decl))
    2688              :     {
    2689              :       int i;
    2690              :       struct ipa_ref *ref;
    2691       408478 :       for (i = 0; iterate_referring (i, ref); i++)
    2692              :         {
    2693       408432 :           if (ref->use == IPA_REF_ALIAS)
    2694           36 :             continue;
    2695       816838 :           if (is_a <cgraph_node *> (ref->referring))
    2696              :             return true;
    2697       403094 :           if (!DECL_EXTERNAL (ref->referring->decl))
    2698              :             return true;
    2699              :         }
    2700              :       return false;
    2701              :     }
    2702              :   return true;
    2703              : }
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.