diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index 837cc92e0c..c513af4def 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -191,7 +191,6 @@ interface FWasmLinkingSubsections: array [low(TWasmLinkingSubsectionType)..high(TWasmLinkingSubsectionType)] of tdynamicarray; procedure WriteWasmSection(wsid: TWasmSectionID); procedure WriteWasmCustomSection(wcst: TWasmCustomSectionType); - procedure WriteZeros(dest: tdynamicarray; size: QWord); function IsExternalFunction(sym: TObjSymbol): Boolean; function IsExportedFunction(sym: TWasmObjSymbol): Boolean; procedure WriteFunctionLocals(dest: tdynamicarray; ed: TWasmObjSymbolExtraData); @@ -497,6 +496,24 @@ implementation end; end; + procedure WriteZeros(dest: tdynamicarray; size: QWord); + var + buf : array[0..1023] of byte; + bs: Integer; + begin + fillchar(buf,sizeof(buf),0); + while size>0 do + begin + if size0 do - begin - if size=max(objsec.SecAlign,1)) then + internalerror(2024010106); + writeZeros(FWasmSections[wsiData],pad); + + objsec.data.seek(0); + CopyDynamicArray(objsec.data,FWasmSections[wsiData],objsec.data.size); + end; + if (FWasmSections[wsiData].size-exesecdatapos)<>exesec.Size then + internalerror(2024010107); + end; + + var + DataCount: Integer; + begin + DataCount:=2; + WriteUleb(FWasmSections[wsiDataCount],DataCount); + WriteUleb(FWasmSections[wsiData],DataCount); + WriteExeSection(FindExeSection('.rodata')); + WriteExeSection(FindExeSection('.data')); + end; + begin result:=false; FFuncTypes.WriteTo(FWasmSections[wsiType]); WriteImportSection; WriteCodeSegments; + WriteDataSegments; WriteUleb(FWasmSections[wsiMemory],1); WriteByte(FWasmSections[wsiMemory],0); @@ -4157,7 +4208,9 @@ implementation WriteWasmSection(wsiImport); WriteWasmSection(wsiFunction); WriteWasmSection(wsiMemory); + WriteWasmSection(wsiDataCount); WriteWasmSection(wsiCode); + WriteWasmSection(wsiData); result := true; end;