summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormeibf <meibf@138bc75d-0d04-0410-961f-82ee72b054a4>2010-06-28 10:39:38 +0000
committermeibf <meibf@138bc75d-0d04-0410-961f-82ee72b054a4>2010-06-28 10:39:38 +0000
commit61a3c321a48afb9f635bf488eec7d2e6208e4d28 (patch)
treefcb4698113cc298ba8c467ab738e7c19bf245308
parentf925fe89b22d5cd843f3d8f2e2c4dc68bdb8262c (diff)
downloadgcc-61a3c321a48afb9f635bf488eec7d2e6208e4d28.tar.gz
2010-06-28 Bingfeng Mei <bmei@broadcom.com>
* cgraph.h (struct varpool_node): new used_from_object_file flag. (struct cgraph_local_info): new used_from_object_file flag. * cgraph.c (dump_cgraph_node): dump used_from_object_file flag. (cgraph_clone_node): initialize used_from_object_file. (cgraph_create_virtual_clone): initialize used_from_object_file. * lto-symbtab.c (lto_symtab_merge_decls_1): Set used_from_object_file flags for symbols of LDPR_PREVAILING_DEF when compiling with -fwhole-program. (lto_symtab_resolve_symbols) Use LDPR_PREVAILING_DEF_IRONLY for internal resolver. * ipa.c (function_and_variable_visibility): Set externally_visible flag of varpool_node if used_from_object_file flag is set. (cgraph_externally_visible_p): check used_from_object_file flag. * doc/invoke.texi (-fwhole-program option): Change description of externally_visible attribute accordingly. * doc/extend.texi (externally_visible): Ditto. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161483 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/cgraph.c4
-rw-r--r--gcc/cgraph.h5
-rw-r--r--gcc/doc/extend.texi2
-rw-r--r--gcc/doc/invoke.texi2
-rw-r--r--gcc/ipa.c3
-rw-r--r--gcc/lto-symtab.c35
7 files changed, 64 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7c3dcf7fb9d..fef5c987ba2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,22 @@
+2010-06-28 Bingfeng Mei <bmei@broadcom.com>
+
+ * cgraph.h (struct varpool_node): new used_from_object_file flag.
+ (struct cgraph_local_info): new used_from_object_file flag.
+ * cgraph.c (dump_cgraph_node): dump used_from_object_file flag.
+ (cgraph_clone_node): initialize used_from_object_file.
+ (cgraph_create_virtual_clone): initialize used_from_object_file.
+ * lto-symbtab.c (lto_symtab_merge_decls_1): Set
+ used_from_object_file flags for symbols of LDPR_PREVAILING_DEF
+ when compiling with -fwhole-program.
+ (lto_symtab_resolve_symbols) Use LDPR_PREVAILING_DEF_IRONLY for
+ internal resolver.
+ * ipa.c (function_and_variable_visibility): Set externally_visible
+ flag of varpool_node if used_from_object_file flag is set.
+ (cgraph_externally_visible_p): check used_from_object_file flag.
+ * doc/invoke.texi (-fwhole-program option): Change description of
+ externally_visible attribute accordingly.
+ * doc/extend.texi (externally_visible): Ditto.
+
2010-06-27 Jan Hubicka <jh@suse.cz>
* params.def (max-inline-insns-auto): Default to 40.
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 557c205e3d1..b63bf314a12 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -1825,6 +1825,8 @@ dump_cgraph_node (FILE *f, struct cgraph_node *node)
fprintf (f, " local");
if (node->local.externally_visible)
fprintf (f, " externally_visible");
+ if (node->local.used_from_object_file)
+ fprintf (f, " used_from_object_file");
if (node->local.finalized)
fprintf (f, " finalized");
if (node->local.disregard_inline_limits)
@@ -2075,6 +2077,7 @@ cgraph_clone_node (struct cgraph_node *n, tree decl, gcov_type count, int freq,
new_node->analyzed = n->analyzed;
new_node->local = n->local;
new_node->local.externally_visible = false;
+ new_node->local.used_from_object_file = false;
new_node->local.local = true;
new_node->local.vtable_method = false;
new_node->global = n->global;
@@ -2266,6 +2269,7 @@ cgraph_create_virtual_clone (struct cgraph_node *old_node,
else
new_node->clone.combined_args_to_skip = args_to_skip;
new_node->local.externally_visible = 0;
+ new_node->local.used_from_object_file = 0;
new_node->local.local = 1;
new_node->lowered = true;
new_node->reachable = true;
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 2c7ddbf123c..ef556b9cd7f 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -102,6 +102,9 @@ struct GTY(()) cgraph_local_info {
/* Set when function is visible by other units. */
unsigned externally_visible : 1;
+ /* Set when resolver determines that function is visible by other units. */
+ unsigned used_from_object_file : 1;
+
/* Set once it has been finalized so we consider it to be output. */
unsigned finalized : 1;
@@ -487,6 +490,8 @@ struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
unsigned output : 1;
/* Set when function is visible by other units. */
unsigned externally_visible : 1;
+ /* Set when resolver determines that variable is visible by other units. */
+ unsigned used_from_object_file : 1;
/* Set for aliases once they got through assemble_alias. Also set for
extra name aliases in varpool_extra_name_alias. */
unsigned alias : 1;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 86de226a812..b967e798b32 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2296,7 +2296,7 @@ attribute is present.
@cindex @code{externally_visible} attribute.
This attribute, attached to a global variable or function, nullifies
the effect of the @option{-fwhole-program} command-line option, so the
-object remains visible outside the current compilation unit.
+object remains visible outside the current compilation unit. If @option{-fwhole-program} is used together with @option{-flto} and @command{gold} is used as the linker plugin, @code{externally_visible} attributes are automatically added to functions (not variable yet due to a current @command{gold} issue) that are accessed outside of LTO objects according to resolution file produced by @command{gold}. For other linkers that cannot generate resolution file, explicit @code{externally_visible} attributes are still necessary.
@item far
@cindex functions which handle memory bank switching
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 85ca14b326e..48716c5283e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7310,7 +7310,7 @@ Enabled by default with @option{-funroll-loops}.
Assume that the current compilation unit represents the whole program being
compiled. All public functions and variables with the exception of @code{main}
and those merged by attribute @code{externally_visible} become static functions
-and in effect are optimized more aggressively by interprocedural optimizers.
+and in effect are optimized more aggressively by interprocedural optimizers. If @command{gold} is used as the linker plugin, @code{externally_visible} attributes are automatically added to functions (not variable yet due to a current @command{gold} issue) that are accessed outside of LTO objects according to resolution file produced by @command{gold}. For other linkers that cannot generate resolution file, explicit @code{externally_visible} attributes are still necessary.
While this option is equivalent to proper use of the @code{static} keyword for
programs consisting of a single file, in combination with option
@option{-combine}, @option{-flto} or @option{-fwhopr} this flag can be used to
diff --git a/gcc/ipa.c b/gcc/ipa.c
index 0cf2987427c..05e164271db 100644
--- a/gcc/ipa.c
+++ b/gcc/ipa.c
@@ -576,6 +576,8 @@ cgraph_externally_visible_p (struct cgraph_node *node, bool whole_program)
return false;
if (!whole_program)
return true;
+ if (node->local.used_from_object_file)
+ return true;
if (DECL_PRESERVE_P (node->decl))
return true;
/* COMDAT functions must be shared only if they have address taken,
@@ -729,6 +731,7 @@ function_and_variable_visibility (bool whole_program)
we start reordering datastructures. */
|| DECL_COMDAT (vnode->decl)
|| DECL_WEAK (vnode->decl)
+ || vnode->used_from_object_file
|| lookup_attribute ("externally_visible",
DECL_ATTRIBUTES (vnode->decl))))
vnode->externally_visible = true;
diff --git a/gcc/lto-symtab.c b/gcc/lto-symtab.c
index 6f46a733b42..e94bc204b22 100644
--- a/gcc/lto-symtab.c
+++ b/gcc/lto-symtab.c
@@ -530,11 +530,20 @@ lto_symtab_resolve_symbols (void **slot)
return;
found:
- if (TREE_CODE (prevailing->decl) == VAR_DECL
- && TREE_READONLY (prevailing->decl))
+ /* If current lto files represent the whole program,
+ it is correct to use LDPR_PREVALING_DEF_IRONLY.
+ If current lto files are part of whole program, internal
+ resolver doesn't know if it is LDPR_PREVAILING_DEF
+ or LDPR_PREVAILING_DEF_IRONLY. Use IRONLY conforms to
+ using -fwhole-program. Otherwise, it doesn't
+ matter using either LDPR_PREVAILING_DEF or
+ LDPR_PREVAILING_DEF_IRONLY
+
+ FIXME: above workaround due to gold plugin makes some
+ variables IRONLY, which are indeed PREVAILING_DEF in
+ resolution file. These variables still need manual
+ externally_visible attribute. */
prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
- else
- prevailing->resolution = LDPR_PREVAILING_DEF;
}
/* Merge all decls in the symbol table chain to the prevailing decl and
@@ -698,6 +707,24 @@ lto_symtab_merge_decls_1 (void **slot, void *data ATTRIBUTE_UNUSED)
&& TREE_CODE (prevailing->decl) != VAR_DECL)
prevailing->next = NULL;
+ /* Set externally_visible flags for declaration of LDPR_PREVAILING_DEF */
+ if (flag_whole_program)
+ {
+ if (prevailing->resolution == LDPR_PREVAILING_DEF)
+ {
+ if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
+ prevailing->node->local.used_from_object_file = true;
+ else
+ prevailing->vnode->used_from_object_file = true;
+ }
+ else if (prevailing->resolution == LDPR_PREVAILING_DEF_IRONLY)
+ {
+ if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
+ prevailing->node->local.used_from_object_file = false;
+ else
+ prevailing->vnode->used_from_object_file = false;
+ }
+ }
return 1;
}