Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 194725)
+++ cp/decl2.c	(working copy)
@@ -3615,79 +3615,53 @@ generate_ctor_and_dtor_functions_for_priority (spl

 /* Java requires that we be able to reference a local address for a
    method, and not be confused by PLT entries.  If hidden aliases are
-   supported, collect and return all the functions for which we should
+   supported, emit one for each java function that we've emitted.
    emit a hidden alias.  */

-static struct pointer_set_t *
-collect_candidates_for_java_method_aliases (void)
+static void
+build_java_method_aliases (void)
 {
+#ifdef HAVE_GAS_HIDDEN
   struct cgraph_node *node;
-  struct pointer_set_t *candidates = NULL;
+  tree fndecl;
+  vec<tree> candidates = vNULL;
+  unsigned int ix;

-#ifndef HAVE_GAS_HIDDEN
-  return candidates;
-#endif
-
+  /* First collect all candidates.  We cannot create the aliases
+     in place, it confuses the FOR_EACH_FUNCTION iterator.  */
   FOR_EACH_FUNCTION (node)
     {
-      tree fndecl = node->symbol.decl;
-
+      fndecl = node->symbol.decl;
       if (DECL_CONTEXT (fndecl)
 	  && TYPE_P (DECL_CONTEXT (fndecl))
 	  && TYPE_FOR_JAVA (DECL_CONTEXT (fndecl))
 	  && TARGET_USE_LOCAL_THUNK_ALIAS_P (fndecl))
-	{
-	  if (candidates == NULL)
-	    candidates = pointer_set_create ();
-	  pointer_set_insert (candidates, fndecl);
-	}
+	candidates.safe_push (fndecl);
     }

-  return candidates;
-}
-
-
-/* Java requires that we be able to reference a local address for a
-   method, and not be confused by PLT entries.  If hidden aliases are
-   supported, emit one for each java function that we've emitted.
-   CANDIDATES is the set of FUNCTION_DECLs that were gathered
-   by collect_candidates_for_java_method_aliases.  */
-
-static void
-build_java_method_aliases (struct pointer_set_t *candidates)
-{
-  struct cgraph_node *node;
-
-#ifndef HAVE_GAS_HIDDEN
-  return;
-#endif
-
-  FOR_EACH_FUNCTION (node)
+  /* Now add the aliases for the candidates collected above.
+     Mangle the name in a predictable way; we need to reference
+     this from a java compiled object file.  */
+  FOR_EACH_VEC_ELT (candidates, ix, fndecl)
     {
-      tree fndecl = node->symbol.decl;
+      tree oid, nid, alias;
+      const char *oname;
+      char *nname;

-      if (TREE_ASM_WRITTEN (fndecl)
-	  && pointer_set_contains (candidates, fndecl))
-	{
-	  /* Mangle the name in a predictable way; we need to reference
-	     this from a java compiled object file.  */
-	  tree oid, nid, alias;
-	  const char *oname;
-	  char *nname;
+      oid = DECL_ASSEMBLER_NAME (fndecl);
+      oname = IDENTIFIER_POINTER (oid);
+      gcc_assert (oname[0] == '_' && oname[1] == 'Z');
+      nname = ACONCAT (("_ZGA", oname+2, NULL));
+      nid = get_identifier (nname);

-	  oid = DECL_ASSEMBLER_NAME (fndecl);
-	  oname = IDENTIFIER_POINTER (oid);
-	  gcc_assert (oname[0] == '_' && oname[1] == 'Z');
-	  nname = ACONCAT (("_ZGA", oname+2, NULL));
-	  nid = get_identifier (nname);
-
-	  alias = make_alias_for (fndecl, nid);
-	  TREE_PUBLIC (alias) = 1;
-	  DECL_VISIBILITY (alias) = VISIBILITY_HIDDEN;
-
-	  assemble_alias (alias, oid);
-	}
+      alias = make_alias_for (fndecl, nid);
+      TREE_PUBLIC (alias) = 1;
+      DECL_VISIBILITY (alias) = VISIBILITY_HIDDEN;
+      node = cgraph_same_body_alias (NULL, alias, fndecl);
+      gcc_assert (node);
     }
+#endif
+  return;
 }

 /* Return C++ property of T, based on given operation OP.  */
@@ -3933,7 +3907,6 @@ cp_write_global_declarations (void)
   unsigned ssdf_count = 0;
   int retries = 0;
   tree decl;
-  struct pointer_set_t *candidates;

   locus = input_location;
   at_eof = 1;
@@ -4282,8 +4255,8 @@ cp_write_global_declarations (void)
      linkage now.  */
   pop_lang_context ();

-  /* Collect candidates for Java hidden aliases.  */
-  candidates = collect_candidates_for_java_method_aliases ();
+  /* Generate hidden aliases for Java.  */
+  build_java_method_aliases ();

   timevar_stop (TV_PHASE_DEFERRED);
   timevar_start (TV_PHASE_OPT_GEN);
@@ -4306,13 +4279,6 @@ cp_write_global_declarations (void)

   perform_deferred_noexcept_checks ();

-  /* Generate hidden aliases for Java.  */
-  if (candidates)
-    {
-      build_java_method_aliases (candidates);
-      pointer_set_destroy (candidates);
-    }
-
   finish_repo ();

   /* The entire file is now complete.  If requested, dump everything
