/* LTO symbol table.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
+ Copyright (C) 2009-2015 Free Software Foundation, Inc.
Contributed by CodeSourcery, Inc.
This file is part of GCC.
#include "system.h"
#include "coretypes.h"
#include "diagnostic-core.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "vec.h"
+#include "double-int.h"
+#include "input.h"
+#include "alias.h"
+#include "symtab.h"
+#include "options.h"
+#include "wide-int.h"
+#include "inchash.h"
#include "tree.h"
+#include "fold-const.h"
+#include "predict.h"
+#include "tm.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
#include "basic-block.h"
#include "tree-ssa-alias.h"
#include "internal-fn.h"
#include "gimple-expr.h"
#include "is-a.h"
#include "gimple.h"
-#include "hashtab.h"
#include "plugin-api.h"
+#include "hash-map.h"
+#include "ipa-ref.h"
+#include "cgraph.h"
#include "lto-streamer.h"
#include "ipa-utils.h"
+#include "alloc-pool.h"
+#include "symbol-summary.h"
+#include "ipa-prop.h"
#include "ipa-inline.h"
+#include "builtins.h"
+#include "print-tree.h"
/* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
all edges and removing the old node. */
struct cgraph_edge *e, *next;
bool compatible_p;
- if (cgraph_dump_file)
+ if (symtab->dump_file)
{
- fprintf (cgraph_dump_file, "Replacing cgraph node %s/%i by %s/%i"
+ fprintf (symtab->dump_file, "Replacing cgraph node %s/%i by %s/%i"
" for symbol %s\n",
node->name (), node->order,
prevailing_node->name (),
/* Merge node flags. */
if (node->force_output)
- cgraph_mark_force_output_node (prevailing_node);
+ prevailing_node->mark_force_output ();
+ if (node->forced_by_abi)
+ prevailing_node->forced_by_abi = true;
if (node->address_taken)
{
gcc_assert (!prevailing_node->global.inlined_to);
- cgraph_mark_address_taken_node (prevailing_node);
+ prevailing_node->mark_address_taken ();
}
+ if (node->definition && prevailing_node->definition)
+ prevailing_node->merged = true;
/* Redirect all incoming edges. */
compatible_p
for (e = node->callers; e; e = next)
{
next = e->next_caller;
- cgraph_redirect_edge_callee (e, prevailing_node);
+ e->redirect_callee (prevailing_node);
/* If there is a mismatch between the supposed callee return type and
the real one do not attempt to inline this function.
??? We really need a way to match function signatures for ABI
e->call_stmt_cannot_inline_p = 1;
}
/* Redirect incomming references. */
- ipa_clone_referring (prevailing_node, &node->ref_list);
+ prevailing_node->clone_referring (node);
+
+ /* Fix instrumentation references. */
+ if (node->instrumented_version)
+ {
+ gcc_assert (node->instrumentation_clone
+ == prevailing_node->instrumentation_clone);
+ node->instrumented_version->instrumented_version = prevailing_node;
+ if (!prevailing_node->instrumented_version)
+ prevailing_node->instrumented_version = node->instrumented_version;
+ /* Need to reset node->instrumented_version to NULL,
+ otherwise node removal code would reset
+ node->instrumented_version->instrumented_version. */
+ node->instrumented_version = NULL;
+ }
ipa_merge_profiles (prevailing_node, node);
lto_free_function_in_decl_state_for_node (node);
if (node->decl != prevailing_node->decl)
- cgraph_release_function_body (node);
-
- /* Time profile merging */
- if (node->tp_first_run)
- prevailing_node->tp_first_run = prevailing_node->tp_first_run ?
- MIN (prevailing_node->tp_first_run, node->tp_first_run) :
- node->tp_first_run;
+ node->release_body ();
/* Finally remove the replaced node. */
- cgraph_remove_node (node);
+ node->remove ();
}
/* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
gcc_assert (!vnode->definition || prevailing_node->definition);
gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
- ipa_clone_referring (prevailing_node, &vnode->ref_list);
+ prevailing_node->clone_referring (vnode);
+ if (vnode->force_output)
+ prevailing_node->force_output = true;
+ if (vnode->forced_by_abi)
+ prevailing_node->forced_by_abi = true;
/* Be sure we can garbage collect the initializer. */
if (DECL_INITIAL (vnode->decl)
&& vnode->decl != prevailing_node->decl)
DECL_INITIAL (vnode->decl) = error_mark_node;
+
+ /* Check and report ODR violations on virtual tables. */
+ if (DECL_VIRTUAL_P (vnode->decl) || DECL_VIRTUAL_P (prevailing_node->decl))
+ compare_virtual_tables (prevailing_node, vnode);
+
+ if (vnode->tls_model != prevailing_node->tls_model)
+ {
+ bool error = false;
+
+ /* Non-TLS and TLS never mix together. Also emulated model is not
+ compatible with anything else. */
+ if (prevailing_node->tls_model == TLS_MODEL_NONE
+ || prevailing_node->tls_model == TLS_MODEL_EMULATED
+ || vnode->tls_model == TLS_MODEL_NONE
+ || vnode->tls_model == TLS_MODEL_EMULATED)
+ error = true;
+ /* Linked is silently supporting transitions
+ GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
+ Do the same transitions and error out on others. */
+ else if ((prevailing_node->tls_model == TLS_MODEL_REAL
+ || prevailing_node->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
+ && (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
+ || vnode->tls_model == TLS_MODEL_LOCAL_EXEC))
+ prevailing_node->tls_model = vnode->tls_model;
+ else if ((vnode->tls_model == TLS_MODEL_REAL
+ || vnode->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
+ && (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
+ || prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC))
+ ;
+ else if (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
+ && vnode->tls_model == TLS_MODEL_LOCAL_EXEC)
+ prevailing_node->tls_model = vnode->tls_model;
+ else if (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
+ && prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC)
+ ;
+ else
+ error = true;
+ if (error)
+ {
+ error_at (DECL_SOURCE_LOCATION (vnode->decl),
+ "%qD is defined with tls model %s", vnode->decl, tls_model_names [vnode->tls_model]);
+ inform (DECL_SOURCE_LOCATION (prevailing_node->decl),
+ "previously defined here as %s",
+ tls_model_names [prevailing_node->tls_model]);
+ }
+ }
/* Finally remove the replaced node. */
- varpool_remove_node (vnode);
+ vnode->remove ();
}
-/* Merge two variable or function symbol table entries PREVAILING and ENTRY.
- Return false if the symbols are not fully compatible and a diagnostic
- should be emitted. */
+/* Return non-zero if we want to output waring about T1 and T2.
+ Return value is a bitmask of reasons of violation:
+ Bit 0 indicates that types are not compatible of memory layout.
+ Bot 1 indicates that types are not compatible because of C++ ODR rule. */
-static bool
-lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
+static int
+warn_type_compatibility_p (tree prevailing_type, tree type)
{
- tree prevailing_decl = prevailing->decl;
- tree decl = entry->decl;
- tree prevailing_type, type;
-
- if (prevailing_decl == decl)
- return true;
-
- /* Merge decl state in both directions, we may still end up using
- the new decl. */
- TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
- TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
-
- /* The linker may ask us to combine two incompatible symbols.
- Detect this case and notify the caller of required diagnostics. */
-
- if (TREE_CODE (decl) == FUNCTION_DECL)
+ int lev = 0;
+ /* C++ provide a robust way to check for type compatibility via the ODR
+ rule. */
+ if (odr_or_derived_type_p (prevailing_type) && odr_type_p (type)
+ && !odr_types_equivalent_p (prevailing_type, type))
+ lev = 2;
+
+ /* Function types needs special care, because types_compatible_p never
+ thinks prototype is compatible to non-prototype. */
+ if ((TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
+ && TREE_CODE (type) == TREE_CODE (prevailing_type))
{
- if (!types_compatible_p (TREE_TYPE (prevailing_decl),
- TREE_TYPE (decl)))
- /* If we don't have a merged type yet...sigh. The linker
- wouldn't complain if the types were mismatched, so we
- probably shouldn't either. Just use the type from
- whichever decl appears to be associated with the
- definition. If for some odd reason neither decl is, the
- older one wins. */
- (void) 0;
-
- return true;
+ lev |= warn_type_compatibility_p (TREE_TYPE (prevailing_type),
+ TREE_TYPE (type));
+ if (TREE_CODE (type) == METHOD_TYPE)
+ lev |= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type),
+ TYPE_METHOD_BASETYPE (type));
+ if (prototype_p (prevailing_type) && prototype_p (type)
+ && TYPE_ARG_TYPES (prevailing_type) != TYPE_ARG_TYPES (type))
+ {
+ tree parm1, parm2;
+ for (parm1 = TYPE_ARG_TYPES (prevailing_type),
+ parm2 = TYPE_ARG_TYPES (type);
+ parm1 && parm2;
+ parm1 = TREE_CHAIN (prevailing_type),
+ parm2 = TREE_CHAIN (type))
+ lev |= warn_type_compatibility_p (TREE_VALUE (parm1),
+ TREE_VALUE (parm2));
+ if (parm1 || parm2)
+ lev = 3;
+ }
+ if (comp_type_attributes (prevailing_type, type) == 0)
+ lev = 3;
+ return lev;
}
-
- /* Now we exclusively deal with VAR_DECLs. */
-
/* Sharing a global symbol is a strong hint that two types are
compatible. We could use this information to complete
incomplete pointed-to types more aggressively here, ignoring
??? In principle we might want to only warn for structurally
incompatible types here, but unless we have protective measures
for TBAA in place that would hide useful information. */
- prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
- type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
+ prevailing_type = TYPE_MAIN_VARIANT (prevailing_type);
+ type = TYPE_MAIN_VARIANT (type);
if (!types_compatible_p (prevailing_type, type))
{
- if (COMPLETE_TYPE_P (type))
- return false;
+ if (TREE_CODE (prevailing_type) == FUNCTION_TYPE
+ || TREE_CODE (type) == METHOD_TYPE)
+ return 1 | lev;
+ if (COMPLETE_TYPE_P (type) && COMPLETE_TYPE_P (prevailing_type))
+ return 1 | lev;
/* If type is incomplete then avoid warnings in the cases
that TBAA handles just fine. */
if (TREE_CODE (prevailing_type) != TREE_CODE (type))
- return false;
+ return 1 | lev;
if (TREE_CODE (prevailing_type) == ARRAY_TYPE)
{
}
if (TREE_CODE (tem1) != TREE_CODE (tem2))
- return false;
+ return 1 | lev;
if (!types_compatible_p (tem1, tem2))
- return false;
+ return 1 | lev;
}
/* Fallthru. Compatible enough. */
/* ??? We might want to emit a warning here if type qualification
differences were spotted. Do not do this unconditionally though. */
+ return lev;
+}
+
+/* Merge two variable or function symbol table entries PREVAILING and ENTRY.
+ Return false if the symbols are not fully compatible and a diagnostic
+ should be emitted. */
+
+static bool
+lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
+{
+ tree prevailing_decl = prevailing->decl;
+ tree decl = entry->decl;
+
+ if (prevailing_decl == decl)
+ return true;
+
+ /* Merge decl state in both directions, we may still end up using
+ the new decl. */
+ TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
+ TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
+
+ /* The linker may ask us to combine two incompatible symbols.
+ Detect this case and notify the caller of required diagnostics. */
+
+ if (TREE_CODE (decl) == FUNCTION_DECL)
+ {
+ if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl),
+ TREE_TYPE (decl)))
+ return false;
+
+ return true;
+ }
+
+ if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl),
+ TREE_TYPE (decl)))
+ return false;
+
/* There is no point in comparing too many details of the decls here.
The type compatibility checks or the completing of types has properly
dealt with most issues. */
{
if (!TREE_PUBLIC (e->decl) && !DECL_EXTERNAL (e->decl))
return false;
- return symtab_real_symbol_p (e);
+ return e->real_symbol_p ();
}
/* Return true if the symtab entry E can be the prevailing one. */
&& (e->resolution == LDPR_PREVAILING_DEF_IRONLY
|| e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
|| e->resolution == LDPR_PREVAILING_DEF))
- fatal_error ("multiple prevailing defs for %qE",
+ fatal_error (input_location, "multiple prevailing defs for %qE",
DECL_NAME (prevailing->decl));
return prevailing;
}
if (TREE_PUBLIC (e->decl))
{
if (!lto_symtab_merge (prevailing, e)
- && !diagnosed_p)
+ && !diagnosed_p
+ && !DECL_ARTIFICIAL (e->decl))
mismatches.safe_push (e->decl);
}
if (mismatches.is_empty ())
/* Diagnose all mismatched re-declarations. */
FOR_EACH_VEC_ELT (mismatches, i, decl)
{
- if (!types_compatible_p (TREE_TYPE (prevailing->decl),
- TREE_TYPE (decl)))
- diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
- "type of %qD does not match original "
- "declaration", decl);
-
+ int level = warn_type_compatibility_p (TREE_TYPE (prevailing->decl),
+ TREE_TYPE (decl));
+ if (level)
+ {
+ bool diag = false;
+ if (level > 1)
+ diag = warning_at (DECL_SOURCE_LOCATION (decl),
+ OPT_Wodr,
+ "%qD violates the C++ One Definition Rule ",
+ decl);
+ if (!diag && (level & 1))
+ diag = warning_at (DECL_SOURCE_LOCATION (decl),
+ OPT_Wlto_type_mismatch,
+ "type of %qD does not match original "
+ "declaration", decl);
+ if (diag)
+ warn_types_mismatch (TREE_TYPE (prevailing->decl),
+ TREE_TYPE (decl));
+ diagnosed_p |= diag;
+ }
else if ((DECL_USER_ALIGN (prevailing->decl)
&& DECL_USER_ALIGN (decl))
&& DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
{
- diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
+ diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl),
+ OPT_Wlto_type_mismatch,
"alignment of %qD is bigger than "
"original declaration", decl);
}
}
if (diagnosed_p)
inform (DECL_SOURCE_LOCATION (prevailing->decl),
- "previously declared here");
+ "%qD was previously declared here", prevailing->decl);
mismatches.release ();
}
symtab_node *prevailing;
bool diagnosed_p = false;
- if (cgraph_dump_file)
+ if (symtab->dump_file)
{
- fprintf (cgraph_dump_file, "Merging nodes for %s. Candidates:\n",
+ fprintf (symtab->dump_file, "Merging nodes for %s. Candidates:\n",
first->asm_name ());
for (e = first; e; e = e->next_sharing_asm_name)
if (TREE_PUBLIC (e->decl))
- dump_symtab_node (cgraph_dump_file, e);
+ e->dump (symtab->dump_file);
}
/* Compute the symbol resolutions. This is a no-op when using the
cgraph or a varpool node. */
if (!prevailing)
{
- prevailing = first;
+ for (prevailing = first;
+ prevailing; prevailing = prevailing->next_sharing_asm_name)
+ if (lto_symtab_symbol_p (prevailing))
+ break;
+ if (!prevailing)
+ return;
/* For variables chose with a priority variant with vnode
attached (i.e. from unit where external declaration of
variable is actually used).
}
}
- symtab_prevail_in_asm_name_hash (prevailing);
+ symtab->symtab_prevail_in_asm_name_hash (prevailing);
/* Diagnose mismatched objects. */
for (e = prevailing->next_sharing_asm_name;
mismatches. */
lto_symtab_merge_decls_2 (prevailing, diagnosed_p);
- if (cgraph_dump_file)
+ if (symtab->dump_file)
{
- fprintf (cgraph_dump_file, "After resolution:\n");
+ fprintf (symtab->dump_file, "After resolution:\n");
for (e = prevailing; e; e = e->next_sharing_asm_name)
- dump_symtab_node (cgraph_dump_file, e);
+ e->dump (symtab->dump_file);
}
}
symtab_node *node;
/* Populate assembler name hash. */
- symtab_initialize_asm_name_hash ();
+ symtab->symtab_initialize_asm_name_hash ();
FOR_EACH_SYMBOL (node)
if (!node->previous_sharing_asm_name
if (!lto_symtab_symbol_p (e))
continue;
- cgraph_node *ce = dyn_cast <cgraph_node> (e);
+ cgraph_node *ce = dyn_cast <cgraph_node *> (e);
if (ce && !DECL_BUILT_IN (e->decl))
- lto_cgraph_replace_node (ce, cgraph (prevailing));
- if (varpool_node *ve = dyn_cast <varpool_node> (e))
- lto_varpool_replace_node (ve, varpool (prevailing));
+ lto_cgraph_replace_node (ce, dyn_cast<cgraph_node *> (prevailing));
+ if (varpool_node *ve = dyn_cast <varpool_node *> (e))
+ lto_varpool_replace_node (ve, dyn_cast<varpool_node *> (prevailing));
}
return;
if (!flag_ltrans)
{
- symtab_initialize_asm_name_hash ();
+ symtab->symtab_initialize_asm_name_hash ();
/* Do the actual merging.
At this point we invalidate hash translating decls into symtab nodes
if (!node->analyzed && node->alias_target)
{
- symtab_node *tgt = symtab_node_for_asm (node->alias_target);
+ symtab_node *tgt = symtab_node::get_for_asmname (node->alias_target);
gcc_assert (node->weakref);
if (tgt)
- symtab_resolve_alias (node, tgt);
+ node->resolve_alias (tgt);
}
node->aux = NULL;
- if (!(cnode = dyn_cast <cgraph_node> (node))
+ if (!(cnode = dyn_cast <cgraph_node *> (node))
|| !cnode->clone_of
|| cnode->clone_of->decl != cnode->decl)
{
possible that tree merging unified the declaration. We
do not want duplicate entries in symbol table. */
if (cnode && DECL_BUILT_IN (node->decl)
- && (cnode2 = cgraph_get_node (node->decl))
+ && (cnode2 = cgraph_node::get (node->decl))
&& cnode2 != cnode)
lto_cgraph_replace_node (cnode2, cnode);
/* The user defined assembler variables are also not unified by their
symbol name (since it is irrelevant), but we need to unify symbol
nodes if tree merging occured. */
- if ((vnode = dyn_cast <varpool_node> (node))
+ if ((vnode = dyn_cast <varpool_node *> (node))
&& DECL_HARD_REGISTER (vnode->decl)
- && (node2 = symtab_get_node (vnode->decl))
+ && (node2 = symtab_node::get (vnode->decl))
&& node2 != node)
- lto_varpool_replace_node (dyn_cast <varpool_node> (node2),
+ lto_varpool_replace_node (dyn_cast <varpool_node *> (node2),
vnode);
/* Abstract functions may have duplicated cgraph nodes attached;
remove them. */
- else if (cnode && DECL_ABSTRACT (cnode->decl)
- && (cnode2 = cgraph_get_node (node->decl))
+ else if (cnode && DECL_ABSTRACT_P (cnode->decl)
+ && (cnode2 = cgraph_node::get (node->decl))
&& cnode2 != cnode)
- cgraph_remove_node (cnode2);
+ cnode2->remove ();
- symtab_insert_node_to_hashtable (node);
+ node->decl->decl_with_vis.symtab_node = node;
}
}
}
if ((!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) || is_builtin_fn (decl))
return decl;
- /* DECL_ABSTRACTs are their own prevailng decl. */
- if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
+ /* DECL_ABSTRACT_Ps are their own prevailing decl. */
+ if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT_P (decl))
return decl;
/* Likewise builtins are their own prevailing decl. This preserves
gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
/* Walk through the list of candidates and return the one we merged to. */
- ret = symtab_node_for_asm (DECL_ASSEMBLER_NAME (decl));
+ ret = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
if (!ret)
return decl;