[PATCH 188/188] fix offset reference within the code section, when

writing relocation info

From ad32136edcdc2c4df42f5a305358aa01b90755b9 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <skalogryz.lists@gmail.com>
Date: Mon, 13 Apr 2020 10:13:06 -0400

git-svn-id: branches/wasm@46184 -
This commit is contained in:
nickysn 2020-08-03 13:02:19 +00:00
parent c2abf3e14b
commit 34460a9fae
2 changed files with 7 additions and 15 deletions

View File

@ -245,17 +245,6 @@ begin
reloc[i].offset:=secOfs;
reloc[i].index:=index;
inc(relocCount);
case relocType of
R_WASM_FUNCTION_INDEX_LEB:
begin
// ok, so this is function.
// the function MUST HAVE a symbol information available
// if it doesn't have a symbol then "wasm-objdump" would fail to read it
f:=module.GetFunc(index);
inc(f.codeRefCount);
end;
end;
end;
procedure TBinWriter.AddRelocToObj(relocType: byte; secOfs: int64; wasmObj: TObject);
@ -512,6 +501,7 @@ var
la : TLocalInfoArray;
f : TWasmFunc;
dofs : Int64;
fnofs : Int64; // function offset in the data of "code section"
main : TMemoryStream;
begin
// for the use of leb128, the header can be written ahead of the body
@ -535,7 +525,7 @@ begin
GetLocalInfo(f, la);
mem.Position:=0;
dofs := dofs + main.Position + 5; // "la" will be written after, 5 is for the writeSize. +5 is for WriteRelocU32(sz)
fnofs := dofs + main.Position + 5; // "la" will be written after, 5 is for the writeSize. +5 is for WriteRelocU32(sz)
pushStream(mem);
WriteU32(dst, length(la));
@ -543,7 +533,7 @@ begin
WriteU32(dst, la[j].count);
dst.WriteByte(la[j].tp);
end;
WriteInstList(f.instr, LongWord(dofs-sc.datapos));
WriteInstList(f.instr, LongWord(fnofs-sc.datapos));
popStream;
sz:=mem.Position;
@ -679,7 +669,6 @@ var
i : integer;
j : integer;
ci : TWasmInstr;
idx : integer;
rt : Byte;
begin
for i:=0 to list.Count-1 do begin
@ -858,7 +847,7 @@ var
begin
for i:=0 to m.FuncCount-1 do begin
f := m.GetFunc(i);
if isFuncLinkSym(f.LinkInfo) or (f.codeRefCount>0) then begin
if isFuncLinkSym(f.LinkInfo) then begin
if f.LinkInfo.Name ='' then f.LinkInfo.Name := f.id;
so:=AddSymbolObject(f);
LinkInfoToBin(f.linkInfo, so.syminfo, SYMTAB_FUNCTION, f.idNum);

View File

@ -29,6 +29,9 @@ begin
ipLeb:
if (INST_RELOC_FLAGS[ci.code].doReloc) then begin
case INST_RELOC_FLAGS[ci.code].relocType of
R_WASM_FUNCTION_INDEX_LEB:
ci.SetReloc(INST_RELOC_FLAGS[ci.code].relocType, GetFuncByNum(module, ci.operandNum));
R_WASM_GLOBAL_INDEX_LEB:
ci.SetReloc(INST_RELOC_FLAGS[ci.code].relocType, GetGlobalByNum(module, ci.operandNum));