LCOV - code coverage report
Current view: top level - gcc - symtab.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.1 % 1234 1050
Test Date: 2024-04-13 14:00:49 Functions: 90.8 % 87 79
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.1-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.