diff --git a/compiler/systems/i_wasi.pas b/compiler/systems/i_wasi.pas index ef9ab62574..6cca240a09 100644 --- a/compiler/systems/i_wasi.pas +++ b/compiler/systems/i_wasi.pas @@ -35,7 +35,7 @@ unit i_wasi; name : 'The WebAssembly System Interface (WASI)'; shortname : 'Wasi'; flags : [tf_under_development,tf_needs_symbol_size,tf_needs_symbol_type, - tf_files_case_sensitive,tf_no_generic_stackcheck,tf_emit_stklen, + tf_files_case_sensitive, tf_smartlink_sections,tf_has_winlike_resources, { avoid the creation of threadvar tables } tf_section_threadvars]; diff --git a/compiler/wasm32/hlcgcpu.pas b/compiler/wasm32/hlcgcpu.pas index c563a5a471..63ae84a9c5 100644 --- a/compiler/wasm32/hlcgcpu.pas +++ b/compiler/wasm32/hlcgcpu.pas @@ -129,6 +129,9 @@ uses procedure gen_entry_code(list: TAsmList); override; procedure gen_exit_code(list: TAsmList); override; + procedure gen_stack_check_size_para(list: TAsmList); override; + procedure gen_stack_check_call(list: TAsmList); override; + { unimplemented/unnecessary routines } procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; srcsize, dstsize: tdef; src, dst: tregister); override; procedure a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister; shuffle: pmmshuffle); override; @@ -2368,6 +2371,24 @@ implementation inherited; end; + procedure thlcgwasm.gen_stack_check_size_para(list: TAsmList); + begin + { HACK: this is called *after* gen_stack_check_call, but the code it + generates is inserted *before* the call. Thus, it breaks our + incstack/decstack tracking and causes an internal error 2010120501. We + workaround this by generating a const instruction without calling + incstack, and instead we call incstack before the call, in + gen_stack_check_call. } + list.concat(taicpu.op_const(a_i32_const,current_procinfo.calc_stackframe_size)); + end; + + procedure thlcgwasm.gen_stack_check_call(list: TAsmList); + begin + { HACK: see the comment in gen_stack_check_size_para } + incstack(list,1); + inherited; + end; + procedure thlcgwasm.a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; srcsize, dstsize: tdef; src, dst: tregister); begin internalerror(2012090201);