annotate gcc/symtab.c @ 158:494b0b89df80 default tip

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