This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] Apply name mappings to alias pairs for static symbols


When a static symbol is read in from an IL file, we rename it so
that it doesn't clash with other static symbols coming from other
IL files that may have the same name.

During this renaming, however, we were failing to update
identifiers that had been registered in alias pairs.  This patch
fixes that by registering old->new name mappings as well as
new->old mappings.

This allows us to find the new name that an identifier has been
given when reading in alias_pairs.

The test case is coming from a fairly large shared library that
I've been trying to reduce for a couple of days.  I've verified
that the application now builds cleanly, but the test case will
take a while longer to reduce.  I will commit it once I get it
down to a manageable size.

Tested on x86_64.


Diego.


	* lto-function-in.c (input_constructors_or_inits): When
	reading alias pairs, rename the target of the alias if a
	new name had been registered for it.
	(input_function_decl): Also register the mapping
	NEW_ASSEMBLER_NAME -> OLD_ASSEMBLER_NAME.
	* lto-section-in.c (lto_record_renamed_decl): Fix documentation.
	(lto_get_decl_name_mapping): Rename from lto_original_decl_name. 
	Fix documentation.
	Update all users.

Index: lto-function-out.c
===================================================================
--- lto-function-out.c	(revision 142843)
+++ lto-function-out.c	(working copy)
@@ -2460,7 +2460,7 @@ copy_function (struct cgraph_node *node)
   free (section_name);
 
   /* We may have renamed the declaration, e.g., a static function.  */
-  name = lto_original_decl_name (file_data, name);
+  name = lto_get_decl_name_mapping (file_data, name);
 
   data = lto_get_section_data (file_data, LTO_section_function_body,
                                name, &len);
Index: lto-function-in.c
===================================================================
--- lto-function-in.c	(revision 142823)
+++ lto-function-in.c	(working copy)
@@ -2316,11 +2316,21 @@ input_constructors_or_inits (struct data
   tag = input_record_start (ib);
   while (tag)
     {
+      const char *orig_name, *new_name;
       alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
       p->decl = input_expr_operand (ib, data_in, NULL, tag);
       LTO_DEBUG_TOKEN ("alias_target");
       tag = input_record_start (ib);
       p->target = input_expr_operand (ib, data_in, NULL, tag);
+
+      /* If the target is a static object, we may have registered a
+	 new name for it to avoid clashes between statics coming from
+	 different files.  In that case, use the new name.  */
+      orig_name = IDENTIFIER_POINTER (p->target);
+      new_name = lto_get_decl_name_mapping (data_in->file_data, orig_name);
+      if (strcmp (orig_name, new_name) != 0)
+	p->target = get_identifier (new_name);
+
       tag = input_record_start (ib);
     }
 
@@ -2925,6 +2935,13 @@ input_function_decl (struct lto_input_bl
 	  lto_record_renamed_decl (data_in->file_data,
 				   IDENTIFIER_POINTER (old_assembler_name),
 				   IDENTIFIER_POINTER (new_assembler_name));
+
+	  /* Also register the reverse mapping so that we can find the
+	     new name given to an existing assembler name (used when
+	     restoring alias pairs in input_constructors_or_inits.  */ 
+	  lto_record_renamed_decl (data_in->file_data,
+				   IDENTIFIER_POINTER (new_assembler_name),
+				   IDENTIFIER_POINTER (old_assembler_name));
 	}				   
     }
 
Index: lto-section-in.c
===================================================================
--- lto-section-in.c	(revision 142843)
+++ lto-section-in.c	(working copy)
@@ -393,7 +393,8 @@ lto_create_renaming_table (void)
   return htab_create (37, hash_name, eq_name, renaming_slot_free);
 }
 
-/* Record a declaration renaming.  */
+/* Record a declaration name mapping OLD_NAME -> NEW_NAME.  DECL_DATA
+   holds the renaming hash table to use.  */
 
 void
 lto_record_renamed_decl (struct lto_file_decl_data *decl_data,
@@ -418,13 +419,14 @@ lto_record_renamed_decl (struct lto_file
     gcc_unreachable ();
 }
 
-/* Return the original name of a declaration.  If the declaration was not
-   renamed, then this is the name we were given, else it is the name that
-   the declaration was previously renamed to.  */
+
+/* Given a string NAME, return the string that it has been mapped to
+   by lto_record_renamed_decl.  If NAME was not renamed, it is
+   returned unchanged.  DECL_DATA holds the renaming hash table to use.  */
 
 const char *
-lto_original_decl_name (struct lto_file_decl_data *decl_data,
-			const char *name)
+lto_get_decl_name_mapping (struct lto_file_decl_data *decl_data,
+			   const char *name)
 {
   htab_t renaming_hash_table = decl_data->renaming_hash_table;
   struct lto_renaming_slot *slot;
Index: lto-section-in.h
===================================================================
--- lto-section-in.h	(revision 142823)
+++ lto-section-in.h	(working copy)
@@ -202,8 +202,8 @@ extern tree lto_input_integer (struct lt
 extern htab_t lto_create_renaming_table (void);
 extern void lto_record_renamed_decl (struct lto_file_decl_data *,
 				     const char *, const char *);
-extern const char *lto_original_decl_name (struct lto_file_decl_data *,
-					   const char *);
+extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
+					      const char *);
 extern struct lto_in_decl_state *lto_new_in_decl_state (void);
 extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
 extern hashval_t lto_hash_in_decl_state (const void *);
Index: lto/lto.c
===================================================================
--- lto/lto.c	(revision 142843)
+++ lto/lto.c	(working copy)
@@ -83,7 +83,7 @@ lto_materialize_function (struct cgraph_
   const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 
 
   /* We may have renamed the declaration, e.g., a static function.  */
-  name = lto_original_decl_name (file_data, name);
+  name = lto_get_decl_name_mapping (file_data, name);
 
   data = lto_get_section_data (file_data, LTO_section_function_body,
 			       name, &len);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]