http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50598
--- Comment #18 from Jan Hubicka <hubicka at ucw dot cz> 2011-11-14 12:18:43 UTC --- Hi, coud you please verify that the attached patch solves the problem? Thanks, Honza Index: cgraph.h =================================================================== --- cgraph.h (revision 181310) +++ cgraph.h (working copy) @@ -641,6 +641,7 @@ void debug_varpool_node_set (varpool_nod void free_varpool_node_set (varpool_node_set); void ipa_discover_readonly_nonaddressable_vars (void); bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *); +bool varpool_externally_visible_p (struct varpool_node *, bool); /* In predict.c */ bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e); @@ -681,6 +682,7 @@ bool const_value_known_p (tree); bool varpool_for_node_and_aliases (struct varpool_node *, bool (*) (struct varpool_node *, void *), void *, bool); +void varpool_add_new_variable (tree); /* Walk all reachable static variables. */ #define FOR_EACH_STATIC_VARIABLE(node) \ Index: tree-emutls.c =================================================================== --- tree-emutls.c (revision 181310) +++ tree-emutls.c (working copy) @@ -262,7 +262,7 @@ get_emutls_init_templ_addr (tree decl) if (DECL_EXTERNAL (to)) varpool_node (to); else - varpool_finalize_decl (to); + varpool_add_new_variable (to); return build_fold_addr_expr (to); } @@ -334,7 +334,7 @@ new_emutls_decl (tree decl, tree alias_o if (DECL_EXTERNAL (to)) varpool_node (to); else if (!alias_of) - varpool_finalize_decl (to); + varpool_add_new_variable (to); else varpool_create_variable_alias (to, varpool_node_for_asm Index: ipa.c =================================================================== --- ipa.c (revision 181310) +++ ipa.c (working copy) @@ -647,7 +647,7 @@ cgraph_externally_visible_p (struct cgra /* Return true when variable VNODE should be considered externally visible. */ -static bool +bool varpool_externally_visible_p (struct varpool_node *vnode, bool aliased) { if (!DECL_COMDAT (vnode->decl) && !TREE_PUBLIC (vnode->decl)) Index: varpool.c =================================================================== --- varpool.c (revision 181310) +++ varpool.c (working copy) @@ -414,6 +414,20 @@ varpool_finalize_decl (tree decl) varpool_assemble_pending_decls (); } +/* Add the variable DECL to the varpool. + Unlike varpool_finalize_decl function is intended to be used + by middle end and allows insertion of new variable at arbitrary point + of compilation. */ +void +varpool_add_new_variable (tree decl) +{ + struct varpool_node *node; + varpool_finalize_decl (decl); + node = varpool_node (decl); + if (varpool_externally_visible_p (node, false)) + node->externally_visible = true; +} + /* Return variable availability. See cgraph.h for description of individual return values. */ enum availability