diff --git a/utils/wasmbin/wasmbinwriter.pas b/utils/wasmbin/wasmbinwriter.pas index 01829cb97a..19997868c4 100644 --- a/utils/wasmbin/wasmbinwriter.pas +++ b/utils/wasmbin/wasmbinwriter.pas @@ -25,9 +25,9 @@ type strm : TList; // the list of relocations per module + writeSec : Byte; reloc : array of TRelocationEntry; relocCount : integer; - procedure AddReloc(relocType: byte; ofs: int64; index: UInt32); procedure WriteRelocU32(u: longword); @@ -130,10 +130,11 @@ begin if relocCount=0 then SetLength(reloc, 16) else SetLength(reloc, relocCount*2); end; + reloc[relocCount].sec:=writeSec; reloc[relocCount].reltype:=relocType; reloc[relocCount].offset:=ofs; reloc[relocCount].index:=index; - inc(relocType); + inc(relocCount); end; procedure TBinWriter.WriteRelocU32(u: longword); @@ -165,17 +166,30 @@ begin l:=NtoLE(Wasm_Version1); dst.Write(l, sizeof(l)); + writeSec:=0; // 01 function type section - WriteFuncTypeSect(m); + if m.TypesCount>0 then begin + WriteFuncTypeSect(m); + inc(writeSec); + end; // 03 function section - WriteFuncSect(m); + if m.FuncCount>0 then begin + WriteFuncSect(m); + inc(writeSec); + end; // 07 export section - WriteExportSect(m); + if m.ExportCount>0 then begin + WriteExportSect(m); + inc(writeSec); + end; // 10 code section - WriteCodeSect(m); + if m.FuncCount>0 then begin + WriteCodeSect(m); + inc(writeSec); + end; if writeReloc then begin WriteLinkingSect(m); @@ -331,8 +345,37 @@ begin end; procedure TBinWriter.WriteRelocSect(m: TWasmModule); +var + i : integer; + j : integer; + si : Byte; + cnt: integer; + sc : TSectionRec; begin + si:=0; + i:=0; + while (si