Browse Source

+ partial implementation of RELOC_FUNCTION_INDEX_LEB relocations in the wasm internal linker

Nikolay Nikolov 1 year ago
parent
commit
1c1dbaf776
1 changed files with 28 additions and 1 deletions
  1. 28 1
      compiler/ogwasm.pas

+ 28 - 1
compiler/ogwasm.pas

@@ -4125,8 +4125,35 @@ implementation
       end;
       end;
 
 
     procedure TWasmExeOutput.DoRelocationFixup(objsec: TObjSection);
     procedure TWasmExeOutput.DoRelocationFixup(objsec: TObjSection);
+      var
+        i: Integer;
+        objreloc: TWasmObjRelocation;
+        objsym: TWasmObjSymbol;
       begin
       begin
-        {TODO: implement}
+        for i:=0 to objsec.ObjRelocations.Count-1 do
+          begin
+            objreloc:=TWasmObjRelocation(objsec.ObjRelocations[i]);
+            if assigned(objreloc.symbol) then
+              begin
+                objsym:=TWasmObjSymbol(objreloc.symbol);
+                case objreloc.typ of
+                  RELOC_FUNCTION_INDEX_LEB:
+                    begin
+                      if objsym.LinkingData.ExeFunctionIndex<>-1 then
+                        begin
+                          objsec.Data.seek(objreloc.DataOffset);
+                          WriteUleb5(objsec.Data,objsym.LinkingData.ExeFunctionIndex);
+                        end
+                      else
+                        Writeln('RELOC_FUNCTION_INDEX_LEB to a function with unresolved index: ', objsym.Name);
+                    end;
+                  else
+                    Writeln('Symbol relocation not yet implemented! ', objreloc.typ);
+                end;
+              end
+            else
+              Writeln('Non-symbol relocation not yet implemented! ', objreloc.typ);
+          end;
       end;
       end;
 
 
     constructor TWasmExeOutput.create;
     constructor TWasmExeOutput.create;