Browse Source

* fix generation of addend for R_WASM_FUNCTION_OFFSET_I32 relocations. This
improves code address accuracy for WebAssembly debug line info information.

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

+ 6 - 1
compiler/ogwasm.pas

@@ -131,6 +131,7 @@ interface
         SegSymIdx: Integer;
         SegOfs: qword;
         FileSectionOfs: qword;
+        EncodedLocalsSize: qword;
         MainFuncSymbol: TWasmObjSymbol;
         CustomSectionIdx: Integer;
         constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:longint;Aoptions:TObjSectionOptions);override;
@@ -1326,6 +1327,7 @@ implementation
         encoded_locals.seek(0);
         CopyDynamicArray(encoded_locals,dest,encoded_locals.size);
         ObjSection.FileSectionOfs:=dest.size-objsym.offset;
+        ObjSection.EncodedLocalsSize:=encoded_locals.size;
         CopyDynamicArray(ObjSection.Data,dest,codeexprlen);
         WriteByte(dest,$0B);
         encoded_locals.Free;
@@ -1607,7 +1609,10 @@ implementation
                             message1(asmw_e_illegal_unset_index,FuncSym.Name)
                           else
                             WriteUleb(relout,FuncSym.SymbolIndex);
-                          WriteSleb(relout,objrel.Addend+objrel.symbol.address);  { addend to add to the address }
+                          if (objrel.Addend+objrel.symbol.address)=0 then
+                            WriteSleb(relout,objrel.Addend+objrel.symbol.address)  { addend to add to the address }
+                          else
+                            WriteSleb(relout,objrel.Addend+objrel.symbol.address+TWasmObjSection(objrel.symbol.objsection).EncodedLocalsSize);  { addend to add to the address }
                         end
                       else if assigned(objrel.symbol) and (objrel.symbol.typ=AT_WASM_GLOBAL) then
                         begin