From 12496a638b4c5b1ec45b5435c8db03ea34e851f1 Mon Sep 17 00:00:00 2001
From: Nikolay Nikolov <nickysn@gmail.com>
Date: Sat, 25 Sep 2021 18:37:10 +0300
Subject: [PATCH] + add relocation objects for the RELOC_FUNCTION_INDEX_LEB
 relocation to   the relocation list. They are not written to the object file,
 yet.

---
 compiler/ogwasm.pas | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas
index 0cfb962f86..e3a29b1e65 100644
--- a/compiler/ogwasm.pas
+++ b/compiler/ogwasm.pas
@@ -40,6 +40,11 @@ interface
 
     type
 
+      { TWasmObjRelocation }
+
+      TWasmObjRelocation = class(TObjRelocation)
+      end;
+
       { TWasmObjSymbolExtraData }
 
       TWasmObjSymbolExtraData = class(TFPHashObject)
@@ -330,7 +335,12 @@ implementation
         p: TObjSymbol; Reloctype: TObjRelocationType);
       const
         leb_zero: array[0..4] of byte=($80,$80,$80,$80,$00);
+      var
+        objreloc: TWasmObjRelocation;
       begin
+        if CurrObjSec=nil then
+          internalerror(200403072);
+        objreloc:=nil;
         case Reloctype of
           RELOC_FUNCTION_INDEX_LEB:
             begin
@@ -338,6 +348,12 @@ implementation
                 internalerror(2021092502);
               if len<>5 then
                 internalerror(2021092503);
+              if not assigned(p) then
+                internalerror(2021092504);
+              if p.bind<>AB_EXTERNAL then
+                internalerror(2021092505);
+              objreloc:=TWasmObjRelocation.CreateSymbol(CurrObjSec.Size,p,Reloctype);
+              CurrObjSec.ObjRelocations.Add(objreloc);
               writebytes(leb_zero,5);
             end;
           RELOC_ABSOLUTE: