Skip to content

Commit 7cbc7e4

Browse files
eukarpovgithub-actions
authored andcommitted
Rebase SEH for aarch64-pe prototype
1 parent 36df869 commit 7cbc7e4

File tree

9 files changed

+730
-21
lines changed

9 files changed

+730
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
.deps
2222
.libs
23+
.vscode
2324

2425
autom4te.cache
2526
config.cache

gcc/common/config/aarch64/aarch64-common.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,32 @@ aarch64_rewrite_mcpu (int argc, const char **argv)
446446
return aarch64_rewrite_selected_cpu (argv[argc - 1]);
447447
}
448448

449+
/* Implement TARGET_EXCEPT_UNWIND_INFO. */
450+
451+
static enum unwind_info_type
452+
aarch64_except_unwind_info (struct gcc_options *opts)
453+
{
454+
/* Honor the --enable-sjlj-exceptions configure switch. */
455+
#ifdef CONFIG_SJLJ_EXCEPTIONS
456+
if (CONFIG_SJLJ_EXCEPTIONS)
457+
return UI_SJLJ;
458+
#endif
459+
460+
/* On windows 64, prefer SEH exceptions over anything else. */
461+
#if defined (TARGET_AARCH64_MS_ABI)
462+
if (opts->x_flag_unwind_tables)
463+
return UI_SEH;
464+
#endif
465+
466+
if (DWARF2_UNWIND_INFO)
467+
return UI_DWARF2;
468+
469+
return UI_SJLJ;
470+
}
471+
472+
#undef TARGET_EXCEPT_UNWIND_INFO
473+
#define TARGET_EXCEPT_UNWIND_INFO aarch64_except_unwind_info
474+
449475
struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
450476

451477
#undef AARCH64_CPU_NAME_LENGTH

gcc/config.gcc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,13 @@ aarch64-*-mingw*)
12881288
target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt-dll.cc"
12891289
extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"
12901290
extra_objs="${extra_objs} winnt.o winnt-dll.o"
1291-
c_target_objs="${c_target_objs} msformat-c.o"
1292-
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
1291+
c_target_objs="${c_target_objs} winnt-c.o msformat-c.o"
1292+
cxx_target_objs="${cxx_target_objs} winnt-c.o winnt-cxx.o msformat-c.o"
12931293
d_target_objs="${d_target_objs} winnt-d.o"
1294-
tmake_file="${tmake_file} mingw/t-cygming"
1295-
aarch64_multilibs="lp64"
1294+
target_has_targetcm="yes"
1295+
target_has_targetdm="yes"
1296+
tmake_file="${tmake_file} t-winnt mingw/t-cygming"
1297+
aarch64_multilibs="llp64"
12961298
case ${enable_threads} in
12971299
"" | yes | win32)
12981300
thread_file='win32'
@@ -1304,7 +1306,7 @@ aarch64-*-mingw*)
13041306
default_use_cxa_atexit=yes
13051307
user_headers_inc_next_post="${user_headers_inc_next_post} float.h"
13061308
tm_defines="${tm_defines} TARGET_AARCH64_MS_ABI=1"
1307-
TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG},lp64"
1309+
TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG},llp64"
13081310
TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
13091311
;;
13101312
aarch64*-wrs-vxworks*)

gcc/config/aarch64/aarch64-coff.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#undef LONG_TYPE_SIZE
3636
#define LONG_TYPE_SIZE 32
3737

38+
#define TARGET_64BIT_MS_ABI 1
39+
#define TARGET_SEH 1
40+
3841
#ifndef ASM_GENERATE_INTERNAL_LABEL
3942
# define ASM_GENERATE_INTERNAL_LABEL(STRING, PREFIX, NUM) \
4043
sprintf (STRING, "*%s%s%u", LOCAL_LABEL_PREFIX, PREFIX, (unsigned int)(NUM))
@@ -99,4 +102,14 @@
99102
#undef DTORS_SECTION_ASM_OP
100103
#define DTORS_SECTION_ASM_OP "\t.section\t.fini_array,\"aw\""
101104

105+
// #undef STACK_CHECK_STATIC_BUILTIN
106+
// #define STACK_CHECK_STATIC_BUILTIN 1
107+
108+
// #undef SUBTARGET_OVERRIDE_OPTIONS
109+
// #define SUBTARGET_OVERRIDE_OPTIONS AARCH64_PE_OVERRIDE_OPTIONS
110+
111+
// #undef AARCH64_PE_OVERRIDE_OPTIONS
112+
// #define AARCH64_PE_OVERRIDE_OPTIONS aarch64_pe_override_options ()
113+
// extern void aarch64_pe_override_options (void);
114+
102115
#endif

gcc/config/aarch64/aarch64.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12724,6 +12724,12 @@ aarch64_label_mentioned_p (rtx x)
1272412724
return 0;
1272512725
}
1272612726

12727+
void
12728+
aarch64_print_reg (rtx x, int code, FILE *file)
12729+
{
12730+
aarch64_print_operand (file, x, code);
12731+
}
12732+
1272712733
/* Implement REGNO_REG_CLASS. */
1272812734

1272912735
enum reg_class
@@ -18383,6 +18389,10 @@ aarch64_override_options_after_change_1 (struct gcc_options *opts)
1838318389
intermediary step for the former. */
1838418390
if (flag_mlow_precision_sqrt)
1838518391
flag_mrecip_low_precision_sqrt = true;
18392+
18393+
/* Enable unwind tables for MS */
18394+
if (TARGET_64BIT_MS_ABI && opts->x_flag_unwind_tables == 0)
18395+
opts->x_flag_unwind_tables = 1;
1838618396
}
1838718397

1838818398
/* 'Unpack' up the internal tuning structs and update the options
@@ -24667,6 +24677,9 @@ aarch64_declare_function_name (FILE *stream, const char* name,
2466724677
/* Don't forget the type directive for ELF. */
2466824678
#ifdef ASM_OUTPUT_TYPE_DIRECTIVE
2466924679
ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function");
24680+
#endif
24681+
#ifdef SUBTARGET_ASM_UNWIND_INIT
24682+
SUBTARGET_ASM_UNWIND_INIT (stream);
2467024683
#endif
2467124684
ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl);
2467224685

gcc/config/aarch64/cygming.h

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ along with GCC; see the file COPYING3. If not see
4040
#define SYMBOL_REF_STUBVAR_P(X) \
4141
((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_STUBVAR) != 0)
4242

43-
/* Disable SEH and declare the required SEH-related macros that are
44-
still needed for compilation. */
45-
#undef TARGET_SEH
46-
#define TARGET_SEH 0
47-
4843
#define SSE_REGNO_P(N) (gcc_unreachable (), 0)
4944
#define GENERAL_REGNO_P(N) (gcc_unreachable (), 0)
50-
#define SEH_MAX_FRAME_SIZE (gcc_unreachable (), 0)
45+
//#define SEH_MAX_FRAME_SIZE (gcc_unreachable (), 0)
5146

5247
#undef TARGET_PECOFF
5348
#define TARGET_PECOFF 1
@@ -57,6 +52,35 @@ still needed for compilation. */
5752
#undef PREFERRED_DEBUGGING_TYPE
5853
#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
5954

55+
56+
/* Support hooks for SEH. */
57+
#undef TARGET_ASM_UNWIND_EMIT
58+
#define TARGET_ASM_UNWIND_EMIT i386_pe_seh_unwind_emit
59+
#undef TARGET_ASM_UNWIND_EMIT_BEFORE_INSN
60+
#define TARGET_ASM_UNWIND_EMIT_BEFORE_INSN false
61+
// #undef TARGET_ASM_FUNCTION_PROLOGUE
62+
// #define TARGET_ASM_FUNCTION_PROLOGUE aarch64_pe_seh_function_prologue
63+
#undef TARGET_ASM_FUNCTION_END_PROLOGUE
64+
#define TARGET_ASM_FUNCTION_END_PROLOGUE i386_pe_seh_end_prologue
65+
#undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
66+
#define TARGET_ASM_EMIT_EXCEPT_PERSONALITY i386_pe_seh_emit_except_personality
67+
#undef TARGET_ASM_INIT_SECTIONS
68+
#define TARGET_ASM_INIT_SECTIONS i386_pe_seh_init_sections
69+
#undef SUBTARGET_ASM_UNWIND_INIT
70+
#define SUBTARGET_ASM_UNWIND_INIT i386_pe_seh_init
71+
// #undef TARGET_ASM_FINAL_POSTSCAN_INSN
72+
// #define TARGET_ASM_FINAL_POSTSCAN_INSN aarch64_pe_seh_asm_final_postscan_insn
73+
74+
#undef TARGET_PECOFF
75+
#define TARGET_PECOFF 1
76+
77+
// #if ! defined (USE_MINGW64_LEADING_UNDERSCORES)
78+
// #undef USER_LABEL_PREFIX
79+
// #define USER_LABEL_PREFIX (TARGET_64BIT ? "" : "_")
80+
81+
// #undef LOCAL_LABEL_PREFIX
82+
// #define LOCAL_LABEL_PREFIX (TARGET_64BIT ? "." : "")
83+
6084
#include <stdbool.h>
6185
#ifdef __MINGW32__
6286
#include <stdio.h>
@@ -70,6 +94,26 @@ still needed for compilation. */
7094
#define TARGET_ASM_UNIQUE_SECTION mingw_pe_unique_section
7195
#define TARGET_ENCODE_SECTION_INFO mingw_pe_encode_section_info
7296

97+
#undef TARGET_SEH
98+
#define TARGET_SEH 1
99+
100+
/* SEH support */
101+
extern void i386_pe_seh_init (FILE *);
102+
extern void i386_pe_seh_end_prologue (FILE *);
103+
// extern void aarch64_pe_seh_function_prologue (FILE *);
104+
// extern void aarch64_pe_seh_cold_init (FILE *, const char *);
105+
extern void i386_pe_seh_unwind_emit (FILE *, rtx_insn *);
106+
extern void i386_pe_seh_emit_except_personality (rtx);
107+
extern void i386_pe_seh_init_sections (void);
108+
// extern void aarch64_pe_seh_asm_final_postscan_insn (FILE *stream, rtx_insn *insn, rtx*, int);
109+
110+
/* In winnt */
111+
// extern void aarch64_print_reg (rtx, int, FILE*);
112+
extern void i386_pe_end_function (FILE *f, const char *, tree);
113+
extern void i386_pe_end_cold_function (FILE *f, const char *, tree);
114+
// extern void aarch64_pe_end_epilogue (FILE *file);
115+
// extern void aarch64_pe_begin_epilogue (FILE *file);
116+
73117
#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P mingw_pe_valid_dllimport_attribute_p
74118

75119
/* Output function declarations at the end of the file. */
@@ -86,6 +130,7 @@ still needed for compilation. */
86130
builtin_define ("__MSVCRT__"); \
87131
builtin_define ("__MINGW32__"); \
88132
builtin_define ("_WIN32"); \
133+
builtin_define ("__SEH__"); \
89134
builtin_define_std ("WIN32"); \
90135
builtin_define_std ("WINNT"); \
91136
builtin_define_with_int_value ("_INTEGRAL_MAX_BITS", \
@@ -217,6 +262,17 @@ still needed for compilation. */
217262
} \
218263
} while(0)
219264

265+
#undef ASM_DECLARE_FUNCTION_SIZE
266+
#define ASM_DECLARE_FUNCTION_SIZE(FILE,NAME,DECL) \
267+
i386_pe_end_function (FILE, NAME, DECL)
268+
269+
#undef ASM_DECLARE_COLD_FUNCTION_SIZE
270+
#define ASM_DECLARE_COLD_FUNCTION_SIZE(FILE,NAME,DECL) \
271+
i386_pe_end_cold_function (FILE, NAME, DECL)
272+
273+
// #undef TARGET_ASM_FUNCTION_BEGIN_EPILOGUE
274+
// #define TARGET_ASM_FUNCTION_BEGIN_EPILOGUE aarch64_pe_begin_epilogue
275+
220276
#define SUBTARGET_ATTRIBUTE_TABLE \
221277
{ "selectany", 0, 0, true, false, false, false, \
222278
mingw_handle_selectany_attribute, NULL }
@@ -231,6 +287,10 @@ still needed for compilation. */
231287

232288
#define HAVE_GAS_ALIGNED_COMM 1
233289

290+
#undef DWARF2_UNWIND_INFO
291+
#define DWARF2_UNWIND_INFO 0
292+
293+
234294
#undef MAX_OFILE_ALIGNMENT
235295
#define MAX_OFILE_ALIGNMENT (8192 * 8)
236296

@@ -241,4 +301,16 @@ still needed for compilation. */
241301

242302
#define HAVE_64BIT_POINTERS 1
243303

304+
/* According to Windows x64 software convention, the maximum stack allocatable
305+
in the prologue is 4G - 8 bytes. Furthermore, there is a limited set of
306+
instructions allowed to adjust the stack pointer in the epilog, forcing the
307+
use of frame pointer for frames larger than 2 GB. This theorical limit
308+
is reduced by 256, an over-estimated upper bound for the stack use by the
309+
prologue.
310+
We define only one threshold for both the prolog and the epilog. When the
311+
frame size is larger than this threshold, we allocate the area to save SSE
312+
regs, then save them, and then allocate the remaining. There is no SEH
313+
unwind info for this later allocation. */
314+
#define SEH_MAX_FRAME_SIZE ((2U << 30) - 256)
315+
244316
#endif

0 commit comments

Comments
 (0)