Browse Source

+ WebAssembly internal object writer: added safety check for catching bugs,
caused by instruction size changes between Pass1 and Pass2

Nikolay Nikolov 11 months ago
parent
commit
c8e4a52428
1 changed files with 8 additions and 0 deletions
  1. 8 0
      compiler/wasm32/aasmcpu.pas

+ 8 - 0
compiler/wasm32/aasmcpu.pas

@@ -145,6 +145,9 @@ uses
       { taicpu }
 
       taicpu = class(tai_cpu_abstract_sym)
+      private
+         insoffset : longint;
+      public
          is_br_generated_by_goto: boolean;
 
          constructor Create(op : tasmop);override;
@@ -2093,6 +2096,8 @@ uses
 
       begin
         result:=0;
+        { Save the old offset and set the new offset }
+        InsOffset:=ObjData.CurrObjSec.Size;
         case opcode of
           a_unreachable,
           a_nop,
@@ -2688,6 +2693,9 @@ uses
           end;
 
       begin
+        { safety check }
+        if objdata.currobjsec.size<>longword(insoffset) then
+          internalerror(200130121);
         case opcode of
           a_unreachable:
             WriteByte($00);