[PATCH] Provide unwind info for i?86 pc thunks even for -fno-dwarf2-cfi-asm (PR debug/43293)

Jakub Jelinek jakub@redhat.com
Wed Mar 24 16:46:00 GMT 2010


Hi!

When writing the PR43498 patch I've realized it is not terribly hard to
support even gcc generated .eh_frame info for pc thunks.
All we need is a target hook which allows us to emit it earlier than
at the file end (as that's after the debug info).
The following patch implements it.  SPARC could use the same for its
pc thunks...

Bootstrapped/regtested on x86_64-linux and i686-linux.  Ok for trunk?

2010-03-24  Jakub Jelinek  <jakub@redhat.com>

	PR debug/43293
	* target.h (struct gcc_target): Add code_end hook.
	* target-def.h (TARGET_ASM_CODE_END): Define to hook_void_void
	if not yet defined.
	(TARGET_ASM_OUT): Add TARGET_ASM_CODE_END.
	* toplev.c (compile_file): Call targetm.asm_out.code_end
	hook before unwind info/debug info output.
	* config/i386/winnt.c (i386_pe_file_end): Don't call ix86_file_end.
	* config/i386/linux.h (NEED_INDICATE_EXEC_STACK): Don't define.
	(TARGET_ASM_FILE_END): Define to file_end_indicate_exec_stack.
	* config/i386/linux64.h (NEED_INDICATE_EXEC_STACK): Don't define.
	(TARGET_ASM_FILE_END): Define to file_end_indicate_exec_stack.
	* config/i386/i386.c (ix86_file_end): Renamed to...
	(ix86_code_end): ... this.  Make static.  Don't call
	file_end_indicate_exec_stack.  Emit unwind info using
	final_start_function/final_end_function.
	(darwin_x86_file_end): Remove.
	(TARGET_ASM_CODE_END): Define.
	* config/i386/i386.h (TARGET_ASM_FILE_END,
	NEED_INDICATE_EXEC_STACK): Don't define.
	* config/i386/darwin.h (darwin_x86_file_end): Remove prototype.
	(TARGET_ASM_FILE_END): Define to darwin_file_end.
	* config/i386/i386-protos.h (ix86_file_end): Remove prototype.

--- gcc/target.h.jj	2010-01-19 10:27:50.000000000 +0100
+++ gcc/target.h	2010-03-24 13:28:31.000000000 +0100
@@ -235,6 +235,10 @@ struct gcc_target
        translation unit.  */
     void (*file_end) (void);
 
+    /* Output any boilerplace text needed at the end of a
+       translation unit before debug and unwind info is emitted.  */
+    void (*code_end) (void);
+
     /* Output an assembler pseudo-op to declare a library function name
        external.  */
     void (*external_libcall) (rtx);
--- gcc/target-def.h.jj	2009-11-26 09:44:44.000000000 +0100
+++ gcc/target-def.h	2010-03-24 13:28:59.000000000 +0100
@@ -204,6 +204,10 @@
 #define TARGET_ASM_FILE_END hook_void_void
 #endif
 
+#ifndef TARGET_ASM_CODE_END
+#define TARGET_ASM_CODE_END hook_void_void
+#endif
+
 #ifndef TARGET_EXTRA_LIVE_ON_ENTRY
 #define TARGET_EXTRA_LIVE_ON_ENTRY hook_void_bitmap
 #endif
@@ -292,6 +296,7 @@
                         TARGET_ASM_CAN_OUTPUT_MI_THUNK,         \
                         TARGET_ASM_FILE_START,                  \
                         TARGET_ASM_FILE_END,			\
+                        TARGET_ASM_CODE_END,			\
 			TARGET_ASM_EXTERNAL_LIBCALL,            \
                         TARGET_ASM_MARK_DECL_PRESERVED,		\
 			TARGET_ASM_RECORD_GCC_SWITCHES,		\
--- gcc/toplev.c.jj	2010-03-01 16:31:50.000000000 +0100
+++ gcc/toplev.c	2010-03-24 13:41:52.000000000 +0100
@@ -1084,6 +1084,10 @@ compile_file (void)
   /* Write out any pending weak symbol declarations.  */
   weak_finish ();
 
+  /* This must be at the end before unwind and debug info.
+     Some target ports emit PIC setup thunks here.  */
+  targetm.asm_out.code_end ();
+
   /* Do dbx symbols.  */
   timevar_push (TV_SYMOUT);
 
--- gcc/config/i386/winnt.c.jj	2009-12-01 20:25:20.000000000 +0100
+++ gcc/config/i386/winnt.c	2010-03-24 13:32:51.000000000 +0100
@@ -670,8 +670,6 @@ i386_pe_file_end (void)
 {
   struct extern_list *p;
 
-  ix86_file_end ();
-
   for (p = extern_head; p != NULL; p = p->next)
     {
       tree decl;
--- gcc/config/i386/linux.h.jj	2009-11-04 08:15:57.000000000 +0100
+++ gcc/config/i386/linux.h	2010-03-24 13:35:44.000000000 +0100
@@ -202,8 +202,7 @@ along with GCC; see the file COPYING3.  
 #define LIBGCC2_TF_CEXT q
 #define TF_SIZE 113
 
-#undef NEED_INDICATE_EXEC_STACK
-#define NEED_INDICATE_EXEC_STACK 1
+#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
 #define MD_UNWIND_SUPPORT "config/i386/linux-unwind.h"
 
--- gcc/config/i386/i386.c.jj	2010-03-24 12:16:04.000000000 +0100
+++ gcc/config/i386/i386.c	2010-03-24 14:25:07.000000000 +0100
@@ -7577,8 +7577,8 @@ get_pc_thunk_name (char name[32], unsign
 /* This function generates code for -fpic that loads %ebx with
    the return address of the caller and then returns.  */
 
-void
-ix86_file_end (void)
+static void
+ix86_code_end (void)
 {
   rtx xops[2];
   int regno;
@@ -7586,15 +7586,21 @@ ix86_file_end (void)
   for (regno = 0; regno < 8; ++regno)
     {
       char name[32];
-#ifdef DWARF2_UNWIND_INFO
-      bool do_cfi;
-#endif
+      tree decl;
 
       if (! ((pic_labels_used >> regno) & 1))
 	continue;
 
       get_pc_thunk_name (name, regno);
 
+      decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
+			 get_identifier (name),
+			 build_function_type (void_type_node, void_list_node));
+      DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
+				       NULL_TREE, void_type_node);
+      TREE_PUBLIC (decl) = 1;
+      TREE_STATIC (decl) = 1;
+
 #if TARGET_MACHO
       if (TARGET_MACHO)
 	{
@@ -7610,13 +7616,6 @@ ix86_file_end (void)
 #endif
       if (USE_HIDDEN_LINKONCE)
 	{
-	  tree decl;
-
-	  decl = build_decl (BUILTINS_LOCATION,
-			     FUNCTION_DECL, get_identifier (name),
-			     error_mark_node);
-	  TREE_PUBLIC (decl) = 1;
-	  TREE_STATIC (decl) = 1;
 	  DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl);
 
 	  (*targetm.asm_out.unique_section) (decl, 0);
@@ -7634,23 +7633,22 @@ ix86_file_end (void)
 	  ASM_OUTPUT_LABEL (asm_out_file, name);
 	}
 
-#ifdef DWARF2_UNWIND_INFO
-      do_cfi = dwarf2out_do_cfi_asm ();
-      if (do_cfi)
-	fprintf (asm_out_file, "\t.cfi_startproc\n");
-#endif
+      DECL_INITIAL (decl) = make_node (BLOCK);
+      current_function_decl = decl;
+      init_function_start (decl);
+      /* Make sure unwind info is emitted for the thunk if needed.  */
+      final_start_function (emit_barrier (), asm_out_file, 1);
+
       xops[0] = gen_rtx_REG (Pmode, regno);
       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
       output_asm_insn ("ret", xops);
-#ifdef DWARF2_UNWIND_INFO
-      if (do_cfi)
-	fprintf (asm_out_file, "\t.cfi_endproc\n");
-#endif
+      final_end_function ();
+      init_insn_lengths ();
+      free_after_compilation (cfun);
+      set_cfun (NULL);
+      current_function_decl = NULL;
     }
-
-  if (NEED_INDICATE_EXEC_STACK)
-    file_end_indicate_exec_stack ();
 }
 
 /* Emit code for the SET_GOT patterns.  */
@@ -25935,13 +25933,6 @@ machopic_output_stub (FILE *file, const 
   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
   fprintf (file, ASM_LONG "%s\n", binder_name);
 }
-
-void
-darwin_x86_file_end (void)
-{
-  darwin_file_end ();
-  ix86_file_end ();
-}
 #endif /* TARGET_MACHO */
 
 /* Order the registers for register allocator.  */
@@ -30547,6 +30538,9 @@ ix86_enum_va_list (int idx, const char *
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE ix86_can_eliminate
 
+#undef TARGET_ASM_CODE_END
+#define TARGET_ASM_CODE_END ix86_code_end
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-i386.h"
--- gcc/config/i386/i386.h.jj	2009-12-22 09:44:24.000000000 +0100
+++ gcc/config/i386/i386.h	2010-03-24 13:34:35.000000000 +0100
@@ -1627,9 +1627,6 @@ typedef struct ix86_args {
 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
   function_arg (&(CUM), (MODE), (TYPE), (NAMED))
 
-#define TARGET_ASM_FILE_END ix86_file_end
-#define NEED_INDICATE_EXEC_STACK 0
-
 /* Output assembler code to FILE to increment profiler label # LABELNO
    for profiling a function entry.  */
 
--- gcc/config/i386/darwin.h.jj	2010-03-01 16:31:50.000000000 +0100
+++ gcc/config/i386/darwin.h	2010-03-24 13:33:45.000000000 +0100
@@ -141,9 +141,8 @@ along with GCC; see the file COPYING3.  
 
 #define SHIFT_DOUBLE_OMITS_COUNT 0
 
-extern void darwin_x86_file_end (void);
 #undef TARGET_ASM_FILE_END
-#define TARGET_ASM_FILE_END darwin_x86_file_end
+#define TARGET_ASM_FILE_END darwin_file_end
 
 /* Define the syntax of pseudo-ops, labels and comments.  */
 
--- gcc/config/i386/linux64.h.jj	2010-03-01 16:31:50.000000000 +0100
+++ gcc/config/i386/linux64.h	2010-03-24 13:35:59.000000000 +0100
@@ -105,8 +105,7 @@ see the files COPYING3 and COPYING.RUNTI
 #define LIBGCC2_TF_CEXT q
 #define TF_SIZE 113
 
-#undef NEED_INDICATE_EXEC_STACK
-#define NEED_INDICATE_EXEC_STACK 1
+#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
 #define MD_UNWIND_SUPPORT "config/i386/linux-unwind.h"
 
--- gcc/config/i386/i386-protos.h.jj	2009-12-07 23:32:53.000000000 +0100
+++ gcc/config/i386/i386-protos.h	2010-03-24 13:34:08.000000000 +0100
@@ -27,7 +27,6 @@ extern void ix86_conditional_register_us
 extern int ix86_can_use_return_insn_p (void);
 extern void ix86_setup_frame_addresses (void);
 
-extern void ix86_file_end (void);
 extern HOST_WIDE_INT ix86_initial_elimination_offset (int, int);
 extern void ix86_expand_prologue (void);
 extern void ix86_expand_epilogue (int);


	Jakub



More information about the Gcc-patches mailing list