Index: lto-symtab.c
===================================================================
--- lto-symtab.c        (revision 160463)
+++ lto-symtab.c        (working copy)
@@ -530,11 +530,15 @@
     return;

 found:
-  if (TREE_CODE (prevailing->decl) == VAR_DECL
-      && TREE_READONLY (prevailing->decl))
-    prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
-  else
-    prevailing->resolution = LDPR_PREVAILING_DEF;
+  /* 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 */
+  prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
 }

 /* Merge all decls in the symbol table chain to the prevailing decl and
@@ -698,6 +702,18 @@
       && TREE_CODE (prevailing->decl) != VAR_DECL)
     prevailing->next = NULL;

+
+  /* Add externally_visible attribute for declaration of LDPR_PREVAILING_DEF */
+  if (prevailing->resolution == LDPR_PREVAILING_DEF && flag_whole_program)
+    {
+      if (!lookup_attribute ("externally_visible",
+                             DECL_ATTRIBUTES (prevailing->decl)))
+        {
+          DECL_ATTRIBUTES (prevailing->decl)
+            = tree_cons (get_identifier ("externally_visible"), NULL_TREE,
+                         DECL_ATTRIBUTES (prevailing->decl));
+        }
+    }
   return 1;
 }

