Browse Source

+ WebAssembly internal linker: take into account the min heap size (specified
with the $M directive), when determining FMinMemoryPages

Nikolay Nikolov 11 months ago
parent
commit
bf78823e60
1 changed files with 5 additions and 1 deletions
  1. 5 1
      compiler/ogwasm.pas

+ 5 - 1
compiler/ogwasm.pas

@@ -5499,13 +5499,17 @@ implementation
       end;
 
     procedure TWasmExeOutput.SetStackPointer;
+      const
+        PageSize = 65536;
       var
         BssSec: TExeSection;
         StackStart, InitialStackPtrAddr: QWord;
       begin
         BssSec:=FindExeSection('.bss');
         InitialStackPtrAddr := (BssSec.MemPos+BssSec.Size+stacksize+15) and (not 15);
-        FMinMemoryPages := (InitialStackPtrAddr+65535) shr 16;
+        FMinMemoryPages := Max(
+          QWord(Align(QWord(InitialStackPtrAddr),QWord(PageSize)) div PageSize),
+          QWord(Align(QWord(heapsize),QWord(PageSize)) div PageSize));
         FStackPointerSym.LinkingData.GlobalInitializer.init_i32:=Int32(InitialStackPtrAddr);
       end;