From b985cd0ea55ca2b91e7b74bd58ccf9688f393bd1 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Sun, 11 Aug 2024 02:24:02 +0300 Subject: [PATCH] * WebAssembly threads internal linker: implement memory initialization in TWasmExeOutput.GenerateCode_InitSharedMemory --- compiler/ogwasm.pas | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index e46fb7f52b..37d078d1d2 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -5569,6 +5569,9 @@ implementation InitFlagOfs=256; var Sec: TObjSection; + DataSecName: string; + DataSecIdx: Integer; + ExeSec: TExeSection; begin if not (ts_wasm_threads in current_settings.targetswitches) then exit; @@ -5599,7 +5602,27 @@ implementation { end } Sec.writeUInt8($0B); - { TODO: memory.init and memory.fill } + DataSecIdx:=-1; + for DataSecName in DataSections do + begin + ExeSec:=FindExeSection(DataSecName); + if Assigned(ExeSec) and (ExeSec.Size>0) then + begin + Inc(DataSecIdx); + { i32.const $memPos } + Sec.writeUInt8($41); + WriteUleb5(sec,ExeSec.MemPos); + { i32.const 0 } + Sec.writeUInt16BE($4100); + { i32.const size } + Sec.writeUInt8($41); + WriteUleb5(sec,ExeSec.Size); + { memory.init $DataSecIdx 0 } + Sec.writeUInt16BE($fc08); + WriteUleb5(sec,DataSecIdx); + Sec.writeUInt8(0); + end; + end; { i32.const $InitFlag } Sec.writeUInt8($41);