handle undefined extern vars in output_in_order
[gcc.git] / gcc / varpool.c
1 /* Callgraph handling code.
2 Copyright (C) 2003-2016 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "target.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "timevar.h"
29 #include "cgraph.h"
30 #include "lto-streamer.h"
31 #include "varasm.h"
32 #include "debug.h"
33 #include "output.h"
34 #include "omp-low.h"
35 #include "context.h"
36
37 const char * const tls_model_names[]={"none", "emulated",
38 "global-dynamic", "local-dynamic",
39 "initial-exec", "local-exec"};
40
41 /* List of hooks triggered on varpool_node events. */
42 struct varpool_node_hook_list {
43 varpool_node_hook hook;
44 void *data;
45 struct varpool_node_hook_list *next;
46 };
47
48 /* Register HOOK to be called with DATA on each removed node. */
49 varpool_node_hook_list *
50 symbol_table::add_varpool_removal_hook (varpool_node_hook hook, void *data)
51 {
52 varpool_node_hook_list *entry;
53 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
54
55 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
56 entry->hook = hook;
57 entry->data = data;
58 entry->next = NULL;
59 while (*ptr)
60 ptr = &(*ptr)->next;
61 *ptr = entry;
62 return entry;
63 }
64
65 /* Remove ENTRY from the list of hooks called on removing nodes. */
66 void
67 symbol_table::remove_varpool_removal_hook (varpool_node_hook_list *entry)
68 {
69 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
70
71 while (*ptr != entry)
72 ptr = &(*ptr)->next;
73 *ptr = entry->next;
74 free (entry);
75 }
76
77 /* Call all node removal hooks. */
78 void
79 symbol_table::call_varpool_removal_hooks (varpool_node *node)
80 {
81 varpool_node_hook_list *entry = m_first_varpool_removal_hook;
82 while (entry)
83 {
84 entry->hook (node, entry->data);
85 entry = entry->next;
86 }
87 }
88
89 /* Register HOOK to be called with DATA on each inserted node. */
90 varpool_node_hook_list *
91 symbol_table::add_varpool_insertion_hook (varpool_node_hook hook, void *data)
92 {
93 varpool_node_hook_list *entry;
94 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
95
96 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
97 entry->hook = hook;
98 entry->data = data;
99 entry->next = NULL;
100 while (*ptr)
101 ptr = &(*ptr)->next;
102 *ptr = entry;
103 return entry;
104 }
105
106 /* Remove ENTRY from the list of hooks called on inserted nodes. */
107 void
108 symbol_table::remove_varpool_insertion_hook (varpool_node_hook_list *entry)
109 {
110 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
111
112 while (*ptr != entry)
113 ptr = &(*ptr)->next;
114 *ptr = entry->next;
115 free (entry);
116 }
117
118 /* Call all node insertion hooks. */
119 void
120 symbol_table::call_varpool_insertion_hooks (varpool_node *node)
121 {
122 varpool_node_hook_list *entry = m_first_varpool_insertion_hook;
123 while (entry)
124 {
125 entry->hook (node, entry->data);
126 entry = entry->next;
127 }
128 }
129
130 /* Allocate new callgraph node and insert it into basic data structures. */
131
132 varpool_node *
133 varpool_node::create_empty (void)
134 {
135 varpool_node *node = ggc_cleared_alloc<varpool_node> ();
136 node->type = SYMTAB_VARIABLE;
137 return node;
138 }
139
140 /* Return varpool node assigned to DECL. Create new one when needed. */
141 varpool_node *
142 varpool_node::get_create (tree decl)
143 {
144 varpool_node *node = varpool_node::get (decl);
145 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
146 if (node)
147 return node;
148
149 node = varpool_node::create_empty ();
150 node->decl = decl;
151
152 if ((flag_openacc || flag_openmp) && !DECL_EXTERNAL (decl)
153 && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
154 {
155 node->offloadable = 1;
156 if (ENABLE_OFFLOADING)
157 {
158 g->have_offload = true;
159 if (!in_lto_p)
160 vec_safe_push (offload_vars, decl);
161 }
162 }
163
164 node->register_symbol ();
165 return node;
166 }
167
168 /* Remove variable from symbol table. */
169
170 void
171 varpool_node::remove (void)
172 {
173 symtab->call_varpool_removal_hooks (this);
174 if (lto_file_data)
175 {
176 lto_free_function_in_decl_state_for_node (this);
177 lto_file_data = NULL;
178 }
179
180 /* When streaming we can have multiple nodes associated with decl. */
181 if (symtab->state == LTO_STREAMING)
182 ;
183 /* Keep constructor when it may be used for folding. We remove
184 references to external variables before final compilation. */
185 else if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node
186 && !ctor_useable_for_folding_p ())
187 remove_initializer ();
188
189 unregister ();
190 ggc_free (this);
191 }
192
193 /* Remove node initializer when it is no longer needed. */
194 void
195 varpool_node::remove_initializer (void)
196 {
197 if (DECL_INITIAL (decl)
198 && !DECL_IN_CONSTANT_POOL (decl)
199 /* Keep vtables for BINFO folding. */
200 && !DECL_VIRTUAL_P (decl)
201 /* FIXME: http://gcc.gnu.org/PR55395 */
202 && debug_info_level == DINFO_LEVEL_NONE
203 /* When doing declaration merging we have duplicate
204 entries for given decl. Do not attempt to remove
205 the boides, or we will end up remiving
206 wrong one. */
207 && symtab->state != LTO_STREAMING)
208 DECL_INITIAL (decl) = error_mark_node;
209 }
210
211 /* Dump given varpool node to F. */
212 void
213 varpool_node::dump (FILE *f)
214 {
215 dump_base (f);
216 fprintf (f, " Availability: %s\n",
217 symtab->function_flags_ready
218 ? cgraph_availability_names[get_availability ()]
219 : "not-ready");
220 fprintf (f, " Varpool flags:");
221 if (DECL_INITIAL (decl))
222 fprintf (f, " initialized");
223 if (output)
224 fprintf (f, " output");
225 if (used_by_single_function)
226 fprintf (f, " used-by-single-function");
227 if (need_bounds_init)
228 fprintf (f, " need-bounds-init");
229 if (TREE_READONLY (decl))
230 fprintf (f, " read-only");
231 if (ctor_useable_for_folding_p ())
232 fprintf (f, " const-value-known");
233 if (writeonly)
234 fprintf (f, " write-only");
235 if (tls_model)
236 fprintf (f, " tls-%s", tls_model_names [tls_model]);
237 fprintf (f, "\n");
238 }
239
240
241 /* Dump given varpool node to stderr. */
242 void varpool_node::debug (void)
243 {
244 varpool_node::dump (stderr);
245 }
246
247 /* Dump the variable pool to F. */
248 void
249 varpool_node::dump_varpool (FILE *f)
250 {
251 varpool_node *node;
252
253 fprintf (f, "variable pool:\n\n");
254 FOR_EACH_VARIABLE (node)
255 node->dump (f);
256 }
257
258 /* Dump the variable pool to stderr. */
259
260 DEBUG_FUNCTION void
261 varpool_node::debug_varpool (void)
262 {
263 dump_varpool (stderr);
264 }
265
266 /* Given an assembler name, lookup node. */
267 varpool_node *
268 varpool_node::get_for_asmname (tree asmname)
269 {
270 if (symtab_node *node = symtab_node::get_for_asmname (asmname))
271 return dyn_cast <varpool_node *> (node);
272 else
273 return NULL;
274 }
275
276 /* When doing LTO, read variable's constructor from disk if
277 it is not already present. */
278
279 tree
280 varpool_node::get_constructor (void)
281 {
282 lto_file_decl_data *file_data;
283 const char *data, *name;
284 size_t len;
285
286 if (DECL_INITIAL (decl) != error_mark_node
287 || !in_lto_p
288 || !lto_file_data)
289 return DECL_INITIAL (decl);
290
291 timevar_push (TV_IPA_LTO_CTORS_IN);
292
293 file_data = lto_file_data;
294 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
295
296 /* We may have renamed the declaration, e.g., a static function. */
297 name = lto_get_decl_name_mapping (file_data, name);
298 struct lto_in_decl_state *decl_state
299 = lto_get_function_in_decl_state (file_data, decl);
300
301 data = lto_get_section_data (file_data, LTO_section_function_body,
302 name, &len, decl_state->compressed);
303 if (!data)
304 fatal_error (input_location, "%s: section %s is missing",
305 file_data->file_name,
306 name);
307
308 lto_input_variable_constructor (file_data, this, data);
309 gcc_assert (DECL_INITIAL (decl) != error_mark_node);
310 lto_stats.num_function_bodies++;
311 lto_free_section_data (file_data, LTO_section_function_body, name,
312 data, len, decl_state->compressed);
313 lto_free_function_in_decl_state_for_node (this);
314 timevar_pop (TV_IPA_LTO_CTORS_IN);
315 return DECL_INITIAL (decl);
316 }
317
318 /* Return true if variable has constructor that can be used for folding. */
319
320 bool
321 varpool_node::ctor_useable_for_folding_p (void)
322 {
323 varpool_node *real_node = this;
324
325 if (real_node->alias && real_node->definition)
326 real_node = ultimate_alias_target ();
327
328 if (TREE_CODE (decl) == CONST_DECL
329 || DECL_IN_CONSTANT_POOL (decl))
330 return true;
331 if (TREE_THIS_VOLATILE (decl))
332 return false;
333
334 /* If we do not have a constructor, we can't use it. */
335 if (DECL_INITIAL (real_node->decl) == error_mark_node
336 && !real_node->lto_file_data)
337 return false;
338
339 /* Avoid attempts to load constructors that was not streamed. */
340 if (flag_ltrans && DECL_INITIAL (real_node->decl) == error_mark_node
341 && real_node->body_removed)
342 return false;
343
344 /* Vtables are defined by their types and must match no matter of interposition
345 rules. */
346 if (DECL_VIRTUAL_P (decl))
347 {
348 /* The C++ front end creates VAR_DECLs for vtables of typeinfo
349 classes not defined in the current TU so that it can refer
350 to them from typeinfo objects. Avoid returning NULL_TREE. */
351 return DECL_INITIAL (real_node->decl) != NULL;
352 }
353
354 /* Alias of readonly variable is also readonly, since the variable is stored
355 in readonly memory. We also accept readonly aliases of non-readonly
356 locations assuming that user knows what he is asking for. */
357 if (!TREE_READONLY (decl) && !TREE_READONLY (real_node->decl))
358 return false;
359
360 /* Variables declared 'const' without an initializer
361 have zero as the initializer if they may not be
362 overridden at link or run time.
363
364 It is actually requirement for C++ compiler to optimize const variables
365 consistently. As a GNU extension, do not enfore this rule for user defined
366 weak variables, so we support interposition on:
367 static const int dummy = 0;
368 extern const int foo __attribute__((__weak__, __alias__("dummy")));
369 */
370 if ((!DECL_INITIAL (real_node->decl)
371 || (DECL_WEAK (decl) && !DECL_COMDAT (decl)))
372 && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
373 return false;
374
375 /* Variables declared `const' with an initializer are considered
376 to not be overwritable with different initializer by default.
377
378 ??? Previously we behaved so for scalar variables but not for array
379 accesses. */
380 return true;
381 }
382
383 /* If DECLARATION is constant variable and its initial value is known
384 (so we can do constant folding), return its constructor (DECL_INITIAL).
385 This may be an expression or NULL when DECL is initialized to 0.
386 Return ERROR_MARK_NODE otherwise.
387
388 In LTO this may actually trigger reading the constructor from disk.
389 For this reason varpool_ctor_useable_for_folding_p should be used when
390 the actual constructor value is not needed. */
391
392 tree
393 ctor_for_folding (tree decl)
394 {
395 varpool_node *node, *real_node;
396 tree real_decl;
397
398 if (TREE_CODE (decl) != VAR_DECL
399 && TREE_CODE (decl) != CONST_DECL)
400 return error_mark_node;
401
402 /* Static constant bounds are created to be
403 used instead of constants and therefore
404 do not let folding it. */
405 if (POINTER_BOUNDS_P (decl))
406 return error_mark_node;
407
408 if (TREE_CODE (decl) == CONST_DECL
409 || DECL_IN_CONSTANT_POOL (decl))
410 return DECL_INITIAL (decl);
411
412 if (TREE_THIS_VOLATILE (decl))
413 return error_mark_node;
414
415 /* Do not care about automatic variables. Those are never initialized
416 anyway, because gimplifier exapnds the code. */
417 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
418 {
419 gcc_assert (!TREE_PUBLIC (decl));
420 return error_mark_node;
421 }
422
423 gcc_assert (TREE_CODE (decl) == VAR_DECL);
424
425 real_node = node = varpool_node::get (decl);
426 if (node)
427 {
428 real_node = node->ultimate_alias_target ();
429 real_decl = real_node->decl;
430 }
431 else
432 real_decl = decl;
433
434 /* See if we are dealing with alias.
435 In most cases alias is just alternative symbol pointing to a given
436 constructor. This allows us to use interposition rules of DECL
437 constructor of REAL_NODE. However weakrefs are special by being just
438 alternative name of their target (if defined). */
439 if (decl != real_decl)
440 {
441 gcc_assert (!DECL_INITIAL (decl)
442 || (node->alias && node->get_alias_target () == real_node)
443 || DECL_INITIAL (decl) == error_mark_node);
444 while (node->transparent_alias && node->analyzed)
445 {
446 node = node->get_alias_target ();
447 decl = node->decl;
448 }
449 }
450
451 if ((!DECL_VIRTUAL_P (real_decl)
452 || DECL_INITIAL (real_decl) == error_mark_node
453 || !DECL_INITIAL (real_decl))
454 && (!node || !node->ctor_useable_for_folding_p ()))
455 return error_mark_node;
456
457 /* OK, we can return constructor. See if we need to fetch it from disk
458 in LTO mode. */
459 if (DECL_INITIAL (real_decl) != error_mark_node
460 || !in_lto_p)
461 return DECL_INITIAL (real_decl);
462 return real_node->get_constructor ();
463 }
464
465 /* Add the variable DECL to the varpool.
466 Unlike finalize_decl function is intended to be used
467 by middle end and allows insertion of new variable at arbitrary point
468 of compilation. */
469 void
470 varpool_node::add (tree decl)
471 {
472 varpool_node *node;
473 varpool_node::finalize_decl (decl);
474 node = varpool_node::get_create (decl);
475 symtab->call_varpool_insertion_hooks (node);
476 if (node->externally_visible_p ())
477 node->externally_visible = true;
478 if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl)))
479 node->no_reorder = 1;
480 }
481
482 /* Return variable availability. See cgraph.h for description of individual
483 return values. */
484 enum availability
485 varpool_node::get_availability (symtab_node *ref)
486 {
487 if (!definition)
488 return AVAIL_NOT_AVAILABLE;
489 if (!TREE_PUBLIC (decl))
490 return AVAIL_AVAILABLE;
491 if (DECL_IN_CONSTANT_POOL (decl)
492 || DECL_VIRTUAL_P (decl))
493 return AVAIL_AVAILABLE;
494 if (transparent_alias && definition)
495 {
496 enum availability avail;
497
498 ultimate_alias_target (&avail, ref);
499 return avail;
500 }
501 /* If this is a reference from symbol itself and there are no aliases, we
502 may be sure that the symbol was not interposed by something else because
503 the symbol itself would be unreachable otherwise. */
504 if ((this == ref && !has_aliases_p ())
505 || (ref && get_comdat_group ()
506 && get_comdat_group () == ref->get_comdat_group ()))
507 return AVAIL_AVAILABLE;
508 /* If the variable can be overwritten, return OVERWRITABLE. Takes
509 care of at least one notable extension - the COMDAT variables
510 used to share template instantiations in C++. */
511 if (decl_replaceable_p (decl)
512 || DECL_EXTERNAL (decl))
513 return AVAIL_INTERPOSABLE;
514 return AVAIL_AVAILABLE;
515 }
516
517 void
518 varpool_node::analyze (void)
519 {
520 /* When reading back varpool at LTO time, we re-construct the queue in order
521 to have "needed" list right by inserting all needed nodes into varpool.
522 We however don't want to re-analyze already analyzed nodes. */
523 if (!analyzed)
524 {
525 gcc_assert (!in_lto_p || symtab->function_flags_ready);
526 /* Compute the alignment early so function body expanders are
527 already informed about increased alignment. */
528 align_variable (decl, 0);
529 }
530 if (alias)
531 resolve_alias (varpool_node::get (alias_target));
532 else if (DECL_INITIAL (decl))
533 record_references_in_initializer (decl, analyzed);
534 analyzed = true;
535 }
536
537 /* Assemble thunks and aliases associated to varpool node. */
538
539 void
540 varpool_node::assemble_aliases (void)
541 {
542 ipa_ref *ref;
543
544 FOR_EACH_ALIAS (this, ref)
545 {
546 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
547 if (!alias->transparent_alias)
548 do_assemble_alias (alias->decl,
549 DECL_ASSEMBLER_NAME (decl));
550 alias->assemble_aliases ();
551 }
552 }
553
554 /* Output one variable, if necessary. Return whether we output it. */
555
556 bool
557 varpool_node::assemble_decl (void)
558 {
559 /* Aliases are outout when their target is produced or by
560 output_weakrefs. */
561 if (alias)
562 return false;
563
564 /* Constant pool is output from RTL land when the reference
565 survive till this level. */
566 if (DECL_IN_CONSTANT_POOL (decl) && TREE_ASM_WRITTEN (decl))
567 return false;
568
569 /* Decls with VALUE_EXPR should not be in the varpool at all. They
570 are not real variables, but just info for debugging and codegen.
571 Unfortunately at the moment emutls is not updating varpool correctly
572 after turning real vars into value_expr vars. */
573 if (DECL_HAS_VALUE_EXPR_P (decl)
574 && !targetm.have_tls)
575 return false;
576
577 /* Hard register vars do not need to be output. */
578 if (DECL_HARD_REGISTER (decl))
579 return false;
580
581 gcc_checking_assert (!TREE_ASM_WRITTEN (decl)
582 && TREE_CODE (decl) == VAR_DECL
583 && !DECL_HAS_VALUE_EXPR_P (decl));
584
585 if (!in_other_partition
586 && !DECL_EXTERNAL (decl))
587 {
588 get_constructor ();
589 assemble_variable (decl, 0, 1, 0);
590 gcc_assert (TREE_ASM_WRITTEN (decl));
591 gcc_assert (definition);
592 assemble_aliases ();
593 /* After the parser has generated debugging information, augment
594 this information with any new location/etc information that may
595 have become available after the compilation proper. */
596 debug_hooks->late_global_decl (decl);
597 return true;
598 }
599
600 return false;
601 }
602
603 /* Add NODE to queue starting at FIRST.
604 The queue is linked via AUX pointers and terminated by pointer to 1. */
605
606 static void
607 enqueue_node (varpool_node *node, varpool_node **first)
608 {
609 if (node->aux)
610 return;
611 gcc_checking_assert (*first);
612 node->aux = *first;
613 *first = node;
614 }
615
616 /* Optimization of function bodies might've rendered some variables as
617 unnecessary so we want to avoid these from being compiled. Re-do
618 reachability starting from variables that are either externally visible
619 or was referred from the asm output routines. */
620
621 void
622 symbol_table::remove_unreferenced_decls (void)
623 {
624 varpool_node *next, *node;
625 varpool_node *first = (varpool_node *)(void *)1;
626 int i;
627 ipa_ref *ref = NULL;
628 hash_set<varpool_node *> referenced;
629
630 if (seen_error ())
631 return;
632
633 if (dump_file)
634 fprintf (dump_file, "Trivially needed variables:");
635 FOR_EACH_DEFINED_VARIABLE (node)
636 {
637 if (node->analyzed
638 && (!node->can_remove_if_no_refs_p ()
639 /* We just expanded all function bodies. See if any of
640 them needed the variable. */
641 || DECL_RTL_SET_P (node->decl)))
642 {
643 enqueue_node (node, &first);
644 if (dump_file)
645 fprintf (dump_file, " %s", node->asm_name ());
646 }
647 }
648 while (first != (varpool_node *)(void *)1)
649 {
650 node = first;
651 first = (varpool_node *)first->aux;
652
653 if (node->same_comdat_group)
654 {
655 symtab_node *next;
656 for (next = node->same_comdat_group;
657 next != node;
658 next = next->same_comdat_group)
659 {
660 varpool_node *vnext = dyn_cast <varpool_node *> (next);
661 if (vnext && vnext->analyzed && !next->comdat_local_p ())
662 enqueue_node (vnext, &first);
663 }
664 }
665 for (i = 0; node->iterate_reference (i, ref); i++)
666 {
667 varpool_node *vnode = dyn_cast <varpool_node *> (ref->referred);
668 if (vnode
669 && !vnode->in_other_partition
670 && (!DECL_EXTERNAL (ref->referred->decl)
671 || vnode->alias)
672 && vnode->analyzed)
673 enqueue_node (vnode, &first);
674 else
675 {
676 referenced.add (vnode);
677 while (vnode && vnode->alias && vnode->definition)
678 {
679 vnode = vnode->get_alias_target ();
680 referenced.add (vnode);
681 }
682 }
683 }
684 }
685 if (dump_file)
686 fprintf (dump_file, "\nRemoving variables:");
687 for (node = first_defined_variable (); node; node = next)
688 {
689 next = next_defined_variable (node);
690 if (!node->aux && !node->no_reorder)
691 {
692 if (dump_file)
693 fprintf (dump_file, " %s", node->asm_name ());
694 if (referenced.contains(node))
695 node->remove_initializer ();
696 else
697 node->remove ();
698 }
699 }
700
701 if (dump_file)
702 fprintf (dump_file, "\n");
703 }
704
705 /* For variables in named sections make sure get_variable_section
706 is called before we switch to those sections. Then section
707 conflicts between read-only and read-only requiring relocations
708 sections can be resolved. */
709 void
710 varpool_node::finalize_named_section_flags (void)
711 {
712 if (!TREE_ASM_WRITTEN (decl)
713 && !alias
714 && !in_other_partition
715 && !DECL_EXTERNAL (decl)
716 && TREE_CODE (decl) == VAR_DECL
717 && !DECL_HAS_VALUE_EXPR_P (decl)
718 && get_section ())
719 get_variable_section (decl, false);
720 }
721
722 /* Output all variables enqueued to be assembled. */
723 bool
724 symbol_table::output_variables (void)
725 {
726 bool changed = false;
727 varpool_node *node;
728
729 if (seen_error ())
730 return false;
731
732 remove_unreferenced_decls ();
733
734 timevar_push (TV_VAROUT);
735
736 FOR_EACH_DEFINED_VARIABLE (node)
737 {
738 /* Handled in output_in_order. */
739 if (node->no_reorder)
740 continue;
741
742 node->finalize_named_section_flags ();
743 }
744
745 /* There is a similar loop in output_in_order. Please keep them in sync. */
746 FOR_EACH_VARIABLE (node)
747 {
748 /* Handled in output_in_order. */
749 if (node->no_reorder)
750 continue;
751 if (DECL_HARD_REGISTER (node->decl)
752 || DECL_HAS_VALUE_EXPR_P (node->decl))
753 continue;
754 if (node->definition)
755 changed |= node->assemble_decl ();
756 else
757 assemble_undefined_decl (node->decl);
758 }
759 timevar_pop (TV_VAROUT);
760 return changed;
761 }
762
763 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
764 Extra name aliases are output whenever DECL is output. */
765
766 varpool_node *
767 varpool_node::create_alias (tree alias, tree decl)
768 {
769 varpool_node *alias_node;
770
771 gcc_assert (TREE_CODE (decl) == VAR_DECL);
772 gcc_assert (TREE_CODE (alias) == VAR_DECL);
773 alias_node = varpool_node::get_create (alias);
774 alias_node->alias = true;
775 alias_node->definition = true;
776 alias_node->alias_target = decl;
777 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
778 alias_node->weakref = alias_node->transparent_alias = true;
779 return alias_node;
780 }
781
782 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
783 Extra name aliases are output whenever DECL is output. */
784
785 varpool_node *
786 varpool_node::create_extra_name_alias (tree alias, tree decl)
787 {
788 varpool_node *alias_node;
789
790 #ifndef ASM_OUTPUT_DEF
791 /* If aliases aren't supported by the assembler, fail. */
792 return NULL;
793 #endif
794 alias_node = varpool_node::create_alias (alias, decl);
795 alias_node->cpp_implicit_alias = true;
796
797 /* Extra name alias mechanizm creates aliases really late
798 via DECL_ASSEMBLER_NAME mechanizm.
799 This is unfortunate because they are not going through the
800 standard channels. Ensure they get output. */
801 if (symtab->cpp_implicit_aliases_done)
802 alias_node->resolve_alias (varpool_node::get_create (decl));
803 return alias_node;
804 }
805
806 /* Worker for call_for_symbol_and_aliases. */
807
808 bool
809 varpool_node::call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *,
810 void *),
811 void *data,
812 bool include_overwritable)
813 {
814 ipa_ref *ref;
815
816 FOR_EACH_ALIAS (this, ref)
817 {
818 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
819 if (include_overwritable
820 || alias->get_availability () > AVAIL_INTERPOSABLE)
821 if (alias->call_for_symbol_and_aliases (callback, data,
822 include_overwritable))
823 return true;
824 }
825 return false;
826 }