From 29ee863e8faedc99e3b12b1e4d66b21bf51cddbb Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Tue, 17 Sep 2024 06:14:03 +0300 Subject: [PATCH] - WebAssembly code generator: removed the g_fingerprint hack, that added 4 useless i64 constants on the stack with random numbers and then drop them. It was used for primitive debugging, since previously it wasn't possible to identify the function name. Now we can produce DWARF debug info, as well as a "names" custom section to give each function a name and most WebAssembly environments support at least one of the two mechanisms. Therefore the g_fingerprint hack is no longer necessary. --- compiler/wasm32/hlcgcpu.pas | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/compiler/wasm32/hlcgcpu.pas b/compiler/wasm32/hlcgcpu.pas index 09eda20465..04670d2e73 100644 --- a/compiler/wasm32/hlcgcpu.pas +++ b/compiler/wasm32/hlcgcpu.pas @@ -220,19 +220,6 @@ 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 @@ -2073,8 +2060,6 @@ implementation if pd.base_pointer_ref.base<>NR_LOCAL_STACK_POINTER_REG then ttgwasm(tg).allocbasepointer(list,pd.base_pointer_ref); - g_fingerprint(list); - list.Concat(taicpu.op_sym(a_global_get,RefStackPointerSym)); incstack(list,1); list.Concat(taicpu.op_ref(a_local_set,pd.base_pointer_ref)); @@ -2819,19 +2804,6 @@ 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