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]

[RFC] Re: Enable -fuse-linker-plugin by default when possible, take 2


On 01/12/2010 13:31, Jan Hubicka wrote:
>> On 01/12/2010 13:19, Jan Hubicka wrote:
>>
>>> To make lto-symtab possible, I think we need new hook
>>> targetm.mangle_assembler_name that will take char * and return identifier
>>> (or string buffer) containing the actual symbol name.
>>>
>>> The default definition calling targetm.strip_name_encoding and prepending
>>> user_label_prefix (if any) should work well enough for ELF targets and for
>>> cygwin we will define custom hook.
>>>
>>> For stage3 we will use it only for lto-symtab and lto-streamer-out
>>> purposes. In the next release we should work towards getting real symbol
>>> table everywhere 
>>   This sounds like a good plan.  Did anyone volunteer to get started on it
>> during the IRC discussion?  Otherwise I could do it.
> 
> I implicitely added it to my TODO (at least adding the target hook and making
> lto-symtab and streamer-out to do the translation), but if you will do so, you
> are very, very welcome.  I am somewhat swamped in the LTO issues at the moment
> :)

  Aren't we all :)

  Anyway this is a nearly-complete(*) but only partially-tested(**) draft
patch, not a submission.  Not having written a new target hook before, I'd
appreciate advice; did I get all the bits in the right places and name them
the right ways?

  Also, Honza, did I catch all the right places you were thinking this should
be used in the lto streamer and symtab code?

    cheers,
      DaveK

-- 
(*) - Needs completing the documentation hunk and removing that fixme comment.
 Probably a testcase or two, too.
(**) - Passed an LTO bootstrap and test without regressions on x86_64 linux,
haven't tested on cygwin yet.

Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	(revision 167443)
+++ gcc/doc/tm.texi	(working copy)
@@ -8037,6 +8037,10 @@ is customary on your operating system, as it is in
 systems.  This macro is used in @code{assemble_name}.
 @end defmac
 
+@deftypefn {Target Hook} tree TARGET_MANGLE_ASSEMBLER_NAME (const char *@var{name})
+Given a symbol @var{name}, perform same mangling as @code{ASM_OUTPUT_LABELREF},  returning result as an @code{IDENTIFIER_NODE}.  Required for correct LTO symtabs.   The default implementation calls the @code{}
+@end deftypefn
+
 @defmac ASM_OUTPUT_SYMBOL_REF (@var{stream}, @var{sym})
 A C statement (sans semicolon) to output a reference to
 @code{SYMBOL_REF} @var{sym}.  If not defined, @code{assemble_name}
Index: gcc/doc/tm.texi.in
===================================================================
--- gcc/doc/tm.texi.in	(revision 167443)
+++ gcc/doc/tm.texi.in	(working copy)
@@ -8011,6 +8011,8 @@ is customary on your operating system, as it is in
 systems.  This macro is used in @code{assemble_name}.
 @end defmac
 
+@hook TARGET_MANGLE_ASSEMBLER_NAME
+
 @defmac ASM_OUTPUT_SYMBOL_REF (@var{stream}, @var{sym})
 A C statement (sans semicolon) to output a reference to
 @code{SYMBOL_REF} @var{sym}.  If not defined, @code{assemble_name}
Index: gcc/lto-symtab.c
===================================================================
--- gcc/lto-symtab.c	(revision 167443)
+++ gcc/lto-symtab.c	(working copy)
@@ -155,7 +155,8 @@ lto_symtab_register_decl (tree decl,
     gcc_assert (!DECL_ABSTRACT (decl));
 
   new_entry = ggc_alloc_cleared_lto_symtab_entry_def ();
-  new_entry->id = DECL_ASSEMBLER_NAME (decl);
+  new_entry->id = (*targetm.asm_out.mangle_assembler_name)
+		  (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
   new_entry->decl = decl;
   new_entry->resolution = resolution;
   new_entry->file_data = file_data;
@@ -190,7 +191,8 @@ lto_symtab_get_resolution (tree decl)
 
   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
 
-  e = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
+  e = lto_symtab_get ((*targetm.asm_out.mangle_assembler_name)
+		      (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
   while (e && e->decl != decl)
     e = e->next;
   if (!e)
@@ -218,7 +220,8 @@ lto_cgraph_replace_node (struct cgraph_node *node,
 	       cgraph_node_name (node), node->uid,
 	       cgraph_node_name (prevailing_node),
 	       prevailing_node->uid,
-	       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
+	       IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name)
+		 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)))));
     }
 
   if (prevailing_node->same_body_alias)
@@ -836,7 +839,8 @@ lto_symtab_prevailing_decl (tree decl)
   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
 
   /* Walk through the list of candidates and return the one we merged to.  */
-  ret = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
+  ret = lto_symtab_get ((*targetm.asm_out.mangle_assembler_name)
+			(IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
   if (!ret)
     return NULL_TREE;
 
Index: gcc/targhooks.c
===================================================================
--- gcc/targhooks.c	(revision 167443)
+++ gcc/targhooks.c	(working copy)
@@ -358,6 +358,16 @@ default_print_operand_punct_valid_p (unsigned char
 #endif
 }
 
+/* The default implementation of TARGET_MANGLE_ASSEMBLER_NAME.  */
+tree
+default_mangle_assembler_name (const char *name ATTRIBUTE_UNUSED)
+{
+  const char *stripped = targetm.strip_name_encoding (name);
+  if (user_label_prefix[0])
+    stripped = ACONCAT ((user_label_prefix, stripped, NULL));
+  return get_identifier (stripped);
+}
+
 /* The default implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
 
 bool
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h	(revision 167443)
+++ gcc/targhooks.h	(working copy)
@@ -65,6 +65,8 @@ extern bool hook_callee_copies_named
 extern void default_print_operand (FILE *, rtx, int);
 extern void default_print_operand_address (FILE *, rtx);
 extern bool default_print_operand_punct_valid_p (unsigned char);
+extern tree default_mangle_assembler_name (const char *);
+
 extern bool default_asm_output_addr_const_extra (FILE *, rtx);
 
 extern bool default_scalar_mode_supported_p (enum machine_mode);
Index: gcc/target.def
===================================================================
--- gcc/target.def	(revision 167443)
+++ gcc/target.def	(working copy)
@@ -524,6 +524,16 @@ DEFHOOK_UNDOC
  bool ,(unsigned char code),
  default_print_operand_punct_valid_p)
 
+/* Given a symbol name, perform same mangling as ASM_OUTPUT_LABELREF,
+   returning result as an IDENTIFIER_NODE.  */
+DEFHOOK
+(mangle_assembler_name,
+ "Given a symbol @var{name}, perform same mangling as @code{ASM_OUTPUT_LABELREF},\
+  returning result as an @code{IDENTIFIER_NODE}.  Required for correct LTO symtabs. \
+  The default implementation calls the @code{}",
+ tree, (const char *name),
+ default_mangle_assembler_name)
+
 HOOK_VECTOR_END (asm_out)
 
 /* Functions relating to instruction scheduling.  All of these
Index: gcc/lto-streamer-out.c
===================================================================
--- gcc/lto-streamer-out.c	(revision 167443)
+++ gcc/lto-streamer-out.c	(working copy)
@@ -2375,8 +2375,7 @@ write_symbol (struct lto_streamer_cache_d *cache,
   /* FIXME lto: this is from assemble_name_raw in varasm.c. For some
      architectures we might have to do the same name manipulations that
      ASM_OUTPUT_LABELREF does. */
-  if (name[0] == '*')
-    name = &name[1];
+  name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
 
   lto_streamer_cache_lookup (cache, t, &slot_num);
   gcc_assert (slot_num >= 0);
Index: gcc/config/i386/cygming.h
===================================================================
--- gcc/config/i386/cygming.h	(revision 167443)
+++ gcc/config/i386/cygming.h	(working copy)
@@ -252,6 +252,10 @@ do {						\
   fputs ((NAME), (STREAM));			\
 } while (0)
 
+/* This does much the same in memory rather than to a stream.  */
+#undef TARGET_MANGLE_ASSEMBLER_NAME
+#define TARGET_MANGLE_ASSEMBLER_NAME i386_pe_mangle_assembler_name
+
 
 /* Emit code to check the stack when allocating more than 4000
    bytes in one go.  */
Index: gcc/config/i386/winnt.c
===================================================================
--- gcc/config/i386/winnt.c	(revision 167443)
+++ gcc/config/i386/winnt.c	(working copy)
@@ -244,6 +244,19 @@ i386_pe_mangle_decl_assembler_name (tree decl, tre
   return (new_id ? new_id : id);
 }
 
+/* This hook behaves the same as varasm.c/assemble_name(), but
+   generates the name into memory rather than outputting it to
+   a file stream.  */
+
+tree
+i386_pe_mangle_assembler_name (const char *name ATTRIBUTE_UNUSED)
+{
+  const char *stripped = targetm.strip_name_encoding (name);
+  if (user_label_prefix[0] && (stripped[0] != FASTCALL_PREFIX))
+    stripped = ACONCAT ((user_label_prefix, stripped, NULL));
+  return get_identifier (stripped);
+}
+
 void
 i386_pe_encode_section_info (tree decl, rtx rtl, int first)
 {
Index: gcc/config/i386/i386-protos.h
===================================================================
--- gcc/config/i386/i386-protos.h	(revision 167443)
+++ gcc/config/i386/i386-protos.h	(working copy)
@@ -226,6 +226,7 @@ extern void i386_pe_file_end (void);
 extern void i386_pe_start_function (FILE *, const char *, tree);
 extern void i386_pe_end_function (FILE *, const char *, tree);
 extern tree i386_pe_mangle_decl_assembler_name (tree, tree);
+extern tree i386_pe_mangle_assembler_name (const char *);
 
 extern void i386_pe_seh_init (FILE *);
 extern void i386_pe_seh_end_prologue (FILE *);

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