Patchwork Fix infinite loop in lto-partition.c

login
register
mail settings
Submitter Jan Hubicka
Date May 17, 2013, 10:22 p.m.
Message ID <20130517222215.GA22755@kam.mff.cuni.cz>
Download mbox | patch
Permalink /patch/244710/
State New
Headers show

Comments

Jan Hubicka - May 17, 2013, 10:22 p.m.
Hi,
privatize_symbol_name skips privatizing of symbols where we know for some reason
that it is needed. Loop in rename_statics however expect privatize_symbol_name
to always rename the var and it can get into an infinite loop.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

	* lto-partition.c (privatize_symbol_name): Return true when
	privatizing happened.
	(rename_statics): Do not go into infinite loop when privatizing
	is not needed.

Patch

Index: lto-partition.c
===================================================================
--- lto-partition.c	(revision 198936)
+++ lto-partition.c	(working copy)
@@ -766,7 +766,7 @@  lto_balanced_map (void)
       with symbols defined out of the LTO world.
 */
 
-static void
+static bool
 privatize_symbol_name (symtab_node node)
 {
   tree decl = node->symbol.decl;
@@ -781,7 +781,7 @@  privatize_symbol_name (symtab_node node)
 	fprintf (cgraph_dump_file,
 		"Not privatizing symbol name: %s. It privatized already.\n",
 		name);
-      return;
+      return false;
     }
   /* Avoid mangling of already mangled clones. 
      ???  should have a flag whether a symbol has a 'private' name already,
@@ -793,7 +793,7 @@  privatize_symbol_name (symtab_node node)
 	fprintf (cgraph_dump_file,
 		"Not privatizing symbol name: %s. Has unique name.\n",
 		name);
-      return;
+      return false;
     }
   change_decl_assembler_name (decl, clone_function_name (decl, "lto_priv"));
   if (node->symbol.lto_file_data)
@@ -804,6 +804,7 @@  privatize_symbol_name (symtab_node node)
     fprintf (cgraph_dump_file,
 	    "Privatizing symbol name: %s -> %s\n",
 	    name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
+  return true;
 }
 
 /* Promote variable VNODE to be static.  */
@@ -906,11 +907,12 @@  rename_statics (lto_symtab_encoder_t enc
 	&& (!encoder
 	    || lto_symtab_encoder_lookup (encoder, s) != LCC_NOT_FOUND))
       {
-        privatize_symbol_name (s);
-	/* Re-start from beggining since we do not know how many symbols changed a name.  */
-	s = symtab_node_for_asm (name);
+        if (privatize_symbol_name (s))
+	  /* Re-start from beggining since we do not know how many symbols changed a name.  */
+	  s = symtab_node_for_asm (name);
+        else s = s->symbol.next_sharing_asm_name;
       }
-   else s = s->symbol.next_sharing_asm_name;
+    else s = s->symbol.next_sharing_asm_name;
 }
 
 /* Find out all static decls that need to be promoted to global because