2 Copyright 2009 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
5 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
28 #include "lambda.h" /* gcd */
30 #include "plugin-api.h"
31 #include "lto-streamer.h"
33 /* Vector to keep track of external variables we've seen so far. */
34 VEC(tree,gc) *lto_global_var_decls;
36 /* Symbol table entry. */
38 struct GTY(()) lto_symtab_entry_def
40 /* The symbol table entry key, an IDENTIFIER. */
42 /* The symbol table entry, a DECL. */
44 /* The cgraph node if decl is a function decl. Filled in during the
46 struct cgraph_node *node;
47 /* The varpool node if decl is a variable decl. Filled in during the
49 struct varpool_node *vnode;
50 /* LTO file-data and symbol resolution for this decl. */
51 struct lto_file_decl_data * GTY((skip (""))) file_data;
52 enum ld_plugin_symbol_resolution resolution;
53 /* Pointer to the next entry with the same key. Before decl merging
54 this links all symbols from the different TUs. After decl merging
55 this links merged but incompatible decls, thus all prevailing ones
57 struct lto_symtab_entry_def *next;
59 typedef struct lto_symtab_entry_def *lto_symtab_entry_t;
61 /* A poor man's symbol table. This hashes identifier to prevailing DECL
64 static GTY ((if_marked ("lto_symtab_entry_marked_p"),
65 param_is (struct lto_symtab_entry_def)))
66 htab_t lto_symtab_identifiers;
68 /* Free symtab hashtable. */
71 lto_symtab_free (void)
73 htab_delete (lto_symtab_identifiers);
74 lto_symtab_identifiers = NULL;
77 /* Return the hash value of an lto_symtab_entry_t object pointed to by P. */
80 lto_symtab_entry_hash (const void *p)
82 const struct lto_symtab_entry_def *base =
83 (const struct lto_symtab_entry_def *) p;
84 return IDENTIFIER_HASH_VALUE (base->id);
87 /* Return non-zero if P1 and P2 points to lto_symtab_entry_def structs
88 corresponding to the same symbol. */
91 lto_symtab_entry_eq (const void *p1, const void *p2)
93 const struct lto_symtab_entry_def *base1 =
94 (const struct lto_symtab_entry_def *) p1;
95 const struct lto_symtab_entry_def *base2 =
96 (const struct lto_symtab_entry_def *) p2;
97 return (base1->id == base2->id);
100 /* Returns non-zero if P points to an lto_symtab_entry_def struct that needs
101 to be marked for GC. */
104 lto_symtab_entry_marked_p (const void *p)
106 const struct lto_symtab_entry_def *base =
107 (const struct lto_symtab_entry_def *) p;
109 /* Keep this only if the common IDENTIFIER_NODE of the symtab chain
110 is marked which it will be if at least one of the DECLs in the
112 return ggc_marked_p (base->id);
115 /* Lazily initialize resolution hash tables. */
118 lto_symtab_maybe_init_hash_table (void)
120 if (lto_symtab_identifiers)
123 lto_symtab_identifiers =
124 htab_create_ggc (1021, lto_symtab_entry_hash,
125 lto_symtab_entry_eq, NULL);
128 /* Registers DECL with the LTO symbol table as having resolution RESOLUTION
129 and read from FILE_DATA. */
132 lto_symtab_register_decl (tree decl,
133 ld_plugin_symbol_resolution_t resolution,
134 struct lto_file_decl_data *file_data)
136 lto_symtab_entry_t new_entry;
139 /* Check that declarations reaching this function do not have
140 properties inconsistent with having external linkage. If any of
141 these asertions fail, then the object file reader has failed to
142 detect these cases and issue appropriate error messages. */
144 && TREE_PUBLIC (decl)
145 && (TREE_CODE (decl) == VAR_DECL
146 || TREE_CODE (decl) == FUNCTION_DECL)
147 && DECL_ASSEMBLER_NAME_SET_P (decl));
148 if (TREE_CODE (decl) == VAR_DECL
149 && DECL_INITIAL (decl))
150 gcc_assert (!DECL_EXTERNAL (decl)
151 || (TREE_STATIC (decl) && TREE_READONLY (decl)));
152 if (TREE_CODE (decl) == FUNCTION_DECL)
153 gcc_assert (!DECL_ABSTRACT (decl));
155 new_entry = ggc_alloc_cleared_lto_symtab_entry_def ();
156 new_entry->id = DECL_ASSEMBLER_NAME (decl);
157 new_entry->decl = decl;
158 new_entry->resolution = resolution;
159 new_entry->file_data = file_data;
161 lto_symtab_maybe_init_hash_table ();
162 slot = htab_find_slot (lto_symtab_identifiers, new_entry, INSERT);
163 new_entry->next = (lto_symtab_entry_t) *slot;
167 /* Get the lto_symtab_entry_def struct associated with ID
170 static lto_symtab_entry_t
171 lto_symtab_get (tree id)
173 struct lto_symtab_entry_def temp;
176 lto_symtab_maybe_init_hash_table ();
178 slot = htab_find_slot (lto_symtab_identifiers, &temp, NO_INSERT);
179 return slot ? (lto_symtab_entry_t) *slot : NULL;
182 /* Get the linker resolution for DECL. */
184 enum ld_plugin_symbol_resolution
185 lto_symtab_get_resolution (tree decl)
187 lto_symtab_entry_t e;
189 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
191 e = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
192 while (e && e->decl != decl)
197 return e->resolution;
201 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
202 all edges and removing the old node. */
205 lto_cgraph_replace_node (struct cgraph_node *node,
206 struct cgraph_node *prevailing_node)
208 struct cgraph_edge *e, *next;
209 bool no_aliases_please = false;
211 if (cgraph_dump_file)
213 fprintf (cgraph_dump_file, "Replacing cgraph node %s/%i by %s/%i"
215 cgraph_node_name (node), node->uid,
216 cgraph_node_name (prevailing_node),
217 prevailing_node->uid,
218 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
221 if (prevailing_node->same_body_alias)
223 if (prevailing_node->thunk.thunk_p)
224 no_aliases_please = true;
225 prevailing_node = prevailing_node->same_body;
228 /* Merge node flags. */
230 cgraph_mark_needed_node (prevailing_node);
232 cgraph_mark_reachable_node (prevailing_node);
233 if (node->address_taken)
235 gcc_assert (!prevailing_node->global.inlined_to);
236 cgraph_mark_address_taken_node (prevailing_node);
239 /* Redirect all incoming edges. */
240 for (e = node->callers; e; e = next)
242 next = e->next_caller;
243 cgraph_redirect_edge_callee (e, prevailing_node);
245 /* Redirect incomming references. */
246 ipa_clone_refering (prevailing_node, NULL, &node->ref_list);
248 /* If we have aliases, redirect them to the prevailing node. */
249 if (!node->same_body_alias && node->same_body)
251 struct cgraph_node *alias, *last;
252 /* We prevail aliases/tunks by a thunk. This is doable but
253 would need thunk combination. Hopefully no ABI changes will
254 every be crazy enough. */
255 gcc_assert (!no_aliases_please);
257 for (alias = node->same_body; alias; alias = alias->next)
260 gcc_assert (alias->same_body_alias);
261 alias->same_body = prevailing_node;
262 alias->thunk.alias = prevailing_node->decl;
264 last->next = prevailing_node->same_body;
265 /* Node with aliases is prevailed by alias.
266 We could handle this, but combining thunks together will be tricky.
267 Hopefully this does not happen. */
268 if (prevailing_node->same_body)
269 prevailing_node->same_body->previous = last;
270 prevailing_node->same_body = node->same_body;
271 node->same_body = NULL;
274 /* Finally remove the replaced node. */
275 if (node->same_body_alias)
276 cgraph_remove_same_body_alias (node);
278 cgraph_remove_node (node);
281 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
282 all edges and removing the old node. */
285 lto_varpool_replace_node (struct varpool_node *vnode,
286 struct varpool_node *prevailing_node)
288 /* Merge node flags. */
291 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
292 varpool_mark_needed_node (prevailing_node);
294 /* Relink aliases. */
295 if (vnode->extra_name && !vnode->alias)
297 struct varpool_node *alias, *last;
298 for (alias = vnode->extra_name;
299 alias; alias = alias->next)
302 alias->extra_name = prevailing_node;
305 if (prevailing_node->extra_name)
307 last->next = prevailing_node->extra_name;
308 prevailing_node->extra_name->prev = last;
310 prevailing_node->extra_name = vnode->extra_name;
311 vnode->extra_name = NULL;
313 gcc_assert (!vnode->finalized || prevailing_node->finalized);
314 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
316 /* When replacing by an alias, the references goes to the original
318 if (prevailing_node->alias && prevailing_node->extra_name)
319 prevailing_node = prevailing_node->extra_name;
320 ipa_clone_refering (NULL, prevailing_node, &vnode->ref_list);
322 /* Be sure we can garbage collect the initializer. */
323 if (DECL_INITIAL (vnode->decl))
324 DECL_INITIAL (vnode->decl) = error_mark_node;
325 /* Finally remove the replaced node. */
326 varpool_remove_node (vnode);
329 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
330 Return false if the symbols are not fully compatible and a diagnostic
331 should be emitted. */
334 lto_symtab_merge (lto_symtab_entry_t prevailing, lto_symtab_entry_t entry)
336 tree prevailing_decl = prevailing->decl;
337 tree decl = entry->decl;
338 tree prevailing_type, type;
340 /* Merge decl state in both directions, we may still end up using
342 TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
343 TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
345 /* The linker may ask us to combine two incompatible symbols.
346 Detect this case and notify the caller of required diagnostics. */
348 if (TREE_CODE (decl) == FUNCTION_DECL)
350 if (TREE_TYPE (prevailing_decl) != TREE_TYPE (decl))
351 /* If we don't have a merged type yet...sigh. The linker
352 wouldn't complain if the types were mismatched, so we
353 probably shouldn't either. Just use the type from
354 whichever decl appears to be associated with the
355 definition. If for some odd reason neither decl is, the
362 /* Now we exclusively deal with VAR_DECLs. */
364 /* Sharing a global symbol is a strong hint that two types are
365 compatible. We could use this information to complete
366 incomplete pointed-to types more aggressively here, ignoring
367 mismatches in both field and tag names. It's difficult though
368 to guarantee that this does not have side-effects on merging
369 more compatible types from other translation units though. */
371 /* We can tolerate differences in type qualification, the
372 qualification of the prevailing definition will prevail.
373 ??? In principle we might want to only warn for structurally
374 incompatible types here, but unless we have protective measures
375 for TBAA in place that would hide useful information. */
376 prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
377 type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
379 /* We have to register and fetch canonical types here as the global
380 fixup process didn't yet run. */
381 prevailing_type = gimple_register_type (prevailing_type);
382 type = gimple_register_type (type);
383 if (prevailing_type != type)
385 if (COMPLETE_TYPE_P (type))
388 /* If type is incomplete then avoid warnings in the cases
389 that TBAA handles just fine. */
391 if (TREE_CODE (prevailing_type) != TREE_CODE (type))
394 if (TREE_CODE (prevailing_type) == ARRAY_TYPE)
396 tree tem1 = TREE_TYPE (prevailing_type);
397 tree tem2 = TREE_TYPE (type);
398 while (TREE_CODE (tem1) == ARRAY_TYPE
399 && TREE_CODE (tem2) == ARRAY_TYPE)
401 tem1 = TREE_TYPE (tem1);
402 tem2 = TREE_TYPE (tem2);
405 if (TREE_CODE (tem1) != TREE_CODE (tem2))
408 if (gimple_register_type (tem1) != gimple_register_type (tem2))
412 /* Fallthru. Compatible enough. */
415 /* ??? We might want to emit a warning here if type qualification
416 differences were spotted. Do not do this unconditionally though. */
418 /* There is no point in comparing too many details of the decls here.
419 The type compatibility checks or the completing of types has properly
420 dealt with most issues. */
422 /* The following should all not invoke fatal errors as in non-LTO
423 mode the linker wouldn't complain either. Just emit warnings. */
425 /* Report a warning if user-specified alignments do not match. */
426 if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
427 && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
433 /* Return true if the symtab entry E can be replaced by another symtab
437 lto_symtab_resolve_replaceable_p (lto_symtab_entry_t e)
439 if (DECL_EXTERNAL (e->decl)
440 || DECL_COMDAT (e->decl)
441 || DECL_WEAK (e->decl))
444 if (TREE_CODE (e->decl) == VAR_DECL)
445 return (DECL_COMMON (e->decl)
446 || (!flag_no_common && !DECL_INITIAL (e->decl)));
451 /* Return true if the symtab entry E can be the prevailing one. */
454 lto_symtab_resolve_can_prevail_p (lto_symtab_entry_t e)
456 /* The C++ frontend ends up neither setting TREE_STATIC nor
457 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
458 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
459 if (DECL_EXTERNAL (e->decl))
462 /* For functions we need a non-discarded body. */
463 if (TREE_CODE (e->decl) == FUNCTION_DECL)
465 && (e->node->analyzed
466 || (e->node->same_body_alias && e->node->same_body->analyzed)));
468 /* A variable should have a size. */
469 else if (TREE_CODE (e->decl) == VAR_DECL)
473 if (e->vnode->finalized)
475 return e->vnode->alias && e->vnode->extra_name->finalized;
481 /* Resolve the symbol with the candidates in the chain *SLOT and store
482 their resolutions. */
485 lto_symtab_resolve_symbols (void **slot)
487 lto_symtab_entry_t e;
488 lto_symtab_entry_t prevailing = NULL;
490 /* Always set e->node so that edges are updated to reflect decl merging. */
491 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
493 if (TREE_CODE (e->decl) == FUNCTION_DECL)
494 e->node = cgraph_get_node_or_alias (e->decl);
495 else if (TREE_CODE (e->decl) == VAR_DECL)
497 e->vnode = varpool_get_node (e->decl);
498 /* The LTO plugin for gold doesn't handle common symbols
499 properly. Let us choose manually. */
500 if (DECL_COMMON (e->decl))
501 e->resolution = LDPR_UNKNOWN;
505 e = (lto_symtab_entry_t) *slot;
507 /* If the chain is already resolved there is nothing else to do. */
508 if (e->resolution != LDPR_UNKNOWN)
511 /* Find the single non-replaceable prevailing symbol and
512 diagnose ODR violations. */
513 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
515 if (!lto_symtab_resolve_can_prevail_p (e))
517 e->resolution = LDPR_RESOLVED_IR;
521 /* Set a default resolution - the final prevailing one will get
523 e->resolution = LDPR_PREEMPTED_IR;
524 if (!lto_symtab_resolve_replaceable_p (e))
528 error_at (DECL_SOURCE_LOCATION (e->decl),
529 "%qD has already been defined", e->decl);
530 inform (DECL_SOURCE_LOCATION (prevailing->decl),
531 "previously defined here");
539 /* Do a second round choosing one from the replaceable prevailing decls. */
540 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
542 if (e->resolution != LDPR_PREEMPTED_IR)
545 /* Choose the first function that can prevail as prevailing. */
546 if (TREE_CODE (e->decl) == FUNCTION_DECL)
552 /* From variables that can prevail choose the largest one. */
554 || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
555 DECL_SIZE (e->decl)))
563 /* If current lto files represent the whole program,
564 it is correct to use LDPR_PREVALING_DEF_IRONLY.
565 If current lto files are part of whole program, internal
566 resolver doesn't know if it is LDPR_PREVAILING_DEF
567 or LDPR_PREVAILING_DEF_IRONLY. Use IRONLY conforms to
568 using -fwhole-program. Otherwise, it doesn't
569 matter using either LDPR_PREVAILING_DEF or
570 LDPR_PREVAILING_DEF_IRONLY
572 FIXME: above workaround due to gold plugin makes some
573 variables IRONLY, which are indeed PREVAILING_DEF in
574 resolution file. These variables still need manual
575 externally_visible attribute. */
576 prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
579 /* Merge all decls in the symbol table chain to the prevailing decl and
580 issue diagnostics about type mismatches. */
583 lto_symtab_merge_decls_2 (void **slot)
585 lto_symtab_entry_t prevailing, e;
586 VEC(tree, heap) *mismatches = NULL;
589 bool diagnosed_p = false;
591 /* Nothing to do for a single entry. */
592 prevailing = (lto_symtab_entry_t) *slot;
593 if (!prevailing->next)
596 /* Try to merge each entry with the prevailing one. */
597 for (e = prevailing->next; e; e = e->next)
599 if (!lto_symtab_merge (prevailing, e))
600 VEC_safe_push (tree, heap, mismatches, e->decl);
602 if (VEC_empty (tree, mismatches))
605 /* Diagnose all mismatched re-declarations. */
606 for (i = 0; VEC_iterate (tree, mismatches, i, decl); ++i)
608 if (TREE_TYPE (prevailing->decl) != TREE_TYPE (decl))
609 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
610 "type of %qD does not match original "
611 "declaration", decl);
613 else if ((DECL_USER_ALIGN (prevailing->decl) && DECL_USER_ALIGN (decl))
614 && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
616 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
617 "alignment of %qD is bigger than "
618 "original declaration", decl);
622 inform (DECL_SOURCE_LOCATION (prevailing->decl),
623 "previously declared here");
625 VEC_free (tree, heap, mismatches);
628 /* Helper to process the decl chain for the symbol table entry *SLOT. */
631 lto_symtab_merge_decls_1 (void **slot, void *data ATTRIBUTE_UNUSED)
633 lto_symtab_entry_t e, prevailing;
634 bool diagnosed_p = false;
636 /* Compute the symbol resolutions. This is a no-op when using the
638 lto_symtab_resolve_symbols (slot);
640 /* Find the prevailing decl. */
641 for (prevailing = (lto_symtab_entry_t) *slot;
643 && prevailing->resolution != LDPR_PREVAILING_DEF_IRONLY
644 && prevailing->resolution != LDPR_PREVAILING_DEF;
645 prevailing = prevailing->next)
648 /* Assert it's the only one. */
650 for (e = prevailing->next; e; e = e->next)
651 gcc_assert (e->resolution != LDPR_PREVAILING_DEF_IRONLY
652 && e->resolution != LDPR_PREVAILING_DEF);
654 /* If there's not a prevailing symbol yet it's an external reference.
655 Happens a lot during ltrans. Choose the first symbol with a
656 cgraph or a varpool node. */
659 prevailing = (lto_symtab_entry_t) *slot;
660 /* For functions choose one with a cgraph node. */
661 if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
662 while (!prevailing->node
664 prevailing = prevailing->next;
665 /* For variables chose with a priority variant with vnode
666 attached (i.e. from unit where external declaration of
667 variable is actually used).
668 When there are multiple variants, chose one with size.
669 This is needed for C++ typeinfos, for example in
670 lto/20081204-1 there are typeifos in both units, just
671 one of them do have size. */
672 if (TREE_CODE (prevailing->decl) == VAR_DECL)
674 for (e = prevailing->next; e; e = e->next)
675 if ((!prevailing->vnode && e->vnode)
676 || ((prevailing->vnode != NULL) == (e->vnode != NULL)
677 && !COMPLETE_TYPE_P (TREE_TYPE (prevailing->decl))
678 && COMPLETE_TYPE_P (TREE_TYPE (e->decl))))
683 /* Move it first in the list. */
684 if ((lto_symtab_entry_t) *slot != prevailing)
686 for (e = (lto_symtab_entry_t) *slot; e->next != prevailing; e = e->next)
688 e->next = prevailing->next;
689 prevailing->next = (lto_symtab_entry_t) *slot;
690 *slot = (void *) prevailing;
693 /* Record the prevailing variable. */
694 if (TREE_CODE (prevailing->decl) == VAR_DECL)
695 VEC_safe_push (tree, gc, lto_global_var_decls, prevailing->decl);
697 /* Diagnose mismatched objects. */
698 for (e = prevailing->next; e; e = e->next)
700 if (TREE_CODE (prevailing->decl) == TREE_CODE (e->decl))
703 switch (TREE_CODE (prevailing->decl))
706 gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
707 error_at (DECL_SOURCE_LOCATION (e->decl),
708 "variable %qD redeclared as function", prevailing->decl);
712 gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
713 error_at (DECL_SOURCE_LOCATION (e->decl),
714 "function %qD redeclared as variable", prevailing->decl);
724 inform (DECL_SOURCE_LOCATION (prevailing->decl),
725 "previously declared here");
727 /* Register and adjust types of the entries. */
728 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
729 TREE_TYPE (e->decl) = gimple_register_type (TREE_TYPE (e->decl));
731 /* Merge the chain to the single prevailing decl and diagnose
733 lto_symtab_merge_decls_2 (slot);
735 /* Drop all but the prevailing decl from the symtab. */
736 if (TREE_CODE (prevailing->decl) != FUNCTION_DECL
737 && TREE_CODE (prevailing->decl) != VAR_DECL)
738 prevailing->next = NULL;
740 /* Set externally_visible flags for declaration of LDPR_PREVAILING_DEF */
741 if (flag_whole_program)
743 if (prevailing->resolution == LDPR_PREVAILING_DEF)
745 if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
746 prevailing->node->local.used_from_object_file = true;
748 prevailing->vnode->used_from_object_file = true;
750 else if (prevailing->resolution == LDPR_PREVAILING_DEF_IRONLY)
752 if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
753 prevailing->node->local.used_from_object_file = false;
755 prevailing->vnode->used_from_object_file = false;
761 /* Resolve and merge all symbol table chains to a prevailing decl. */
764 lto_symtab_merge_decls (void)
766 lto_symtab_maybe_init_hash_table ();
767 htab_traverse (lto_symtab_identifiers, lto_symtab_merge_decls_1, NULL);
770 /* Helper to process the decl chain for the symbol table entry *SLOT. */
773 lto_symtab_merge_cgraph_nodes_1 (void **slot, void *data ATTRIBUTE_UNUSED)
775 lto_symtab_entry_t e, prevailing = (lto_symtab_entry_t) *slot;
777 if (!prevailing->next)
780 /* Replace the cgraph node of each entry with the prevailing one. */
781 for (e = prevailing->next; e; e = e->next)
784 lto_cgraph_replace_node (e->node, prevailing->node);
785 if (e->vnode != NULL)
786 lto_varpool_replace_node (e->vnode, prevailing->vnode);
789 /* Drop all but the prevailing decl from the symtab. */
790 prevailing->next = NULL;
795 /* Merge cgraph nodes according to the symbol merging done by
796 lto_symtab_merge_decls. */
799 lto_symtab_merge_cgraph_nodes (void)
801 lto_symtab_maybe_init_hash_table ();
802 htab_traverse (lto_symtab_identifiers, lto_symtab_merge_cgraph_nodes_1, NULL);
805 /* Given the decl DECL, return the prevailing decl with the same name. */
808 lto_symtab_prevailing_decl (tree decl)
810 lto_symtab_entry_t ret;
812 /* Builtins and local symbols are their own prevailing decl. */
813 if (!TREE_PUBLIC (decl) || is_builtin_fn (decl))
816 /* DECL_ABSTRACTs are their own prevailng decl. */
817 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
820 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
821 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
823 /* Walk through the list of candidates and return the one we merged to. */
824 ret = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
831 #include "gt-lto-symtab.h"