diff mbox series

[CFI,Darwin] A hook to allow target-handling of Personality and LSDA indirections.

Message ID E28BC21C-1EA2-49A5-B55E-A0C22BA3A215@sandoe.co.uk
State New
Headers show
Series [CFI,Darwin] A hook to allow target-handling of Personality and LSDA indirections. | expand

Commit Message

Iain Sandoe Sept. 16, 2019, 1:30 a.m. UTC
If an assembler is used that supports .cfi_xxx, then (usually) GCC's configuration will detect this and try to use it to generate frame insns.

This will not work for Darwin since the default implementation for the personality and LSDA indirection is not correct for Mach-O ABI. 

As of now we are currently “lucky” in that the Darwin implementation of objdump (based on LLVM) does not recognise “-Wf” (and also has slightly different whitespace output) which means that even tho most of the modern assemblers for Darwin *do* consume .cfi_xxxx instructions, the GCC configure is not detecting this and we are falling back to the old direct DWARF output for CFA/FDEs.

There is no point in fixing the configure, until the codegen will produce useful output.

So, this patch introduces a target hook to allow target-specific processing of personality and LSDA indirections (if the hook is not populated, the default implementation is used).

Once this fixed is applied it is possible to make progress towards modernising the Darwin handling of the frame insns (and, hopefully, with the newer dsymutil implementations to progress towards consuming DWARF4, at least).

OK for trunk?
thanks
Iain

gcc/ChangeLog:

2019-09-16  Iain Sandoe  <iain@sandoe.co.uk>

	* config/darwin-protos.h (darwin_make_eh_symbol_indirect): New.
	* config/darwin.c (darwin_make_eh_symbol_indirect): New.
	* config/darwin.h (TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT): New hook.
	* doc/tm.texi: Regenerated.
	* doc/tm.texi.in: Declare new hook.
	* dwarf2out.c (dwarf2out_do_cfi_startproc): Allow for target hook to alter the code gen
	for personality and LSDA indirections.
	* target.def: Describe new hook.

Comments

Iain Sandoe Oct. 12, 2019, 9:27 p.m. UTC | #1
I hadn’t realised it had been so long since I posted this:

ping.

Iain Sandoe <iain@sandoe.co.uk> wrote:

> If an assembler is used that supports .cfi_xxx, then (usually) GCC's configuration will detect this and try to use it to generate frame insns.
> 
> This will not work for Darwin since the default implementation for the personality and LSDA indirection is not correct for Mach-O ABI. 
> 
> As of now we are currently “lucky” in that the Darwin implementation of objdump (based on LLVM) does not recognise “-Wf” (and also has slightly different whitespace output) which means that even tho most of the modern assemblers for Darwin *do* consume .cfi_xxxx instructions, the GCC configure is not detecting this and we are falling back to the old direct DWARF output for CFA/FDEs.
> 
> There is no point in fixing the configure, until the codegen will produce useful output.
> 
> So, this patch introduces a target hook to allow target-specific processing of personality and LSDA indirections (if the hook is not populated, the default implementation is used).
> 
> Once this fixed is applied it is possible to make progress towards modernising the Darwin handling of the frame insns (and, hopefully, with the newer dsymutil implementations to progress towards consuming DWARF4, at least).
> 
> OK for trunk?
> thanks
> Iain
> 
> gcc/ChangeLog:
> 
> 2019-09-16  Iain Sandoe  <iain@sandoe.co.uk>
> 
> 	* config/darwin-protos.h (darwin_make_eh_symbol_indirect): New.
> 	* config/darwin.c (darwin_make_eh_symbol_indirect): New.
> 	* config/darwin.h (TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT): New hook.
> 	* doc/tm.texi: Regenerated.
> 	* doc/tm.texi.in: Declare new hook.
> 	* dwarf2out.c (dwarf2out_do_cfi_startproc): Allow for target hook to alter the code gen
> 	for personality and LSDA indirections.
> 	* target.def: Describe new hook.
> 
> 
> diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h
> index e5614b627d..bb3fe19e0d 100644
> --- a/gcc/config/darwin-protos.h
> +++ b/gcc/config/darwin-protos.h
> @@ -68,6 +68,7 @@ extern void darwin_non_lazy_pcrel (FILE *, rtx);
> 
> extern void darwin_emit_unwind_label (FILE *, tree, int, int);
> extern void darwin_emit_except_table_label (FILE *);
> +extern rtx darwin_make_eh_symbol_indirect (rtx, bool);
> 
> extern void darwin_pragma_ignore (struct cpp_reader *);
> extern void darwin_pragma_options (struct cpp_reader *);
> diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
> index e62a5c6595..7ef73cc58b 100644
> --- a/gcc/config/darwin.c
> +++ b/gcc/config/darwin.c
> @@ -2157,6 +2157,18 @@ darwin_emit_except_table_label (FILE *file)
> 			       except_table_label_num++);
>   ASM_OUTPUT_LABEL (file, section_start_label);
> }
> +
> +rtx
> +darwin_make_eh_symbol_indirect (rtx orig, bool ARG_UNUSED (pubvis))
> +{
> +  if (DARWIN_PPC == 0 && TARGET_64BIT)
> +    return orig;
> +
> +  return gen_rtx_SYMBOL_REF (Pmode,
> +			     machopic_indirection_name (orig,
> +							/*stub_p=*/false));
> +}
> +
> /* Generate a PC-relative reference to a Mach-O non-lazy-symbol.  */
> 
> void
> diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
> index fde191d5c4..06e6f0c3da 100644
> --- a/gcc/config/darwin.h
> +++ b/gcc/config/darwin.h
> @@ -593,6 +593,9 @@ extern GTY(()) int darwin_ms_struct;
> /* Emit a label to separate the exception table.  */
> #define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
> 
> +/* Make an EH (personality or LDSA) symbol indirect as needed.  */
> +#define TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT darwin_make_eh_symbol_indirect
> +
> /* Our profiling scheme doesn't LP labels and counter words.  */
> 
> #define NO_PROFILE_COUNTERS	1
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index 0b5a08d490..635faa22dc 100644
> diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
> index a9200551ed..c6d457cb5e 100644
> --- a/gcc/doc/tm.texi.in
> +++ b/gcc/doc/tm.texi.in
> @@ -6445,6 +6445,8 @@ the jump-table.
> 
> @hook TARGET_ASM_UNWIND_EMIT
> 
> +@hook TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT
> +
> @hook TARGET_ASM_UNWIND_EMIT_BEFORE_INSN
> 
> @node Exception Region Output
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index aa7fd7eb46..b6d25c109a 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -988,7 +988,12 @@ dwarf2out_do_cfi_startproc (bool second)
> 	 in the assembler.  Further, the assembler can't handle any
> 	 of the weirder relocation types.  */
>       if (enc & DW_EH_PE_indirect)
> -	ref = dw2_force_const_mem (ref, true);
> +	{
> +	  if (targetm.asm_out.make_eh_symbol_indirect != NULL)
> +	    ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
> +	  else
> +	    ref = dw2_force_const_mem (ref, true);
> +	}
> 
>       fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
>       output_addr_const (asm_out_file, ref);
> @@ -1006,7 +1011,12 @@ dwarf2out_do_cfi_startproc (bool second)
>       SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
> 
>       if (enc & DW_EH_PE_indirect)
> -	ref = dw2_force_const_mem (ref, true);
> +	{
> +	  if (targetm.asm_out.make_eh_symbol_indirect != NULL)
> +	    ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
> +	  else
> +	    ref = dw2_force_const_mem (ref, true);
> +	}
> 
>       fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
>       output_addr_const (asm_out_file, ref);
> diff --git a/gcc/target.def b/gcc/target.def
> index ca7e7ad96b..7fdf5a8845 100644
> --- a/gcc/target.def
> +++ b/gcc/target.def
> @@ -185,6 +185,16 @@ DEFHOOK
>  void, (rtx personality),
>  NULL)
> 
> +/* If necessary, modify personality and LSDA references to handle
> +   indirection.  This is used when the assembler supports CFI directives.  */
> +DEFHOOK
> +(make_eh_symbol_indirect,
> + "If necessary, modify personality and LSDA references to handle indirection.\
> +  The original symbol is in @code{origsymbol} and if @code{pubvis} is true\
> +  the symbol is visible outside the TU.",
> + rtx, (rtx origsymbol, bool pubvis),
> + NULL)
> +
> /* Emit any directives required to unwind this instruction.  */
> DEFHOOK
> (unwind_emit,
> -- 
> 2.17.1
diff mbox series

Patch

diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h
index e5614b627d..bb3fe19e0d 100644
--- a/gcc/config/darwin-protos.h
+++ b/gcc/config/darwin-protos.h
@@ -68,6 +68,7 @@  extern void darwin_non_lazy_pcrel (FILE *, rtx);
 
 extern void darwin_emit_unwind_label (FILE *, tree, int, int);
 extern void darwin_emit_except_table_label (FILE *);
+extern rtx darwin_make_eh_symbol_indirect (rtx, bool);
 
 extern void darwin_pragma_ignore (struct cpp_reader *);
 extern void darwin_pragma_options (struct cpp_reader *);
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index e62a5c6595..7ef73cc58b 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -2157,6 +2157,18 @@  darwin_emit_except_table_label (FILE *file)
 			       except_table_label_num++);
   ASM_OUTPUT_LABEL (file, section_start_label);
 }
+
+rtx
+darwin_make_eh_symbol_indirect (rtx orig, bool ARG_UNUSED (pubvis))
+{
+  if (DARWIN_PPC == 0 && TARGET_64BIT)
+    return orig;
+
+  return gen_rtx_SYMBOL_REF (Pmode,
+			     machopic_indirection_name (orig,
+							/*stub_p=*/false));
+}
+
 /* Generate a PC-relative reference to a Mach-O non-lazy-symbol.  */
 
 void
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index fde191d5c4..06e6f0c3da 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -593,6 +593,9 @@  extern GTY(()) int darwin_ms_struct;
 /* Emit a label to separate the exception table.  */
 #define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
 
+/* Make an EH (personality or LDSA) symbol indirect as needed.  */
+#define TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT darwin_make_eh_symbol_indirect
+
 /* Our profiling scheme doesn't LP labels and counter words.  */
 
 #define NO_PROFILE_COUNTERS	1
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 0b5a08d490..635faa22dc 100644
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index a9200551ed..c6d457cb5e 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -6445,6 +6445,8 @@  the jump-table.
 
 @hook TARGET_ASM_UNWIND_EMIT
 
+@hook TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT
+
 @hook TARGET_ASM_UNWIND_EMIT_BEFORE_INSN
 
 @node Exception Region Output
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index aa7fd7eb46..b6d25c109a 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -988,7 +988,12 @@  dwarf2out_do_cfi_startproc (bool second)
 	 in the assembler.  Further, the assembler can't handle any
 	 of the weirder relocation types.  */
       if (enc & DW_EH_PE_indirect)
-	ref = dw2_force_const_mem (ref, true);
+	{
+	  if (targetm.asm_out.make_eh_symbol_indirect != NULL)
+	    ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
+	  else
+	    ref = dw2_force_const_mem (ref, true);
+	}
 
       fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
       output_addr_const (asm_out_file, ref);
@@ -1006,7 +1011,12 @@  dwarf2out_do_cfi_startproc (bool second)
       SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
 
       if (enc & DW_EH_PE_indirect)
-	ref = dw2_force_const_mem (ref, true);
+	{
+	  if (targetm.asm_out.make_eh_symbol_indirect != NULL)
+	    ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
+	  else
+	    ref = dw2_force_const_mem (ref, true);
+	}
 
       fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
       output_addr_const (asm_out_file, ref);
diff --git a/gcc/target.def b/gcc/target.def
index ca7e7ad96b..7fdf5a8845 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -185,6 +185,16 @@  DEFHOOK
  void, (rtx personality),
  NULL)
 
+/* If necessary, modify personality and LSDA references to handle
+   indirection.  This is used when the assembler supports CFI directives.  */
+DEFHOOK
+(make_eh_symbol_indirect,
+ "If necessary, modify personality and LSDA references to handle indirection.\
+  The original symbol is in @code{origsymbol} and if @code{pubvis} is true\
+  the symbol is visible outside the TU.",
+ rtx, (rtx origsymbol, bool pubvis),
+ NULL)
+
 /* Emit any directives required to unwind this instruction.  */
 DEFHOOK
 (unwind_emit,