]>
Commit | Line | Data |
---|---|---|
0704fb2e | 1 | /* Symbol table. |
d353bf18 | 2 | Copyright (C) 2012-2015 Free Software Foundation, Inc. |
0704fb2e | 3 | Contributed by Jan Hubicka |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 3, or (at your option) any later | |
10 | version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING3. If not see | |
19 | <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
9ef16211 | 24 | #include "backend.h" |
25 | #include "tree.h" | |
26 | #include "gimple.h" | |
9ed99284 | 27 | #include "rtl.h" |
b20a8bb4 | 28 | #include "alias.h" |
b20a8bb4 | 29 | #include "fold-const.h" |
9ed99284 | 30 | #include "print-tree.h" |
31 | #include "varasm.h" | |
9ed99284 | 32 | #include "emit-rtl.h" |
bc61cadb | 33 | #include "internal-fn.h" |
0704fb2e | 34 | #include "tree-inline.h" |
18841b0c | 35 | #include "langhooks.h" |
0704fb2e | 36 | #include "cgraph.h" |
cfbe30aa | 37 | #include "diagnostic.h" |
3e7775f6 | 38 | #include "timevar.h" |
f61de240 | 39 | #include "target.h" |
cf951b1a | 40 | #include "lto-streamer.h" |
0e80b01d | 41 | #include "output.h" |
51ce5652 | 42 | #include "ipa-utils.h" |
c16b9430 | 43 | #include "calls.h" |
51ce5652 | 44 | |
058a1b7a | 45 | static const char *ipa_ref_use_name[] = {"read","write","addr","alias","chkp"}; |
cf951b1a | 46 | |
47 | const char * const ld_plugin_symbol_resolution_names[]= | |
48 | { | |
49 | "", | |
50 | "undef", | |
51 | "prevailing_def", | |
52 | "prevailing_def_ironly", | |
53 | "preempted_reg", | |
54 | "preempted_ir", | |
55 | "resolved_ir", | |
56 | "resolved_exec", | |
57 | "resolved_dyn", | |
58 | "prevailing_def_ironly_exp" | |
59 | }; | |
cfbe30aa | 60 | |
0e80b01d | 61 | /* Hash asmnames ignoring the user specified marks. */ |
62 | ||
35ee1c66 | 63 | hashval_t |
64 | symbol_table::decl_assembler_name_hash (const_tree asmname) | |
0e80b01d | 65 | { |
66 | if (IDENTIFIER_POINTER (asmname)[0] == '*') | |
67 | { | |
68 | const char *decl_str = IDENTIFIER_POINTER (asmname) + 1; | |
69 | size_t ulp_len = strlen (user_label_prefix); | |
70 | ||
71 | if (ulp_len == 0) | |
72 | ; | |
73 | else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
74 | decl_str += ulp_len; | |
75 | ||
76 | return htab_hash_string (decl_str); | |
77 | } | |
78 | ||
79 | return htab_hash_string (IDENTIFIER_POINTER (asmname)); | |
80 | } | |
81 | ||
82 | ||
0e80b01d | 83 | /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */ |
84 | ||
35ee1c66 | 85 | bool |
86 | symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname) | |
0e80b01d | 87 | { |
88 | tree decl_asmname = DECL_ASSEMBLER_NAME (decl); | |
89 | const char *decl_str; | |
90 | const char *asmname_str; | |
91 | bool test = false; | |
92 | ||
93 | if (decl_asmname == asmname) | |
94 | return true; | |
95 | ||
96 | decl_str = IDENTIFIER_POINTER (decl_asmname); | |
97 | asmname_str = IDENTIFIER_POINTER (asmname); | |
98 | ||
99 | ||
100 | /* If the target assembler name was set by the user, things are trickier. | |
101 | We have a leading '*' to begin with. After that, it's arguable what | |
102 | is the correct thing to do with -fleading-underscore. Arguably, we've | |
103 | historically been doing the wrong thing in assemble_alias by always | |
104 | printing the leading underscore. Since we're not changing that, make | |
105 | sure user_label_prefix follows the '*' before matching. */ | |
106 | if (decl_str[0] == '*') | |
107 | { | |
108 | size_t ulp_len = strlen (user_label_prefix); | |
109 | ||
110 | decl_str ++; | |
111 | ||
112 | if (ulp_len == 0) | |
113 | test = true; | |
114 | else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
115 | decl_str += ulp_len, test=true; | |
116 | else | |
117 | decl_str --; | |
118 | } | |
119 | if (asmname_str[0] == '*') | |
120 | { | |
121 | size_t ulp_len = strlen (user_label_prefix); | |
122 | ||
123 | asmname_str ++; | |
124 | ||
125 | if (ulp_len == 0) | |
126 | test = true; | |
127 | else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0) | |
128 | asmname_str += ulp_len, test=true; | |
129 | else | |
130 | asmname_str --; | |
131 | } | |
132 | ||
133 | if (!test) | |
134 | return false; | |
135 | return strcmp (decl_str, asmname_str) == 0; | |
136 | } | |
137 | ||
138 | ||
cfbe30aa | 139 | /* Returns nonzero if P1 and P2 are equal. */ |
140 | ||
cfbe30aa | 141 | /* Insert NODE to assembler name hash. */ |
142 | ||
35ee1c66 | 143 | void |
144 | symbol_table::insert_to_assembler_name_hash (symtab_node *node, | |
145 | bool with_clones) | |
cfbe30aa | 146 | { |
13cbeaac | 147 | if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl)) |
c9aa6453 | 148 | return; |
02774f2d | 149 | gcc_checking_assert (!node->previous_sharing_asm_name |
150 | && !node->next_sharing_asm_name); | |
cfbe30aa | 151 | if (assembler_name_hash) |
152 | { | |
2ef51f0e | 153 | symtab_node **aslot; |
35ee1c66 | 154 | cgraph_node *cnode; |
02774f2d | 155 | tree decl = node->decl; |
6f4cfc6d | 156 | |
02774f2d | 157 | tree name = DECL_ASSEMBLER_NAME (node->decl); |
cfbe30aa | 158 | |
fdd4ca00 | 159 | /* C++ FE can produce decls without associated assembler name and insert |
160 | them to symtab to hold section or TLS information. */ | |
161 | if (!name) | |
162 | return; | |
163 | ||
2ef51f0e | 164 | hashval_t hash = decl_assembler_name_hash (name); |
165 | aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT); | |
cfbe30aa | 166 | gcc_assert (*aslot != node); |
452659af | 167 | node->next_sharing_asm_name = (symtab_node *)*aslot; |
cfbe30aa | 168 | if (*aslot != NULL) |
2ef51f0e | 169 | (*aslot)->previous_sharing_asm_name = node; |
cfbe30aa | 170 | *aslot = node; |
6f4cfc6d | 171 | |
172 | /* Update also possible inline clones sharing a decl. */ | |
13cbeaac | 173 | cnode = dyn_cast <cgraph_node *> (node); |
6f4cfc6d | 174 | if (cnode && cnode->clones && with_clones) |
175 | for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone) | |
02774f2d | 176 | if (cnode->decl == decl) |
177 | insert_to_assembler_name_hash (cnode, true); | |
cfbe30aa | 178 | } |
179 | ||
180 | } | |
181 | ||
182 | /* Remove NODE from assembler name hash. */ | |
183 | ||
35ee1c66 | 184 | void |
185 | symbol_table::unlink_from_assembler_name_hash (symtab_node *node, | |
186 | bool with_clones) | |
cfbe30aa | 187 | { |
188 | if (assembler_name_hash) | |
189 | { | |
35ee1c66 | 190 | cgraph_node *cnode; |
02774f2d | 191 | tree decl = node->decl; |
6f4cfc6d | 192 | |
02774f2d | 193 | if (node->next_sharing_asm_name) |
194 | node->next_sharing_asm_name->previous_sharing_asm_name | |
195 | = node->previous_sharing_asm_name; | |
196 | if (node->previous_sharing_asm_name) | |
cfbe30aa | 197 | { |
02774f2d | 198 | node->previous_sharing_asm_name->next_sharing_asm_name |
199 | = node->next_sharing_asm_name; | |
cfbe30aa | 200 | } |
201 | else | |
202 | { | |
02774f2d | 203 | tree name = DECL_ASSEMBLER_NAME (node->decl); |
2ef51f0e | 204 | symtab_node **slot; |
fdd4ca00 | 205 | |
206 | if (!name) | |
207 | return; | |
208 | ||
2ef51f0e | 209 | hashval_t hash = decl_assembler_name_hash (name); |
210 | slot = assembler_name_hash->find_slot_with_hash (name, hash, | |
211 | NO_INSERT); | |
cfbe30aa | 212 | gcc_assert (*slot == node); |
02774f2d | 213 | if (!node->next_sharing_asm_name) |
2ef51f0e | 214 | assembler_name_hash->clear_slot (slot); |
cfbe30aa | 215 | else |
02774f2d | 216 | *slot = node->next_sharing_asm_name; |
cfbe30aa | 217 | } |
02774f2d | 218 | node->next_sharing_asm_name = NULL; |
219 | node->previous_sharing_asm_name = NULL; | |
6f4cfc6d | 220 | |
221 | /* Update also possible inline clones sharing a decl. */ | |
13cbeaac | 222 | cnode = dyn_cast <cgraph_node *> (node); |
6f4cfc6d | 223 | if (cnode && cnode->clones && with_clones) |
224 | for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone) | |
02774f2d | 225 | if (cnode->decl == decl) |
226 | unlink_from_assembler_name_hash (cnode, true); | |
cfbe30aa | 227 | } |
228 | } | |
229 | ||
c9aa6453 | 230 | /* Arrange node to be first in its entry of assembler_name_hash. */ |
231 | ||
232 | void | |
35ee1c66 | 233 | symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node) |
c9aa6453 | 234 | { |
6f4cfc6d | 235 | unlink_from_assembler_name_hash (node, false); |
236 | insert_to_assembler_name_hash (node, false); | |
c9aa6453 | 237 | } |
238 | ||
c9aa6453 | 239 | /* Initalize asm name hash unless. */ |
cfbe30aa | 240 | |
c9aa6453 | 241 | void |
35ee1c66 | 242 | symbol_table::symtab_initialize_asm_name_hash (void) |
cfbe30aa | 243 | { |
452659af | 244 | symtab_node *node; |
cfbe30aa | 245 | if (!assembler_name_hash) |
246 | { | |
2ef51f0e | 247 | assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10); |
cfbe30aa | 248 | FOR_EACH_SYMBOL (node) |
6f4cfc6d | 249 | insert_to_assembler_name_hash (node, false); |
cfbe30aa | 250 | } |
c9aa6453 | 251 | } |
cfbe30aa | 252 | |
cfbe30aa | 253 | /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */ |
254 | ||
255 | void | |
35ee1c66 | 256 | symbol_table::change_decl_assembler_name (tree decl, tree name) |
cfbe30aa | 257 | { |
452659af | 258 | symtab_node *node = NULL; |
cfbe30aa | 259 | |
260 | /* We can have user ASM names on things, like global register variables, that | |
261 | are not in the symbol table. */ | |
262 | if ((TREE_CODE (decl) == VAR_DECL | |
263 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) | |
264 | || TREE_CODE (decl) == FUNCTION_DECL) | |
415d1b9a | 265 | node = symtab_node::get (decl); |
cfbe30aa | 266 | if (!DECL_ASSEMBLER_NAME_SET_P (decl)) |
267 | { | |
268 | SET_DECL_ASSEMBLER_NAME (decl, name); | |
269 | if (node) | |
6f4cfc6d | 270 | insert_to_assembler_name_hash (node, true); |
cfbe30aa | 271 | } |
272 | else | |
273 | { | |
274 | if (name == DECL_ASSEMBLER_NAME (decl)) | |
275 | return; | |
276 | ||
2fe870c5 | 277 | tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl)) |
278 | ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl)) | |
279 | : NULL); | |
cfbe30aa | 280 | if (node) |
6f4cfc6d | 281 | unlink_from_assembler_name_hash (node, true); |
cfbe30aa | 282 | if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) |
283 | && DECL_RTL_SET_P (decl)) | |
284 | warning (0, "%D renamed after being referenced in assembly", decl); | |
285 | ||
286 | SET_DECL_ASSEMBLER_NAME (decl, name); | |
2fe870c5 | 287 | if (alias) |
288 | { | |
289 | IDENTIFIER_TRANSPARENT_ALIAS (name) = 1; | |
7b324376 | 290 | TREE_CHAIN (name) = alias; |
2fe870c5 | 291 | } |
cfbe30aa | 292 | if (node) |
6f4cfc6d | 293 | insert_to_assembler_name_hash (node, true); |
cfbe30aa | 294 | } |
295 | } | |
296 | ||
415d1b9a | 297 | /* Hash sections by their names. */ |
298 | ||
2ef51f0e | 299 | hashval_t |
300 | section_name_hasher::hash (section_hash_entry *n) | |
415d1b9a | 301 | { |
415d1b9a | 302 | return htab_hash_string (n->name); |
303 | } | |
304 | ||
305 | /* Return true if section P1 name equals to P2. */ | |
306 | ||
2ef51f0e | 307 | bool |
308 | section_name_hasher::equal (section_hash_entry *n1, const char *name) | |
415d1b9a | 309 | { |
415d1b9a | 310 | return n1->name == name || !strcmp (n1->name, name); |
311 | } | |
312 | ||
313 | /* Add node into symbol table. This function is not used directly, but via | |
314 | cgraph/varpool node creation routines. */ | |
315 | ||
316 | void | |
317 | symtab_node::register_symbol (void) | |
318 | { | |
35ee1c66 | 319 | symtab->register_symbol (this); |
415d1b9a | 320 | |
321 | if (!decl->decl_with_vis.symtab_node) | |
322 | decl->decl_with_vis.symtab_node = this; | |
323 | ||
324 | ref_list.clear (); | |
325 | ||
415d1b9a | 326 | /* Be sure to do this last; C++ FE might create new nodes via |
327 | DECL_ASSEMBLER_NAME langhook! */ | |
35ee1c66 | 328 | symtab->insert_to_assembler_name_hash (this, false); |
415d1b9a | 329 | } |
330 | ||
331 | /* Remove NODE from same comdat group. */ | |
332 | ||
333 | void | |
334 | symtab_node::remove_from_same_comdat_group (void) | |
335 | { | |
336 | if (same_comdat_group) | |
337 | { | |
338 | symtab_node *prev; | |
339 | for (prev = same_comdat_group; | |
340 | prev->same_comdat_group != this; | |
341 | prev = prev->same_comdat_group) | |
342 | ; | |
343 | if (same_comdat_group == prev) | |
344 | prev->same_comdat_group = NULL; | |
345 | else | |
346 | prev->same_comdat_group = same_comdat_group; | |
347 | same_comdat_group = NULL; | |
348 | set_comdat_group (NULL); | |
349 | } | |
350 | } | |
351 | ||
352 | /* Remove node from symbol table. This function is not used directly, but via | |
353 | cgraph/varpool node removal routines. */ | |
354 | ||
355 | void | |
356 | symtab_node::unregister (void) | |
357 | { | |
358 | remove_all_references (); | |
359 | remove_all_referring (); | |
360 | ||
361 | /* Remove reference to section. */ | |
362 | set_section_for_node (NULL); | |
363 | ||
364 | remove_from_same_comdat_group (); | |
365 | ||
35ee1c66 | 366 | symtab->unregister (this); |
415d1b9a | 367 | |
368 | /* During LTO symtab merging we temporarily corrupt decl to symtab node | |
369 | hash. */ | |
370 | gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p); | |
371 | if (decl->decl_with_vis.symtab_node == this) | |
372 | { | |
373 | symtab_node *replacement_node = NULL; | |
374 | if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this)) | |
375 | replacement_node = cnode->find_replacement (); | |
376 | decl->decl_with_vis.symtab_node = replacement_node; | |
377 | } | |
378 | if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl)) | |
35ee1c66 | 379 | symtab->unlink_from_assembler_name_hash (this, false); |
415d1b9a | 380 | if (in_init_priority_hash) |
8f359205 | 381 | symtab->init_priority_hash->remove (this); |
415d1b9a | 382 | } |
383 | ||
384 | ||
385 | /* Remove symbol from symbol table. */ | |
386 | ||
387 | void | |
388 | symtab_node::remove (void) | |
389 | { | |
390 | if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this)) | |
391 | cnode->remove (); | |
392 | else if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) | |
393 | vnode->remove (); | |
394 | } | |
395 | ||
cf951b1a | 396 | /* Add NEW_ to the same comdat group that OLD is in. */ |
397 | ||
398 | void | |
415d1b9a | 399 | symtab_node::add_to_same_comdat_group (symtab_node *old_node) |
cf951b1a | 400 | { |
8c016392 | 401 | gcc_assert (old_node->get_comdat_group ()); |
415d1b9a | 402 | gcc_assert (!same_comdat_group); |
403 | gcc_assert (this != old_node); | |
cf951b1a | 404 | |
415d1b9a | 405 | set_comdat_group (old_node->get_comdat_group ()); |
406 | same_comdat_group = old_node; | |
02774f2d | 407 | if (!old_node->same_comdat_group) |
415d1b9a | 408 | old_node->same_comdat_group = this; |
cf951b1a | 409 | else |
410 | { | |
452659af | 411 | symtab_node *n; |
02774f2d | 412 | for (n = old_node->same_comdat_group; |
413 | n->same_comdat_group != old_node; | |
414 | n = n->same_comdat_group) | |
cf951b1a | 415 | ; |
415d1b9a | 416 | n->same_comdat_group = this; |
cf951b1a | 417 | } |
418 | } | |
419 | ||
420 | /* Dissolve the same_comdat_group list in which NODE resides. */ | |
421 | ||
422 | void | |
415d1b9a | 423 | symtab_node::dissolve_same_comdat_group_list (void) |
cf951b1a | 424 | { |
415d1b9a | 425 | symtab_node *n = this; |
452659af | 426 | symtab_node *next; |
cf951b1a | 427 | |
415d1b9a | 428 | if (!same_comdat_group) |
cf951b1a | 429 | return; |
430 | do | |
431 | { | |
02774f2d | 432 | next = n->same_comdat_group; |
433 | n->same_comdat_group = NULL; | |
8c016392 | 434 | /* Clear comdat_group for comdat locals, since |
468088ac | 435 | make_decl_local doesn't. */ |
436 | if (!TREE_PUBLIC (n->decl)) | |
8c016392 | 437 | n->set_comdat_group (NULL); |
cf951b1a | 438 | n = next; |
439 | } | |
415d1b9a | 440 | while (n != this); |
cf951b1a | 441 | } |
442 | ||
18841b0c | 443 | /* Return printable assembler name of NODE. |
444 | This function is used only for debugging. When assembler name | |
445 | is unknown go with identifier name. */ | |
446 | ||
447 | const char * | |
f1c8b4d7 | 448 | symtab_node::asm_name () const |
18841b0c | 449 | { |
f1c8b4d7 | 450 | if (!DECL_ASSEMBLER_NAME_SET_P (decl)) |
451 | return lang_hooks.decl_printable_name (decl, 2); | |
452 | return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
18841b0c | 453 | } |
454 | ||
455 | /* Return printable identifier name. */ | |
456 | ||
457 | const char * | |
f1c8b4d7 | 458 | symtab_node::name () const |
18841b0c | 459 | { |
f1c8b4d7 | 460 | return lang_hooks.decl_printable_name (decl, 2); |
18841b0c | 461 | } |
462 | ||
51ce5652 | 463 | /* Return ipa reference from this symtab_node to |
464 | REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type | |
465 | of the use. */ | |
466 | ||
35ee1c66 | 467 | ipa_ref * |
468 | symtab_node::create_reference (symtab_node *referred_node, | |
469 | enum ipa_ref_use use_type) | |
51ce5652 | 470 | { |
35ee1c66 | 471 | return create_reference (referred_node, use_type, NULL); |
51ce5652 | 472 | } |
473 | ||
474 | ||
475 | /* Return ipa reference from this symtab_node to | |
476 | REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type | |
477 | of the use and STMT the statement (if it exists). */ | |
478 | ||
35ee1c66 | 479 | ipa_ref * |
480 | symtab_node::create_reference (symtab_node *referred_node, | |
481 | enum ipa_ref_use use_type, gimple stmt) | |
51ce5652 | 482 | { |
35ee1c66 | 483 | ipa_ref *ref = NULL, *ref2 = NULL; |
484 | ipa_ref_list *list, *list2; | |
51ce5652 | 485 | ipa_ref_t *old_references; |
486 | ||
487 | gcc_checking_assert (!stmt || is_a <cgraph_node *> (this)); | |
488 | gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt); | |
489 | ||
490 | list = &ref_list; | |
491 | old_references = vec_safe_address (list->references); | |
492 | vec_safe_grow (list->references, vec_safe_length (list->references) + 1); | |
493 | ref = &list->references->last (); | |
494 | ||
495 | list2 = &referred_node->ref_list; | |
e4a2b488 | 496 | |
497 | /* IPA_REF_ALIAS is always inserted at the beginning of the list. */ | |
498 | if(use_type == IPA_REF_ALIAS) | |
50f2a18b | 499 | { |
500 | list2->referring.safe_insert (0, ref); | |
501 | ref->referred_index = 0; | |
e4a2b488 | 502 | |
50f2a18b | 503 | for (unsigned int i = 1; i < list2->referring.length (); i++) |
504 | list2->referring[i]->referred_index = i; | |
505 | } | |
e4a2b488 | 506 | else |
50f2a18b | 507 | { |
508 | list2->referring.safe_push (ref); | |
509 | ref->referred_index = list2->referring.length () - 1; | |
510 | } | |
e4a2b488 | 511 | |
51ce5652 | 512 | ref->referring = this; |
513 | ref->referred = referred_node; | |
514 | ref->stmt = stmt; | |
515 | ref->lto_stmt_uid = 0; | |
516 | ref->use = use_type; | |
517 | ref->speculative = 0; | |
518 | ||
519 | /* If vector was moved in memory, update pointers. */ | |
520 | if (old_references != list->references->address ()) | |
521 | { | |
522 | int i; | |
523 | for (i = 0; iterate_reference(i, ref2); i++) | |
524 | ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2; | |
525 | } | |
526 | return ref; | |
527 | } | |
528 | ||
529 | /* If VAL is a reference to a function or a variable, add a reference from | |
530 | this symtab_node to the corresponding symbol table node. USE_TYPE specify | |
531 | type of the use and STMT the statement (if it exists). Return the new | |
532 | reference or NULL if none was created. */ | |
533 | ||
35ee1c66 | 534 | ipa_ref * |
535 | symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type, | |
536 | gimple stmt) | |
51ce5652 | 537 | { |
538 | STRIP_NOPS (val); | |
539 | if (TREE_CODE (val) != ADDR_EXPR) | |
540 | return NULL; | |
541 | val = get_base_var (val); | |
542 | if (val && (TREE_CODE (val) == FUNCTION_DECL | |
543 | || TREE_CODE (val) == VAR_DECL)) | |
544 | { | |
415d1b9a | 545 | symtab_node *referred = symtab_node::get (val); |
51ce5652 | 546 | gcc_checking_assert (referred); |
35ee1c66 | 547 | return create_reference (referred, use_type, stmt); |
51ce5652 | 548 | } |
549 | return NULL; | |
550 | } | |
551 | ||
552 | /* Clone all references from symtab NODE to this symtab_node. */ | |
553 | ||
554 | void | |
35ee1c66 | 555 | symtab_node::clone_references (symtab_node *node) |
51ce5652 | 556 | { |
35ee1c66 | 557 | ipa_ref *ref = NULL, *ref2 = NULL; |
51ce5652 | 558 | int i; |
559 | for (i = 0; node->iterate_reference (i, ref); i++) | |
560 | { | |
561 | bool speculative = ref->speculative; | |
562 | unsigned int stmt_uid = ref->lto_stmt_uid; | |
563 | ||
35ee1c66 | 564 | ref2 = create_reference (ref->referred, ref->use, ref->stmt); |
51ce5652 | 565 | ref2->speculative = speculative; |
566 | ref2->lto_stmt_uid = stmt_uid; | |
567 | } | |
568 | } | |
569 | ||
570 | /* Clone all referring from symtab NODE to this symtab_node. */ | |
571 | ||
572 | void | |
35ee1c66 | 573 | symtab_node::clone_referring (symtab_node *node) |
51ce5652 | 574 | { |
35ee1c66 | 575 | ipa_ref *ref = NULL, *ref2 = NULL; |
51ce5652 | 576 | int i; |
577 | for (i = 0; node->iterate_referring(i, ref); i++) | |
578 | { | |
579 | bool speculative = ref->speculative; | |
580 | unsigned int stmt_uid = ref->lto_stmt_uid; | |
581 | ||
35ee1c66 | 582 | ref2 = ref->referring->create_reference (this, ref->use, ref->stmt); |
51ce5652 | 583 | ref2->speculative = speculative; |
584 | ref2->lto_stmt_uid = stmt_uid; | |
585 | } | |
586 | } | |
587 | ||
588 | /* Clone reference REF to this symtab_node and set its stmt to STMT. */ | |
589 | ||
35ee1c66 | 590 | ipa_ref * |
591 | symtab_node::clone_reference (ipa_ref *ref, gimple stmt) | |
51ce5652 | 592 | { |
593 | bool speculative = ref->speculative; | |
594 | unsigned int stmt_uid = ref->lto_stmt_uid; | |
35ee1c66 | 595 | ipa_ref *ref2; |
51ce5652 | 596 | |
35ee1c66 | 597 | ref2 = create_reference (ref->referred, ref->use, stmt); |
51ce5652 | 598 | ref2->speculative = speculative; |
599 | ref2->lto_stmt_uid = stmt_uid; | |
600 | return ref2; | |
601 | } | |
602 | ||
603 | /* Find the structure describing a reference to REFERRED_NODE | |
604 | and associated with statement STMT. */ | |
605 | ||
35ee1c66 | 606 | ipa_ref * |
51ce5652 | 607 | symtab_node::find_reference (symtab_node *referred_node, |
608 | gimple stmt, unsigned int lto_stmt_uid) | |
609 | { | |
35ee1c66 | 610 | ipa_ref *r = NULL; |
51ce5652 | 611 | int i; |
612 | ||
613 | for (i = 0; iterate_reference (i, r); i++) | |
614 | if (r->referred == referred_node | |
615 | && !r->speculative | |
616 | && ((stmt && r->stmt == stmt) | |
617 | || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid) | |
618 | || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid))) | |
619 | return r; | |
620 | return NULL; | |
621 | } | |
622 | ||
623 | /* Remove all references that are associated with statement STMT. */ | |
624 | ||
625 | void | |
626 | symtab_node::remove_stmt_references (gimple stmt) | |
627 | { | |
35ee1c66 | 628 | ipa_ref *r = NULL; |
51ce5652 | 629 | int i = 0; |
630 | ||
631 | while (iterate_reference (i, r)) | |
632 | if (r->stmt == stmt) | |
633 | r->remove_reference (); | |
634 | else | |
635 | i++; | |
636 | } | |
637 | ||
638 | /* Remove all stmt references in non-speculative references. | |
639 | Those are not maintained during inlining & clonning. | |
640 | The exception are speculative references that are updated along | |
641 | with callgraph edges associated with them. */ | |
642 | ||
643 | void | |
644 | symtab_node::clear_stmts_in_references (void) | |
645 | { | |
35ee1c66 | 646 | ipa_ref *r = NULL; |
51ce5652 | 647 | int i; |
648 | ||
649 | for (i = 0; iterate_reference (i, r); i++) | |
650 | if (!r->speculative) | |
651 | { | |
652 | r->stmt = NULL; | |
653 | r->lto_stmt_uid = 0; | |
654 | } | |
655 | } | |
656 | ||
657 | /* Remove all references in ref list. */ | |
658 | ||
659 | void | |
660 | symtab_node::remove_all_references (void) | |
661 | { | |
662 | while (vec_safe_length (ref_list.references)) | |
663 | ref_list.references->last ().remove_reference (); | |
664 | vec_free (ref_list.references); | |
665 | } | |
666 | ||
667 | /* Remove all referring items in ref list. */ | |
668 | ||
669 | void | |
670 | symtab_node::remove_all_referring (void) | |
671 | { | |
672 | while (ref_list.referring.length ()) | |
673 | ref_list.referring.last ()->remove_reference (); | |
674 | ref_list.referring.release (); | |
675 | } | |
676 | ||
677 | /* Dump references in ref list to FILE. */ | |
678 | ||
679 | void | |
680 | symtab_node::dump_references (FILE *file) | |
681 | { | |
35ee1c66 | 682 | ipa_ref *ref = NULL; |
51ce5652 | 683 | int i; |
684 | for (i = 0; iterate_reference (i, ref); i++) | |
685 | { | |
686 | fprintf (file, "%s/%i (%s)", | |
687 | ref->referred->asm_name (), | |
688 | ref->referred->order, | |
689 | ipa_ref_use_name [ref->use]); | |
690 | if (ref->speculative) | |
691 | fprintf (file, " (speculative)"); | |
692 | } | |
693 | fprintf (file, "\n"); | |
694 | } | |
695 | ||
696 | /* Dump referring in list to FILE. */ | |
697 | ||
698 | void | |
699 | symtab_node::dump_referring (FILE *file) | |
700 | { | |
35ee1c66 | 701 | ipa_ref *ref = NULL; |
51ce5652 | 702 | int i; |
703 | for (i = 0; iterate_referring(i, ref); i++) | |
704 | { | |
705 | fprintf (file, "%s/%i (%s)", | |
706 | ref->referring->asm_name (), | |
707 | ref->referring->order, | |
708 | ipa_ref_use_name [ref->use]); | |
709 | if (ref->speculative) | |
710 | fprintf (file, " (speculative)"); | |
711 | } | |
712 | fprintf (file, "\n"); | |
713 | } | |
714 | ||
18841b0c | 715 | static const char * const symtab_type_names[] = {"symbol", "function", "variable"}; |
716 | ||
415d1b9a | 717 | /* Dump base fields of symtab nodes to F. Not to be used directly. */ |
18841b0c | 718 | |
719 | void | |
415d1b9a | 720 | symtab_node::dump_base (FILE *f) |
18841b0c | 721 | { |
722 | static const char * const visibility_types[] = { | |
723 | "default", "protected", "hidden", "internal" | |
724 | }; | |
725 | ||
415d1b9a | 726 | fprintf (f, "%s/%i (%s)", asm_name (), order, name ()); |
727 | dump_addr (f, " @", (void *)this); | |
728 | fprintf (f, "\n Type: %s", symtab_type_names[type]); | |
15ca8f90 | 729 | |
415d1b9a | 730 | if (definition) |
15ca8f90 | 731 | fprintf (f, " definition"); |
415d1b9a | 732 | if (analyzed) |
15ca8f90 | 733 | fprintf (f, " analyzed"); |
415d1b9a | 734 | if (alias) |
15ca8f90 | 735 | fprintf (f, " alias"); |
415d1b9a | 736 | if (weakref) |
f2526cce | 737 | fprintf (f, " weakref"); |
415d1b9a | 738 | if (cpp_implicit_alias) |
48669653 | 739 | fprintf (f, " cpp_implicit_alias"); |
415d1b9a | 740 | if (alias_target) |
48669653 | 741 | fprintf (f, " target:%s", |
415d1b9a | 742 | DECL_P (alias_target) |
48669653 | 743 | ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME |
415d1b9a | 744 | (alias_target)) |
745 | : IDENTIFIER_POINTER (alias_target)); | |
746 | if (body_removed) | |
fa4052b3 | 747 | fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes"); |
15ca8f90 | 748 | fprintf (f, "\n Visibility:"); |
415d1b9a | 749 | if (in_other_partition) |
18841b0c | 750 | fprintf (f, " in_other_partition"); |
415d1b9a | 751 | if (used_from_other_partition) |
18841b0c | 752 | fprintf (f, " used_from_other_partition"); |
415d1b9a | 753 | if (force_output) |
8efa224a | 754 | fprintf (f, " force_output"); |
415d1b9a | 755 | if (forced_by_abi) |
6a1c0403 | 756 | fprintf (f, " forced_by_abi"); |
415d1b9a | 757 | if (externally_visible) |
a1d135c3 | 758 | fprintf (f, " externally_visible"); |
6b722052 | 759 | if (no_reorder) |
760 | fprintf (f, " no_reorder"); | |
415d1b9a | 761 | if (resolution != LDPR_UNKNOWN) |
18841b0c | 762 | fprintf (f, " %s", |
415d1b9a | 763 | ld_plugin_symbol_resolution_names[(int)resolution]); |
764 | if (TREE_ASM_WRITTEN (decl)) | |
18841b0c | 765 | fprintf (f, " asm_written"); |
415d1b9a | 766 | if (DECL_EXTERNAL (decl)) |
18841b0c | 767 | fprintf (f, " external"); |
415d1b9a | 768 | if (TREE_PUBLIC (decl)) |
18841b0c | 769 | fprintf (f, " public"); |
415d1b9a | 770 | if (DECL_COMMON (decl)) |
18841b0c | 771 | fprintf (f, " common"); |
415d1b9a | 772 | if (DECL_WEAK (decl)) |
18841b0c | 773 | fprintf (f, " weak"); |
415d1b9a | 774 | if (DECL_DLLIMPORT_P (decl)) |
18841b0c | 775 | fprintf (f, " dll_import"); |
415d1b9a | 776 | if (DECL_COMDAT (decl)) |
18841b0c | 777 | fprintf (f, " comdat"); |
415d1b9a | 778 | if (get_comdat_group ()) |
18841b0c | 779 | fprintf (f, " comdat_group:%s", |
415d1b9a | 780 | IDENTIFIER_POINTER (get_comdat_group_id ())); |
781 | if (DECL_ONE_ONLY (decl)) | |
18841b0c | 782 | fprintf (f, " one_only"); |
415d1b9a | 783 | if (get_section ()) |
71e19e54 | 784 | fprintf (f, " section:%s", |
415d1b9a | 785 | get_section ()); |
786 | if (implicit_section) | |
e4c07a06 | 787 | fprintf (f," (implicit_section)"); |
415d1b9a | 788 | if (DECL_VISIBILITY_SPECIFIED (decl)) |
18841b0c | 789 | fprintf (f, " visibility_specified"); |
415d1b9a | 790 | if (DECL_VISIBILITY (decl)) |
18841b0c | 791 | fprintf (f, " visibility:%s", |
415d1b9a | 792 | visibility_types [DECL_VISIBILITY (decl)]); |
793 | if (DECL_VIRTUAL_P (decl)) | |
18841b0c | 794 | fprintf (f, " virtual"); |
415d1b9a | 795 | if (DECL_ARTIFICIAL (decl)) |
18841b0c | 796 | fprintf (f, " artificial"); |
415d1b9a | 797 | if (TREE_CODE (decl) == FUNCTION_DECL) |
9a2639fc | 798 | { |
415d1b9a | 799 | if (DECL_STATIC_CONSTRUCTOR (decl)) |
9a2639fc | 800 | fprintf (f, " constructor"); |
415d1b9a | 801 | if (DECL_STATIC_DESTRUCTOR (decl)) |
9a2639fc | 802 | fprintf (f, " destructor"); |
803 | } | |
18841b0c | 804 | fprintf (f, "\n"); |
805 | ||
415d1b9a | 806 | if (same_comdat_group) |
18841b0c | 807 | fprintf (f, " Same comdat group as: %s/%i\n", |
415d1b9a | 808 | same_comdat_group->asm_name (), |
809 | same_comdat_group->order); | |
810 | if (next_sharing_asm_name) | |
18841b0c | 811 | fprintf (f, " next sharing asm name: %i\n", |
415d1b9a | 812 | next_sharing_asm_name->order); |
813 | if (previous_sharing_asm_name) | |
18841b0c | 814 | fprintf (f, " previous sharing asm name: %i\n", |
415d1b9a | 815 | previous_sharing_asm_name->order); |
18841b0c | 816 | |
415d1b9a | 817 | if (address_taken) |
cfacc26f | 818 | fprintf (f, " Address is taken.\n"); |
415d1b9a | 819 | if (aux) |
ff2a5ada | 820 | { |
821 | fprintf (f, " Aux:"); | |
415d1b9a | 822 | dump_addr (f, " @", (void *)aux); |
ff2a5ada | 823 | } |
18841b0c | 824 | |
825 | fprintf (f, " References: "); | |
415d1b9a | 826 | dump_references (f); |
04ec15fa | 827 | fprintf (f, " Referring: "); |
415d1b9a | 828 | dump_referring (f); |
829 | if (lto_file_data) | |
c9aa6453 | 830 | fprintf (f, " Read from file: %s\n", |
415d1b9a | 831 | lto_file_data->file_name); |
18841b0c | 832 | } |
833 | ||
415d1b9a | 834 | /* Dump symtab node to F. */ |
18841b0c | 835 | |
836 | void | |
415d1b9a | 837 | symtab_node::dump (FILE *f) |
18841b0c | 838 | { |
415d1b9a | 839 | if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this)) |
840 | cnode->dump (f); | |
841 | else if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) | |
842 | vnode->dump (f); | |
18841b0c | 843 | } |
844 | ||
415d1b9a | 845 | /* Dump symbol table to F. */ |
18841b0c | 846 | |
847 | void | |
415d1b9a | 848 | symtab_node::dump_table (FILE *f) |
18841b0c | 849 | { |
452659af | 850 | symtab_node *node; |
18841b0c | 851 | fprintf (f, "Symbol table:\n\n"); |
852 | FOR_EACH_SYMBOL (node) | |
415d1b9a | 853 | node->dump (f); |
18841b0c | 854 | } |
855 | ||
35ee1c66 | 856 | |
857 | /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. | |
858 | Return NULL if there's no such node. */ | |
859 | ||
860 | symtab_node * | |
861 | symtab_node::get_for_asmname (const_tree asmname) | |
862 | { | |
863 | symtab_node *node; | |
35ee1c66 | 864 | |
865 | symtab->symtab_initialize_asm_name_hash (); | |
2ef51f0e | 866 | hashval_t hash = symtab->decl_assembler_name_hash (asmname); |
867 | symtab_node **slot | |
868 | = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash, | |
869 | NO_INSERT); | |
35ee1c66 | 870 | |
871 | if (slot) | |
872 | { | |
2ef51f0e | 873 | node = *slot; |
35ee1c66 | 874 | return node; |
875 | } | |
876 | return NULL; | |
877 | } | |
878 | ||
18841b0c | 879 | /* Dump symtab node NODE to stderr. */ |
880 | ||
881 | DEBUG_FUNCTION void | |
415d1b9a | 882 | symtab_node::debug (void) |
18841b0c | 883 | { |
415d1b9a | 884 | dump (stderr); |
18841b0c | 885 | } |
886 | ||
3e7775f6 | 887 | /* Verify common part of symtab nodes. */ |
888 | ||
889 | DEBUG_FUNCTION bool | |
415d1b9a | 890 | symtab_node::verify_base (void) |
3e7775f6 | 891 | { |
892 | bool error_found = false; | |
452659af | 893 | symtab_node *hashed_node; |
3e7775f6 | 894 | |
415d1b9a | 895 | if (is_a <cgraph_node *> (this)) |
3e7775f6 | 896 | { |
415d1b9a | 897 | if (TREE_CODE (decl) != FUNCTION_DECL) |
3e7775f6 | 898 | { |
899 | error ("function symbol is not function"); | |
900 | error_found = true; | |
901 | } | |
902 | } | |
415d1b9a | 903 | else if (is_a <varpool_node *> (this)) |
3e7775f6 | 904 | { |
415d1b9a | 905 | if (TREE_CODE (decl) != VAR_DECL) |
3e7775f6 | 906 | { |
907 | error ("variable symbol is not variable"); | |
908 | error_found = true; | |
909 | } | |
910 | } | |
911 | else | |
912 | { | |
913 | error ("node has unknown type"); | |
914 | error_found = true; | |
915 | } | |
916 | ||
35ee1c66 | 917 | if (symtab->state != LTO_STREAMING) |
3e7775f6 | 918 | { |
415d1b9a | 919 | hashed_node = symtab_node::get (decl); |
da4b8721 | 920 | if (!hashed_node) |
921 | { | |
8c016392 | 922 | error ("node not found node->decl->decl_with_vis.symtab_node"); |
da4b8721 | 923 | error_found = true; |
924 | } | |
415d1b9a | 925 | if (hashed_node != this |
926 | && (!is_a <cgraph_node *> (this) | |
927 | || !dyn_cast <cgraph_node *> (this)->clone_of | |
928 | || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl)) | |
a1d135c3 | 929 | { |
8c016392 | 930 | error ("node differs from node->decl->decl_with_vis.symtab_node"); |
a1d135c3 | 931 | error_found = true; |
932 | } | |
3e7775f6 | 933 | } |
35ee1c66 | 934 | if (symtab->assembler_name_hash) |
3e7775f6 | 935 | { |
35ee1c66 | 936 | hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl)); |
02774f2d | 937 | if (hashed_node && hashed_node->previous_sharing_asm_name) |
3e7775f6 | 938 | { |
939 | error ("assembler name hash list corrupted"); | |
940 | error_found = true; | |
941 | } | |
942 | while (hashed_node) | |
943 | { | |
415d1b9a | 944 | if (hashed_node == this) |
3e7775f6 | 945 | break; |
02774f2d | 946 | hashed_node = hashed_node->next_sharing_asm_name; |
3e7775f6 | 947 | } |
c9aa6453 | 948 | if (!hashed_node |
415d1b9a | 949 | && !(is_a <varpool_node *> (this) |
950 | || DECL_HARD_REGISTER (decl))) | |
3e7775f6 | 951 | { |
952 | error ("node not found in symtab assembler name hash"); | |
953 | error_found = true; | |
954 | } | |
955 | } | |
415d1b9a | 956 | if (previous_sharing_asm_name |
957 | && previous_sharing_asm_name->next_sharing_asm_name != this) | |
3e7775f6 | 958 | { |
959 | error ("double linked list of assembler names corrupted"); | |
ddd4cdce | 960 | error_found = true; |
961 | } | |
962 | if (body_removed && definition) | |
963 | { | |
964 | error ("node has body_removed but is definition"); | |
15ca8f90 | 965 | error_found = true; |
966 | } | |
415d1b9a | 967 | if (analyzed && !definition) |
15ca8f90 | 968 | { |
969 | error ("node is analyzed byt it is not a definition"); | |
970 | error_found = true; | |
3e7775f6 | 971 | } |
415d1b9a | 972 | if (cpp_implicit_alias && !alias) |
48669653 | 973 | { |
974 | error ("node is alias but not implicit alias"); | |
975 | error_found = true; | |
976 | } | |
415d1b9a | 977 | if (alias && !definition && !weakref) |
48669653 | 978 | { |
979 | error ("node is alias but not definition"); | |
980 | error_found = true; | |
981 | } | |
415d1b9a | 982 | if (weakref && !alias) |
f2526cce | 983 | { |
984 | error ("node is weakref but not an alias"); | |
985 | error_found = true; | |
986 | } | |
415d1b9a | 987 | if (same_comdat_group) |
3e7775f6 | 988 | { |
415d1b9a | 989 | symtab_node *n = same_comdat_group; |
3e7775f6 | 990 | |
8c016392 | 991 | if (!n->get_comdat_group ()) |
3e7775f6 | 992 | { |
8c016392 | 993 | error ("node is in same_comdat_group list but has no comdat_group"); |
3e7775f6 | 994 | error_found = true; |
995 | } | |
415d1b9a | 996 | if (n->get_comdat_group () != get_comdat_group ()) |
04f65f92 | 997 | { |
998 | error ("same_comdat_group list across different groups"); | |
999 | error_found = true; | |
1000 | } | |
415d1b9a | 1001 | if (n->type != type) |
3e7775f6 | 1002 | { |
1003 | error ("mixing different types of symbol in same comdat groups is not supported"); | |
1004 | error_found = true; | |
1005 | } | |
415d1b9a | 1006 | if (n == this) |
3e7775f6 | 1007 | { |
1008 | error ("node is alone in a comdat group"); | |
1009 | error_found = true; | |
1010 | } | |
1011 | do | |
1012 | { | |
02774f2d | 1013 | if (!n->same_comdat_group) |
3e7775f6 | 1014 | { |
1015 | error ("same_comdat_group is not a circular list"); | |
1016 | error_found = true; | |
1017 | break; | |
1018 | } | |
02774f2d | 1019 | n = n->same_comdat_group; |
3e7775f6 | 1020 | } |
415d1b9a | 1021 | while (n != this); |
1022 | if (comdat_local_p ()) | |
468088ac | 1023 | { |
35ee1c66 | 1024 | ipa_ref *ref = NULL; |
e4c07a06 | 1025 | |
415d1b9a | 1026 | for (int i = 0; iterate_referring (i, ref); ++i) |
468088ac | 1027 | { |
415d1b9a | 1028 | if (!in_same_comdat_group_p (ref->referring)) |
468088ac | 1029 | { |
1030 | error ("comdat-local symbol referred to by %s outside its " | |
1031 | "comdat", | |
1032 | identifier_to_locale (ref->referring->name())); | |
1033 | error_found = true; | |
1034 | } | |
1035 | } | |
1036 | } | |
3e7775f6 | 1037 | } |
415d1b9a | 1038 | if (implicit_section && !get_section ()) |
e4c07a06 | 1039 | { |
1040 | error ("implicit_section flag is set but section isn't"); | |
1041 | error_found = true; | |
1042 | } | |
415d1b9a | 1043 | if (get_section () && get_comdat_group () |
04430e3b | 1044 | && !implicit_section |
1045 | && !lookup_attribute ("section", DECL_ATTRIBUTES (decl))) | |
e4c07a06 | 1046 | { |
1047 | error ("Both section and comdat group is set"); | |
1048 | error_found = true; | |
1049 | } | |
1050 | /* TODO: Add string table for sections, so we do not keep holding duplicated | |
1051 | strings. */ | |
415d1b9a | 1052 | if (alias && definition |
1053 | && get_section () != get_alias_target ()->get_section () | |
1054 | && (!get_section() | |
1055 | || !get_alias_target ()->get_section () | |
1056 | || strcmp (get_section(), | |
1057 | get_alias_target ()->get_section ()))) | |
e4c07a06 | 1058 | { |
1059 | error ("Alias and target's section differs"); | |
415d1b9a | 1060 | get_alias_target ()->dump (stderr); |
e4c07a06 | 1061 | error_found = true; |
1062 | } | |
415d1b9a | 1063 | if (alias && definition |
1064 | && get_comdat_group () != get_alias_target ()->get_comdat_group ()) | |
e4c07a06 | 1065 | { |
1066 | error ("Alias and target's comdat groups differs"); | |
415d1b9a | 1067 | get_alias_target ()->dump (stderr); |
e4c07a06 | 1068 | error_found = true; |
1069 | } | |
1070 | ||
3e7775f6 | 1071 | return error_found; |
1072 | } | |
1073 | ||
1074 | /* Verify consistency of NODE. */ | |
1075 | ||
1076 | DEBUG_FUNCTION void | |
415d1b9a | 1077 | symtab_node::verify (void) |
3e7775f6 | 1078 | { |
1079 | if (seen_error ()) | |
1080 | return; | |
1081 | ||
1082 | timevar_push (TV_CGRAPH_VERIFY); | |
415d1b9a | 1083 | if (cgraph_node *node = dyn_cast <cgraph_node *> (this)) |
1084 | node->verify_node (); | |
3e7775f6 | 1085 | else |
415d1b9a | 1086 | if (verify_base ()) |
3e7775f6 | 1087 | { |
415d1b9a | 1088 | debug (); |
1089 | internal_error ("symtab_node::verify failed"); | |
3e7775f6 | 1090 | } |
1091 | timevar_pop (TV_CGRAPH_VERIFY); | |
1092 | } | |
1093 | ||
1094 | /* Verify symbol table for internal consistency. */ | |
1095 | ||
1096 | DEBUG_FUNCTION void | |
415d1b9a | 1097 | symtab_node::verify_symtab_nodes (void) |
3e7775f6 | 1098 | { |
452659af | 1099 | symtab_node *node; |
d62dd039 | 1100 | hash_map<tree, symtab_node *> comdat_head_map (251); |
e4c07a06 | 1101 | |
3e7775f6 | 1102 | FOR_EACH_SYMBOL (node) |
e4c07a06 | 1103 | { |
415d1b9a | 1104 | node->verify (); |
e4c07a06 | 1105 | if (node->get_comdat_group ()) |
1106 | { | |
1107 | symtab_node **entry, *s; | |
1108 | bool existed; | |
1109 | ||
d62dd039 | 1110 | entry = &comdat_head_map.get_or_insert (node->get_comdat_group (), |
1111 | &existed); | |
e4c07a06 | 1112 | if (!existed) |
1113 | *entry = node; | |
cabdaed9 | 1114 | else if (!DECL_EXTERNAL (node->decl)) |
1115 | { | |
4811e339 | 1116 | for (s = (*entry)->same_comdat_group; |
1117 | s != NULL && s != node && s != *entry; | |
cabdaed9 | 1118 | s = s->same_comdat_group) |
1119 | ; | |
e4c07a06 | 1120 | if (!s || s == *entry) |
1121 | { | |
cabdaed9 | 1122 | error ("Two symbols with same comdat_group are not linked by " |
1123 | "the same_comdat_group list."); | |
415d1b9a | 1124 | (*entry)->debug (); |
1125 | node->debug (); | |
1126 | internal_error ("symtab_node::verify failed"); | |
e4c07a06 | 1127 | } |
cabdaed9 | 1128 | } |
e4c07a06 | 1129 | } |
1130 | } | |
3e7775f6 | 1131 | } |
1132 | ||
cf951b1a | 1133 | /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early, |
1134 | but other code such as notice_global_symbol generates rtl. */ | |
48669653 | 1135 | |
cf951b1a | 1136 | void |
415d1b9a | 1137 | symtab_node::make_decl_local (void) |
cf951b1a | 1138 | { |
1139 | rtx rtl, symbol; | |
1140 | ||
8c016392 | 1141 | /* Avoid clearing comdat_groups on comdat-local decls. */ |
468088ac | 1142 | if (TREE_PUBLIC (decl) == 0) |
1143 | return; | |
1144 | ||
cf951b1a | 1145 | if (TREE_CODE (decl) == VAR_DECL) |
ce7711df | 1146 | { |
1147 | DECL_COMMON (decl) = 0; | |
1148 | /* ADDRESSABLE flag is not defined for public symbols. */ | |
1149 | TREE_ADDRESSABLE (decl) = 1; | |
1150 | } | |
cf951b1a | 1151 | else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); |
1152 | ||
71e19e54 | 1153 | DECL_COMDAT (decl) = 0; |
cf951b1a | 1154 | DECL_WEAK (decl) = 0; |
1155 | DECL_EXTERNAL (decl) = 0; | |
c9aa6453 | 1156 | DECL_VISIBILITY_SPECIFIED (decl) = 0; |
1157 | DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; | |
cf951b1a | 1158 | TREE_PUBLIC (decl) = 0; |
76284587 | 1159 | DECL_DLLIMPORT_P (decl) = 0; |
cf951b1a | 1160 | if (!DECL_RTL_SET_P (decl)) |
1161 | return; | |
1162 | ||
1163 | /* Update rtl flags. */ | |
1164 | make_decl_rtl (decl); | |
1165 | ||
1166 | rtl = DECL_RTL (decl); | |
1167 | if (!MEM_P (rtl)) | |
1168 | return; | |
1169 | ||
1170 | symbol = XEXP (rtl, 0); | |
1171 | if (GET_CODE (symbol) != SYMBOL_REF) | |
1172 | return; | |
1173 | ||
1174 | SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl); | |
1175 | } | |
15ca8f90 | 1176 | |
415d1b9a | 1177 | /* Walk the alias chain to return the symbol NODE is alias of. |
15ca8f90 | 1178 | If NODE is not an alias, return NODE. |
50f2a18b | 1179 | Assumes NODE is known to be alias. */ |
15ca8f90 | 1180 | |
452659af | 1181 | symtab_node * |
50f2a18b | 1182 | symtab_node::ultimate_alias_target_1 (enum availability *availability) |
15ca8f90 | 1183 | { |
9817f2cd | 1184 | bool weakref_p = false; |
1185 | ||
9817f2cd | 1186 | /* To determine visibility of the target, we follow ELF semantic of aliases. |
1187 | Here alias is an alternative assembler name of a given definition. Its | |
75de4aa2 | 1188 | availability prevails the availability of its target (i.e. static alias of |
9817f2cd | 1189 | weak definition is available. |
1190 | ||
1191 | Weakref is a different animal (and not part of ELF per se). It is just | |
1192 | alternative name of a given symbol used within one complation unit | |
1193 | and is translated prior hitting the object file. It inherits the | |
1194 | visibility of its target (i.e. weakref of non-overwritable definition | |
1195 | is non-overwritable, while weakref of weak definition is weak). | |
1196 | ||
1197 | If we ever get into supporting targets with different semantics, a target | |
1198 | hook will be needed here. */ | |
1199 | ||
15ca8f90 | 1200 | if (availability) |
9817f2cd | 1201 | { |
415d1b9a | 1202 | weakref_p = weakref; |
9817f2cd | 1203 | if (!weakref_p) |
415d1b9a | 1204 | *availability = get_availability (); |
9817f2cd | 1205 | else |
1206 | *availability = AVAIL_LOCAL; | |
1207 | } | |
415d1b9a | 1208 | |
1209 | symtab_node *node = this; | |
15ca8f90 | 1210 | while (node) |
1211 | { | |
02774f2d | 1212 | if (node->alias && node->analyzed) |
415d1b9a | 1213 | node = node->get_alias_target (); |
15ca8f90 | 1214 | else |
9817f2cd | 1215 | { |
1216 | if (!availability) | |
1217 | ; | |
02774f2d | 1218 | else if (node->analyzed) |
9817f2cd | 1219 | { |
1220 | if (weakref_p) | |
1221 | { | |
415d1b9a | 1222 | enum availability a = node->get_availability (); |
9817f2cd | 1223 | if (a < *availability) |
1224 | *availability = a; | |
1225 | } | |
1226 | } | |
1227 | else | |
1228 | *availability = AVAIL_NOT_AVAILABLE; | |
1229 | return node; | |
1230 | } | |
1231 | if (node && availability && weakref_p) | |
15ca8f90 | 1232 | { |
415d1b9a | 1233 | enum availability a = node->get_availability (); |
15ca8f90 | 1234 | if (a < *availability) |
1235 | *availability = a; | |
02774f2d | 1236 | weakref_p = node->weakref; |
15ca8f90 | 1237 | } |
1238 | } | |
1239 | if (availability) | |
1240 | *availability = AVAIL_NOT_AVAILABLE; | |
1241 | return NULL; | |
1242 | } | |
48669653 | 1243 | |
1244 | /* C++ FE sometimes change linkage flags after producing same body aliases. | |
1245 | ||
1246 | FIXME: C++ produce implicit aliases for virtual functions and vtables that | |
1247 | are obviously equivalent. The way it is doing so is however somewhat | |
1248 | kludgy and interferes with the visibility code. As a result we need to | |
1249 | copy the visibility from the target to get things right. */ | |
1250 | ||
1251 | void | |
415d1b9a | 1252 | symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target) |
48669653 | 1253 | { |
415d1b9a | 1254 | if (is_a <cgraph_node *> (this)) |
48669653 | 1255 | { |
415d1b9a | 1256 | DECL_DECLARED_INLINE_P (decl) |
02774f2d | 1257 | = DECL_DECLARED_INLINE_P (target->decl); |
415d1b9a | 1258 | DECL_DISREGARD_INLINE_LIMITS (decl) |
02774f2d | 1259 | = DECL_DISREGARD_INLINE_LIMITS (target->decl); |
48669653 | 1260 | } |
1261 | /* FIXME: It is not really clear why those flags should not be copied for | |
1262 | functions, too. */ | |
1263 | else | |
1264 | { | |
415d1b9a | 1265 | DECL_WEAK (decl) = DECL_WEAK (target->decl); |
1266 | DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl); | |
1267 | DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl); | |
48669653 | 1268 | } |
415d1b9a | 1269 | DECL_VIRTUAL_P (decl) = DECL_VIRTUAL_P (target->decl); |
1270 | if (TREE_PUBLIC (decl)) | |
48669653 | 1271 | { |
8c016392 | 1272 | tree group; |
1273 | ||
415d1b9a | 1274 | DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl); |
1275 | DECL_COMDAT (decl) = DECL_COMDAT (target->decl); | |
8c016392 | 1276 | group = target->get_comdat_group (); |
415d1b9a | 1277 | set_comdat_group (group); |
1278 | if (group && !same_comdat_group) | |
1279 | add_to_same_comdat_group (target); | |
48669653 | 1280 | } |
415d1b9a | 1281 | externally_visible = target->externally_visible; |
738a6bda | 1282 | } |
1283 | ||
1284 | /* Set section, do not recurse into aliases. | |
1285 | When one wants to change section of symbol and its aliases, | |
415d1b9a | 1286 | use set_section. */ |
738a6bda | 1287 | |
1288 | void | |
1289 | symtab_node::set_section_for_node (const char *section) | |
1290 | { | |
1291 | const char *current = get_section (); | |
2ef51f0e | 1292 | section_hash_entry **slot; |
738a6bda | 1293 | |
1294 | if (current == section | |
1295 | || (current && section | |
1296 | && !strcmp (current, section))) | |
1297 | return; | |
1298 | ||
1299 | if (current) | |
1300 | { | |
1301 | x_section->ref_count--; | |
1302 | if (!x_section->ref_count) | |
1303 | { | |
2ef51f0e | 1304 | hashval_t hash = htab_hash_string (x_section->name); |
1305 | slot = symtab->section_hash->find_slot_with_hash (x_section->name, | |
1306 | hash, INSERT); | |
738a6bda | 1307 | ggc_free (x_section); |
2ef51f0e | 1308 | symtab->section_hash->clear_slot (slot); |
738a6bda | 1309 | } |
1310 | x_section = NULL; | |
1311 | } | |
1312 | if (!section) | |
1313 | { | |
1314 | implicit_section = false; | |
1315 | return; | |
1316 | } | |
35ee1c66 | 1317 | if (!symtab->section_hash) |
2ef51f0e | 1318 | symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10); |
1319 | slot = symtab->section_hash->find_slot_with_hash (section, | |
1320 | htab_hash_string (section), | |
1321 | INSERT); | |
738a6bda | 1322 | if (*slot) |
1323 | x_section = (section_hash_entry *)*slot; | |
1324 | else | |
1325 | { | |
1326 | int len = strlen (section); | |
1327 | *slot = x_section = ggc_cleared_alloc<section_hash_entry> (); | |
1328 | x_section->name = ggc_vec_alloc<char> (len + 1); | |
1329 | memcpy (x_section->name, section, len + 1); | |
1330 | } | |
1331 | x_section->ref_count++; | |
1332 | } | |
1333 | ||
e4c07a06 | 1334 | /* Worker for set_section. */ |
1335 | ||
415d1b9a | 1336 | bool |
1337 | symtab_node::set_section (symtab_node *n, void *s) | |
e4c07a06 | 1338 | { |
738a6bda | 1339 | n->set_section_for_node ((char *)s); |
e4c07a06 | 1340 | return false; |
1341 | } | |
1342 | ||
1343 | /* Set section of symbol and its aliases. */ | |
1344 | ||
1345 | void | |
738a6bda | 1346 | symtab_node::set_section (const char *section) |
e4c07a06 | 1347 | { |
1348 | gcc_assert (!this->alias); | |
415d1b9a | 1349 | call_for_symbol_and_aliases |
1350 | (symtab_node::set_section, const_cast<char *>(section), true); | |
e4c07a06 | 1351 | } |
1352 | ||
9db80d42 | 1353 | /* Return the initialization priority. */ |
1354 | ||
1355 | priority_type | |
1356 | symtab_node::get_init_priority () | |
1357 | { | |
9db80d42 | 1358 | if (!this->in_init_priority_hash) |
1359 | return DEFAULT_INIT_PRIORITY; | |
8f359205 | 1360 | |
1361 | symbol_priority_map *h = symtab->init_priority_hash->get (this); | |
9db80d42 | 1362 | return h ? h->init : DEFAULT_INIT_PRIORITY; |
1363 | } | |
1364 | ||
1365 | /* Return the finalization priority. */ | |
1366 | ||
1367 | priority_type | |
1368 | cgraph_node::get_fini_priority () | |
1369 | { | |
9db80d42 | 1370 | if (!this->in_init_priority_hash) |
1371 | return DEFAULT_INIT_PRIORITY; | |
8f359205 | 1372 | symbol_priority_map *h = symtab->init_priority_hash->get (this); |
9db80d42 | 1373 | return h ? h->fini : DEFAULT_INIT_PRIORITY; |
1374 | } | |
1375 | ||
9db80d42 | 1376 | /* Return the initialization and finalization priority information for |
1377 | DECL. If there is no previous priority information, a freshly | |
1378 | allocated structure is returned. */ | |
1379 | ||
35ee1c66 | 1380 | symbol_priority_map * |
415d1b9a | 1381 | symtab_node::priority_info (void) |
9db80d42 | 1382 | { |
35ee1c66 | 1383 | if (!symtab->init_priority_hash) |
8f359205 | 1384 | symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13); |
9db80d42 | 1385 | |
8f359205 | 1386 | bool existed; |
1387 | symbol_priority_map *h | |
1388 | = &symtab->init_priority_hash->get_or_insert (this, &existed); | |
1389 | if (!existed) | |
9db80d42 | 1390 | { |
9db80d42 | 1391 | h->init = DEFAULT_INIT_PRIORITY; |
1392 | h->fini = DEFAULT_INIT_PRIORITY; | |
415d1b9a | 1393 | in_init_priority_hash = true; |
9db80d42 | 1394 | } |
1395 | ||
1396 | return h; | |
1397 | } | |
1398 | ||
1399 | /* Set initialization priority to PRIORITY. */ | |
1400 | ||
1401 | void | |
1402 | symtab_node::set_init_priority (priority_type priority) | |
1403 | { | |
35ee1c66 | 1404 | symbol_priority_map *h; |
9db80d42 | 1405 | |
1406 | if (is_a <cgraph_node *> (this)) | |
1407 | gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl)); | |
1408 | ||
1409 | if (priority == DEFAULT_INIT_PRIORITY) | |
1410 | { | |
1411 | gcc_assert (get_init_priority() == priority); | |
1412 | return; | |
1413 | } | |
415d1b9a | 1414 | h = priority_info (); |
9db80d42 | 1415 | h->init = priority; |
1416 | } | |
1417 | ||
1418 | /* Set fialization priority to PRIORITY. */ | |
1419 | ||
1420 | void | |
1421 | cgraph_node::set_fini_priority (priority_type priority) | |
1422 | { | |
35ee1c66 | 1423 | symbol_priority_map *h; |
9db80d42 | 1424 | |
1425 | gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl)); | |
1426 | ||
1427 | if (priority == DEFAULT_INIT_PRIORITY) | |
1428 | { | |
1429 | gcc_assert (get_fini_priority() == priority); | |
1430 | return; | |
1431 | } | |
415d1b9a | 1432 | h = priority_info (); |
9db80d42 | 1433 | h->fini = priority; |
1434 | } | |
1435 | ||
e4c07a06 | 1436 | /* Worker for symtab_resolve_alias. */ |
1437 | ||
415d1b9a | 1438 | bool |
1439 | symtab_node::set_implicit_section (symtab_node *n, | |
1440 | void *data ATTRIBUTE_UNUSED) | |
e4c07a06 | 1441 | { |
1442 | n->implicit_section = true; | |
1443 | return false; | |
1444 | } | |
1445 | ||
415d1b9a | 1446 | /* Add reference recording that symtab node is alias of TARGET. |
48669653 | 1447 | The function can fail in the case of aliasing cycles; in this case |
1448 | it returns false. */ | |
1449 | ||
1450 | bool | |
415d1b9a | 1451 | symtab_node::resolve_alias (symtab_node *target) |
48669653 | 1452 | { |
452659af | 1453 | symtab_node *n; |
48669653 | 1454 | |
415d1b9a | 1455 | gcc_assert (!analyzed && !vec_safe_length (ref_list.references)); |
48669653 | 1456 | |
1457 | /* Never let cycles to creep into the symbol table alias references; | |
1458 | those will make alias walkers to be infinite. */ | |
02774f2d | 1459 | for (n = target; n && n->alias; |
415d1b9a | 1460 | n = n->analyzed ? n->get_alias_target () : NULL) |
1461 | if (n == this) | |
48669653 | 1462 | { |
415d1b9a | 1463 | if (is_a <cgraph_node *> (this)) |
1464 | error ("function %q+D part of alias cycle", decl); | |
1465 | else if (is_a <varpool_node *> (this)) | |
1466 | error ("variable %q+D part of alias cycle", decl); | |
48669653 | 1467 | else |
1468 | gcc_unreachable (); | |
415d1b9a | 1469 | alias = false; |
48669653 | 1470 | return false; |
1471 | } | |
1472 | ||
1473 | /* "analyze" the node - i.e. mark the reference. */ | |
415d1b9a | 1474 | definition = true; |
1475 | alias = true; | |
1476 | analyzed = true; | |
35ee1c66 | 1477 | create_reference (target, IPA_REF_ALIAS, NULL); |
48669653 | 1478 | |
e4c07a06 | 1479 | /* Add alias into the comdat group of its target unless it is already there. */ |
415d1b9a | 1480 | if (same_comdat_group) |
1481 | remove_from_same_comdat_group (); | |
1482 | set_comdat_group (NULL); | |
e4c07a06 | 1483 | if (target->get_comdat_group ()) |
415d1b9a | 1484 | add_to_same_comdat_group (target); |
e4c07a06 | 1485 | |
415d1b9a | 1486 | if ((get_section () != target->get_section () |
1487 | || target->get_comdat_group ()) && get_section () && !implicit_section) | |
e4c07a06 | 1488 | { |
415d1b9a | 1489 | error ("section of alias %q+D must match section of its target", decl); |
e4c07a06 | 1490 | } |
415d1b9a | 1491 | call_for_symbol_and_aliases (symtab_node::set_section, |
1492 | const_cast<char *>(target->get_section ()), true); | |
e4c07a06 | 1493 | if (target->implicit_section) |
415d1b9a | 1494 | call_for_symbol_and_aliases (set_implicit_section, NULL, true); |
e4c07a06 | 1495 | |
1d9ca4f0 | 1496 | /* Alias targets become redundant after alias is resolved into an reference. |
48669653 | 1497 | We do not want to keep it around or we would have to mind updating them |
1498 | when renaming symbols. */ | |
415d1b9a | 1499 | alias_target = NULL; |
48669653 | 1500 | |
35ee1c66 | 1501 | if (cpp_implicit_alias && symtab->state >= CONSTRUCTION) |
415d1b9a | 1502 | fixup_same_cpp_alias_visibility (target); |
48669653 | 1503 | |
1504 | /* If alias has address taken, so does the target. */ | |
415d1b9a | 1505 | if (address_taken) |
1506 | target->ultimate_alias_target ()->address_taken = true; | |
ce7711df | 1507 | |
1508 | /* All non-weakref aliases of THIS are now in fact aliases of TARGET. */ | |
1509 | ipa_ref *ref; | |
1510 | for (unsigned i = 0; iterate_direct_aliases (i, ref);) | |
1511 | { | |
1512 | struct symtab_node *alias_alias = ref->referring; | |
1513 | if (!alias_alias->weakref) | |
1514 | { | |
1515 | alias_alias->remove_all_references (); | |
1516 | alias_alias->create_reference (target, IPA_REF_ALIAS, NULL); | |
1517 | } | |
1518 | else i++; | |
1519 | } | |
48669653 | 1520 | return true; |
1521 | } | |
44e82502 | 1522 | |
415d1b9a | 1523 | /* Worker searching noninterposable alias. */ |
44e82502 | 1524 | |
415d1b9a | 1525 | bool |
1526 | symtab_node::noninterposable_alias (symtab_node *node, void *data) | |
44e82502 | 1527 | { |
02774f2d | 1528 | if (decl_binds_to_current_def_p (node->decl)) |
44e82502 | 1529 | { |
415d1b9a | 1530 | symtab_node *fn = node->ultimate_alias_target (); |
c16b9430 | 1531 | |
1532 | /* Ensure that the alias is well formed this may not be the case | |
1533 | of user defined aliases and currently it is not always the case | |
1534 | of C++ same body aliases (that is a bug). */ | |
1535 | if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl) | |
1536 | || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl) | |
1537 | || (TREE_CODE (node->decl) == FUNCTION_DECL | |
1538 | && flags_from_decl_or_type (node->decl) | |
1539 | != flags_from_decl_or_type (fn->decl)) | |
1540 | || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl)) | |
1541 | return false; | |
452659af | 1542 | *(symtab_node **)data = node; |
44e82502 | 1543 | return true; |
1544 | } | |
1545 | return false; | |
1546 | } | |
1547 | ||
415d1b9a | 1548 | /* If node can not be overwriten by static or dynamic linker to point to |
1549 | different definition, return NODE. Otherwise look for alias with such | |
1550 | property and if none exists, introduce new one. */ | |
44e82502 | 1551 | |
452659af | 1552 | symtab_node * |
415d1b9a | 1553 | symtab_node::noninterposable_alias (void) |
44e82502 | 1554 | { |
1555 | tree new_decl; | |
452659af | 1556 | symtab_node *new_node = NULL; |
2fe870c5 | 1557 | |
1558 | /* First try to look up existing alias or base object | |
1559 | (if that is already non-overwritable). */ | |
415d1b9a | 1560 | symtab_node *node = ultimate_alias_target (); |
02774f2d | 1561 | gcc_assert (!node->alias && !node->weakref); |
415d1b9a | 1562 | node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias, |
1563 | (void *)&new_node, true); | |
44e82502 | 1564 | if (new_node) |
1565 | return new_node; | |
cb064935 | 1566 | #ifndef ASM_OUTPUT_DEF |
1567 | /* If aliases aren't supported by the assembler, fail. */ | |
1568 | return NULL; | |
1569 | #endif | |
44e82502 | 1570 | |
2fe870c5 | 1571 | /* Otherwise create a new one. */ |
02774f2d | 1572 | new_decl = copy_node (node->decl); |
76284587 | 1573 | DECL_DLLIMPORT_P (new_decl) = 0; |
02774f2d | 1574 | DECL_NAME (new_decl) = clone_function_name (node->decl, "localalias"); |
44e82502 | 1575 | if (TREE_CODE (new_decl) == FUNCTION_DECL) |
1576 | DECL_STRUCT_FUNCTION (new_decl) = NULL; | |
1577 | DECL_INITIAL (new_decl) = NULL; | |
1578 | SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl)); | |
1579 | SET_DECL_RTL (new_decl, NULL); | |
1580 | ||
1581 | /* Update the properties. */ | |
1582 | DECL_EXTERNAL (new_decl) = 0; | |
44e82502 | 1583 | TREE_PUBLIC (new_decl) = 0; |
1584 | DECL_COMDAT (new_decl) = 0; | |
1585 | DECL_WEAK (new_decl) = 0; | |
338af93e | 1586 | |
1587 | /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */ | |
1588 | DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl); | |
44e82502 | 1589 | if (TREE_CODE (new_decl) == FUNCTION_DECL) |
1590 | { | |
1591 | DECL_STATIC_CONSTRUCTOR (new_decl) = 0; | |
1592 | DECL_STATIC_DESTRUCTOR (new_decl) = 0; | |
415d1b9a | 1593 | new_node = cgraph_node::create_alias (new_decl, node->decl); |
44e82502 | 1594 | } |
1595 | else | |
19b03318 | 1596 | { |
1597 | TREE_READONLY (new_decl) = TREE_READONLY (node->decl); | |
338af93e | 1598 | DECL_INITIAL (new_decl) = error_mark_node; |
97221fd7 | 1599 | new_node = varpool_node::create_alias (new_decl, node->decl); |
19b03318 | 1600 | } |
415d1b9a | 1601 | new_node->resolve_alias (node); |
19b03318 | 1602 | gcc_assert (decl_binds_to_current_def_p (new_decl) |
1603 | && targetm.binds_local_p (new_decl)); | |
44e82502 | 1604 | return new_node; |
1605 | } | |
e9de52cc | 1606 | |
415d1b9a | 1607 | /* Return true if symtab node and TARGET represents |
1608 | semantically equivalent symbols. */ | |
e9de52cc | 1609 | |
1610 | bool | |
415d1b9a | 1611 | symtab_node::semantically_equivalent_p (symtab_node *target) |
e9de52cc | 1612 | { |
1613 | enum availability avail; | |
452659af | 1614 | symtab_node *ba; |
1615 | symtab_node *bb; | |
e9de52cc | 1616 | |
1617 | /* Equivalent functions are equivalent. */ | |
415d1b9a | 1618 | if (decl == target->decl) |
e9de52cc | 1619 | return true; |
1620 | ||
1621 | /* If symbol is not overwritable by different implementation, | |
1622 | walk to the base object it defines. */ | |
415d1b9a | 1623 | ba = ultimate_alias_target (&avail); |
e9de52cc | 1624 | if (avail >= AVAIL_AVAILABLE) |
1625 | { | |
415d1b9a | 1626 | if (target == ba) |
e9de52cc | 1627 | return true; |
1628 | } | |
1629 | else | |
415d1b9a | 1630 | ba = this; |
1631 | bb = target->ultimate_alias_target (&avail); | |
e9de52cc | 1632 | if (avail >= AVAIL_AVAILABLE) |
1633 | { | |
415d1b9a | 1634 | if (this == bb) |
e9de52cc | 1635 | return true; |
1636 | } | |
1637 | else | |
415d1b9a | 1638 | bb = target; |
e9de52cc | 1639 | return bb == ba; |
1640 | } | |
2b7cb172 | 1641 | |
415d1b9a | 1642 | /* Classify symbol symtab node for partitioning. */ |
2b7cb172 | 1643 | |
1644 | enum symbol_partitioning_class | |
415d1b9a | 1645 | symtab_node::get_partitioning_class (void) |
2b7cb172 | 1646 | { |
1647 | /* Inline clones are always duplicated. | |
1648 | This include external delcarations. */ | |
415d1b9a | 1649 | cgraph_node *cnode = dyn_cast <cgraph_node *> (this); |
2b7cb172 | 1650 | |
16d41ae2 | 1651 | if (DECL_ABSTRACT_P (decl)) |
2b7cb172 | 1652 | return SYMBOL_EXTERNAL; |
1653 | ||
1654 | if (cnode && cnode->global.inlined_to) | |
1655 | return SYMBOL_DUPLICATE; | |
1656 | ||
1657 | /* Weakref aliases are always duplicated. */ | |
415d1b9a | 1658 | if (weakref) |
2b7cb172 | 1659 | return SYMBOL_DUPLICATE; |
1660 | ||
1661 | /* External declarations are external. */ | |
415d1b9a | 1662 | if (DECL_EXTERNAL (decl)) |
2b7cb172 | 1663 | return SYMBOL_EXTERNAL; |
1664 | ||
415d1b9a | 1665 | if (varpool_node *vnode = dyn_cast <varpool_node *> (this)) |
2b7cb172 | 1666 | { |
6cb8fb82 | 1667 | if (alias && definition && !ultimate_alias_target ()->definition) |
1668 | return SYMBOL_EXTERNAL; | |
2b7cb172 | 1669 | /* Constant pool references use local symbol names that can not |
1670 | be promoted global. We should never put into a constant pool | |
1671 | objects that can not be duplicated across partitions. */ | |
415d1b9a | 1672 | if (DECL_IN_CONSTANT_POOL (decl)) |
2b7cb172 | 1673 | return SYMBOL_DUPLICATE; |
d1528ba2 | 1674 | if (DECL_HARD_REGISTER (decl)) |
1675 | return SYMBOL_DUPLICATE; | |
2b7cb172 | 1676 | gcc_checking_assert (vnode->definition); |
1677 | } | |
1678 | /* Functions that are cloned may stay in callgraph even if they are unused. | |
1679 | Handle them as external; compute_ltrans_boundary take care to make | |
1680 | proper things to happen (i.e. to make them appear in the boundary but | |
1681 | with body streamed, so clone can me materialized). */ | |
6cb8fb82 | 1682 | else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition) |
2b7cb172 | 1683 | return SYMBOL_EXTERNAL; |
1684 | ||
1685 | /* Linker discardable symbols are duplicated to every use unless they are | |
b395f451 | 1686 | keyed. */ |
415d1b9a | 1687 | if (DECL_ONE_ONLY (decl) |
1688 | && !force_output | |
1689 | && !forced_by_abi | |
1690 | && !used_from_object_file_p ()) | |
2b7cb172 | 1691 | return SYMBOL_DUPLICATE; |
1692 | ||
1693 | return SYMBOL_PARTITION; | |
1694 | } | |
56ac70ed | 1695 | |
1696 | /* Return true when symbol is known to be non-zero. */ | |
1697 | ||
1698 | bool | |
1699 | symtab_node::nonzero_address () | |
1700 | { | |
1701 | /* Weakrefs may be NULL when their target is not defined. */ | |
8e857c41 | 1702 | if (alias && weakref) |
56ac70ed | 1703 | { |
8e857c41 | 1704 | if (analyzed) |
56ac70ed | 1705 | { |
415d1b9a | 1706 | symtab_node *target = ultimate_alias_target (); |
56ac70ed | 1707 | |
1708 | if (target->alias && target->weakref) | |
1709 | return false; | |
1710 | /* We can not recurse to target::nonzero. It is possible that the | |
1711 | target is used only via the alias. | |
1712 | We may walk references and look for strong use, but we do not know | |
1713 | if this strong use will survive to final binary, so be | |
1714 | conservative here. | |
1715 | ??? Maybe we could do the lookup during late optimization that | |
1716 | could be useful to eliminate the NULL pointer checks in LTO | |
1717 | programs. */ | |
1718 | if (target->definition && !DECL_EXTERNAL (target->decl)) | |
8e857c41 | 1719 | return true; |
56ac70ed | 1720 | if (target->resolution != LDPR_UNKNOWN |
1721 | && target->resolution != LDPR_UNDEF | |
1722 | && flag_delete_null_pointer_checks) | |
1723 | return true; | |
1724 | return false; | |
1725 | } | |
1726 | else | |
1727 | return false; | |
1728 | } | |
1729 | ||
1730 | /* With !flag_delete_null_pointer_checks we assume that symbols may | |
1731 | bind to NULL. This is on by default on embedded targets only. | |
1732 | ||
1733 | Otherwise all non-WEAK symbols must be defined and thus non-NULL or | |
1734 | linking fails. Important case of WEAK we want to do well are comdats. | |
1735 | Those are handled by later check for definition. | |
1736 | ||
1737 | When parsing, beware the cases when WEAK attribute is added later. */ | |
8e857c41 | 1738 | if (!DECL_WEAK (decl) |
1739 | && flag_delete_null_pointer_checks) | |
1740 | { | |
1741 | refuse_visibility_changes = true; | |
1742 | return true; | |
1743 | } | |
56ac70ed | 1744 | |
1745 | /* If target is defined and not extern, we know it will be output and thus | |
1746 | it will bind to non-NULL. | |
1747 | Play safe for flag_delete_null_pointer_checks where weak definition maye | |
1748 | be re-defined by NULL. */ | |
8e857c41 | 1749 | if (definition && !DECL_EXTERNAL (decl) |
1750 | && (flag_delete_null_pointer_checks || !DECL_WEAK (decl))) | |
1751 | { | |
1752 | if (!DECL_WEAK (decl)) | |
1753 | refuse_visibility_changes = true; | |
1754 | return true; | |
1755 | } | |
56ac70ed | 1756 | |
1757 | /* As the last resort, check the resolution info. */ | |
8e857c41 | 1758 | if (resolution != LDPR_UNKNOWN |
1759 | && resolution != LDPR_UNDEF | |
56ac70ed | 1760 | && flag_delete_null_pointer_checks) |
1761 | return true; | |
1762 | return false; | |
1763 | } | |
c11b875d | 1764 | |
1765 | /* Return 0 if symbol is known to have different address than S2, | |
1766 | Return 1 if symbol is known to have same address as S2, | |
1767 | return 2 otherwise. */ | |
1768 | int | |
1769 | symtab_node::equal_address_to (symtab_node *s2) | |
1770 | { | |
1771 | enum availability avail1, avail2; | |
1772 | ||
1773 | /* A Shortcut: equivalent symbols are always equivalent. */ | |
1774 | if (this == s2) | |
1775 | return 1; | |
1776 | ||
1777 | /* For non-interposable aliases, lookup and compare their actual definitions. | |
1778 | Also check if the symbol needs to bind to given definition. */ | |
1779 | symtab_node *rs1 = ultimate_alias_target (&avail1); | |
1780 | symtab_node *rs2 = s2->ultimate_alias_target (&avail2); | |
1781 | bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl); | |
1782 | bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl); | |
1783 | bool really_binds_local1 = binds_local1; | |
1784 | bool really_binds_local2 = binds_local2; | |
1785 | ||
1786 | /* Addresses of vtables and virtual functions can not be used by user | |
1787 | code and are used only within speculation. In this case we may make | |
1788 | symbol equivalent to its alias even if interposition may break this | |
1789 | rule. Doing so will allow us to turn speculative inlining into | |
1790 | non-speculative more agressively. */ | |
1791 | if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE) | |
1792 | binds_local1 = true; | |
1793 | if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE) | |
1794 | binds_local2 = true; | |
1795 | ||
1796 | /* If both definitions are available we know that even if they are bound | |
1797 | to other unit they must be defined same way and therefore we can use | |
1798 | equivalence test. */ | |
1799 | if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE) | |
1800 | binds_local1 = binds_local2 = true; | |
1801 | ||
1802 | if ((binds_local1 ? rs1 : this) | |
1803 | == (binds_local2 ? rs2 : s2)) | |
1804 | { | |
1805 | /* We made use of the fact that alias is not weak. */ | |
1806 | if (binds_local1 && rs1 != this) | |
1807 | refuse_visibility_changes = true; | |
1808 | if (binds_local2 && rs2 != s2) | |
1809 | s2->refuse_visibility_changes = true; | |
1810 | return 1; | |
1811 | } | |
1812 | ||
1813 | /* If both symbols may resolve to NULL, we can not really prove them different. */ | |
1814 | if (!nonzero_address () && !s2->nonzero_address ()) | |
1815 | return 2; | |
1816 | ||
1817 | /* Except for NULL, functions and variables never overlap. */ | |
1818 | if (TREE_CODE (decl) != TREE_CODE (s2->decl)) | |
1819 | return 0; | |
1820 | ||
1821 | /* If one of the symbols is unresolved alias, punt. */ | |
1822 | if (rs1->alias || rs2->alias) | |
1823 | return 2; | |
1824 | ||
1825 | /* If we have a non-interposale definition of at least one of the symbols | |
1826 | and the other symbol is different, we know other unit can not interpose | |
1827 | it to the first symbol; all aliases of the definition needs to be | |
1828 | present in the current unit. */ | |
1829 | if (((really_binds_local1 || really_binds_local2) | |
1830 | /* If we have both definitions and they are different, we know they | |
1831 | will be different even in units they binds to. */ | |
1832 | || (binds_local1 && binds_local2)) | |
1833 | && rs1 != rs2) | |
1834 | { | |
1835 | /* We make use of the fact that one symbol is not alias of the other | |
1836 | and that the definition is non-interposable. */ | |
1837 | refuse_visibility_changes = true; | |
1838 | s2->refuse_visibility_changes = true; | |
1839 | rs1->refuse_visibility_changes = true; | |
1840 | rs2->refuse_visibility_changes = true; | |
1841 | return 0; | |
1842 | } | |
1843 | ||
1844 | /* TODO: Alias oracle basically assume that addresses of global variables | |
1845 | are different unless they are declared as alias of one to another. | |
1846 | We probably should be consistent and use this fact here, too, and update | |
1847 | alias oracle to use this predicate. */ | |
1848 | ||
1849 | return 2; | |
1850 | } | |
50f2a18b | 1851 | |
1852 | /* Worker for call_for_symbol_and_aliases. */ | |
1853 | ||
1854 | bool | |
1855 | symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *, | |
1856 | void *), | |
1857 | void *data, | |
1858 | bool include_overwritable) | |
1859 | { | |
1860 | ipa_ref *ref; | |
1861 | FOR_EACH_ALIAS (this, ref) | |
1862 | { | |
1863 | symtab_node *alias = ref->referring; | |
1864 | if (include_overwritable | |
1865 | || alias->get_availability () > AVAIL_INTERPOSABLE) | |
1866 | if (alias->call_for_symbol_and_aliases (callback, data, | |
1867 | include_overwritable)) | |
1868 | return true; | |
1869 | } | |
1870 | return false; | |
1871 | } | |
ce7711df | 1872 | |
ad782aec | 1873 | /* Return true if address of N is possibly compared. */ |
ce7711df | 1874 | |
1875 | static bool | |
1876 | address_matters_1 (symtab_node *n, void *) | |
1877 | { | |
1878 | struct ipa_ref *ref; | |
1879 | ||
1880 | if (!n->address_can_be_compared_p ()) | |
1881 | return false; | |
1882 | if (n->externally_visible || n->force_output) | |
1883 | return true; | |
1884 | ||
1885 | for (unsigned int i = 0; n->iterate_referring (i, ref); i++) | |
1886 | if (ref->address_matters_p ()) | |
1887 | return true; | |
1888 | return false; | |
1889 | } | |
1890 | ||
1891 | /* Return true if symbol's address may possibly be compared to other | |
1892 | symbol's address. */ | |
1893 | ||
1894 | bool | |
1895 | symtab_node::address_matters_p () | |
1896 | { | |
1897 | gcc_assert (!alias); | |
1898 | return call_for_symbol_and_aliases (address_matters_1, NULL, true); | |
1899 | } | |
331d5983 | 1900 | |
ad782aec | 1901 | /* Return true if symbol's alignment may be increased. */ |
331d5983 | 1902 | |
1903 | bool | |
1904 | symtab_node::can_increase_alignment_p (void) | |
1905 | { | |
1906 | symtab_node *target = ultimate_alias_target (); | |
1907 | ||
1908 | /* For now support only variables. */ | |
1909 | if (TREE_CODE (decl) != VAR_DECL) | |
1910 | return false; | |
1911 | ||
1912 | /* With -fno-toplevel-reorder we may have already output the constant. */ | |
1913 | if (TREE_ASM_WRITTEN (target->decl)) | |
1914 | return false; | |
1915 | ||
5c8bc079 | 1916 | /* If target is already placed in an anchor, we can not touch its |
1917 | alignment. */ | |
1918 | if (DECL_RTL_SET_P (target->decl) | |
1919 | && MEM_P (DECL_RTL (target->decl)) | |
1920 | && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0))) | |
1921 | return false; | |
1922 | ||
331d5983 | 1923 | /* Constant pool entries may be shared. */ |
1924 | if (DECL_IN_CONSTANT_POOL (target->decl)) | |
1925 | return false; | |
1926 | ||
1927 | /* We cannot change alignment of symbols that may bind to symbols | |
1928 | in other translation unit that may contain a definition with lower | |
1929 | alignment. */ | |
1930 | if (!decl_binds_to_current_def_p (decl)) | |
1931 | return false; | |
1932 | ||
1933 | /* When compiling partition, be sure the symbol is not output by other | |
1934 | partition. */ | |
1935 | if (flag_ltrans | |
1936 | && (target->in_other_partition | |
1937 | || target->get_partitioning_class () == SYMBOL_DUPLICATE)) | |
1938 | return false; | |
1939 | ||
1940 | /* Do not override the alignment as specified by the ABI when the used | |
1941 | attribute is set. */ | |
1942 | if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl)) | |
1943 | return false; | |
1944 | ||
1945 | /* Do not override explicit alignment set by the user when an explicit | |
1946 | section name is also used. This is a common idiom used by many | |
1947 | software projects. */ | |
1948 | if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section) | |
1949 | return false; | |
1950 | ||
1951 | return true; | |
1952 | } | |
1953 | ||
1954 | /* Worker for symtab_node::increase_alignment. */ | |
1955 | ||
1956 | static bool | |
1957 | increase_alignment_1 (symtab_node *n, void *v) | |
1958 | { | |
1959 | unsigned int align = (size_t)v; | |
1960 | if (DECL_ALIGN (n->decl) < align | |
1961 | && n->can_increase_alignment_p ()) | |
1962 | { | |
1963 | DECL_ALIGN (n->decl) = align; | |
1964 | DECL_USER_ALIGN (n->decl) = 1; | |
1965 | } | |
1966 | return false; | |
1967 | } | |
1968 | ||
1969 | /* Increase alignment of THIS to ALIGN. */ | |
1970 | ||
1971 | void | |
1972 | symtab_node::increase_alignment (unsigned int align) | |
1973 | { | |
1974 | gcc_assert (can_increase_alignment_p () && align < MAX_OFILE_ALIGNMENT); | |
1975 | ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1, | |
1976 | (void *)(size_t) align, | |
1977 | true); | |
1978 | gcc_assert (DECL_ALIGN (decl) >= align); | |
1979 | } | |
1980 | ||
1981 | /* Helper for symtab_node::definition_alignment. */ | |
1982 | ||
1983 | static bool | |
1984 | get_alignment_1 (symtab_node *n, void *v) | |
1985 | { | |
1986 | *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl)); | |
1987 | return false; | |
1988 | } | |
1989 | ||
1990 | /* Return desired alignment of the definition. This is NOT alignment useful | |
1991 | to access THIS, because THIS may be interposable and DECL_ALIGN should | |
1992 | be used instead. It however must be guaranteed when output definition | |
1993 | of THIS. */ | |
1994 | ||
1995 | unsigned int | |
1996 | symtab_node::definition_alignment () | |
1997 | { | |
1998 | unsigned int align = 0; | |
1999 | gcc_assert (!alias); | |
2000 | call_for_symbol_and_aliases (get_alignment_1, &align, true); | |
2001 | return align; | |
2002 | } |