2 Copyright 2009, 2010 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"
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 /* True when resolution was guessed and not read from the file. */
55 /* Pointer to the next entry with the same key. Before decl merging
56 this links all symbols from the different TUs. After decl merging
57 this links merged but incompatible decls, thus all prevailing ones
59 struct lto_symtab_entry_def
*next
;
61 typedef struct lto_symtab_entry_def
*lto_symtab_entry_t
;
63 /* A poor man's symbol table. This hashes identifier to prevailing DECL
66 static GTY ((if_marked ("lto_symtab_entry_marked_p"),
67 param_is (struct lto_symtab_entry_def
)))
68 htab_t lto_symtab_identifiers
;
70 /* Free symtab hashtable. */
73 lto_symtab_free (void)
75 htab_delete (lto_symtab_identifiers
);
76 lto_symtab_identifiers
= NULL
;
79 /* Return the hash value of an lto_symtab_entry_t object pointed to by P. */
82 lto_symtab_entry_hash (const void *p
)
84 const struct lto_symtab_entry_def
*base
=
85 (const struct lto_symtab_entry_def
*) p
;
86 return IDENTIFIER_HASH_VALUE (base
->id
);
89 /* Return non-zero if P1 and P2 points to lto_symtab_entry_def structs
90 corresponding to the same symbol. */
93 lto_symtab_entry_eq (const void *p1
, const void *p2
)
95 const struct lto_symtab_entry_def
*base1
=
96 (const struct lto_symtab_entry_def
*) p1
;
97 const struct lto_symtab_entry_def
*base2
=
98 (const struct lto_symtab_entry_def
*) p2
;
99 return (base1
->id
== base2
->id
);
102 /* Returns non-zero if P points to an lto_symtab_entry_def struct that needs
103 to be marked for GC. */
106 lto_symtab_entry_marked_p (const void *p
)
108 const struct lto_symtab_entry_def
*base
=
109 (const struct lto_symtab_entry_def
*) p
;
111 /* Keep this only if the common IDENTIFIER_NODE of the symtab chain
112 is marked which it will be if at least one of the DECLs in the
114 return ggc_marked_p (base
->id
);
117 /* Lazily initialize resolution hash tables. */
120 lto_symtab_maybe_init_hash_table (void)
122 if (lto_symtab_identifiers
)
125 lto_symtab_identifiers
=
126 htab_create_ggc (1021, lto_symtab_entry_hash
,
127 lto_symtab_entry_eq
, NULL
);
130 /* Registers DECL with the LTO symbol table as having resolution RESOLUTION
131 and read from FILE_DATA. */
134 lto_symtab_register_decl (tree decl
,
135 ld_plugin_symbol_resolution_t resolution
,
136 struct lto_file_decl_data
*file_data
)
138 lto_symtab_entry_t new_entry
;
141 /* Check that declarations reaching this function do not have
142 properties inconsistent with having external linkage. If any of
143 these asertions fail, then the object file reader has failed to
144 detect these cases and issue appropriate error messages. */
146 && TREE_PUBLIC (decl
)
147 && (TREE_CODE (decl
) == VAR_DECL
148 || TREE_CODE (decl
) == FUNCTION_DECL
)
149 && DECL_ASSEMBLER_NAME_SET_P (decl
));
150 if (TREE_CODE (decl
) == VAR_DECL
151 && DECL_INITIAL (decl
))
152 gcc_assert (!DECL_EXTERNAL (decl
)
153 || (TREE_STATIC (decl
) && TREE_READONLY (decl
)));
154 if (TREE_CODE (decl
) == FUNCTION_DECL
)
155 gcc_assert (!DECL_ABSTRACT (decl
));
157 new_entry
= ggc_alloc_cleared_lto_symtab_entry_def ();
158 new_entry
->id
= (*targetm
.asm_out
.mangle_assembler_name
)
159 (IDENTIFIER_POINTER (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 ((*targetm
.asm_out
.mangle_assembler_name
)
195 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
))));
196 while (e
&& e
->decl
!= decl
)
201 return e
->resolution
;
205 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
206 all edges and removing the old node. */
209 lto_cgraph_replace_node (struct cgraph_node
*node
,
210 struct cgraph_node
*prevailing_node
)
212 struct cgraph_edge
*e
, *next
;
213 bool no_aliases_please
= false;
216 if (cgraph_dump_file
)
218 fprintf (cgraph_dump_file
, "Replacing cgraph node %s/%i by %s/%i"
220 cgraph_node_name (node
), node
->uid
,
221 cgraph_node_name (prevailing_node
),
222 prevailing_node
->uid
,
223 IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
)
224 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->decl
)))));
227 if (prevailing_node
->same_body_alias
)
229 if (prevailing_node
->thunk
.thunk_p
)
230 no_aliases_please
= true;
231 prevailing_node
= prevailing_node
->same_body
;
234 /* Merge node flags. */
236 cgraph_mark_needed_node (prevailing_node
);
238 cgraph_mark_reachable_node (prevailing_node
);
239 if (node
->address_taken
)
241 gcc_assert (!prevailing_node
->global
.inlined_to
);
242 cgraph_mark_address_taken_node (prevailing_node
);
245 /* Redirect all incoming edges. */
247 = gimple_types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node
->decl
)),
248 TREE_TYPE (TREE_TYPE (node
->decl
)), GTC_DIAG
);
249 for (e
= node
->callers
; e
; e
= next
)
251 next
= e
->next_caller
;
252 cgraph_redirect_edge_callee (e
, prevailing_node
);
253 /* If there is a mismatch between the supposed callee return type and
254 the real one do not attempt to inline this function.
255 ??? We really need a way to match function signatures for ABI
256 compatibility and perform related promotions at inlining time. */
258 e
->call_stmt_cannot_inline_p
= 1;
260 /* Redirect incomming references. */
261 ipa_clone_refering (prevailing_node
, NULL
, &node
->ref_list
);
263 /* If we have aliases, redirect them to the prevailing node. */
264 if (!node
->same_body_alias
&& node
->same_body
)
266 struct cgraph_node
*alias
, *last
;
267 /* We prevail aliases/tunks by a thunk. This is doable but
268 would need thunk combination. Hopefully no ABI changes will
269 every be crazy enough. */
270 gcc_assert (!no_aliases_please
);
272 for (alias
= node
->same_body
; alias
; alias
= alias
->next
)
275 gcc_assert (alias
->same_body_alias
);
276 alias
->same_body
= prevailing_node
;
277 alias
->thunk
.alias
= prevailing_node
->decl
;
279 last
->next
= prevailing_node
->same_body
;
280 /* Node with aliases is prevailed by alias.
281 We could handle this, but combining thunks together will be tricky.
282 Hopefully this does not happen. */
283 if (prevailing_node
->same_body
)
284 prevailing_node
->same_body
->previous
= last
;
285 prevailing_node
->same_body
= node
->same_body
;
286 node
->same_body
= NULL
;
289 /* Finally remove the replaced node. */
290 if (node
->same_body_alias
)
291 cgraph_remove_same_body_alias (node
);
293 cgraph_remove_node (node
);
296 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
297 all edges and removing the old node. */
300 lto_varpool_replace_node (struct varpool_node
*vnode
,
301 struct varpool_node
*prevailing_node
)
303 /* Merge node flags. */
306 gcc_assert (!vnode
->analyzed
|| prevailing_node
->analyzed
);
307 varpool_mark_needed_node (prevailing_node
);
309 /* Relink aliases. */
310 if (vnode
->extra_name
&& !vnode
->alias
)
312 struct varpool_node
*alias
, *last
;
313 for (alias
= vnode
->extra_name
;
314 alias
; alias
= alias
->next
)
317 alias
->extra_name
= prevailing_node
;
320 if (prevailing_node
->extra_name
)
322 last
->next
= prevailing_node
->extra_name
;
323 prevailing_node
->extra_name
->prev
= last
;
325 prevailing_node
->extra_name
= vnode
->extra_name
;
326 vnode
->extra_name
= NULL
;
328 gcc_assert (!vnode
->finalized
|| prevailing_node
->finalized
);
329 gcc_assert (!vnode
->analyzed
|| prevailing_node
->analyzed
);
331 /* When replacing by an alias, the references goes to the original
333 if (prevailing_node
->alias
&& prevailing_node
->extra_name
)
334 prevailing_node
= prevailing_node
->extra_name
;
335 ipa_clone_refering (NULL
, prevailing_node
, &vnode
->ref_list
);
337 /* Be sure we can garbage collect the initializer. */
338 if (DECL_INITIAL (vnode
->decl
))
339 DECL_INITIAL (vnode
->decl
) = error_mark_node
;
340 /* Finally remove the replaced node. */
341 varpool_remove_node (vnode
);
344 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
345 Return false if the symbols are not fully compatible and a diagnostic
346 should be emitted. */
349 lto_symtab_merge (lto_symtab_entry_t prevailing
, lto_symtab_entry_t entry
)
351 tree prevailing_decl
= prevailing
->decl
;
352 tree decl
= entry
->decl
;
353 tree prevailing_type
, type
;
355 /* Merge decl state in both directions, we may still end up using
357 TREE_ADDRESSABLE (prevailing_decl
) |= TREE_ADDRESSABLE (decl
);
358 TREE_ADDRESSABLE (decl
) |= TREE_ADDRESSABLE (prevailing_decl
);
360 /* The linker may ask us to combine two incompatible symbols.
361 Detect this case and notify the caller of required diagnostics. */
363 if (TREE_CODE (decl
) == FUNCTION_DECL
)
365 if (!gimple_types_compatible_p (TREE_TYPE (prevailing_decl
),
366 TREE_TYPE (decl
), GTC_DIAG
))
367 /* If we don't have a merged type yet...sigh. The linker
368 wouldn't complain if the types were mismatched, so we
369 probably shouldn't either. Just use the type from
370 whichever decl appears to be associated with the
371 definition. If for some odd reason neither decl is, the
378 /* Now we exclusively deal with VAR_DECLs. */
380 /* Sharing a global symbol is a strong hint that two types are
381 compatible. We could use this information to complete
382 incomplete pointed-to types more aggressively here, ignoring
383 mismatches in both field and tag names. It's difficult though
384 to guarantee that this does not have side-effects on merging
385 more compatible types from other translation units though. */
387 /* We can tolerate differences in type qualification, the
388 qualification of the prevailing definition will prevail.
389 ??? In principle we might want to only warn for structurally
390 incompatible types here, but unless we have protective measures
391 for TBAA in place that would hide useful information. */
392 prevailing_type
= TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl
));
393 type
= TYPE_MAIN_VARIANT (TREE_TYPE (decl
));
395 /* We have to register and fetch canonical types here as the global
396 fixup process didn't yet run. */
397 prevailing_type
= gimple_register_type (prevailing_type
);
398 type
= gimple_register_type (type
);
399 if (!gimple_types_compatible_p (prevailing_type
, type
, GTC_DIAG
))
401 if (COMPLETE_TYPE_P (type
))
404 /* If type is incomplete then avoid warnings in the cases
405 that TBAA handles just fine. */
407 if (TREE_CODE (prevailing_type
) != TREE_CODE (type
))
410 if (TREE_CODE (prevailing_type
) == ARRAY_TYPE
)
412 tree tem1
= TREE_TYPE (prevailing_type
);
413 tree tem2
= TREE_TYPE (type
);
414 while (TREE_CODE (tem1
) == ARRAY_TYPE
415 && TREE_CODE (tem2
) == ARRAY_TYPE
)
417 tem1
= TREE_TYPE (tem1
);
418 tem2
= TREE_TYPE (tem2
);
421 if (TREE_CODE (tem1
) != TREE_CODE (tem2
))
424 if (!gimple_types_compatible_p (gimple_register_type (tem1
),
425 gimple_register_type (tem2
),
430 /* Fallthru. Compatible enough. */
433 /* ??? We might want to emit a warning here if type qualification
434 differences were spotted. Do not do this unconditionally though. */
436 /* There is no point in comparing too many details of the decls here.
437 The type compatibility checks or the completing of types has properly
438 dealt with most issues. */
440 /* The following should all not invoke fatal errors as in non-LTO
441 mode the linker wouldn't complain either. Just emit warnings. */
443 /* Report a warning if user-specified alignments do not match. */
444 if ((DECL_USER_ALIGN (prevailing_decl
) && DECL_USER_ALIGN (decl
))
445 && DECL_ALIGN (prevailing_decl
) < DECL_ALIGN (decl
))
451 /* Return true if the symtab entry E can be replaced by another symtab
455 lto_symtab_resolve_replaceable_p (lto_symtab_entry_t e
)
457 if (DECL_EXTERNAL (e
->decl
)
458 || DECL_COMDAT (e
->decl
)
459 || DECL_ONE_ONLY (e
->decl
)
460 || DECL_WEAK (e
->decl
))
463 if (TREE_CODE (e
->decl
) == VAR_DECL
)
464 return (DECL_COMMON (e
->decl
)
465 || (!flag_no_common
&& !DECL_INITIAL (e
->decl
)));
470 /* Return true if the symtab entry E can be the prevailing one. */
473 lto_symtab_resolve_can_prevail_p (lto_symtab_entry_t e
)
475 /* The C++ frontend ends up neither setting TREE_STATIC nor
476 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
477 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
478 if (DECL_EXTERNAL (e
->decl
))
481 /* For functions we need a non-discarded body. */
482 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
)
484 && (e
->node
->analyzed
485 || (e
->node
->same_body_alias
&& e
->node
->same_body
->analyzed
)));
487 /* A variable should have a size. */
488 else if (TREE_CODE (e
->decl
) == VAR_DECL
)
492 if (e
->vnode
->finalized
)
494 return e
->vnode
->alias
&& e
->vnode
->extra_name
->finalized
;
500 /* Resolve the symbol with the candidates in the chain *SLOT and store
501 their resolutions. */
504 lto_symtab_resolve_symbols (void **slot
)
506 lto_symtab_entry_t e
;
507 lto_symtab_entry_t prevailing
= NULL
;
509 /* Always set e->node so that edges are updated to reflect decl merging. */
510 for (e
= (lto_symtab_entry_t
) *slot
; e
; e
= e
->next
)
512 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
)
513 e
->node
= cgraph_get_node_or_alias (e
->decl
);
514 else if (TREE_CODE (e
->decl
) == VAR_DECL
)
515 e
->vnode
= varpool_get_node (e
->decl
);
518 e
= (lto_symtab_entry_t
) *slot
;
520 /* If the chain is already resolved there is nothing else to do. */
521 if (e
->resolution
!= LDPR_UNKNOWN
)
524 /* Find the single non-replaceable prevailing symbol and
525 diagnose ODR violations. */
526 for (e
= (lto_symtab_entry_t
) *slot
; e
; e
= e
->next
)
528 if (!lto_symtab_resolve_can_prevail_p (e
))
530 e
->resolution
= LDPR_RESOLVED_IR
;
535 /* Set a default resolution - the final prevailing one will get
537 e
->resolution
= LDPR_PREEMPTED_IR
;
539 if (!lto_symtab_resolve_replaceable_p (e
))
543 error_at (DECL_SOURCE_LOCATION (e
->decl
),
544 "%qD has already been defined", e
->decl
);
545 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
546 "previously defined here");
554 /* Do a second round choosing one from the replaceable prevailing decls. */
555 for (e
= (lto_symtab_entry_t
) *slot
; e
; e
= e
->next
)
557 if (e
->resolution
!= LDPR_PREEMPTED_IR
)
560 /* Choose the first function that can prevail as prevailing. */
561 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
)
567 /* From variables that can prevail choose the largest one. */
569 || tree_int_cst_lt (DECL_SIZE (prevailing
->decl
),
570 DECL_SIZE (e
->decl
)))
578 /* If current lto files represent the whole program,
579 it is correct to use LDPR_PREVALING_DEF_IRONLY.
580 If current lto files are part of whole program, internal
581 resolver doesn't know if it is LDPR_PREVAILING_DEF
582 or LDPR_PREVAILING_DEF_IRONLY. Use IRONLY conforms to
583 using -fwhole-program. Otherwise, it doesn't
584 matter using either LDPR_PREVAILING_DEF or
585 LDPR_PREVAILING_DEF_IRONLY
587 FIXME: above workaround due to gold plugin makes some
588 variables IRONLY, which are indeed PREVAILING_DEF in
589 resolution file. These variables still need manual
590 externally_visible attribute. */
591 prevailing
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
592 prevailing
->guessed
= true;
595 /* Merge all decls in the symbol table chain to the prevailing decl and
596 issue diagnostics about type mismatches. If DIAGNOSED_P is true
597 do not issue further diagnostics.*/
600 lto_symtab_merge_decls_2 (void **slot
, bool diagnosed_p
)
602 lto_symtab_entry_t prevailing
, e
;
603 VEC(tree
, heap
) *mismatches
= NULL
;
607 /* Nothing to do for a single entry. */
608 prevailing
= (lto_symtab_entry_t
) *slot
;
609 if (!prevailing
->next
)
612 /* Try to merge each entry with the prevailing one. */
613 for (e
= prevailing
->next
; e
; e
= e
->next
)
615 if (!lto_symtab_merge (prevailing
, e
)
617 VEC_safe_push (tree
, heap
, mismatches
, e
->decl
);
619 if (VEC_empty (tree
, mismatches
))
622 /* Diagnose all mismatched re-declarations. */
623 FOR_EACH_VEC_ELT (tree
, mismatches
, i
, decl
)
625 if (!gimple_types_compatible_p (TREE_TYPE (prevailing
->decl
),
626 TREE_TYPE (decl
), GTC_DIAG
))
627 diagnosed_p
|= warning_at (DECL_SOURCE_LOCATION (decl
), 0,
628 "type of %qD does not match original "
629 "declaration", decl
);
631 else if ((DECL_USER_ALIGN (prevailing
->decl
) && DECL_USER_ALIGN (decl
))
632 && DECL_ALIGN (prevailing
->decl
) < DECL_ALIGN (decl
))
634 diagnosed_p
|= warning_at (DECL_SOURCE_LOCATION (decl
), 0,
635 "alignment of %qD is bigger than "
636 "original declaration", decl
);
640 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
641 "previously declared here");
643 VEC_free (tree
, heap
, mismatches
);
646 /* Helper to process the decl chain for the symbol table entry *SLOT. */
649 lto_symtab_merge_decls_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
651 lto_symtab_entry_t e
, prevailing
;
652 bool diagnosed_p
= false;
654 /* Compute the symbol resolutions. This is a no-op when using the
656 lto_symtab_resolve_symbols (slot
);
658 /* Find the prevailing decl. */
659 for (prevailing
= (lto_symtab_entry_t
) *slot
;
661 && prevailing
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
662 && prevailing
->resolution
!= LDPR_PREVAILING_DEF
;
663 prevailing
= prevailing
->next
)
666 /* Assert it's the only one. */
668 for (e
= prevailing
->next
; e
; e
= e
->next
)
670 if (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
671 || e
->resolution
== LDPR_PREVAILING_DEF
)
672 fatal_error ("multiple prevailing defs for %qE",
673 DECL_NAME (prevailing
->decl
));
676 /* If there's not a prevailing symbol yet it's an external reference.
677 Happens a lot during ltrans. Choose the first symbol with a
678 cgraph or a varpool node. */
681 prevailing
= (lto_symtab_entry_t
) *slot
;
682 /* For functions choose one with a cgraph node. */
683 if (TREE_CODE (prevailing
->decl
) == FUNCTION_DECL
)
684 while (!prevailing
->node
686 prevailing
= prevailing
->next
;
687 /* For variables chose with a priority variant with vnode
688 attached (i.e. from unit where external declaration of
689 variable is actually used).
690 When there are multiple variants, chose one with size.
691 This is needed for C++ typeinfos, for example in
692 lto/20081204-1 there are typeifos in both units, just
693 one of them do have size. */
694 if (TREE_CODE (prevailing
->decl
) == VAR_DECL
)
696 for (e
= prevailing
->next
; e
; e
= e
->next
)
697 if ((!prevailing
->vnode
&& e
->vnode
)
698 || ((prevailing
->vnode
!= NULL
) == (e
->vnode
!= NULL
)
699 && !COMPLETE_TYPE_P (TREE_TYPE (prevailing
->decl
))
700 && COMPLETE_TYPE_P (TREE_TYPE (e
->decl
))))
705 /* Move it first in the list. */
706 if ((lto_symtab_entry_t
) *slot
!= prevailing
)
708 for (e
= (lto_symtab_entry_t
) *slot
; e
->next
!= prevailing
; e
= e
->next
)
710 e
->next
= prevailing
->next
;
711 prevailing
->next
= (lto_symtab_entry_t
) *slot
;
712 *slot
= (void *) prevailing
;
715 /* Record the prevailing variable. */
716 if (TREE_CODE (prevailing
->decl
) == VAR_DECL
)
717 VEC_safe_push (tree
, gc
, lto_global_var_decls
, prevailing
->decl
);
719 /* Diagnose mismatched objects. */
720 for (e
= prevailing
->next
; e
; e
= e
->next
)
722 if (TREE_CODE (prevailing
->decl
) == TREE_CODE (e
->decl
))
725 switch (TREE_CODE (prevailing
->decl
))
728 gcc_assert (TREE_CODE (e
->decl
) == FUNCTION_DECL
);
729 error_at (DECL_SOURCE_LOCATION (e
->decl
),
730 "variable %qD redeclared as function", prevailing
->decl
);
734 gcc_assert (TREE_CODE (e
->decl
) == VAR_DECL
);
735 error_at (DECL_SOURCE_LOCATION (e
->decl
),
736 "function %qD redeclared as variable", prevailing
->decl
);
746 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
747 "previously declared here");
749 /* Register and adjust types of the entries. */
750 for (e
= (lto_symtab_entry_t
) *slot
; e
; e
= e
->next
)
751 TREE_TYPE (e
->decl
) = gimple_register_type (TREE_TYPE (e
->decl
));
753 /* Merge the chain to the single prevailing decl and diagnose
755 lto_symtab_merge_decls_2 (slot
, diagnosed_p
);
757 /* Store resolution decision into the callgraph.
758 In LTRANS don't overwrite information we stored into callgraph at
761 Do not bother to store guessed decisions. Generic code knows how
762 to handle UNKNOWN relocation well.
764 The problem with storing guessed decision is whether to use
765 PREVAILING_DEF or PREVAILING_DEF_IRONLY. First one would disable
766 some whole program optimizations, while ther second would imply
767 to many whole program assumptions. */
768 if (prevailing
->node
&& !flag_ltrans
&& !prevailing
->guessed
)
769 prevailing
->node
->resolution
= prevailing
->resolution
;
770 else if (prevailing
->vnode
&& !flag_ltrans
&& !prevailing
->guessed
)
771 prevailing
->vnode
->resolution
= prevailing
->resolution
;
775 /* Resolve and merge all symbol table chains to a prevailing decl. */
778 lto_symtab_merge_decls (void)
780 lto_symtab_maybe_init_hash_table ();
781 htab_traverse (lto_symtab_identifiers
, lto_symtab_merge_decls_1
, NULL
);
784 /* Helper to process the decl chain for the symbol table entry *SLOT. */
787 lto_symtab_merge_cgraph_nodes_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
789 lto_symtab_entry_t e
, prevailing
= (lto_symtab_entry_t
) *slot
;
791 if (!prevailing
->next
)
794 /* Replace the cgraph node of each entry with the prevailing one. */
795 for (e
= prevailing
->next
; e
; e
= e
->next
)
799 /* In case we prevail funcion by an alias, we can run into case
800 that the alias has no cgraph node attached, since it was
801 previously unused. Create the node. */
802 if (!prevailing
->node
)
804 prevailing
->node
= cgraph_node (prevailing
->decl
);
805 prevailing
->node
->alias
= true;
807 lto_cgraph_replace_node (e
->node
, prevailing
->node
);
809 if (e
->vnode
!= NULL
)
811 if (!prevailing
->vnode
)
813 prevailing
->vnode
= varpool_node (prevailing
->decl
);
814 prevailing
->vnode
->alias
= true;
816 lto_varpool_replace_node (e
->vnode
, prevailing
->vnode
);
820 /* Drop all but the prevailing decl from the symtab. */
821 prevailing
->next
= NULL
;
826 /* Merge cgraph nodes according to the symbol merging done by
827 lto_symtab_merge_decls. */
830 lto_symtab_merge_cgraph_nodes (void)
832 lto_symtab_maybe_init_hash_table ();
833 htab_traverse (lto_symtab_identifiers
, lto_symtab_merge_cgraph_nodes_1
, NULL
);
836 /* Given the decl DECL, return the prevailing decl with the same name. */
839 lto_symtab_prevailing_decl (tree decl
)
841 lto_symtab_entry_t ret
;
843 /* Builtins and local symbols are their own prevailing decl. */
844 if (!TREE_PUBLIC (decl
) || is_builtin_fn (decl
))
847 /* DECL_ABSTRACTs are their own prevailng decl. */
848 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_ABSTRACT (decl
))
851 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
852 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl
));
854 /* Walk through the list of candidates and return the one we merged to. */
855 ret
= lto_symtab_get ((*targetm
.asm_out
.mangle_assembler_name
)
856 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
))));
863 #include "gt-lto-symtab.h"