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"
24 #include "diagnostic-core.h"
29 #include "lambda.h" /* gcd */
31 #include "plugin-api.h"
32 #include "lto-streamer.h"
34 /* Vector to keep track of external variables we've seen so far. */
35 VEC(tree,gc) *lto_global_var_decls;
37 /* Symbol table entry. */
39 struct GTY(()) lto_symtab_entry_def
41 /* The symbol table entry key, an IDENTIFIER. */
43 /* The symbol table entry, a DECL. */
45 /* The cgraph node if decl is a function decl. Filled in during the
47 struct cgraph_node *node;
48 /* The varpool node if decl is a variable decl. Filled in during the
50 struct varpool_node *vnode;
51 /* LTO file-data and symbol resolution for this decl. */
52 struct lto_file_decl_data * GTY((skip (""))) file_data;
53 enum ld_plugin_symbol_resolution resolution;
54 /* True when resolution was guessed and not read from the file. */
56 /* Pointer to the next entry with the same key. Before decl merging
57 this links all symbols from the different TUs. After decl merging
58 this links merged but incompatible decls, thus all prevailing ones
60 struct lto_symtab_entry_def *next;
62 typedef struct lto_symtab_entry_def *lto_symtab_entry_t;
64 /* A poor man's symbol table. This hashes identifier to prevailing DECL
67 static GTY ((if_marked ("lto_symtab_entry_marked_p"),
68 param_is (struct lto_symtab_entry_def)))
69 htab_t lto_symtab_identifiers;
71 /* Free symtab hashtable. */
74 lto_symtab_free (void)
76 htab_delete (lto_symtab_identifiers);
77 lto_symtab_identifiers = NULL;
80 /* Return the hash value of an lto_symtab_entry_t object pointed to by P. */
83 lto_symtab_entry_hash (const void *p)
85 const struct lto_symtab_entry_def *base =
86 (const struct lto_symtab_entry_def *) p;
87 return IDENTIFIER_HASH_VALUE (base->id);
90 /* Return non-zero if P1 and P2 points to lto_symtab_entry_def structs
91 corresponding to the same symbol. */
94 lto_symtab_entry_eq (const void *p1, const void *p2)
96 const struct lto_symtab_entry_def *base1 =
97 (const struct lto_symtab_entry_def *) p1;
98 const struct lto_symtab_entry_def *base2 =
99 (const struct lto_symtab_entry_def *) p2;
100 return (base1->id == base2->id);
103 /* Returns non-zero if P points to an lto_symtab_entry_def struct that needs
104 to be marked for GC. */
107 lto_symtab_entry_marked_p (const void *p)
109 const struct lto_symtab_entry_def *base =
110 (const struct lto_symtab_entry_def *) p;
112 /* Keep this only if the common IDENTIFIER_NODE of the symtab chain
113 is marked which it will be if at least one of the DECLs in the
115 return ggc_marked_p (base->id);
118 /* Lazily initialize resolution hash tables. */
121 lto_symtab_maybe_init_hash_table (void)
123 if (lto_symtab_identifiers)
126 lto_symtab_identifiers =
127 htab_create_ggc (1021, lto_symtab_entry_hash,
128 lto_symtab_entry_eq, NULL);
131 /* Registers DECL with the LTO symbol table as having resolution RESOLUTION
132 and read from FILE_DATA. */
135 lto_symtab_register_decl (tree decl,
136 ld_plugin_symbol_resolution_t resolution,
137 struct lto_file_decl_data *file_data)
139 lto_symtab_entry_t new_entry;
142 /* Check that declarations reaching this function do not have
143 properties inconsistent with having external linkage. If any of
144 these asertions fail, then the object file reader has failed to
145 detect these cases and issue appropriate error messages. */
147 && TREE_PUBLIC (decl)
148 && (TREE_CODE (decl) == VAR_DECL
149 || TREE_CODE (decl) == FUNCTION_DECL)
150 && DECL_ASSEMBLER_NAME_SET_P (decl));
151 if (TREE_CODE (decl) == VAR_DECL
152 && DECL_INITIAL (decl))
153 gcc_assert (!DECL_EXTERNAL (decl)
154 || (TREE_STATIC (decl) && TREE_READONLY (decl)));
155 if (TREE_CODE (decl) == FUNCTION_DECL)
156 gcc_assert (!DECL_ABSTRACT (decl));
158 new_entry = ggc_alloc_cleared_lto_symtab_entry_def ();
159 new_entry->id = DECL_ASSEMBLER_NAME (decl);
160 new_entry->decl = decl;
161 new_entry->resolution = resolution;
162 new_entry->file_data = file_data;
164 lto_symtab_maybe_init_hash_table ();
165 slot = htab_find_slot (lto_symtab_identifiers, new_entry, INSERT);
166 new_entry->next = (lto_symtab_entry_t) *slot;
170 /* Get the lto_symtab_entry_def struct associated with ID
173 static lto_symtab_entry_t
174 lto_symtab_get (tree id)
176 struct lto_symtab_entry_def temp;
179 lto_symtab_maybe_init_hash_table ();
181 slot = htab_find_slot (lto_symtab_identifiers, &temp, NO_INSERT);
182 return slot ? (lto_symtab_entry_t) *slot : NULL;
185 /* Get the linker resolution for DECL. */
187 enum ld_plugin_symbol_resolution
188 lto_symtab_get_resolution (tree decl)
190 lto_symtab_entry_t e;
192 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
194 e = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
195 while (e && e->decl != decl)
200 return e->resolution;
204 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
205 all edges and removing the old node. */
208 lto_cgraph_replace_node (struct cgraph_node *node,
209 struct cgraph_node *prevailing_node)
211 struct cgraph_edge *e, *next;
212 bool no_aliases_please = false;
214 if (cgraph_dump_file)
216 fprintf (cgraph_dump_file, "Replacing cgraph node %s/%i by %s/%i"
218 cgraph_node_name (node), node->uid,
219 cgraph_node_name (prevailing_node),
220 prevailing_node->uid,
221 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
224 if (prevailing_node->same_body_alias)
226 if (prevailing_node->thunk.thunk_p)
227 no_aliases_please = true;
228 prevailing_node = prevailing_node->same_body;
231 /* Merge node flags. */
233 cgraph_mark_needed_node (prevailing_node);
235 cgraph_mark_reachable_node (prevailing_node);
236 if (node->address_taken)
238 gcc_assert (!prevailing_node->global.inlined_to);
239 cgraph_mark_address_taken_node (prevailing_node);
242 /* Redirect all incoming edges. */
243 for (e = node->callers; e; e = next)
245 next = e->next_caller;
246 cgraph_redirect_edge_callee (e, prevailing_node);
248 /* Redirect incomming references. */
249 ipa_clone_refering (prevailing_node, NULL, &node->ref_list);
251 /* If we have aliases, redirect them to the prevailing node. */
252 if (!node->same_body_alias && node->same_body)
254 struct cgraph_node *alias, *last;
255 /* We prevail aliases/tunks by a thunk. This is doable but
256 would need thunk combination. Hopefully no ABI changes will
257 every be crazy enough. */
258 gcc_assert (!no_aliases_please);
260 for (alias = node->same_body; alias; alias = alias->next)
263 gcc_assert (alias->same_body_alias);
264 alias->same_body = prevailing_node;
265 alias->thunk.alias = prevailing_node->decl;
267 last->next = prevailing_node->same_body;
268 /* Node with aliases is prevailed by alias.
269 We could handle this, but combining thunks together will be tricky.
270 Hopefully this does not happen. */
271 if (prevailing_node->same_body)
272 prevailing_node->same_body->previous = last;
273 prevailing_node->same_body = node->same_body;
274 node->same_body = NULL;
277 /* Finally remove the replaced node. */
278 if (node->same_body_alias)
279 cgraph_remove_same_body_alias (node);
281 cgraph_remove_node (node);
284 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
285 all edges and removing the old node. */
288 lto_varpool_replace_node (struct varpool_node *vnode,
289 struct varpool_node *prevailing_node)
291 /* Merge node flags. */
294 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
295 varpool_mark_needed_node (prevailing_node);
297 /* Relink aliases. */
298 if (vnode->extra_name && !vnode->alias)
300 struct varpool_node *alias, *last;
301 for (alias = vnode->extra_name;
302 alias; alias = alias->next)
305 alias->extra_name = prevailing_node;
308 if (prevailing_node->extra_name)
310 last->next = prevailing_node->extra_name;
311 prevailing_node->extra_name->prev = last;
313 prevailing_node->extra_name = vnode->extra_name;
314 vnode->extra_name = NULL;
316 gcc_assert (!vnode->finalized || prevailing_node->finalized);
317 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
319 /* When replacing by an alias, the references goes to the original
321 if (prevailing_node->alias && prevailing_node->extra_name)
322 prevailing_node = prevailing_node->extra_name;
323 ipa_clone_refering (NULL, prevailing_node, &vnode->ref_list);
325 /* Be sure we can garbage collect the initializer. */
326 if (DECL_INITIAL (vnode->decl))
327 DECL_INITIAL (vnode->decl) = error_mark_node;
328 /* Finally remove the replaced node. */
329 varpool_remove_node (vnode);
332 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
333 Return false if the symbols are not fully compatible and a diagnostic
334 should be emitted. */
337 lto_symtab_merge (lto_symtab_entry_t prevailing, lto_symtab_entry_t entry)
339 tree prevailing_decl = prevailing->decl;
340 tree decl = entry->decl;
341 tree prevailing_type, type;
343 /* Merge decl state in both directions, we may still end up using
345 TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
346 TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
348 /* The linker may ask us to combine two incompatible symbols.
349 Detect this case and notify the caller of required diagnostics. */
351 if (TREE_CODE (decl) == FUNCTION_DECL)
353 if (!gimple_types_compatible_p (TREE_TYPE (prevailing_decl),
354 TREE_TYPE (decl), GTC_DIAG))
355 /* If we don't have a merged type yet...sigh. The linker
356 wouldn't complain if the types were mismatched, so we
357 probably shouldn't either. Just use the type from
358 whichever decl appears to be associated with the
359 definition. If for some odd reason neither decl is, the
366 /* Now we exclusively deal with VAR_DECLs. */
368 /* Sharing a global symbol is a strong hint that two types are
369 compatible. We could use this information to complete
370 incomplete pointed-to types more aggressively here, ignoring
371 mismatches in both field and tag names. It's difficult though
372 to guarantee that this does not have side-effects on merging
373 more compatible types from other translation units though. */
375 /* We can tolerate differences in type qualification, the
376 qualification of the prevailing definition will prevail.
377 ??? In principle we might want to only warn for structurally
378 incompatible types here, but unless we have protective measures
379 for TBAA in place that would hide useful information. */
380 prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
381 type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
383 /* We have to register and fetch canonical types here as the global
384 fixup process didn't yet run. */
385 prevailing_type = gimple_register_type (prevailing_type);
386 type = gimple_register_type (type);
387 if (!gimple_types_compatible_p (prevailing_type, type, GTC_DIAG))
389 if (COMPLETE_TYPE_P (type))
392 /* If type is incomplete then avoid warnings in the cases
393 that TBAA handles just fine. */
395 if (TREE_CODE (prevailing_type) != TREE_CODE (type))
398 if (TREE_CODE (prevailing_type) == ARRAY_TYPE)
400 tree tem1 = TREE_TYPE (prevailing_type);
401 tree tem2 = TREE_TYPE (type);
402 while (TREE_CODE (tem1) == ARRAY_TYPE
403 && TREE_CODE (tem2) == ARRAY_TYPE)
405 tem1 = TREE_TYPE (tem1);
406 tem2 = TREE_TYPE (tem2);
409 if (TREE_CODE (tem1) != TREE_CODE (tem2))
412 if (!gimple_types_compatible_p (gimple_register_type (tem1),
413 gimple_register_type (tem2),
418 /* Fallthru. Compatible enough. */
421 /* ??? We might want to emit a warning here if type qualification
422 differences were spotted. Do not do this unconditionally though. */
424 /* There is no point in comparing too many details of the decls here.
425 The type compatibility checks or the completing of types has properly
426 dealt with most issues. */
428 /* The following should all not invoke fatal errors as in non-LTO
429 mode the linker wouldn't complain either. Just emit warnings. */
431 /* Report a warning if user-specified alignments do not match. */
432 if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
433 && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
439 /* Return true if the symtab entry E can be replaced by another symtab
443 lto_symtab_resolve_replaceable_p (lto_symtab_entry_t e)
445 if (DECL_EXTERNAL (e->decl)
446 || DECL_COMDAT (e->decl)
447 || DECL_ONE_ONLY (e->decl)
448 || DECL_WEAK (e->decl))
451 if (TREE_CODE (e->decl) == VAR_DECL)
452 return (DECL_COMMON (e->decl)
453 || (!flag_no_common && !DECL_INITIAL (e->decl)));
458 /* Return true if the symtab entry E can be the prevailing one. */
461 lto_symtab_resolve_can_prevail_p (lto_symtab_entry_t e)
463 /* The C++ frontend ends up neither setting TREE_STATIC nor
464 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
465 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
466 if (DECL_EXTERNAL (e->decl))
469 /* For functions we need a non-discarded body. */
470 if (TREE_CODE (e->decl) == FUNCTION_DECL)
472 && (e->node->analyzed
473 || (e->node->same_body_alias && e->node->same_body->analyzed)));
475 /* A variable should have a size. */
476 else if (TREE_CODE (e->decl) == VAR_DECL)
480 if (e->vnode->finalized)
482 return e->vnode->alias && e->vnode->extra_name->finalized;
488 /* Resolve the symbol with the candidates in the chain *SLOT and store
489 their resolutions. */
492 lto_symtab_resolve_symbols (void **slot)
494 lto_symtab_entry_t e;
495 lto_symtab_entry_t prevailing = NULL;
497 /* Always set e->node so that edges are updated to reflect decl merging. */
498 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
500 if (TREE_CODE (e->decl) == FUNCTION_DECL)
501 e->node = cgraph_get_node_or_alias (e->decl);
502 else if (TREE_CODE (e->decl) == VAR_DECL)
503 e->vnode = varpool_get_node (e->decl);
506 e = (lto_symtab_entry_t) *slot;
508 /* If the chain is already resolved there is nothing else to do. */
509 if (e->resolution != LDPR_UNKNOWN)
512 /* Find the single non-replaceable prevailing symbol and
513 diagnose ODR violations. */
514 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
516 if (!lto_symtab_resolve_can_prevail_p (e))
518 e->resolution = LDPR_RESOLVED_IR;
523 /* Set a default resolution - the final prevailing one will get
525 e->resolution = LDPR_PREEMPTED_IR;
527 if (!lto_symtab_resolve_replaceable_p (e))
531 error_at (DECL_SOURCE_LOCATION (e->decl),
532 "%qD has already been defined", e->decl);
533 inform (DECL_SOURCE_LOCATION (prevailing->decl),
534 "previously defined here");
542 /* Do a second round choosing one from the replaceable prevailing decls. */
543 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
545 if (e->resolution != LDPR_PREEMPTED_IR)
548 /* Choose the first function that can prevail as prevailing. */
549 if (TREE_CODE (e->decl) == FUNCTION_DECL)
555 /* From variables that can prevail choose the largest one. */
557 || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
558 DECL_SIZE (e->decl)))
566 /* If current lto files represent the whole program,
567 it is correct to use LDPR_PREVALING_DEF_IRONLY.
568 If current lto files are part of whole program, internal
569 resolver doesn't know if it is LDPR_PREVAILING_DEF
570 or LDPR_PREVAILING_DEF_IRONLY. Use IRONLY conforms to
571 using -fwhole-program. Otherwise, it doesn't
572 matter using either LDPR_PREVAILING_DEF or
573 LDPR_PREVAILING_DEF_IRONLY
575 FIXME: above workaround due to gold plugin makes some
576 variables IRONLY, which are indeed PREVAILING_DEF in
577 resolution file. These variables still need manual
578 externally_visible attribute. */
579 prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
580 prevailing->guessed = true;
583 /* Merge all decls in the symbol table chain to the prevailing decl and
584 issue diagnostics about type mismatches. */
587 lto_symtab_merge_decls_2 (void **slot)
589 lto_symtab_entry_t prevailing, e;
590 VEC(tree, heap) *mismatches = NULL;
593 bool diagnosed_p = false;
595 /* Nothing to do for a single entry. */
596 prevailing = (lto_symtab_entry_t) *slot;
597 if (!prevailing->next)
600 /* Try to merge each entry with the prevailing one. */
601 for (e = prevailing->next; e; e = e->next)
603 if (!lto_symtab_merge (prevailing, e))
604 VEC_safe_push (tree, heap, mismatches, e->decl);
606 if (VEC_empty (tree, mismatches))
609 /* Diagnose all mismatched re-declarations. */
610 FOR_EACH_VEC_ELT (tree, mismatches, i, decl)
612 if (!gimple_types_compatible_p (TREE_TYPE (prevailing->decl),
613 TREE_TYPE (decl), GTC_DIAG))
614 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
615 "type of %qD does not match original "
616 "declaration", decl);
618 else if ((DECL_USER_ALIGN (prevailing->decl) && DECL_USER_ALIGN (decl))
619 && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
621 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
622 "alignment of %qD is bigger than "
623 "original declaration", decl);
627 inform (DECL_SOURCE_LOCATION (prevailing->decl),
628 "previously declared here");
630 VEC_free (tree, heap, mismatches);
633 /* Helper to process the decl chain for the symbol table entry *SLOT. */
636 lto_symtab_merge_decls_1 (void **slot, void *data ATTRIBUTE_UNUSED)
638 lto_symtab_entry_t e, prevailing;
639 bool diagnosed_p = false;
641 /* Compute the symbol resolutions. This is a no-op when using the
643 lto_symtab_resolve_symbols (slot);
645 /* Find the prevailing decl. */
646 for (prevailing = (lto_symtab_entry_t) *slot;
648 && prevailing->resolution != LDPR_PREVAILING_DEF_IRONLY
649 && prevailing->resolution != LDPR_PREVAILING_DEF;
650 prevailing = prevailing->next)
653 /* Assert it's the only one. */
655 for (e = prevailing->next; e; e = e->next)
657 if (e->resolution == LDPR_PREVAILING_DEF_IRONLY
658 || e->resolution == LDPR_PREVAILING_DEF)
659 fatal_error ("multiple prevailing defs for %qE",
660 DECL_NAME (prevailing->decl));
663 /* If there's not a prevailing symbol yet it's an external reference.
664 Happens a lot during ltrans. Choose the first symbol with a
665 cgraph or a varpool node. */
668 prevailing = (lto_symtab_entry_t) *slot;
669 /* For functions choose one with a cgraph node. */
670 if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
671 while (!prevailing->node
673 prevailing = prevailing->next;
674 /* For variables chose with a priority variant with vnode
675 attached (i.e. from unit where external declaration of
676 variable is actually used).
677 When there are multiple variants, chose one with size.
678 This is needed for C++ typeinfos, for example in
679 lto/20081204-1 there are typeifos in both units, just
680 one of them do have size. */
681 if (TREE_CODE (prevailing->decl) == VAR_DECL)
683 for (e = prevailing->next; e; e = e->next)
684 if ((!prevailing->vnode && e->vnode)
685 || ((prevailing->vnode != NULL) == (e->vnode != NULL)
686 && !COMPLETE_TYPE_P (TREE_TYPE (prevailing->decl))
687 && COMPLETE_TYPE_P (TREE_TYPE (e->decl))))
692 /* Move it first in the list. */
693 if ((lto_symtab_entry_t) *slot != prevailing)
695 for (e = (lto_symtab_entry_t) *slot; e->next != prevailing; e = e->next)
697 e->next = prevailing->next;
698 prevailing->next = (lto_symtab_entry_t) *slot;
699 *slot = (void *) prevailing;
702 /* Record the prevailing variable. */
703 if (TREE_CODE (prevailing->decl) == VAR_DECL)
704 VEC_safe_push (tree, gc, lto_global_var_decls, prevailing->decl);
706 /* Diagnose mismatched objects. */
707 for (e = prevailing->next; e; e = e->next)
709 if (TREE_CODE (prevailing->decl) == TREE_CODE (e->decl))
712 switch (TREE_CODE (prevailing->decl))
715 gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
716 error_at (DECL_SOURCE_LOCATION (e->decl),
717 "variable %qD redeclared as function", prevailing->decl);
721 gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
722 error_at (DECL_SOURCE_LOCATION (e->decl),
723 "function %qD redeclared as variable", prevailing->decl);
733 inform (DECL_SOURCE_LOCATION (prevailing->decl),
734 "previously declared here");
736 /* Register and adjust types of the entries. */
737 for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
738 TREE_TYPE (e->decl) = gimple_register_type (TREE_TYPE (e->decl));
740 /* Merge the chain to the single prevailing decl and diagnose
742 lto_symtab_merge_decls_2 (slot);
744 /* Drop all but the prevailing decl from the symtab. */
745 if (TREE_CODE (prevailing->decl) != FUNCTION_DECL
746 && TREE_CODE (prevailing->decl) != VAR_DECL)
747 prevailing->next = NULL;
749 /* Store resolution decision into the callgraph.
750 In LTRANS don't overwrite information we stored into callgraph at
753 Do not bother to store guessed decisions. Generic code knows how
754 to handle UNKNOWN relocation well.
756 The problem with storing guessed decision is whether to use
757 PREVAILING_DEF or PREVAILING_DEF_IRONLY. First one would disable
758 some whole program optimizations, while ther second would imply
759 to many whole program assumptions. */
760 if (prevailing->node && !flag_ltrans && !prevailing->guessed)
761 prevailing->node->resolution = prevailing->resolution;
762 else if (prevailing->vnode && !flag_ltrans && !prevailing->guessed)
763 prevailing->vnode->resolution = prevailing->resolution;
767 /* Resolve and merge all symbol table chains to a prevailing decl. */
770 lto_symtab_merge_decls (void)
772 lto_symtab_maybe_init_hash_table ();
773 htab_traverse (lto_symtab_identifiers, lto_symtab_merge_decls_1, NULL);
776 /* Helper to process the decl chain for the symbol table entry *SLOT. */
779 lto_symtab_merge_cgraph_nodes_1 (void **slot, void *data ATTRIBUTE_UNUSED)
781 lto_symtab_entry_t e, prevailing = (lto_symtab_entry_t) *slot;
783 if (!prevailing->next)
786 /* Replace the cgraph node of each entry with the prevailing one. */
787 for (e = prevailing->next; e; e = e->next)
790 lto_cgraph_replace_node (e->node, prevailing->node);
791 if (e->vnode != NULL)
792 lto_varpool_replace_node (e->vnode, prevailing->vnode);
795 /* Drop all but the prevailing decl from the symtab. */
796 prevailing->next = NULL;
801 /* Merge cgraph nodes according to the symbol merging done by
802 lto_symtab_merge_decls. */
805 lto_symtab_merge_cgraph_nodes (void)
807 lto_symtab_maybe_init_hash_table ();
808 htab_traverse (lto_symtab_identifiers, lto_symtab_merge_cgraph_nodes_1, NULL);
811 /* Given the decl DECL, return the prevailing decl with the same name. */
814 lto_symtab_prevailing_decl (tree decl)
816 lto_symtab_entry_t ret;
818 /* Builtins and local symbols are their own prevailing decl. */
819 if (!TREE_PUBLIC (decl) || is_builtin_fn (decl))
822 /* DECL_ABSTRACTs are their own prevailng decl. */
823 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
826 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
827 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
829 /* Walk through the list of candidates and return the one we merged to. */
830 ret = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
837 #include "gt-lto-symtab.h"