From 72abf6f4727933546411df27071990a0461ee9e7 Mon Sep 17 00:00:00 2001 From: nickysn Date: Thu, 21 Jan 2021 16:34:39 +0000 Subject: [PATCH] + add "fingerprints" in the beginning of each routine for easier debugging (this will be disabled later, and only enabled with -g or some other target flag, but for now, it's always on) git-svn-id: branches/wasm@48272 - --- compiler/wasm32/hlcgcpu.pas | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/compiler/wasm32/hlcgcpu.pas b/compiler/wasm32/hlcgcpu.pas index 530d533f7e..e5a393b653 100644 --- a/compiler/wasm32/hlcgcpu.pas +++ b/compiler/wasm32/hlcgcpu.pas @@ -201,6 +201,19 @@ uses slots used for parameters and the provided resultdef } procedure g_adjust_stack_after_call(list: TAsmList; pd: tabstractprocdef); + { because WebAssembly has no spec for any sort of debug info, and the + only linker that we support (LLVM's wasm-ld) does not support creating + map files in its stable version, and crashes when attempting to create + a map file in its development version from git, we have no way to + identify which procedure a crash occurred in. So, to identify the + procedure, we call this procedure on proc entry, which generates a few + useless loads of random numbers on the stack, that are immediately + discarded, so they are essentially equivalent to a nop. This allows + finding the procedure in the FPC output assembly, produced with -al by + searching for these random numbers, as taken from the disassembly of the + final binary. } + procedure g_fingerprint(list: TAsmList); + property maxevalstackheight: longint read fmaxevalstackheight; protected @@ -1510,6 +1523,8 @@ implementation list.Concat(tai_local.create(wbt_i32,FRAME_POINTER_SYM)); //TWasmBasicType list.Concat(tai_local.create(wbt_i32,BASE_POINTER_SYM)); //TWasmBasicType + g_fingerprint(list); + list.Concat(taicpu.op_sym(a_get_global,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL))); incstack(list,1); list.Concat(taicpu.op_ref(a_set_local,pd.base_pointer_ref)); @@ -1951,6 +1966,19 @@ implementation end; + procedure thlcgwasm.g_fingerprint(list: TAsmList); + begin + list.concat(taicpu.op_const(a_i64_const,Random(high(int64)))); + list.concat(taicpu.op_const(a_i64_const,Random(high(int64)))); + list.concat(taicpu.op_const(a_i64_const,Random(high(int64)))); + list.concat(taicpu.op_const(a_i64_const,Random(high(int64)))); + list.concat(taicpu.op_none(a_drop)); + list.concat(taicpu.op_none(a_drop)); + list.concat(taicpu.op_none(a_drop)); + list.concat(taicpu.op_none(a_drop)); + end; + + procedure thlcgwasm.resizestackfpuval(list: TAsmList; fromsize, tosize: tcgsize); begin if (fromsize=OS_F32) and