Browse Source

+ WebAssembly internal linker: write the indirect function table to the linker map file

Nikolay Nikolov 6 months ago
parent
commit
4e3fc8290a
1 changed files with 13 additions and 0 deletions
  1. 13 0
      compiler/ogwasm.pas

+ 13 - 0
compiler/ogwasm.pas

@@ -321,6 +321,7 @@ interface
         procedure GenerateCode_InvokeHelper;
         procedure GenerateCode_InvokeHelper;
         procedure WriteExeSectionToDynArray(exesec: TExeSection; dynarr: tdynamicarray);
         procedure WriteExeSectionToDynArray(exesec: TExeSection; dynarr: tdynamicarray);
         procedure WriteMap_TypeSection;
         procedure WriteMap_TypeSection;
+        procedure WriteMap_IndirectFunctionTable;
       protected
       protected
         function writeData:boolean;override;
         function writeData:boolean;override;
         procedure DoRelocationFixup(objsec:TObjSection);override;
         procedure DoRelocationFixup(objsec:TObjSection);override;
@@ -5549,6 +5550,9 @@ implementation
           follow it in the Code section, and we want our DWARF debug info to
           follow it in the Code section, and we want our DWARF debug info to
           contain correct code offsets. }
           contain correct code offsets. }
         GenerateCode_InvokeHelper;
         GenerateCode_InvokeHelper;
+
+        if Assigned(exemap) then
+          WriteMap_IndirectFunctionTable;
       end;
       end;
 
 
     procedure TWasmExeOutput.MemPos_ExeSection(const aname: string);
     procedure TWasmExeOutput.MemPos_ExeSection(const aname: string);
@@ -6371,6 +6375,15 @@ implementation
           exemap.Add('  Type[' + tostr(i) + '] ' + FFuncTypes.Items[i].ToString);
           exemap.Add('  Type[' + tostr(i) + '] ' + FFuncTypes.Items[i].ToString);
       end;
       end;
 
 
+    procedure TWasmExeOutput.WriteMap_IndirectFunctionTable;
+      var
+        i: Integer;
+      begin
+        exemap.AddHeader('Indirect function table');
+        for i:=1 to High(FIndirectFunctionTable) do
+          exemap.Add('  Elem[' + tostr(i) + '] = Function[' + tostr(FIndirectFunctionTable[i].FuncIdx) + ']');
+      end;
+
 
 
 {****************************************************************************
 {****************************************************************************
                                TWasmAssembler
                                TWasmAssembler