This patch renames functions related to SEH functionality. These
functions will be reused in the aarch64-w64-mingw32 target.

Signed-off-by: Evgeny Karpov <[email protected]>

gcc/ChangeLog:

        * config/i386/cygming.h (TARGET_ASM_FUNCTION_END_PROLOGUE):
        Rename.
        (TARGET_ASM_EMIT_EXCEPT_PERSONALITY): Likewise.
        (TARGET_ASM_INIT_SECTIONS): Likewise.
        (SUBTARGET_ASM_UNWIND_INIT): Likewise.
        (ASM_DECLARE_FUNCTION_SIZE): Likewise.
        (ASM_DECLARE_COLD_FUNCTION_SIZE): Likewise.
        * config/i386/i386-protos.h (i386_pe_end_function):
        Remove declarations.
        (i386_pe_end_cold_function): Likewise.
        (i386_pe_seh_init): Likewise.
        (i386_pe_seh_end_prologue): Likewise.
        (i386_pe_seh_cold_init): Likewise.
        (i386_pe_seh_emit_except_personality): Likewise.
        (i386_pe_seh_init_sections): Likewise.
        * config/mingw/winnt.cc (defined): Update.
        (struct seh_frame_state): Move to mingw/winnt.h.
        (i386_pe_seh_init): Rename into ...
        (mingw_pe_seh_init): ... this.
        (i386_pe_seh_end_prologue): Rename into ...
        (mingw_pe_seh_end_prologue): ... this.
        (i386_pe_seh_cold_init): Rename into ...
        (mingw_pe_seh_cold_init): ... this.
        (i386_pe_seh_fini): Rename into ...
        (mingw_pe_seh_fini): ... this.
        (seh_emit_stackalloc): Rename into ...
        (mingw_pe_seh_emit_stackalloc): ... this.
        (seh_cfa_adjust_cfa): Update.
        (seh_frame_related_expr): Update.
        (i386_pe_seh_emit_except_personality): Rename into ...
        (mingw_pe_seh_emit_except_personality): ... this.
        (i386_pe_seh_init_sections): Rename into ...
        (mingw_pe_seh_init_sections): ... this.
        (i386_pe_end_function): Rename into ...
        (mingw_pe_end_function): ... this.
        (i386_pe_end_cold_function): Rename into ...
        (mingw_pe_end_cold_function): ... this.
        * config/mingw/winnt.h (struct seh_frame_state):
        Move from mingw/winnt.cc.
        (mingw_pe_end_cold_function): Add declarations.
        (mingw_pe_end_function): Likewise.
        (mingw_pe_seh_init): Likewise.
        (mingw_pe_seh_init_sections): Likewise.
        (mingw_pe_seh_cold_init): Likewise.
        (mingw_pe_seh_emit_except_personality): Likewise.
        (mingw_pe_seh_end_prologue): Likewise.
---
 gcc/config/i386/cygming.h     | 14 +++----
 gcc/config/i386/i386-protos.h |  7 ----
 gcc/config/mingw/winnt.cc     | 69 +++++++++--------------------------
 gcc/config/mingw/winnt.h      | 44 ++++++++++++++++++++++
 4 files changed, 68 insertions(+), 66 deletions(-)

diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index c32f228044e..59ee1c4c69d 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -47,12 +47,12 @@ along with GCC; see the file COPYING3.  If not see
 #undef  TARGET_ASM_UNWIND_EMIT_BEFORE_INSN
 #define TARGET_ASM_UNWIND_EMIT_BEFORE_INSN  false
 #undef  TARGET_ASM_FUNCTION_END_PROLOGUE
-#define TARGET_ASM_FUNCTION_END_PROLOGUE  i386_pe_seh_end_prologue
+#define TARGET_ASM_FUNCTION_END_PROLOGUE  mingw_pe_seh_end_prologue
 #undef  TARGET_ASM_EMIT_EXCEPT_PERSONALITY
-#define TARGET_ASM_EMIT_EXCEPT_PERSONALITY i386_pe_seh_emit_except_personality
+#define TARGET_ASM_EMIT_EXCEPT_PERSONALITY mingw_pe_seh_emit_except_personality
 #undef  TARGET_ASM_INIT_SECTIONS
-#define TARGET_ASM_INIT_SECTIONS  i386_pe_seh_init_sections
-#define SUBTARGET_ASM_UNWIND_INIT  i386_pe_seh_init
+#define TARGET_ASM_INIT_SECTIONS  mingw_pe_seh_init_sections
+#define SUBTARGET_ASM_UNWIND_INIT  mingw_pe_seh_init
 
 #undef DEFAULT_ABI
 #define DEFAULT_ABI (TARGET_64BIT ? MS_ABI : SYSV_ABI)
@@ -314,18 +314,18 @@ do {                                              \
   do                                                           \
     {                                                          \
       mingw_pe_declare_type (FILE, NAME, 0, 1);                \
-      i386_pe_seh_cold_init (FILE, NAME);                      \
+      mingw_pe_seh_cold_init (FILE, NAME);                     \
       ASM_OUTPUT_LABEL (FILE, NAME);                           \
     }                                                          \
   while (0)
 
 #undef ASM_DECLARE_FUNCTION_SIZE
 #define ASM_DECLARE_FUNCTION_SIZE(FILE,NAME,DECL) \
-  i386_pe_end_function (FILE, NAME, DECL)
+  mingw_pe_end_function (FILE, NAME, DECL)
 
 #undef ASM_DECLARE_COLD_FUNCTION_SIZE
 #define ASM_DECLARE_COLD_FUNCTION_SIZE(FILE,NAME,DECL) \
-  i386_pe_end_cold_function (FILE, NAME, DECL)
+  mingw_pe_end_cold_function (FILE, NAME, DECL)
 
 /* Add an external function to the list of functions to be declared at
    the end of the file.  */
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 15d71debbf5..fc45aaf23aa 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -329,18 +329,11 @@ extern void i386_pe_asm_output_aligned_decl_common (FILE 
*, tree,
                                                    HOST_WIDE_INT,
                                                    HOST_WIDE_INT);
 extern void i386_pe_start_function (FILE *, const char *, tree);
-extern void i386_pe_end_function (FILE *, const char *, tree);
-extern void i386_pe_end_cold_function (FILE *, const char *, tree);
 extern void i386_pe_assemble_visibility (tree, int);
 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 *);
-extern void i386_pe_seh_cold_init (FILE *, const char *);
 extern void i386_pe_seh_unwind_emit (FILE *, rtx_insn *);
-extern void i386_pe_seh_emit_except_personality (rtx);
-extern void i386_pe_seh_init_sections (void);
 
 /* In winnt-cxx.cc and winnt-stubs.cc  */
 extern void i386_pe_adjust_class_at_definition (tree);
diff --git a/gcc/config/mingw/winnt.cc b/gcc/config/mingw/winnt.cc
index c73aa15ad37..66d7450652d 100644
--- a/gcc/config/mingw/winnt.cc
+++ b/gcc/config/mingw/winnt.cc
@@ -169,6 +169,8 @@ mingw_pe_valid_dllimport_attribute_p (const_tree decl)
    return true;
 }
 
+#if !defined (TARGET_AARCH64_MS_ABI)
+
 /* Return string which is the function name, identified by ID, modified
    with a suffix consisting of an atsign (@) followed by the number of
    bytes of arguments.  If ID is NULL use the DECL_NAME as base. If
@@ -224,8 +226,6 @@ gen_stdcall_or_fastcall_suffix (tree decl, tree id, bool 
fastcall)
   return get_identifier (new_str);
 }
 
-#if !defined (TARGET_AARCH64_MS_ABI)
-
 /* Maybe decorate and get a new identifier for the DECL of a stdcall or
    fastcall function. The original identifier is supplied in ID. */
 
@@ -884,45 +884,10 @@ mingw_pe_asm_lto_end (void)
   debug_info_level = saved_debug_info_level;
 }
 
-
-/* x64 Structured Exception Handling unwind info.  */
-
-struct seh_frame_state
-{
-  /* SEH records offsets relative to the lowest address of the fixed stack
-     allocation.  If there is no frame pointer, these offsets are from the
-     stack pointer; if there is a frame pointer, these offsets are from the
-     value of the stack pointer when the frame pointer was established, i.e.
-     the frame pointer minus the offset in the .seh_setframe directive.
-
-     We do not distinguish these two cases, i.e. we consider that the offsets
-     are always relative to the "current" stack pointer.  This means that we
-     need to perform the fixed stack allocation before establishing the frame
-     pointer whenever there are registers to be saved, and this is guaranteed
-     by the prologue provided that we force the frame pointer to point at or
-     below the lowest used register save area, see ix86_compute_frame_layout.
-
-     This tracks the current stack pointer offset from the CFA.  */
-  HOST_WIDE_INT sp_offset;
-
-  /* The CFA is located at CFA_REG + CFA_OFFSET.  */
-  HOST_WIDE_INT cfa_offset;
-  rtx cfa_reg;
-
-  /* The offset wrt the CFA where register N has been saved.  */
-  HOST_WIDE_INT reg_offset[FIRST_PSEUDO_REGISTER];
-
-  /* True if we are past the end of the epilogue.  */
-  bool after_prologue;
-
-  /* True if we are in the cold section.  */
-  bool in_cold_section;
-};
-
 /* Set up data structures beginning output for SEH.  */
 
 void
-i386_pe_seh_init (FILE *f)
+mingw_pe_seh_init (FILE *f)
 {
   struct seh_frame_state *seh;
 
@@ -950,7 +915,7 @@ i386_pe_seh_init (FILE *f)
 /* Emit an assembler directive for the end of the prologue.  */
 
 void
-i386_pe_seh_end_prologue (FILE *f)
+mingw_pe_seh_end_prologue (FILE *f)
 {
   if (!TARGET_SEH)
     return;
@@ -963,7 +928,7 @@ i386_pe_seh_end_prologue (FILE *f)
 /* Emit assembler directives to reconstruct the SEH state.  */
 
 void
-i386_pe_seh_cold_init (FILE *f, const char *name)
+mingw_pe_seh_cold_init (FILE *f, const char *name)
 {
   struct seh_frame_state *seh;
   HOST_WIDE_INT alloc_offset, offset;
@@ -1046,7 +1011,7 @@ i386_pe_seh_cold_init (FILE *f, const char *name)
 /* Emit an assembler directive for the end of the function.  */
 
 static void
-i386_pe_seh_fini (FILE *f, bool cold)
+mingw_pe_seh_fini (FILE *f, bool cold)
 {
   struct seh_frame_state *seh;
 
@@ -1106,8 +1071,8 @@ seh_emit_save (FILE *f, struct seh_frame_state *seh,
 
 /* Emit an assembler directive to adjust RSP by OFFSET.  */
 
-static void
-seh_emit_stackalloc (FILE *f, struct seh_frame_state *seh,
+void
+mingw_pe_seh_emit_stackalloc (FILE *f, struct seh_frame_state *seh,
                     HOST_WIDE_INT offset)
 {
   /* We're only concerned with prologue stack allocations, which all
@@ -1152,7 +1117,7 @@ seh_cfa_adjust_cfa (FILE *f, struct seh_frame_state *seh, 
rtx pat)
   dest_regno = REGNO (dest);
 
   if (dest_regno == STACK_POINTER_REGNUM)
-    seh_emit_stackalloc (f, seh, reg_offset);
+    mingw_pe_seh_emit_stackalloc (f, seh, reg_offset);
   else if (dest_regno == HARD_FRAME_POINTER_REGNUM)
     {
       HOST_WIDE_INT offset;
@@ -1258,7 +1223,7 @@ seh_frame_related_expr (FILE *f, struct seh_frame_state 
*seh, rtx pat)
          else if (dest == stack_pointer_rtx)
            {
              gcc_assert (src == stack_pointer_rtx);
-             seh_emit_stackalloc (f, seh, addend);
+             mingw_pe_seh_emit_stackalloc (f, seh, addend);
            }
          else
            gcc_unreachable ();
@@ -1370,7 +1335,7 @@ i386_pe_seh_unwind_emit (FILE *out_file, rtx_insn *insn)
 }
 
 void
-i386_pe_seh_emit_except_personality (rtx personality)
+mingw_pe_seh_emit_except_personality (rtx personality)
 {
   int flags = 0;
 
@@ -1404,7 +1369,7 @@ i386_pe_seh_emit_except_personality (rtx personality)
 }
 
 void
-i386_pe_seh_init_sections (void)
+mingw_pe_seh_init_sections (void)
 {
   if (TARGET_SEH)
     exception_section = get_unnamed_section (0, output_section_asm_op,
@@ -1423,15 +1388,15 @@ i386_pe_start_function (FILE *f, const char *name, tree 
decl)
 }
 
 void
-i386_pe_end_function (FILE *f, const char *, tree)
+mingw_pe_end_function (FILE *f, const char *, tree)
 {
-  i386_pe_seh_fini (f, false);
+  mingw_pe_seh_fini (f, false);
 }
-
+
 void
-i386_pe_end_cold_function (FILE *f, const char *, tree)
+mingw_pe_end_cold_function (FILE *f, const char *, tree)
 {
-  i386_pe_seh_fini (f, true);
+  mingw_pe_seh_fini (f, true);
 }
 
 #include "gt-winnt.h"
diff --git a/gcc/config/mingw/winnt.h b/gcc/config/mingw/winnt.h
index 68bdbff7f8b..cc7490939d5 100644
--- a/gcc/config/mingw/winnt.h
+++ b/gcc/config/mingw/winnt.h
@@ -20,6 +20,40 @@ http://www.gnu.org/licenses/.  */
 
 #ifndef USED_FOR_TARGET
 
+/* Structured Exception Handling unwind info.  */
+
+struct seh_frame_state
+{
+  /* SEH records offsets relative to the lowest address of the fixed stack
+     allocation.  If there is no frame pointer, these offsets are from the
+     stack pointer; if there is a frame pointer, these offsets are from the
+     value of the stack pointer when the frame pointer was established, i.e.
+     the frame pointer minus the offset in the .seh_setframe directive.
+
+     We do not distinguish these two cases, i.e. we consider that the offsets
+     are always relative to the "current" stack pointer.  This means that we
+     need to perform the fixed stack allocation before establishing the frame
+     pointer whenever there are registers to be saved, and this is guaranteed
+     by the prologue provided that we force the frame pointer to point at or
+     below the lowest used register save area, see ix86_compute_frame_layout.
+
+     This tracks the current stack pointer offset from the CFA.  */
+  HOST_WIDE_INT sp_offset;
+
+  /* The CFA is located at CFA_REG + CFA_OFFSET.  */
+  HOST_WIDE_INT cfa_offset;
+  rtx cfa_reg;
+
+  /* The offset wrt the CFA where register N has been saved.  */
+  HOST_WIDE_INT reg_offset[FIRST_PSEUDO_REGISTER];
+
+  /* True if we are past the end of the epilogue.  */
+  bool after_prologue;
+
+  /* True if we are in the cold section.  */
+  bool in_cold_section;
+};
+
 extern tree aarch64_handle_ms_abi_attribute (tree *, tree, tree, int, bool *);
 extern tree mingw_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 
@@ -28,6 +62,8 @@ extern void mingw_pe_asm_lto_start (void);
 extern void mingw_pe_asm_lto_end (void);
 extern void mingw_pe_declare_type (FILE *, const char *, bool, bool);
 extern void mingw_pe_encode_section_info (tree, rtx, int);
+extern void mingw_pe_end_cold_function (FILE *, const char *, tree);
+extern void mingw_pe_end_function (FILE *, const char *, tree);
 extern void mingw_pe_file_end (void);
 extern void mingw_pe_maybe_record_exported_symbol (tree, const char *, int);
 extern void mingw_pe_record_stub (const char *, bool);
@@ -36,6 +72,14 @@ extern section *mingw_pe_select_section (tree, int, unsigned 
HOST_WIDE_INT);
 extern void mingw_pe_unique_section (tree, int);
 extern bool mingw_pe_valid_dllimport_attribute_p (const_tree);
 
+extern void mingw_pe_seh_init (FILE *);
+extern void mingw_pe_seh_init_sections (void);
+extern void mingw_pe_seh_cold_init (FILE *, const char *);
+extern void mingw_pe_seh_emit_except_personality (rtx);
+extern void mingw_pe_seh_emit_stackalloc (FILE *, struct seh_frame_state *,
+                                         HOST_WIDE_INT);
+extern void mingw_pe_seh_end_prologue (FILE *);
+
 #endif /* not USED_FOR_TARGET.  */
 
 #endif /* GCC_MINGW_WINNT_H.  */

Reply via email to