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-02-28 14:20:25 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    556256282 : symbol_table::decl_assembler_name_hash (const_tree asmname)
      83              : {
      84    556256282 :   if (IDENTIFIER_POINTER (asmname)[0] == '*')
      85              :     {
      86      2975777 :       const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
      87      2975777 :       size_t ulp_len = strlen (user_label_prefix);
      88              : 
      89      2975777 :       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      2975777 :       return htab_hash_string (decl_str);
      95              :     }
      96              : 
      97    553280505 :   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    482334903 : symbol_table::assembler_names_equal_p (const char *name1, const char *name2)
     105              : {
     106    482334903 :   if (name1 != name2)
     107              :     {
     108    482334804 :       if (name1[0] == '*')
     109              :         {
     110      2512709 :           size_t ulp_len = strlen (user_label_prefix);
     111              : 
     112      2512709 :           name1 ++;
     113              : 
     114      2512709 :           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    482334804 :       if (name2[0] == '*')
     122              :         {
     123      2347989 :           size_t ulp_len = strlen (user_label_prefix);
     124              : 
     125      2347989 :           name2 ++;
     126              : 
     127      2347989 :           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    482334804 :       return !strcmp (name1, name2);
     135              :     }
     136              :   return true;
     137              : }
     138              : 
     139              : /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL.  */
     140              : 
     141              : bool
     142    577499105 : symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
     143              : {
     144    577499105 :   tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
     145    577499105 :   const char *decl_str;
     146    577499105 :   const char *asmname_str;
     147              : 
     148    577499105 :   if (decl_asmname == asmname)
     149              :     return true;
     150              : 
     151    482334804 :   decl_str = IDENTIFIER_POINTER (decl_asmname);
     152    482334804 :   asmname_str = IDENTIFIER_POINTER (asmname);
     153    482334804 :   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    164679775 : symbol_table::insert_to_assembler_name_hash (symtab_node *node,
     163              :                                              bool with_clones)
     164              : {
     165    208133414 :   if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
     166              :     return;
     167    164679566 :   gcc_checking_assert (!node->previous_sharing_asm_name
     168              :                        && !node->next_sharing_asm_name);
     169    164679566 :   if (assembler_name_hash)
     170              :     {
     171     11698659 :       symtab_node **aslot;
     172     11698659 :       cgraph_node *cnode;
     173     11698659 :       tree decl = node->decl;
     174              : 
     175     11698659 :       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     11698659 :       if (!name)
     180            0 :         return;
     181              : 
     182     11698659 :       hashval_t hash = decl_assembler_name_hash (name);
     183     11698659 :       aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
     184     11698659 :       gcc_assert (*aslot != node);
     185     11698659 :       node->next_sharing_asm_name = (symtab_node *)*aslot;
     186     11698659 :       if (*aslot != NULL)
     187      3085795 :         (*aslot)->previous_sharing_asm_name = node;
     188     11698659 :       *aslot = node;
     189              : 
     190              :       /* Update also possible inline clones sharing a decl.  */
     191     23397318 :       cnode = dyn_cast <cgraph_node *> (node);
     192      8334905 :       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    149115703 : symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
     204              :                                                bool with_clones)
     205              : {
     206    149115703 :   if (assembler_name_hash)
     207              :     {
     208      4908464 :       cgraph_node *cnode;
     209      4908464 :       tree decl = node->decl;
     210              : 
     211      4908464 :       if (node->next_sharing_asm_name)
     212      2679211 :         node->next_sharing_asm_name->previous_sharing_asm_name
     213      2679211 :           = node->previous_sharing_asm_name;
     214      4908464 :       if (node->previous_sharing_asm_name)
     215              :         {
     216       991867 :           node->previous_sharing_asm_name->next_sharing_asm_name
     217       991867 :             = node->next_sharing_asm_name;
     218              :         }
     219              :       else
     220              :         {
     221      3916597 :           tree name = DECL_ASSEMBLER_NAME (node->decl);
     222      3916597 :           symtab_node **slot;
     223              : 
     224      3916597 :           if (!name)
     225            0 :             return;
     226              : 
     227      3916597 :           hashval_t hash = decl_assembler_name_hash (name);
     228      3916597 :           slot = assembler_name_hash->find_slot_with_hash (name, hash,
     229              :                                                            NO_INSERT);
     230      3916597 :           gcc_assert (*slot == node);
     231      3916597 :           if (!node->next_sharing_asm_name)
     232      1993722 :             assembler_name_hash->clear_slot (slot);
     233              :           else
     234      1922875 :             *slot = node->next_sharing_asm_name;
     235              :         }
     236      4908464 :       node->next_sharing_asm_name = NULL;
     237      4908464 :       node->previous_sharing_asm_name = NULL;
     238              : 
     239              :       /* Update also possible inline clones sharing a decl.  */
     240      4908464 :       cnode = dyn_cast <cgraph_node *> (node);
     241      4805132 :       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         2082 : symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
     252              : {
     253         2082 :   unlink_from_assembler_name_hash (node, false);
     254         2082 :   insert_to_assembler_name_hash (node, false);
     255         2082 : }
     256              : 
     257              : /* Initialize asm name hash unless.  */
     258              : 
     259              : void
     260     83360154 : symbol_table::symtab_initialize_asm_name_hash (void)
     261              : {
     262     83360154 :   symtab_node *node;
     263     83360154 :   if (!assembler_name_hash)
     264              :     {
     265       242189 :       assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
     266      8712803 :       FOR_EACH_SYMBOL (node)
     267      8470614 :         insert_to_assembler_name_hash (node, false);
     268              :     }
     269     83360154 : }
     270              : 
     271              : /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables.  */
     272              : 
     273              : void
     274      2856998 : symbol_table::change_decl_assembler_name (tree decl, tree name)
     275              : {
     276      2856998 :   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      2858092 :       || TREE_CODE (decl) == FUNCTION_DECL)
     282      2855904 :     node = symtab_node::get (decl);
     283      2856998 :   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
     284              :     {
     285      1842799 :       SET_DECL_ASSEMBLER_NAME (decl, name);
     286      1842799 :       if (node)
     287           11 :         insert_to_assembler_name_hash (node, true);
     288              :     }
     289              :   else
     290              :     {
     291      1014199 :       if (name == DECL_ASSEMBLER_NAME (decl))
     292              :         return;
     293              : 
     294       156425 :       tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
     295       156425 :                     ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
     296            0 :                     : NULL);
     297       156425 :       if (node)
     298         7986 :         unlink_from_assembler_name_hash (node, true);
     299              : 
     300       156425 :       const char *old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
     301       156425 :       if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
     302       156425 :           && DECL_RTL_SET_P (decl))
     303            0 :         warning (0, "%qD renamed after being referenced in assembly", decl);
     304              : 
     305       156425 :       SET_DECL_ASSEMBLER_NAME (decl, name);
     306       156425 :       if (DECL_RTL_SET_P (decl))
     307              :         {
     308            1 :           SET_DECL_RTL (decl, NULL);
     309            1 :           make_decl_rtl (decl);
     310              :         }
     311       156425 :       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       156425 :       if (node)
     322              :         {
     323         7986 :           insert_to_assembler_name_hash (node, true);
     324         7986 :           ipa_ref *ref;
     325         8012 :           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         7986 :           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     12318174 : section_name_hasher::hash (section_hash_entry *n)
     366              : {
     367     12318174 :   return htab_hash_string (n->name);
     368              : }
     369              : 
     370              : /* Return true if section P1 name equals to P2.  */
     371              : 
     372              : bool
     373     12260104 : section_name_hasher::equal (section_hash_entry *n1, const char *name)
     374              : {
     375     12260104 :   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        47931 : retain_section_hash_entry (section_hash_entry *entry)
     382              : {
     383        47931 :   entry->ref_count++;
     384        47931 :   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      1875753 : release_section_hash_entry (section_hash_entry *entry)
     392              : {
     393      1875753 :   if (entry)
     394              :     {
     395        27688 :       entry->ref_count--;
     396        27688 :       if (!entry->ref_count)
     397              :         {
     398        24181 :           hashval_t hash = htab_hash_string (entry->name);
     399        24181 :           section_hash_entry **slot
     400        24181 :             = symtab->section_hash->find_slot_with_hash (entry->name,
     401              :                                                  hash, INSERT);
     402        24181 :           ggc_free (entry);
     403        24181 :           symtab->section_hash->clear_slot (slot);
     404              :         }
     405              :     }
     406      1875753 : }
     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    156199080 : symtab_node::register_symbol (void)
     413              : {
     414    156199080 :   symtab->register_symbol (this);
     415              : 
     416    156199080 :   if (!decl->decl_with_vis.symtab_node)
     417    153248509 :     decl->decl_with_vis.symtab_node = this;
     418              : 
     419    156199080 :   ref_list.clear ();
     420              : 
     421              :   /* Be sure to do this last; C++ FE might create new nodes via
     422              :      DECL_ASSEMBLER_NAME langhook!  */
     423    156199080 :   symtab->insert_to_assembler_name_hash (this, false);
     424    156199080 : }
     425              : 
     426              : /* Remove NODE from same comdat group.   */
     427              : 
     428              : void
     429    161315245 : symtab_node::remove_from_same_comdat_group (void)
     430              : {
     431    161315245 :   if (same_comdat_group)
     432              :     {
     433              :       symtab_node *prev;
     434              :       for (prev = same_comdat_group;
     435     17828555 :            prev->same_comdat_group != this;
     436              :            prev = prev->same_comdat_group)
     437              :         ;
     438     17174756 :       if (same_comdat_group == prev)
     439     16762356 :         prev->same_comdat_group = NULL;
     440              :       else
     441       412400 :         prev->same_comdat_group = same_comdat_group;
     442     17174756 :       same_comdat_group = NULL;
     443     17174756 :       set_comdat_group (NULL);
     444              :     }
     445    161315245 : }
     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    149105634 : symtab_node::unregister (clone_info *info)
     453              : {
     454    149105634 :   remove_all_references ();
     455    149105634 :   remove_all_referring ();
     456              : 
     457              :   /* Remove reference to section.  */
     458    149105634 :   set_section_for_node (NULL);
     459              : 
     460    149105634 :   remove_from_same_comdat_group ();
     461              : 
     462    149105634 :   symtab->unregister (this);
     463              : 
     464              :   /* During LTO symtab merging we temporarily corrupt decl to symtab node
     465              :      hash.  */
     466    149105634 :   gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
     467    149105634 :   if (decl->decl_with_vis.symtab_node == this)
     468              :     {
     469    146625409 :       symtab_node *replacement_node = NULL;
     470    146625409 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
     471    109859277 :         replacement_node = cnode->find_replacement (info);
     472    146625409 :       decl->decl_with_vis.symtab_node = replacement_node;
     473              :     }
     474    149105634 :   if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
     475    149105633 :     symtab->unlink_from_assembler_name_hash (this, false);
     476    149105634 :   if (in_init_priority_hash)
     477          107 :     symtab->init_priority_hash->remove (this);
     478    149105634 : }
     479              : 
     480              : 
     481              : /* Remove symbol from symbol table.  */
     482              : 
     483              : void
     484    144210317 : symtab_node::remove (void)
     485              : {
     486    144210317 :   if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
     487    107543863 :     cnode->remove ();
     488     36666454 :   else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
     489     36666454 :     vnode->remove ();
     490    144210317 : }
     491              : 
     492              : /* Add NEW_ to the same comdat group that OLD is in.  */
     493              : 
     494              : void
     495     17249386 : symtab_node::add_to_same_comdat_group (symtab_node *old_node)
     496              : {
     497     17249386 :   gcc_assert (old_node->get_comdat_group ());
     498     17249386 :   gcc_assert (!same_comdat_group);
     499     17249386 :   gcc_assert (this != old_node);
     500              : 
     501     17249386 :   set_comdat_group (old_node->get_comdat_group ());
     502     17249386 :   same_comdat_group = old_node;
     503     17249386 :   if (!old_node->same_comdat_group)
     504     16818379 :     old_node->same_comdat_group = this;
     505              :   else
     506              :     {
     507              :       symtab_node *n;
     508              :       for (n = old_node->same_comdat_group;
     509       777808 :            n->same_comdat_group != old_node;
     510              :            n = n->same_comdat_group)
     511              :         ;
     512       431007 :       n->same_comdat_group = this;
     513              :     }
     514              : 
     515     17249386 :   cgraph_node *n;
     516     17262137 :   if (comdat_local_p ()
     517     17262130 :       && (n = dyn_cast <cgraph_node *> (this)) != NULL)
     518              :     {
     519        28725 :       for (cgraph_edge *e = n->callers; e; e = e->next_caller)
     520        15981 :         if (e->caller->inlined_to)
     521         4322 :           e->caller->inlined_to->calls_comdat_local = true;
     522              :         else
     523        11659 :           e->caller->calls_comdat_local = true;
     524              :     }
     525     17249386 : }
     526              : 
     527              : /* Dissolve the same_comdat_group list in which NODE resides.  */
     528              : 
     529              : void
     530         2032 : symtab_node::dissolve_same_comdat_group_list (void)
     531              : {
     532         2032 :   symtab_node *n = this;
     533         2032 :   symtab_node *next;
     534              : 
     535         2032 :   if (!same_comdat_group)
     536              :     return;
     537         3768 :   do
     538              :     {
     539         3768 :       next = n->same_comdat_group;
     540         3768 :       n->same_comdat_group = NULL;
     541         3768 :       if (dyn_cast <cgraph_node *> (n))
     542         3498 :         dyn_cast <cgraph_node *> (n)->calls_comdat_local = false;
     543              :       /* Clear comdat_group for comdat locals, since
     544              :          make_decl_local doesn't.  */
     545         3768 :       if (!TREE_PUBLIC (n->decl))
     546         2025 :         n->set_comdat_group (NULL);
     547         3768 :       n = next;
     548              :     }
     549         3768 :   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        44791 : symtab_node::asm_name () const
     558              : {
     559        44791 :   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
     560          195 :     return name ();
     561        44596 :   return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
     562              : }
     563              : 
     564              : /* Return printable identifier name.  */
     565              : 
     566              : const char *
     567        45422 : symtab_node::name () const
     568              : {
     569        45422 :   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        45422 :   return lang_hooks.decl_printable_name (decl, 2);
     577              : }
     578              : 
     579              : const char *
     580        81064 : symtab_node::get_dump_name (bool asm_name_p) const
     581              : {
     582              : #define EXTRA 16
     583        81064 :   const char *fname = asm_name_p ? asm_name () : name ();
     584        81064 :   unsigned l = strlen (fname);
     585              : 
     586        81064 :   char *s = (char *)ggc_internal_cleared_alloc (l + EXTRA);
     587        81064 :   snprintf (s, l + EXTRA, "%s/%d", fname, m_uid);
     588              : 
     589        81064 :   return s;
     590              : }
     591              : 
     592              : const char *
     593        36644 : symtab_node::dump_name () const
     594              : {
     595        36644 :   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      6554061 : symtab_node::create_reference (symtab_node *referred_node,
     610              :                                enum ipa_ref_use use_type)
     611              : {
     612      6554061 :   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     42123536 : symtab_node::create_reference (symtab_node *referred_node,
     622              :                                enum ipa_ref_use use_type, gimple *stmt)
     623              : {
     624     42123536 :   ipa_ref *ref = NULL, *ref2 = NULL;
     625     42123536 :   ipa_ref_list *list, *list2;
     626     42123536 :   ipa_ref_t *old_references;
     627              : 
     628     42123536 :   gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
     629     42123536 :   gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
     630              : 
     631     42123536 :   list = &ref_list;
     632     42123536 :   old_references = list->references.address ();
     633     69638742 :   list->references.safe_grow (list->references.length () + 1, false);
     634     42123536 :   ref = &list->references.last ();
     635              : 
     636     42123536 :   list2 = &referred_node->ref_list;
     637              : 
     638              :   /* IPA_REF_ALIAS is always inserted at the beginning of the list.   */
     639     42123536 :   if(use_type == IPA_REF_ALIAS)
     640              :     {
     641      8688736 :       list2->referring.safe_insert (0, ref);
     642      8688736 :       ref->referred_index = 0;
     643              : 
     644      8837243 :       for (unsigned int i = 1; i < list2->referring.length (); i++)
     645       148507 :         list2->referring[i]->referred_index = i;
     646              :     }
     647              :   else
     648              :     {
     649     33434800 :       list2->referring.safe_push (ref);
     650     66869600 :       ref->referred_index = list2->referring.length () - 1;
     651              :     }
     652              : 
     653     42123536 :   ref->referring = this;
     654     42123536 :   ref->referred = referred_node;
     655     42123536 :   ref->stmt = stmt;
     656     42123536 :   ref->lto_stmt_uid = 0;
     657     42123536 :   ref->speculative_id = 0;
     658     42123536 :   ref->use = use_type;
     659     42123536 :   ref->speculative = 0;
     660              : 
     661              :   /* If vector was moved in memory, update pointers.  */
     662     84247072 :   if (old_references != list->references.address ())
     663              :     {
     664              :       int i;
     665     53834813 :       for (i = 0; iterate_reference(i, ref2); i++)
     666     37900758 :         ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
     667              :     }
     668     42123536 :   return ref;
     669              : }
     670              : 
     671              : ipa_ref *
     672        58623 : symtab_node::maybe_create_reference (tree val, gimple *stmt)
     673              : {
     674        58623 :   STRIP_NOPS (val);
     675        58623 :   ipa_ref_use use_type;
     676              : 
     677        58623 :   switch (TREE_CODE (val))
     678              :     {
     679              :     case VAR_DECL:
     680              :       use_type = IPA_REF_LOAD;
     681              :       break;
     682         8344 :     case ADDR_EXPR:
     683         8344 :       use_type = IPA_REF_ADDR;
     684         8344 :       break;
     685        49862 :     default:
     686        49862 :       gcc_assert (!handled_component_p (val));
     687              :       return NULL;
     688              :     }
     689              : 
     690         8761 :   val = get_base_var (val);
     691         8761 :   if (val && VAR_OR_FUNCTION_DECL_P (val))
     692              :     {
     693         4987 :       symtab_node *referred = symtab_node::get (val);
     694         4987 :       gcc_checking_assert (referred);
     695         4987 :       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      3081396 : symtab_node::clone_references (symtab_node *node)
     704              : {
     705      3081396 :   ipa_ref *ref = NULL, *ref2 = NULL;
     706      3081396 :   int i;
     707      3901463 :   for (i = 0; node->iterate_reference (i, ref); i++)
     708              :     {
     709       820067 :       bool speculative = ref->speculative;
     710       820067 :       unsigned int stmt_uid = ref->lto_stmt_uid;
     711       820067 :       unsigned int spec_id = ref->speculative_id;
     712              : 
     713       820067 :       ref2 = create_reference (ref->referred, ref->use, ref->stmt);
     714       820067 :       ref2->speculative = speculative;
     715       820067 :       ref2->lto_stmt_uid = stmt_uid;
     716       820067 :       ref2->speculative_id = spec_id;
     717              :     }
     718      3081396 : }
     719              : 
     720              : /* Clone all referring from symtab NODE to this symtab_node.  */
     721              : 
     722              : void
     723         2678 : symtab_node::clone_referring (symtab_node *node)
     724              : {
     725         2678 :   ipa_ref *ref = NULL, *ref2 = NULL;
     726         2678 :   int i;
     727         4605 :   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         2678 : }
     739              : 
     740              : /* Clone reference REF to this symtab_node and set its stmt to STMT.  */
     741              : 
     742              : ipa_ref *
     743        25739 : symtab_node::clone_reference (ipa_ref *ref, gimple *stmt)
     744              : {
     745        25739 :   bool speculative = ref->speculative;
     746        25739 :   unsigned int stmt_uid = ref->lto_stmt_uid;
     747        25739 :   unsigned int spec_id = ref->speculative_id;
     748        25739 :   ipa_ref *ref2;
     749              : 
     750        25739 :   ref2 = create_reference (ref->referred, ref->use, stmt);
     751        25739 :   ref2->speculative = speculative;
     752        25739 :   ref2->lto_stmt_uid = stmt_uid;
     753        25739 :   ref2->speculative_id = spec_id;
     754        25739 :   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         9022 : 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         9022 :   ipa_ref *r = NULL;
     766         9022 :   int i;
     767              : 
     768        51204 :   for (i = 0; iterate_reference (i, r); i++)
     769        51201 :     if (r->referred == referred_node
     770        15131 :         && !r->speculative
     771        15131 :         && r->use == use_type
     772        12014 :         && ((stmt && r->stmt == stmt)
     773         3556 :             || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
     774         3392 :             || (!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        63224 : symtab_node::remove_stmt_references (gimple *stmt)
     783              : {
     784        63224 :   ipa_ref *r = NULL;
     785        63224 :   int i = 0;
     786              : 
     787        67289 :   while (iterate_reference (i, r))
     788         4065 :     if (r->stmt == stmt)
     789            0 :       r->remove_reference ();
     790              :     else
     791         4065 :       i++;
     792        63224 : }
     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      2164018 : symtab_node::clear_stmts_in_references (void)
     802              : {
     803      2164018 :   ipa_ref *r = NULL;
     804      2164018 :   int i;
     805              : 
     806      8663808 :   for (i = 0; iterate_reference (i, r); i++)
     807      6499790 :     if (!r->speculative)
     808              :       {
     809      6485188 :         r->stmt = NULL;
     810      6485188 :         r->lto_stmt_uid = 0;
     811      6485188 :         r->speculative_id = 0;
     812              :       }
     813      2164018 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
     814      2164018 :   if (cnode)
     815              :     {
     816      2164018 :       if (cnode->clones)
     817       693283 :         for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
     818       569699 :           cnode->clear_stmts_in_references ();
     819              :     }
     820      2164018 : }
     821              : 
     822              : /* Remove all references in ref list.  */
     823              : 
     824              : void
     825    290394352 : symtab_node::remove_all_references (void)
     826              : {
     827    328272541 :   while (ref_list.references.length ())
     828     37878189 :     ref_list.references.last ().remove_reference ();
     829    290394352 :   ref_list.references.release ();
     830    290394352 : }
     831              : 
     832              : /* Remove all referring items in ref list.  */
     833              : 
     834              : void
     835    149105634 : symtab_node::remove_all_referring (void)
     836              : {
     837    149190489 :   while (ref_list.referring.length ())
     838        84855 :     ref_list.referring.last ()->remove_reference ();
     839    149105634 :   ref_list.referring.release ();
     840    149105634 : }
     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     82875830 : symtab_node::get_for_asmname (const_tree asmname)
    1078              : {
    1079     82875830 :   symtab_node *node;
    1080              : 
    1081     82875830 :   symtab->symtab_initialize_asm_name_hash ();
    1082     82875830 :   hashval_t hash = symtab->decl_assembler_name_hash (asmname);
    1083     82875830 :   symtab_node **slot
    1084     82875830 :     = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
    1085              :                                                         NO_INSERT);
    1086              : 
    1087     82875830 :   if (slot)
    1088              :     {
    1089     82872069 :       node = *slot;
    1090     82872069 :       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     83353261 : symtab_node::verify_base (void)
    1116              : {
    1117     83353261 :   bool error_found = false;
    1118     83353261 :   symtab_node *hashed_node;
    1119              : 
    1120     83353261 :   if (is_a <cgraph_node *> (this))
    1121              :     {
    1122     51526688 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    1123              :         {
    1124            0 :           error ("function symbol is not function");
    1125            0 :           error_found = true;
    1126              :         }
    1127     51526688 :       else if ((lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl))
    1128     51526688 :                 != NULL)
    1129     51526688 :                != dyn_cast <cgraph_node *> (this)->ifunc_resolver)
    1130              :         {
    1131            0 :           error ("inconsistent %<ifunc%> attribute");
    1132            0 :           error_found = true;
    1133              :         }
    1134              :     }
    1135     31826573 :   else if (is_a <varpool_node *> (this))
    1136              :     {
    1137     31826573 :       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     83353261 :   if (order < 0 || order >= symtab->order)
    1149              :     {
    1150            0 :       error ("node has invalid order %i", order);
    1151            0 :       error_found = true;
    1152              :     }
    1153              : 
    1154     83353261 :   if (symtab->state != LTO_STREAMING)
    1155              :     {
    1156     83198508 :       hashed_node = symtab_node::get (decl);
    1157     83198508 :       if (!hashed_node)
    1158              :         {
    1159            0 :           error ("node not found node->decl->decl_with_vis.symtab_node");
    1160            0 :           error_found = true;
    1161              :         }
    1162     83198508 :       if (hashed_node != this
    1163     88476140 :           && (!is_a <cgraph_node *> (this)
    1164      5277632 :               || !dyn_cast <cgraph_node *> (this)->clone_of
    1165      5277632 :               || 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     83353261 :   if (symtab->assembler_name_hash)
    1172              :     {
    1173     82793766 :       hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
    1174     82793766 :       if (hashed_node)
    1175              :         {
    1176     82792093 :           if (hashed_node->previous_sharing_asm_name)
    1177              :             {
    1178            0 :               error ("assembler name hash list corrupted");
    1179            0 :               error_found = true;
    1180              :             }
    1181     82792093 :           else if (previous_sharing_asm_name == NULL)
    1182              :             {
    1183     77494062 :               if (hashed_node != this)
    1184              :                 {
    1185            0 :                   error ("assembler name hash list corrupted");
    1186            0 :                   error_found = true;
    1187              :                 }
    1188              :             }
    1189      5298031 :           else if (!(is_a <varpool_node *> (this) && DECL_HARD_REGISTER (decl)))
    1190              :             {
    1191      5298031 :               if (!asmname_hasher::equal (previous_sharing_asm_name,
    1192      5298031 :                                           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     83353261 :   if (previous_sharing_asm_name
    1201      5298448 :       && 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     83353261 :   if (body_removed && definition)
    1207              :     {
    1208            0 :       error ("node has body_removed but is definition");
    1209            0 :       error_found = true;
    1210              :     }
    1211     83353261 :   if (analyzed && !definition)
    1212              :     {
    1213            0 :       error ("node is analyzed but it is not a definition");
    1214            0 :       error_found = true;
    1215              :     }
    1216     83353261 :   if (cpp_implicit_alias && !alias)
    1217              :     {
    1218            0 :       error ("node is alias but not implicit alias");
    1219            0 :       error_found = true;
    1220              :     }
    1221     83353261 :   if (alias && !definition && !weakref)
    1222              :     {
    1223            0 :       error ("node is alias but not definition");
    1224            0 :       error_found = true;
    1225              :     }
    1226     83353261 :   if (weakref && !transparent_alias)
    1227              :     {
    1228            0 :       error ("node is weakref but not an transparent_alias");
    1229            0 :       error_found = true;
    1230              :     }
    1231     83353261 :   if (transparent_alias && !alias)
    1232              :     {
    1233            0 :       error ("node is transparent_alias but not an alias");
    1234            0 :       error_found = true;
    1235              :     }
    1236     83353261 :   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     83353261 :   if (symver
    1244     83353261 :       && (!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     83353261 :   if (symver
    1251     83353261 :       && (!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     83353261 :   if (same_comdat_group)
    1258              :     {
    1259      3198892 :       symtab_node *n = same_comdat_group;
    1260              : 
    1261      3198892 :       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      3198892 :       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      3198892 :       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      3198892 :       if (n == this)
    1277              :         {
    1278            0 :           error ("node is alone in a comdat group");
    1279            0 :           error_found = true;
    1280              :         }
    1281      5741595 :       do
    1282              :         {
    1283      5741595 :           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      5741595 :           n = n->same_comdat_group;
    1290              :         }
    1291      5741595 :       while (n != this);
    1292      3198892 :       if (comdat_local_p ())
    1293              :         {
    1294        52683 :           ipa_ref *ref = NULL;
    1295              : 
    1296        54123 :           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     98721300 :   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     98725451 :   if (get_section () && get_comdat_group ()
    1314      2839893 :       && !implicit_section
    1315     15372400 :       && !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      1459485 :   if (alias && definition
    1323      1518884 :       && get_section () != get_alias_target ()->get_section ()
    1324     83353261 :       && (!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      1459485 :   if (alias && definition
    1334     84811496 :       && 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     83353261 :   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     83353453 :       && 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     83353261 :   return error_found;
    1365              : }
    1366              : 
    1367              : /* Verify consistency of NODE.  */
    1368              : 
    1369              : DEBUG_FUNCTION void
    1370     83355611 : symtab_node::verify (void)
    1371              : {
    1372     83355611 :   if (seen_error ())
    1373              :     return;
    1374              : 
    1375     83353261 :   timevar_push (TV_CGRAPH_VERIFY);
    1376     83353261 :   if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
    1377     51526688 :     node->verify_node ();
    1378              :   else
    1379     31826573 :     if (verify_base ())
    1380              :       {
    1381            0 :         debug ();
    1382            0 :         internal_error ("symtab_node::verify failed");
    1383              :       }
    1384     83353261 :   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      5491622 : check_ifunc_resolver (cgraph_node *node, void *data)
    1391              : {
    1392      5491622 :   if (node->ifunc_resolver)
    1393              :     {
    1394          430 :       bool *is_ifunc_resolver = (bool *) data;
    1395          430 :       *is_ifunc_resolver = true;
    1396          430 :       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      5144005 : is_caller_ifunc_resolver (cgraph_node *node)
    1407              : {
    1408      5144005 :   bool is_ifunc_resolver = false;
    1409              : 
    1410     15200421 :   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     10056730 :       if (e->caller->called_by_ifunc_resolver)
    1414              :         return true;
    1415              : 
    1416              :       /* Check for recursive call.  */
    1417     10056563 :       if (e->caller == node)
    1418        11383 :         continue;
    1419              : 
    1420              :       /* Skip if it has been visited.  */
    1421     10045180 :       unsigned int uid = e->caller->get_uid ();
    1422     10045180 :       if (!bitmap_set_bit (ifunc_ref_map, uid))
    1423      8143925 :         continue;
    1424              : 
    1425      1901255 :       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      1901233 :       e->caller->call_for_symbol_and_aliases (check_ifunc_resolver,
    1434              :                                               &is_ifunc_resolver,
    1435              :                                               true);
    1436      1901233 :       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       242530 : symtab_node::check_ifunc_callee_symtab_nodes (void)
    1451              : {
    1452       242530 :   symtab_node *node;
    1453              : 
    1454       242530 :   bitmap_obstack_initialize (NULL);
    1455       242530 :   ifunc_ref_map = BITMAP_ALLOC (NULL);
    1456              : 
    1457      8707875 :   FOR_EACH_SYMBOL (node)
    1458              :     {
    1459      8465345 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    1460      8465345 :       if (!cnode)
    1461      5222290 :         continue;
    1462              : 
    1463      5144310 :       unsigned int uid = cnode->get_uid ();
    1464      5144310 :       if (bitmap_bit_p (ifunc_ref_map, uid))
    1465      1901255 :         continue;
    1466      3243055 :       bitmap_set_bit (ifunc_ref_map, uid);
    1467              : 
    1468      3243055 :       bool is_ifunc_resolver = false;
    1469      3243055 :       cnode->call_for_symbol_and_aliases (check_ifunc_resolver,
    1470              :                                           &is_ifunc_resolver, true);
    1471      3243055 :       if (is_ifunc_resolver || is_caller_ifunc_resolver (cnode))
    1472          597 :         cnode->called_by_ifunc_resolver = true;
    1473              :     }
    1474              : 
    1475       242530 :   BITMAP_FREE (ifunc_ref_map);
    1476       242530 :   bitmap_obstack_release (NULL);
    1477       242530 : }
    1478              : 
    1479              : /* Verify symbol table for internal consistency.  */
    1480              : 
    1481              : DEBUG_FUNCTION void
    1482      2169101 : symtab_node::verify_symtab_nodes (void)
    1483              : {
    1484      2169101 :   symtab_node *node;
    1485      2169101 :   hash_map<tree, symtab_node *> comdat_head_map (251);
    1486      2169101 :   asm_node *anode;
    1487              : 
    1488      2169101 :   for (anode = symtab->first_asm_symbol ();
    1489      2287771 :        anode;
    1490       118670 :        anode = safe_as_a<asm_node*>(anode->next))
    1491       118670 :     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     75029268 :   FOR_EACH_SYMBOL (node)
    1498              :     {
    1499     72860167 :       node->verify ();
    1500     72860167 :       if (node->get_comdat_group ())
    1501              :         {
    1502     10602636 :           symtab_node **entry, *s;
    1503     10602636 :           bool existed;
    1504              : 
    1505     10602636 :           entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
    1506              :                                                   &existed);
    1507     10602636 :           if (!existed)
    1508      9292504 :             *entry = node;
    1509      1310132 :           else if (!DECL_EXTERNAL (node->decl))
    1510              :             {
    1511      1309987 :               for (s = (*entry)->same_comdat_group;
    1512      2451371 :                    s != NULL && s != node && s != *entry;
    1513      1141384 :                    s = s->same_comdat_group)
    1514              :                 ;
    1515      1309987 :               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      2169101 : }
    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      3644427 : symtab_node::make_decl_local (void)
    1537              : {
    1538      3644427 :   rtx rtl, symbol;
    1539              : 
    1540      3644427 :   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      3644427 :   else if (TREE_PUBLIC (decl) == 0)
    1552      3644413 :     return;
    1553              : 
    1554              :   /* Localizing a symbol also make all its transparent aliases local.  */
    1555              :   ipa_ref *ref;
    1556       102329 :   for (unsigned i = 0; iterate_direct_aliases (i, ref); i++)
    1557              :     {
    1558         1767 :       struct symtab_node *alias = ref->referring;
    1559         1767 :       if (alias->transparent_alias)
    1560            5 :         alias->make_decl_local ();
    1561              :     }
    1562              : 
    1563       100562 :   if (VAR_P (decl))
    1564              :     {
    1565        12513 :       DECL_COMMON (decl) = 0;
    1566              :       /* ADDRESSABLE flag is not defined for public symbols.  */
    1567        12513 :       TREE_ADDRESSABLE (decl) = 1;
    1568        12513 :       TREE_STATIC (decl) = 1;
    1569              :     }
    1570              :   else
    1571        88049 :     gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    1572              : 
    1573       100562 :   DECL_COMDAT (decl) = 0;
    1574       100562 :   DECL_WEAK (decl) = 0;
    1575       100562 :   DECL_EXTERNAL (decl) = 0;
    1576       100562 :   DECL_VISIBILITY_SPECIFIED (decl) = 0;
    1577       100562 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    1578       100562 :   TREE_PUBLIC (decl) = 0;
    1579       100562 :   DECL_DLLIMPORT_P (decl) = 0;
    1580       100562 :   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     36785172 : symtab_node::ultimate_alias_target_1 (enum availability *availability,
    1657              :                                       symtab_node *ref)
    1658              : {
    1659     36785172 :   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     36785172 :   if (availability)
    1675              :     {
    1676     12021675 :       transparent_p = transparent_alias;
    1677     12021675 :       if (!transparent_p)
    1678     12015879 :         *availability = get_availability (ref);
    1679              :       else
    1680         5796 :         *availability = AVAIL_NOT_AVAILABLE;
    1681              :     }
    1682              : 
    1683              :   symtab_node *node = this;
    1684     73561724 :   while (node)
    1685              :     {
    1686     73561724 :       if (node->alias && node->analyzed)
    1687     36776552 :         node = node->get_alias_target ();
    1688              :       else
    1689              :         {
    1690     36785172 :           if (!availability || (!transparent_p && node->analyzed))
    1691              :             ;
    1692        39737 :           else if (node->analyzed && !node->transparent_alias)
    1693          308 :             *availability = node->get_availability (ref);
    1694              :           else
    1695        39429 :             *availability = AVAIL_NOT_AVAILABLE;
    1696     36785172 :           return node;
    1697              :         }
    1698     36776552 :       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      8979069 : symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
    1719              : {
    1720      8979069 :   if (is_a <cgraph_node *> (this))
    1721              :     {
    1722     26937027 :       DECL_DECLARED_INLINE_P (decl)
    1723      8979009 :          = DECL_DECLARED_INLINE_P (target->decl);
    1724     26937027 :       DECL_DISREGARD_INLINE_LIMITS (decl)
    1725      8979009 :          = 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      8979069 :   if (TREE_PUBLIC (decl))
    1736              :     {
    1737      8958100 :       tree group;
    1738              : 
    1739      8958100 :       DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
    1740      8958100 :       DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
    1741      8958100 :       group = target->get_comdat_group ();
    1742      8958100 :       set_comdat_group (group);
    1743      8958100 :       if (group && !same_comdat_group)
    1744            0 :         add_to_same_comdat_group (target);
    1745              :     }
    1746      8979069 :   externally_visible = target->externally_visible;
    1747      8979069 : }
    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    150956304 : symtab_node::set_section_for_node (const char *section)
    1755              : {
    1756    150956304 :   const char *current = get_section ();
    1757              : 
    1758    150956304 :   if (current == section
    1759      1868935 :       || (current && section
    1760            0 :           && !strcmp (current, section)))
    1761              :     return;
    1762              : 
    1763      1868935 :   release_section_hash_entry (x_section);
    1764      1868935 :   if (!section)
    1765              :     {
    1766        27100 :       x_section = NULL;
    1767        27100 :       implicit_section = false;
    1768        27100 :       return;
    1769              :     }
    1770      1841835 :   if (!symtab->section_hash)
    1771        35939 :     symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
    1772      1841835 :   section_hash_entry **slot = symtab->section_hash->find_slot_with_hash
    1773      1841835 :     (section, htab_hash_string (section), INSERT);
    1774      1841835 :   if (*slot)
    1775        41121 :     x_section = retain_section_hash_entry (*slot);
    1776              :   else
    1777              :     {
    1778      1800714 :       int len = strlen (section);
    1779      1800714 :       *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
    1780      1800714 :       x_section->ref_count = 1;
    1781      1800714 :       x_section->name = ggc_vec_alloc<char> (len + 1);
    1782      1800714 :       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     26426347 : symtab_node::set_section_for_node (const symtab_node &other)
    1792              : {
    1793     26426347 :   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      1848168 : symtab_node::set_section_from_string (symtab_node *n, void *s)
    1811              : {
    1812      1848168 :   n->set_section_for_node ((char *)s);
    1813      1848168 :   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     26426347 : symtab_node::set_section_from_node (symtab_node *n, void *o)
    1821              : {
    1822     26426347 :   const symtab_node &other = *static_cast<const symtab_node *> (o);
    1823     26426347 :   n->set_section_for_node (other);
    1824     26426347 :   return false;
    1825              : }
    1826              : 
    1827              : /* Set section of symbol and its aliases.  */
    1828              : 
    1829              : void
    1830      1805625 : symtab_node::set_section (const char *section)
    1831              : {
    1832      1805625 :   gcc_assert (!this->alias || !this->analyzed);
    1833      1805625 :   call_for_symbol_and_aliases
    1834      1805625 :     (symtab_node::set_section_from_string, const_cast<char *>(section), true);
    1835      1805625 : }
    1836              : 
    1837              : void
    1838     26426102 : symtab_node::set_section (const symtab_node &other)
    1839              : {
    1840     26426102 :   call_for_symbol_and_aliases
    1841     26426102 :     (symtab_node::set_section_from_node, const_cast<symtab_node *>(&other), true);
    1842     26426102 : }
    1843              : 
    1844              : /* Return the initialization priority.  */
    1845              : 
    1846              : priority_type
    1847        42249 : symtab_node::get_init_priority ()
    1848              : {
    1849        42249 :   if (!this->in_init_priority_hash)
    1850              :     return DEFAULT_INIT_PRIORITY;
    1851              : 
    1852         3706 :   symbol_priority_map *h = symtab->init_priority_hash->get (this);
    1853         3706 :   return h ? h->init : DEFAULT_INIT_PRIORITY;
    1854              : }
    1855              : 
    1856              : /* Return the finalization priority.  */
    1857              : 
    1858              : priority_type
    1859         1903 : cgraph_node::get_fini_priority ()
    1860              : {
    1861         1903 :   if (!this->in_init_priority_hash)
    1862              :     return DEFAULT_INIT_PRIORITY;
    1863         1825 :   symbol_priority_map *h = symtab->init_priority_hash->get (this);
    1864         1825 :   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         5126 : symtab_node::priority_info (void)
    1873              : {
    1874         5126 :   if (!symtab->init_priority_hash)
    1875         3354 :     symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
    1876              : 
    1877         5126 :   bool existed;
    1878         5126 :   symbol_priority_map *h
    1879         5126 :     = &symtab->init_priority_hash->get_or_insert (this, &existed);
    1880         5126 :   if (!existed)
    1881              :     {
    1882         5106 :       h->init = DEFAULT_INIT_PRIORITY;
    1883         5106 :       h->fini = DEFAULT_INIT_PRIORITY;
    1884         5106 :       in_init_priority_hash = true;
    1885              :     }
    1886              : 
    1887         5126 :   return h;
    1888              : }
    1889              : 
    1890              : /* Set initialization priority to PRIORITY.  */
    1891              : 
    1892              : void
    1893        23155 : symtab_node::set_init_priority (priority_type priority)
    1894              : {
    1895        23155 :   symbol_priority_map *h;
    1896              : 
    1897        23155 :   if (is_a <cgraph_node *> (this))
    1898        23110 :     gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
    1899              : 
    1900        23155 :   if (priority == DEFAULT_INIT_PRIORITY)
    1901              :     {
    1902        19648 :       gcc_assert (get_init_priority() == priority);
    1903              :       return;
    1904              :     }
    1905         3507 :   h = priority_info ();
    1906         3507 :   h->init = priority;
    1907              : }
    1908              : 
    1909              : /* Set finalization priority to PRIORITY.  */
    1910              : 
    1911              : void
    1912         1632 : cgraph_node::set_fini_priority (priority_type priority)
    1913              : {
    1914         1632 :   symbol_priority_map *h;
    1915              : 
    1916         1632 :   gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
    1917              : 
    1918         1632 :   if (priority == DEFAULT_INIT_PRIORITY)
    1919              :     {
    1920           13 :       gcc_assert (get_fini_priority() == priority);
    1921              :       return;
    1922              :     }
    1923         1619 :   h = priority_info ();
    1924         1619 :   h->fini = priority;
    1925              : }
    1926              : 
    1927              : /* Worker for symtab_resolve_alias.  */
    1928              : 
    1929              : bool
    1930         3140 : symtab_node::set_implicit_section (symtab_node *n,
    1931              :                                    void *data ATTRIBUTE_UNUSED)
    1932              : {
    1933         3140 :   n->implicit_section = true;
    1934         3140 :   return false;
    1935              : }
    1936              : 
    1937              : /* Add reference recording that symtab node is alias of TARGET.
    1938              :    The function can fail in the case of aliasing cycles; in this case
    1939              :    it returns false.  */
    1940              : 
    1941              : bool
    1942      8676312 : symtab_node::resolve_alias (symtab_node *target, bool transparent)
    1943              : {
    1944      8676312 :   symtab_node *n;
    1945              : 
    1946      8676312 :   gcc_assert (!analyzed && !ref_list.references.length ());
    1947              : 
    1948              :   /* Never let cycles to creep into the symbol table alias references;
    1949              :      those will make alias walkers to be infinite.  */
    1950      8680769 :   for (n = target; n && n->alias;
    1951         4671 :        n = n->analyzed ? n->get_alias_target () : NULL)
    1952         4673 :     if (n == this)
    1953              :        {
    1954            2 :          if (is_a <cgraph_node *> (this))
    1955            2 :            error ("function %q+D part of alias cycle", decl);
    1956            0 :          else if (is_a <varpool_node *> (this))
    1957            0 :            error ("variable %q+D part of alias cycle", decl);
    1958              :          else
    1959            0 :            gcc_unreachable ();
    1960            2 :          alias = false;
    1961            2 :          return false;
    1962              :        }
    1963              : 
    1964              :   /* "analyze" the node - i.e. mark the reference.  */
    1965      8676310 :   definition = true;
    1966      8676310 :   alias = true;
    1967      8676310 :   analyzed = true;
    1968      8676310 :   transparent |= transparent_alias;
    1969      8676310 :   transparent_alias = transparent;
    1970      8676310 :   if (transparent)
    1971           54 :     while (target->transparent_alias && target->analyzed)
    1972            0 :       target = target->get_alias_target ();
    1973      8676310 :   create_reference (target, IPA_REF_ALIAS, NULL);
    1974              : 
    1975              :   /* Add alias into the comdat group of its target unless it is already there.  */
    1976      8676310 :   if (same_comdat_group)
    1977      4013727 :     remove_from_same_comdat_group ();
    1978      8676310 :   set_comdat_group (NULL);
    1979      8676310 :   if (target->get_comdat_group ())
    1980      8487959 :     add_to_same_comdat_group (target);
    1981              : 
    1982      8676323 :   if ((get_section () != target->get_section ()
    1983      8676315 :        || target->get_comdat_group ()) && get_section () && !implicit_section)
    1984              :     {
    1985            2 :       error ("section of alias %q+D must match section of its target", decl);
    1986              :     }
    1987      8676310 :   set_section (*target);
    1988      8676310 :   if (target->implicit_section)
    1989         2954 :     call_for_symbol_and_aliases (set_implicit_section, NULL, true);
    1990              : 
    1991              :   /* Alias targets become redundant after alias is resolved into an reference.
    1992              :      We do not want to keep it around or we would have to mind updating them
    1993              :      when renaming symbols.  */
    1994      8676310 :   alias_target = NULL;
    1995              : 
    1996      8676310 :   if (!transparent && cpp_implicit_alias && symtab->state >= CONSTRUCTION)
    1997        16967 :     fixup_same_cpp_alias_visibility (target);
    1998              : 
    1999              :   /* If alias has address taken, so does the target.  */
    2000      8676310 :   if (address_taken)
    2001          973 :     target->ultimate_alias_target ()->address_taken = true;
    2002              : 
    2003              :   /* All non-transparent aliases of THIS are now in fact aliases of TARGET.
    2004              :      If alias is transparent, also all transparent aliases of THIS are now
    2005              :      aliases of TARGET.
    2006              :      Also merge same comdat group lists.  */
    2007              :   ipa_ref *ref;
    2008      8676555 :   for (unsigned i = 0; iterate_direct_aliases (i, ref);)
    2009              :     {
    2010          245 :       struct symtab_node *alias_alias = ref->referring;
    2011          245 :       if (alias_alias->get_comdat_group ())
    2012              :         {
    2013          184 :           alias_alias->remove_from_same_comdat_group ();
    2014          184 :           alias_alias->set_comdat_group (NULL);
    2015          184 :           if (target->get_comdat_group ())
    2016          184 :             alias_alias->add_to_same_comdat_group (target);
    2017              :         }
    2018          245 :       if ((!alias_alias->transparent_alias
    2019          233 :            && !alias_alias->symver)
    2020           12 :           || transparent)
    2021              :         {
    2022          245 :           alias_alias->remove_all_references ();
    2023          245 :           alias_alias->create_reference (target, IPA_REF_ALIAS, NULL);
    2024              :         }
    2025            0 :       else i++;
    2026              :     }
    2027              :   return true;
    2028              : }
    2029              : 
    2030              : /* Worker searching noninterposable alias.  */
    2031              : 
    2032              : bool
    2033        61550 : symtab_node::noninterposable_alias (symtab_node *node, void *data)
    2034              : {
    2035        61550 :   if (!node->transparent_alias && decl_binds_to_current_def_p (node->decl))
    2036              :     {
    2037        59272 :       symtab_node *fn = node->ultimate_alias_target ();
    2038              : 
    2039              :       /* Ensure that the alias is well formed this may not be the case
    2040              :          of user defined aliases and currently it is not always the case
    2041              :          of C++ same body aliases (that is a bug).  */
    2042        59272 :       if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
    2043        59272 :           || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
    2044        59272 :           || (TREE_CODE (node->decl) == FUNCTION_DECL
    2045       118544 :               && flags_from_decl_or_type (node->decl)
    2046        59272 :                  != flags_from_decl_or_type (fn->decl))
    2047       118526 :           || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
    2048           20 :         return false;
    2049        59252 :       *(symtab_node **)data = node;
    2050        59252 :       return true;
    2051              :     }
    2052              :   return false;
    2053              : }
    2054              : 
    2055              : /* If node cannot be overwriten by static or dynamic linker to point to
    2056              :    different definition, return NODE. Otherwise look for alias with such
    2057              :    property and if none exists, introduce new one.  */
    2058              : 
    2059              : symtab_node *
    2060        60251 : symtab_node::noninterposable_alias (void)
    2061              : {
    2062        60251 :   tree new_decl;
    2063        60251 :   symtab_node *new_node = NULL;
    2064              : 
    2065              :   /* First try to look up existing alias or base object
    2066              :      (if that is already non-overwritable).  */
    2067        60251 :   symtab_node *node = ultimate_alias_target ();
    2068        60251 :   gcc_assert (!node->alias && !node->weakref);
    2069        60251 :   node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
    2070              :                                      (void *)&new_node, true);
    2071        60251 :   if (new_node)
    2072              :     return new_node;
    2073              : 
    2074              :   /* If aliases aren't supported by the assembler, fail.  */
    2075          999 :   if (!TARGET_SUPPORTS_ALIASES)
    2076              :     return NULL;
    2077          999 :   else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)))
    2078              :     return NULL;
    2079              : 
    2080              :   /* Otherwise create a new one.  */
    2081          998 :   new_decl = copy_node (node->decl);
    2082          998 :   DECL_DLLIMPORT_P (new_decl) = 0;
    2083          998 :   tree name = clone_function_name (node->decl, "localalias");
    2084          998 :   if (!flag_wpa)
    2085              :     {
    2086              :       unsigned long num = 0;
    2087              :       /* In the rare case we already have a localalias, but the above
    2088              :          node->call_for_symbol_and_aliases call didn't find any suitable,
    2089              :          iterate until we find one not used yet.  */
    2090          992 :       while (symtab_node::get_for_asmname (name))
    2091            0 :         name = clone_function_name (node->decl, "localalias", num++);
    2092              :     }
    2093          998 :   DECL_NAME (new_decl) = name;
    2094          998 :   if (TREE_CODE (new_decl) == FUNCTION_DECL)
    2095          996 :     DECL_STRUCT_FUNCTION (new_decl) = NULL;
    2096          998 :   DECL_INITIAL (new_decl) = NULL;
    2097          998 :   SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
    2098          998 :   SET_DECL_RTL (new_decl, NULL);
    2099              : 
    2100              :   /* Update the properties.  */
    2101          998 :   DECL_EXTERNAL (new_decl) = 0;
    2102          998 :   TREE_PUBLIC (new_decl) = 0;
    2103          998 :   DECL_COMDAT (new_decl) = 0;
    2104          998 :   DECL_WEAK (new_decl) = 0;
    2105              : 
    2106              :   /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag.  */
    2107          998 :   DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
    2108          998 :   if (TREE_CODE (new_decl) == FUNCTION_DECL)
    2109              :     {
    2110          996 :       DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
    2111          996 :       DECL_STATIC_DESTRUCTOR (new_decl) = 0;
    2112          996 :       new_node = cgraph_node::create_alias (new_decl, node->decl);
    2113              : 
    2114         1992 :       cgraph_node *new_cnode = dyn_cast <cgraph_node *> (new_node),
    2115          996 :                    *cnode = dyn_cast <cgraph_node *> (node);
    2116              : 
    2117          996 :       new_cnode->unit_id = cnode->unit_id;
    2118          996 :       new_cnode->merged_comdat = cnode->merged_comdat;
    2119          996 :       new_cnode->merged_extern_inline = cnode->merged_extern_inline;
    2120              :     }
    2121              :   else
    2122              :     {
    2123            2 :       TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
    2124            2 :       DECL_INITIAL (new_decl) = error_mark_node;
    2125            2 :       new_node = varpool_node::create_alias (new_decl, node->decl);
    2126              :     }
    2127          998 :   new_node->resolve_alias (node);
    2128          998 :   gcc_assert (decl_binds_to_current_def_p (new_decl)
    2129              :               && targetm.binds_local_p (new_decl));
    2130          998 :   return new_node;
    2131              : }
    2132              : 
    2133              : /* Return true if symtab node and TARGET represents
    2134              :    semantically equivalent symbols.  */
    2135              : 
    2136              : bool
    2137       357001 : symtab_node::semantically_equivalent_p (symtab_node *target)
    2138              : {
    2139       357001 :   enum availability avail;
    2140       357001 :   symtab_node *ba;
    2141       357001 :   symtab_node *bb;
    2142              : 
    2143              :   /* Equivalent functions are equivalent.  */
    2144       357001 :   if (decl == target->decl)
    2145              :     return true;
    2146              : 
    2147              :   /* If symbol is not overwritable by different implementation,
    2148              :      walk to the base object it defines.  */
    2149       266963 :   ba = ultimate_alias_target (&avail);
    2150       266963 :   if (avail >= AVAIL_AVAILABLE)
    2151              :     {
    2152        52581 :       if (target == ba)
    2153              :         return true;
    2154              :     }
    2155              :   else
    2156              :     ba = this;
    2157       266947 :   bb = target->ultimate_alias_target (&avail);
    2158       266947 :   if (avail >= AVAIL_AVAILABLE)
    2159              :     {
    2160        52050 :       if (this == bb)
    2161              :         return true;
    2162              :     }
    2163              :   else
    2164              :     bb = target;
    2165       266888 :   return bb == ba;
    2166              : }
    2167              : 
    2168              : /* Classify symbol symtab node for partitioning.  */
    2169              : 
    2170              : enum symbol_partitioning_class
    2171      2296457 : symtab_node::get_partitioning_class (void)
    2172              : {
    2173              :   /* Inline clones are always duplicated.
    2174              :      This include external declarations.   */
    2175      2296457 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
    2176              : 
    2177      2296457 :   if (DECL_ABSTRACT_P (decl))
    2178              :     return SYMBOL_EXTERNAL;
    2179              : 
    2180      2296457 :   if (cnode && cnode->inlined_to)
    2181              :     return SYMBOL_DUPLICATE;
    2182              : 
    2183              :   /* Transparent aliases are always duplicated.  */
    2184      2232875 :   if (transparent_alias)
    2185           66 :     return definition ? SYMBOL_DUPLICATE : SYMBOL_EXTERNAL;
    2186              : 
    2187              :   /* External declarations are external.  */
    2188      2232809 :   if (DECL_EXTERNAL (decl))
    2189              :     return SYMBOL_EXTERNAL;
    2190              : 
    2191              :   /* Even static aliases of external functions as external.  Those can happen
    2192              :      when COMDAT got resolved to non-IL implementation.  */
    2193      2073526 :   if (alias && DECL_EXTERNAL (ultimate_alias_target ()->decl))
    2194              :     return SYMBOL_EXTERNAL;
    2195              : 
    2196      2073526 :   if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
    2197              :     {
    2198       935176 :       if (alias && definition && !ultimate_alias_target ()->definition)
    2199              :         return SYMBOL_EXTERNAL;
    2200              :       /* Constant pool references use local symbol names that cannot
    2201              :          be promoted global.  We should never put into a constant pool
    2202              :          objects that cannot be duplicated across partitions.  */
    2203       935176 :       if (DECL_IN_CONSTANT_POOL (decl))
    2204              :         return SYMBOL_DUPLICATE;
    2205       934986 :       if (DECL_HARD_REGISTER (decl))
    2206              :         return SYMBOL_DUPLICATE;
    2207       934890 :       gcc_checking_assert (vnode->definition);
    2208              :     }
    2209              :   /* Functions that are cloned may stay in callgraph even if they are unused.
    2210              :      Handle them as external; compute_ltrans_boundary take care to make
    2211              :      proper things to happen (i.e. to make them appear in the boundary but
    2212              :      with body streamed, so clone can me materialized).  */
    2213      1138350 :   else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
    2214              :     return SYMBOL_EXTERNAL;
    2215              : 
    2216              :   /* Linker discardable symbols are duplicated to every use unless they are
    2217              :      keyed.  */
    2218      2083375 :   if (DECL_ONE_ONLY (decl)
    2219        13833 :       && !force_output
    2220        13789 :       && !forced_by_abi
    2221      2081705 :       && !used_from_object_file_p ())
    2222              :     return SYMBOL_DUPLICATE;
    2223              : 
    2224              :   return SYMBOL_PARTITION;
    2225              : }
    2226              : 
    2227              : /* Return true when symbol is known to be non-zero, assume that
    2228              :    flag_delete_null_pointer_checks is equal to delete_null_pointer_checks.  */
    2229              : 
    2230              : bool
    2231     14314880 : symtab_node::nonzero_address (bool delete_null_pointer_checks)
    2232              : {
    2233              :   /* Weakrefs may be NULL when their target is not defined.  */
    2234     14314880 :   if (alias && weakref)
    2235              :     {
    2236         2746 :       if (analyzed)
    2237              :         {
    2238          188 :           symtab_node *target = ultimate_alias_target ();
    2239              : 
    2240          188 :           if (target->alias && target->weakref)
    2241              :             return false;
    2242              :           /* We cannot recurse to target::nonzero.  It is possible that the
    2243              :              target is used only via the alias.
    2244              :              We may walk references and look for strong use, but we do not know
    2245              :              if this strong use will survive to final binary, so be
    2246              :              conservative here.
    2247              :              ??? Maybe we could do the lookup during late optimization that
    2248              :              could be useful to eliminate the NULL pointer checks in LTO
    2249              :              programs.  */
    2250            0 :           if (target->definition && !DECL_EXTERNAL (target->decl))
    2251              :               return true;
    2252            0 :           if (target->resolution != LDPR_UNKNOWN
    2253              :               && target->resolution != LDPR_UNDEF
    2254            0 :               && !target->can_be_discarded_p ()
    2255            0 :               && delete_null_pointer_checks)
    2256              :             return true;
    2257            0 :           return false;
    2258              :         }
    2259              :       else
    2260              :         return false;
    2261              :     }
    2262              : 
    2263              :   /* With !flag_delete_null_pointer_checks we assume that symbols may
    2264              :      bind to NULL. This is on by default on embedded targets only.
    2265              : 
    2266              :      Otherwise all non-WEAK symbols must be defined and thus non-NULL or
    2267              :      linking fails.  Important case of WEAK we want to do well are comdats,
    2268              :      which also must be defined somewhere.
    2269              : 
    2270              :      When parsing, beware the cases when WEAK attribute is added later.  */
    2271     18044521 :   if ((!DECL_WEAK (decl) || DECL_COMDAT (decl))
    2272     15291397 :       && delete_null_pointer_checks)
    2273              :     {
    2274     11548400 :       refuse_visibility_changes = true;
    2275     11548400 :       return true;
    2276              :     }
    2277              : 
    2278              :   /* If target is defined and not extern, we know it will be
    2279              :      output and thus it will bind to non-NULL.
    2280              :      Play safe for flag_delete_null_pointer_checks where weak definition may
    2281              :      be re-defined by NULL.  */
    2282      2738654 :   if (definition && !DECL_EXTERNAL (decl)
    2283      5502387 :       && (delete_null_pointer_checks || !DECL_WEAK (decl)))
    2284              :     {
    2285      2737936 :       if (!DECL_WEAK (decl))
    2286         9110 :         refuse_visibility_changes = true;
    2287      2737936 :       return true;
    2288              :     }
    2289              : 
    2290              :   /* As the last resort, check the resolution info.  */
    2291        25798 :   if (resolution != LDPR_UNKNOWN
    2292              :       && resolution != LDPR_UNDEF
    2293            0 :       && !can_be_discarded_p ()
    2294        25798 :       && delete_null_pointer_checks)
    2295              :     return true;
    2296              :   return false;
    2297              : }
    2298              : 
    2299              : /* Return true when symbol is known to be non-zero.  */
    2300              : 
    2301              : bool
    2302     14314019 : symtab_node::nonzero_address ()
    2303              : {
    2304     14314019 :   return nonzero_address (flag_delete_null_pointer_checks);
    2305              : }
    2306              : 
    2307              : /* Return 0 if symbol is known to have different address than S2,
    2308              :    Return 1 if symbol is known to have same address as S2,
    2309              :    return -1 otherwise.
    2310              : 
    2311              :    If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
    2312              :    and S2 is going to be accessed.  This eliminates the situations when
    2313              :    either THIS or S2 is NULL and is useful for comparing bases when deciding
    2314              :    about memory aliasing.  */
    2315              : int
    2316     85495923 : symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed)
    2317              : {
    2318     85495923 :   enum availability avail1, avail2;
    2319              : 
    2320              :   /* A Shortcut: equivalent symbols are always equivalent.  */
    2321     85495923 :   if (this == s2)
    2322              :     return 1;
    2323              : 
    2324              :   /* Unwind transparent aliases first; those are always equal to their
    2325              :      target.  */
    2326     84968523 :   if (this->transparent_alias && this->analyzed)
    2327            0 :     return this->get_alias_target ()->equal_address_to (s2);
    2328     84968523 :   while (s2->transparent_alias && s2->analyzed)
    2329            0 :     s2 = s2->get_alias_target();
    2330              : 
    2331     84968523 :   if (this == s2)
    2332              :     return 1;
    2333              : 
    2334              :   /* For non-interposable aliases, lookup and compare their actual definitions.
    2335              :      Also check if the symbol needs to bind to given definition.  */
    2336     84968523 :   symtab_node *rs1 = ultimate_alias_target (&avail1);
    2337     84968523 :   symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
    2338     84968523 :   bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
    2339     84968523 :   bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
    2340     84968523 :   bool really_binds_local1 = binds_local1;
    2341     84968523 :   bool really_binds_local2 = binds_local2;
    2342              : 
    2343              :   /* Addresses of vtables and virtual functions cannot be used by user
    2344              :      code and are used only within speculation.  In this case we may make
    2345              :      symbol equivalent to its alias even if interposition may break this
    2346              :      rule.  Doing so will allow us to turn speculative inlining into
    2347              :      non-speculative more aggressively.  */
    2348     84968523 :   if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
    2349              :     binds_local1 = true;
    2350     84968523 :   if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
    2351     84968523 :     binds_local2 = true;
    2352              : 
    2353              :   /* If both definitions are available we know that even if they are bound
    2354              :      to other unit they must be defined same way and therefore we can use
    2355              :      equivalence test.  */
    2356     84968523 :   if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
    2357              :     binds_local1 = binds_local2 = true;
    2358              : 
    2359     84968523 :   if (binds_local1 && binds_local2 && rs1 == rs2)
    2360              :     {
    2361              :       /* We made use of the fact that alias is not weak.  */
    2362          358 :       if (rs1 != this)
    2363          232 :         refuse_visibility_changes = true;
    2364          358 :       if (rs2 != s2)
    2365          126 :         s2->refuse_visibility_changes = true;
    2366          358 :       return 1;
    2367              :     }
    2368              : 
    2369              :   /* If both symbols may resolve to NULL, we cannot really prove them
    2370              :      different.  */
    2371     84968165 :   if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ())
    2372              :     return -1;
    2373              : 
    2374              :   /* Except for NULL, functions and variables never overlap.  */
    2375     84968106 :   if (TREE_CODE (decl) != TREE_CODE (s2->decl))
    2376              :     return 0;
    2377              : 
    2378              :   /* If one of the symbols is unresolved alias, punt.  */
    2379     84798412 :   if (rs1->alias || rs2->alias)
    2380              :     return -1;
    2381              : 
    2382              :   /* If we have a non-interposable definition of at least one of the symbols
    2383              :      and the other symbol is different, we know other unit cannot interpose
    2384              :      it to the first symbol; all aliases of the definition needs to be
    2385              :      present in the current unit.  */
    2386     84798404 :   if (((really_binds_local1 || really_binds_local2)
    2387              :       /* If we have both definitions and they are different, we know they
    2388              :          will be different even in units they binds to.  */
    2389     11539272 :        || (binds_local1 && binds_local2))
    2390     73343550 :       && rs1 != rs2)
    2391              :     {
    2392              :       /* We make use of the fact that one symbol is not alias of the other
    2393              :          and that the definition is non-interposable.  */
    2394     73343457 :       refuse_visibility_changes = true;
    2395     73343457 :       s2->refuse_visibility_changes = true;
    2396     73343457 :       rs1->refuse_visibility_changes = true;
    2397     73343457 :       rs2->refuse_visibility_changes = true;
    2398     73343457 :       return 0;
    2399              :     }
    2400              : 
    2401     11454947 :   if (rs1 == rs2)
    2402              :     return -1;
    2403              : 
    2404              :   /* If the FE tells us at least one of the decls will never be aliased nor
    2405              :      overlapping with other vars in some other way, return 0.  */
    2406     11454854 :   if (VAR_P (decl)
    2407     11454854 :       && (lookup_attribute ("non overlapping", DECL_ATTRIBUTES (decl))
    2408     11450898 :           || lookup_attribute ("non overlapping", DECL_ATTRIBUTES (s2->decl))))
    2409         3929 :     return 0;
    2410              : 
    2411              :   /* TODO: Alias oracle basically assume that addresses of global variables
    2412              :      are different unless they are declared as alias of one to another while
    2413              :      the code folding comparisons doesn't.
    2414              :      We probably should be consistent and use this fact here, too, but for
    2415              :      the moment return false only when we are called from the alias oracle.
    2416              :      Return 0 in C constant initializers and C++ manifestly constant
    2417              :      expressions, the likelyhood that different vars will be aliases is
    2418              :      small and returning -1 lets us reject too many initializers.  */
    2419     11450925 :   if (memory_accessed || folding_initializer)
    2420              :     return 0;
    2421              : 
    2422              :   return -1;
    2423              : }
    2424              : 
    2425              : /* Worker for call_for_symbol_and_aliases.  */
    2426              : 
    2427              : bool
    2428       146814 : symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
    2429              :                                                               void *),
    2430              :                                             void *data,
    2431              :                                             bool include_overwritable)
    2432              : {
    2433       146814 :   ipa_ref *ref;
    2434       318396 :   FOR_EACH_ALIAS (this, ref)
    2435              :     {
    2436       172861 :       symtab_node *alias = ref->referring;
    2437       172861 :       if (include_overwritable
    2438       172861 :           || alias->get_availability () > AVAIL_INTERPOSABLE)
    2439       172861 :         if (alias->call_for_symbol_and_aliases (callback, data,
    2440              :                                               include_overwritable))
    2441              :           return true;
    2442              :     }
    2443              :   return false;
    2444              : }
    2445              : 
    2446              : /* Return true if address of N is possibly compared.  */
    2447              : 
    2448              : static bool
    2449       612818 : address_matters_1 (symtab_node *n, void *)
    2450              : {
    2451       612818 :   struct ipa_ref *ref;
    2452              : 
    2453       612818 :   if (!n->address_can_be_compared_p ())
    2454              :     return false;
    2455       600549 :   if (n->externally_visible || n->force_output || n->ref_by_asm)
    2456              :     return true;
    2457              : 
    2458       506081 :   for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
    2459       447356 :     if (ref->address_matters_p ())
    2460              :       return true;
    2461              :   return false;
    2462              : }
    2463              : 
    2464              : /* Return true if symbol's address may possibly be compared to other
    2465              :    symbol's address.  */
    2466              : 
    2467              : bool
    2468       586109 : symtab_node::address_matters_p ()
    2469              : {
    2470       586109 :   gcc_assert (!alias);
    2471       586109 :   return call_for_symbol_and_aliases (address_matters_1, NULL, true);
    2472              : }
    2473              : 
    2474              : /* Return true if symbol's alignment may be increased.  */
    2475              : 
    2476              : bool
    2477        30046 : symtab_node::can_increase_alignment_p (void)
    2478              : {
    2479        30046 :   symtab_node *target = ultimate_alias_target ();
    2480              : 
    2481              :   /* For now support only variables.  */
    2482        30046 :   if (!VAR_P (decl))
    2483              :     return false;
    2484              : 
    2485              :   /* With -fno-toplevel-reorder we may have already output the constant.  */
    2486        30046 :   if (TREE_ASM_WRITTEN (target->decl))
    2487              :     return false;
    2488              : 
    2489              :   /* If target is already placed in an anchor, we cannot touch its
    2490              :      alignment.  */
    2491        29359 :   if (DECL_RTL_SET_P (target->decl)
    2492        14172 :       && MEM_P (DECL_RTL (target->decl))
    2493        43531 :       && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
    2494              :     return false;
    2495              : 
    2496              :   /* Constant pool entries may be shared.  */
    2497        29359 :   if (DECL_IN_CONSTANT_POOL (target->decl))
    2498              :     return false;
    2499              : 
    2500              :   /* We cannot change alignment of symbols that may bind to symbols
    2501              :      in other translation unit that may contain a definition with lower
    2502              :      alignment.  */
    2503        27237 :   if (!decl_binds_to_current_def_p (decl))
    2504              :     return false;
    2505              : 
    2506              :   /* When compiling partition, be sure the symbol is not output by other
    2507              :      partition.  */
    2508        17137 :   if (flag_ltrans
    2509        17137 :       && (target->in_other_partition
    2510          265 :           || target->get_partitioning_class () == SYMBOL_DUPLICATE))
    2511            0 :     return false;
    2512              : 
    2513              :   /* Do not override the alignment as specified by the ABI when the used
    2514              :      attribute is set.  */
    2515        17137 :   if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl))
    2516              :     return false;
    2517              : 
    2518              :   /* Do not override explicit alignment set by the user when an explicit
    2519              :      section name is also used.  This is a common idiom used by many
    2520              :      software projects.  */
    2521        17137 :   if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section)
    2522              :     return false;
    2523              : 
    2524              :   return true;
    2525              : }
    2526              : 
    2527              : /* Worker for symtab_node::increase_alignment.  */
    2528              : 
    2529              : static bool
    2530         5160 : increase_alignment_1 (symtab_node *n, void *v)
    2531              : {
    2532         5160 :   unsigned int align = (size_t)v;
    2533         5160 :   if (DECL_ALIGN (n->decl) < align
    2534         5160 :       && n->can_increase_alignment_p ())
    2535              :     {
    2536         4006 :       SET_DECL_ALIGN (n->decl, align);
    2537         4006 :       DECL_USER_ALIGN (n->decl) = 1;
    2538              :     }
    2539         5160 :   return false;
    2540              : }
    2541              : 
    2542              : /* Increase alignment of THIS to ALIGN.  */
    2543              : 
    2544              : void
    2545         4612 : symtab_node::increase_alignment (unsigned int align)
    2546              : {
    2547         4612 :   gcc_assert (can_increase_alignment_p () && align <= MAX_OFILE_ALIGNMENT);
    2548         4612 :   ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
    2549         4612 :                                                         (void *)(size_t) align,
    2550              :                                                         true);
    2551         4612 :   gcc_assert (DECL_ALIGN (decl) >= align);
    2552         4612 : }
    2553              : 
    2554              : /* Helper for symtab_node::definition_alignment.  */
    2555              : 
    2556              : static bool
    2557      1690358 : get_alignment_1 (symtab_node *n, void *v)
    2558              : {
    2559      1690358 :   *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
    2560      1690358 :   return false;
    2561              : }
    2562              : 
    2563              : /* Return desired alignment of the definition.  This is NOT alignment useful
    2564              :    to access THIS, because THIS may be interposable and DECL_ALIGN should
    2565              :    be used instead.  It however must be guaranteed when output definition
    2566              :    of THIS.  */
    2567              : 
    2568              : unsigned int
    2569      1629955 : symtab_node::definition_alignment ()
    2570              : {
    2571      1629955 :   unsigned int align = 0;
    2572      1629955 :   gcc_assert (!alias);
    2573      1629955 :   call_for_symbol_and_aliases (get_alignment_1, &align, true);
    2574      1629955 :   return align;
    2575              : }
    2576              : 
    2577              : /* Return symbol used to separate symbol name from suffix.  */
    2578              : 
    2579              : char
    2580       308785 : symbol_table::symbol_suffix_separator ()
    2581              : {
    2582              : #ifndef NO_DOT_IN_LABEL
    2583       308785 :   return '.';
    2584              : #elif !defined NO_DOLLAR_IN_LABEL
    2585              :   return '$';
    2586              : #else
    2587              :   return '_';
    2588              : #endif
    2589              : }
    2590              : 
    2591              : /* Return true when references to this symbol from REF must bind to current
    2592              :    definition in final executable.  */
    2593              : 
    2594              : bool
    2595     94418470 : symtab_node::binds_to_current_def_p (symtab_node *ref)
    2596              : {
    2597     94418470 :   if (!definition && !in_other_partition)
    2598              :     return false;
    2599     46253315 :   if (transparent_alias)
    2600           13 :     return definition
    2601           13 :            && get_alias_target()->binds_to_current_def_p (ref);
    2602     46253302 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
    2603     46253302 :   if (cnode && cnode->ifunc_resolver)
    2604              :     return false;
    2605     46253202 :   if (decl_binds_to_current_def_p (decl))
    2606              :     return true;
    2607              : 
    2608              :   /* Inline clones always binds locally.  */
    2609     21607487 :   if (cnode && cnode->inlined_to)
    2610              :     return true;
    2611              : 
    2612     21582079 :   if (DECL_EXTERNAL (decl))
    2613              :     return false;
    2614              : 
    2615     19119432 :   gcc_assert (externally_visible);
    2616              : 
    2617     19119432 :   if (ref)
    2618              :     {
    2619       143512 :       cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
    2620       143512 :       if (cref)
    2621       143512 :         ref = cref->inlined_to;
    2622              :     }
    2623              : 
    2624              :   /* If this is a reference from symbol itself and there are no aliases, we
    2625              :      may be sure that the symbol was not interposed by something else because
    2626              :      the symbol itself would be unreachable otherwise.  This is important
    2627              :      to optimize recursive functions well.
    2628              : 
    2629              :      This assumption may be broken by inlining: if symbol is interposable
    2630              :      but the body is available (i.e. declared inline), inliner may make
    2631              :      the body reachable even with interposition.  */
    2632          479 :   if (this == ref && !has_aliases_p ()
    2633       143914 :       && (!cnode
    2634          402 :           || symtab->state >= IPA_SSA_AFTER_INLINING
    2635            0 :           || get_availability () >= AVAIL_INTERPOSABLE))
    2636          402 :     return true;
    2637              : 
    2638              : 
    2639              :   /* References within one comdat group are always bound in a group.  */
    2640     19119030 :   if (ref
    2641        70318 :       && symtab->state >= IPA_SSA_AFTER_INLINING
    2642        70318 :       && get_comdat_group ()
    2643     19189344 :       && get_comdat_group () == ref->get_comdat_group ())
    2644              :     return true;
    2645              : 
    2646              :   return false;
    2647              : }
    2648              : 
    2649              : /* Return true if symbol should be output to the symbol table.  */
    2650              : 
    2651              : bool
    2652      1195940 : symtab_node::output_to_lto_symbol_table_p (void)
    2653              : {
    2654              :   /* Only externally visible symbols matter.  */
    2655      1195940 :   if (!TREE_PUBLIC (decl))
    2656              :     return false;
    2657      1125660 :   if (!real_symbol_p ())
    2658              :     return false;
    2659              :   /* FIXME: variables probably should not be considered as real symbols at
    2660              :      first place.  */
    2661      1125660 :   if (VAR_P (decl) && DECL_HARD_REGISTER (decl))
    2662              :     return false;
    2663       658004 :   if (TREE_CODE (decl) == FUNCTION_DECL && !definition
    2664      1590842 :       && fndecl_built_in_p (decl))
    2665              :     {
    2666              :       /* Builtins like those for most math functions have actual implementations
    2667              :          in libraries so make sure to output references into the symbol table to
    2668              :          make those libraries referenced.  Note this is incomplete handling for
    2669              :          now and only covers math functions.  */
    2670        41394 :       return builtin_with_linkage_p (decl);
    2671              :     }
    2672              : 
    2673              :   /* We have real symbol that should be in symbol table.  However try to trim
    2674              :      down the references to libraries bit more because linker will otherwise
    2675              :      bring unnecessary object files into the final link.
    2676              :      FIXME: The following checks can easily be confused i.e. by self recursive
    2677              :      function or self-referring variable.  */
    2678              : 
    2679              :   /* We keep external functions in symtab for sake of inlining
    2680              :      and devirtualization.  We do not want to see them in symbol table as
    2681              :      references unless they are really used.  */
    2682      1084242 :   cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
    2683       616610 :   if (cnode && (!definition || DECL_EXTERNAL (decl))
    2684       424042 :       && cnode->callers)
    2685              :     return true;
    2686              : 
    2687              :  /* Ignore all references from external vars initializers - they are not really
    2688              :     part of the compilation unit until they are used by folding.  Some symbols,
    2689              :     like references to external construction vtables cannot be referred to at
    2690              :     all.  We decide this at can_refer_decl_in_current_unit_p.  */
    2691      1062094 :  if (!definition || DECL_EXTERNAL (decl))
    2692              :     {
    2693              :       int i;
    2694              :       struct ipa_ref *ref;
    2695       408444 :       for (i = 0; iterate_referring (i, ref); i++)
    2696              :         {
    2697       408398 :           if (ref->use == IPA_REF_ALIAS)
    2698           36 :             continue;
    2699       816770 :           if (is_a <cgraph_node *> (ref->referring))
    2700              :             return true;
    2701       403078 :           if (!DECL_EXTERNAL (ref->referring->decl))
    2702              :             return true;
    2703              :         }
    2704              :       return false;
    2705              :     }
    2706              :   return true;
    2707              : }
        

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.