Browse Source

* wasm internal linker: start the data section at offset 0, as WebAssembly is a Harvard architecture.

Nikolay Nikolov 1 year ago
parent
commit
dc4689ba1b
1 changed files with 10 additions and 0 deletions
  1. 10 0
      compiler/ogwasm.pas

+ 10 - 0
compiler/ogwasm.pas

@@ -248,6 +248,7 @@ interface
         destructor destroy;override;
         procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);override;
         procedure AfterUnusedSectionRemoval;override;
+        procedure MemPos_ExeSection(const aname:string);override;
       end;
 
       { TWasmAssembler }
@@ -4252,6 +4253,15 @@ implementation
         PrepareFunctions;
       end;
 
+    procedure TWasmExeOutput.MemPos_ExeSection(const aname: string);
+      begin
+        { WebAssembly is a Harvard architecture.
+          Data lives in a separate address space, so start addressing back from 0. }
+        if aname='.data' then
+          CurrMemPos:=0;
+        inherited MemPos_ExeSection(aname);
+      end;
+
     procedure TWasmExeOutput.PrepareImports;
 
       function AddFunctionImport(const libname,symname:TCmdStr; functype: TWasmFuncType): Integer;