From 2f8fcf7819ef4a7c8a2332d7548c31c768d80b7b Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 29 Nov 2018 21:31:30 +0000 Subject: [PATCH] + new tf_use_psabieh target flag to indicate a target uses PSABI/Dwarf EH o use this flag to set the personality routine of a function if it uses exception handlinga o also define FPC_USE_PSABIEH if this target flag is set o set this target flag for darwin/x86-64 if the compiler is compiled with -dllvm git-svn-id: branches/debug_eh@40415 - --- compiler/llvm/llvmpi.pas | 10 ---------- compiler/options.pas | 6 ++++++ compiler/procinfo.pas | 8 ++++++++ compiler/psub.pas | 13 +++++++++++++ compiler/systems.pas | 4 +++- compiler/systems/i_bsd.pas | 3 ++- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/compiler/llvm/llvmpi.pas b/compiler/llvm/llvmpi.pas index 6bbc723ce7..e214de9e19 100644 --- a/compiler/llvm/llvmpi.pas +++ b/compiler/llvm/llvmpi.pas @@ -38,7 +38,6 @@ interface public constructor create(aparent: tprocinfo); override; destructor destroy; override; - procedure set_first_temp_offset; override; procedure pushexceptlabel(lab: TAsmLabel); procedure popexceptlabel(lab: TAsmLabel); function CurrExceptLabel: TAsmLabel; inline; @@ -66,15 +65,6 @@ implementation end; - procedure tllvmprocinfo.set_first_temp_offset; - begin - inherited; - if not(target_info.system in systems_windows) and - (([pi_uses_exceptions,pi_needs_implicit_finally]*flags)<>[]) then - procdef.personality:=search_system_proc('_FPC_EXCEPTION_PERSONALITY_DO_NOTHING_V0'); - end; - - procedure tllvmprocinfo.pushexceptlabel(lab: TAsmLabel); begin fexceptlabelstack.add(lab); diff --git a/compiler/options.pas b/compiler/options.pas index 366e9f1301..e6a1e68590 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -3157,6 +3157,12 @@ begin else undef_system_macro('FPC_SECTION_THREADVARS'); + if (tf_use_psabieh in target_info.flags) then + if def then + def_system_macro('FPC_USE_PSABIEH') + else + undef_system_macro('FPC_USE_PSABIEH'); + { Code generation flags } if (tf_pic_default in target_info.flags) then if def then diff --git a/compiler/procinfo.pas b/compiler/procinfo.pas index 7e2fe97f25..d09d269c46 100644 --- a/compiler/procinfo.pas +++ b/compiler/procinfo.pas @@ -178,6 +178,9 @@ unit procinfo; procedure updatestackalignment(alignment: longint); { Specific actions after the code has been generated } procedure postprocess_code; virtual; + + { set exception handling info } + procedure set_eh_info; virtual; end; tcprocinfo = class of tprocinfo; @@ -312,4 +315,9 @@ implementation { no action by default } end; + procedure tprocinfo.set_eh_info; + begin + { default code is in tcgprocinfo } + end; + end. diff --git a/compiler/psub.pas b/compiler/psub.pas index 090003ab04..ddcce14d32 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -65,6 +65,7 @@ interface procedure parse_body; function has_assembler_child : boolean; + procedure set_eh_info; override; end; @@ -1126,6 +1127,16 @@ implementation end; end; + procedure tcgprocinfo.set_eh_info; + begin + inherited; + if (tf_use_psabieh in target_info.flags) and + ((pi_uses_exceptions in flags) or + ((cs_implicit_exceptions in current_settings.moduleswitches) and + (pi_needs_implicit_finally in flags))) then + procdef.personality:=search_system_proc('_FPC_PSABIEH_PERSONALITY_V0'); + end; + procedure tcgprocinfo.generate_code_tree; var hpi : tcgprocinfo; @@ -1749,6 +1760,8 @@ implementation not(target_info.system in systems_garbage_collected_managed_types) then internalerror(200405231); + current_procinfo.set_eh_info; + { Position markers are only used to insert additional code after the secondpass and before this point. They are of no use in optimizer. Instead of checking and ignoring all over the optimizer, just remove them here. } diff --git a/compiler/systems.pas b/compiler/systems.pas index 19c004feb5..1a413c5b7d 100644 --- a/compiler/systems.pas +++ b/compiler/systems.pas @@ -165,7 +165,9 @@ interface tf_x86_far_procs_push_odd_bp, { indicates that this target can use dynamic packages otherwise an error will be generated if a package file is compiled } - tf_supports_packages + tf_supports_packages, + { use PSABI/Dwarf-based "zero cost" exception handling } + tf_use_psabieh ); psysteminfo = ^tsysteminfo; diff --git a/compiler/systems/i_bsd.pas b/compiler/systems/i_bsd.pas index d14bf7fd2f..8882a62748 100644 --- a/compiler/systems/i_bsd.pas +++ b/compiler/systems/i_bsd.pas @@ -1015,7 +1015,8 @@ unit i_bsd; system : system_x86_64_darwin; name : 'Darwin for x86_64'; shortname : 'Darwin'; - flags : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources]; + flags : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources + {$ifdef llvm},tf_use_psabieh{$endif}]; cpu : cpu_x86_64; unit_env : 'BSDUNITS'; extradefines : 'UNIX;BSD;HASUNIX';