diff mbox series

CFI-handling : Add a hook to allow target-specific Personality and LSDA indirections.

Message ID 61C11AEA-56F4-4BEB-9084-B7117F9C5C42@sandoe.co.uk
State New
Headers show
Series CFI-handling : Add a hook to allow target-specific Personality and LSDA indirections. | expand

Commit Message

Iain Sandoe Nov. 7, 2020, 3:41 p.m. UTC
Hi

** Actually, this was originally posted during last stage-1, but I forgot to keep
   pinging it…

====

At present, the output of .cfi_personality and .cfi_lsda assumes
ELF semantics for indirections.  This isn't suitable for all targets
and is one blocker to moving Darwin to use .cfi_xxxx.

The patch adds a target hook that allows non-ELF targets to use
indirections appropriate to their needs.

tested across the Darwin range and on x86_64-linux-gnu,
OK for master?
thanks
Iain

--

gcc/ChangeLog:

	* config/darwin-protos.h (darwin_make_eh_symbol_indirect): New.
	* config/darwin.c (darwin_make_eh_symbol_indirect): New. Use
	Mach-O semantics for personality and ldsa indirections.
	* config/darwin.h (TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT): New.
	* doc/tm.texi: Regenerate.
	* doc/tm.texi.in: Add TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT hook.
	* dwarf2out.c (dwarf2out_do_cfi_startproc): If the target defines
	a hook for indirecting personality and ldsa references, use that
	otherwise default to ELF semantics.
	* target.def (make_eh_symbol_indirect): New target hook.
---
 gcc/config/darwin-protos.h |  1 +
 gcc/config/darwin.c        | 11 +++++++++++
 gcc/config/darwin.h        |  3 +++
 gcc/doc/tm.texi            |  4 ++++
 gcc/doc/tm.texi.in         |  2 ++
 gcc/dwarf2out.c            | 14 ++++++++++++--
 gcc/target.def             | 10 ++++++++++
 7 files changed, 43 insertions(+), 2 deletions(-)

Comments

Jeff Law Nov. 11, 2020, 4:17 a.m. UTC | #1
On 11/7/20 8:41 AM, Iain Sandoe wrote:
> Hi
>
> ** Actually, this was originally posted during last stage-1, but I forgot to keep
>    pinging it…
>
> ====
>
> At present, the output of .cfi_personality and .cfi_lsda assumes
> ELF semantics for indirections.  This isn't suitable for all targets
> and is one blocker to moving Darwin to use .cfi_xxxx.
>
> The patch adds a target hook that allows non-ELF targets to use
> indirections appropriate to their needs.
>
> tested across the Darwin range and on x86_64-linux-gnu,
> OK for master?
> thanks
> Iain
>
> --
>
> gcc/ChangeLog:
>
> 	* config/darwin-protos.h (darwin_make_eh_symbol_indirect): New.
> 	* config/darwin.c (darwin_make_eh_symbol_indirect): New. Use
> 	Mach-O semantics for personality and ldsa indirections.
> 	* config/darwin.h (TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT): New.
> 	* doc/tm.texi: Regenerate.
> 	* doc/tm.texi.in: Add TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT hook.
> 	* dwarf2out.c (dwarf2out_do_cfi_startproc): If the target defines
> 	a hook for indirecting personality and ldsa references, use that
> 	otherwise default to ELF semantics.
> 	* target.def (make_eh_symbol_indirect): New target hook.

OK

jeff
diff mbox series

Patch

diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h
index 49c540fe08e..3f222c3bbdc 100644
--- a/gcc/config/darwin-protos.h
+++ b/gcc/config/darwin-protos.h
@@ -69,6 +69,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 dd4857f9e34..3265e3e6cb7 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -2225,6 +2225,17 @@  darwin_emit_except_table_label (FILE *file)
   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));
+}
+
 /* Return, and mark as used, the name of the stub for the mcount function.
    Currently, this is only called by X86 code in the expansion of the
    FUNCTION_PROFILER macro, when stubs are enabled.  */
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index f9d4fec30a0..5a766319cb0 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -591,6 +591,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 833320ba7bf..a783a21f6cf 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -9560,6 +9560,10 @@  given instruction.  This is only used when @code{TARGET_EXCEPT_UNWIND_INFO}
 returns @code{UI_TARGET}.
 @end deftypefn
 
+@deftypefn {Target Hook} rtx TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT (rtx @var{origsymbol}, bool @var{pubvis})
+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.
+@end deftypefn
+
 @deftypevr {Target Hook} bool TARGET_ASM_UNWIND_EMIT_BEFORE_INSN
 True if the @code{TARGET_ASM_UNWIND_EMIT} hook should be called before the assembly for @var{insn} has been emitted, false if the hook should be called afterward.
 @end deftypevr
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 58109be3693..897f2896266 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -6456,6 +6456,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 bc32a17efcd..bea02f9fbce 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -991,7 +991,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);
@@ -1009,7 +1014,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 b916635be18..71411d85559 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,