https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65263

--- Comment #5 from Jan Hubicka <hubicka at ucw dot cz> ---
Hi,
the following (untested) patch should prevent redirection to happen.  
Index: ipa-icf.c
===================================================================
--- ipa-icf.c    (revision 221096)
+++ ipa-icf.c    (working copy)
@@ -697,12 +697,22 @@ redirect_all_callers (cgraph_node *n, cg
 {
   int nredirected = 0;
   ipa_ref *ref;
+  cgraph_edge *e = n->callers;

-  while (n->callers)
+  while (e)
     {
-      cgraph_edge *e = n->callers;
-      e->redirect_callee (to);
-      nredirected++;
+      /* Redirecting thunks to interposable symbols or symbols in other
sections
+     may not be supported by target output code.  Play safe for now and
+     punt on redirection.  */
+      if (!e->caller->thunk.thunk_p)
+    {
+      struct cgraph_edge *nexte = e->next_callee;
+          e->redirect_callee (to);
+      e = nexte;
+          nredirected++;
+    }
+      else
+    e = e->next_callee;
     }
   for (unsigned i = 0; n->iterate_direct_aliases (i, ref);)
     {
@@ -726,6 +736,17 @@ redirect_all_callers (cgraph_node *n, cg
   return nredirected;
 }

+/* Return true if NODE has thunk.  */
+
+bool
+has_thunk_p (cgraph_node *node, void *)
+{
+  for (cgraph_edge *e = node->callers; e; e = e->next_caller)
+    if (e->caller->thunk.thunk_p)
+      return true;
+  return false;
+}
+
 /* Merges instance with an ALIAS_ITEM, where alias, thunk or redirection can
    be applied.  */

@@ -907,6 +928,7 @@ sem_function::merge (sem_item *alias_ite
       return false;
     }
       if (!create_wrapper
+      && !alias->call_for_symbol_and_aliases (has_thunk_p, NULL, true)
       && !alias->can_remove_if_no_direct_calls_p ())
     {
       if (dump_file)

Reply via email to