mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 04:29:20 +02:00
+ fixed the addend in the relocations that point to data
This commit is contained in:
parent
2d1ebe4cb3
commit
abf831c430
@ -59,6 +59,7 @@ interface
|
|||||||
TWasmObjRelocation = class(TObjRelocation)
|
TWasmObjRelocation = class(TObjRelocation)
|
||||||
public
|
public
|
||||||
TypeIndex: Integer;
|
TypeIndex: Integer;
|
||||||
|
Addend: LongInt;
|
||||||
constructor CreateTypeIndex(ADataOffset:TObjSectionOfs; ATypeIndex: Integer);
|
constructor CreateTypeIndex(ADataOffset:TObjSectionOfs; ATypeIndex: Integer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -276,6 +277,26 @@ implementation
|
|||||||
WriteUleb5(d,q);
|
WriteUleb5(d,q);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure AddInt32(d: tdynamicarray; v: int32);
|
||||||
|
var
|
||||||
|
q: int32;
|
||||||
|
p: LongWord;
|
||||||
|
begin
|
||||||
|
p:=d.Pos;
|
||||||
|
|
||||||
|
d.read(q,4);
|
||||||
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
|
q:=SwapEndian(q);
|
||||||
|
{$endif FPC_BIG_ENDIAN}
|
||||||
|
q:=q+v;
|
||||||
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
|
q:=SwapEndian(q);
|
||||||
|
{$endif FPC_BIG_ENDIAN}
|
||||||
|
|
||||||
|
d.seek(p);
|
||||||
|
d.write(q,4);
|
||||||
|
end;
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
TWasmObjRelocation
|
TWasmObjRelocation
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
@ -559,6 +580,7 @@ implementation
|
|||||||
if not assigned(p) then
|
if not assigned(p) then
|
||||||
internalerror(2021092504);
|
internalerror(2021092504);
|
||||||
objreloc:=TWasmObjRelocation.CreateSymbol(CurrObjSec.Size,p,Reloctype);
|
objreloc:=TWasmObjRelocation.CreateSymbol(CurrObjSec.Size,p,Reloctype);
|
||||||
|
objreloc.Addend:=Data;
|
||||||
CurrObjSec.ObjRelocations.Add(objreloc);
|
CurrObjSec.ObjRelocations.Add(objreloc);
|
||||||
if RelocType=RELOC_MEMORY_ADDR_LEB then
|
if RelocType=RELOC_MEMORY_ADDR_LEB then
|
||||||
WriteUleb5(CurrObjSec,Data)
|
WriteUleb5(CurrObjSec,Data)
|
||||||
@ -572,6 +594,7 @@ implementation
|
|||||||
if not assigned(p) then
|
if not assigned(p) then
|
||||||
internalerror(2021092608);
|
internalerror(2021092608);
|
||||||
objreloc:=TWasmObjRelocation.CreateSymbol(CurrObjSec.Size,p,Reloctype);
|
objreloc:=TWasmObjRelocation.CreateSymbol(CurrObjSec.Size,p,Reloctype);
|
||||||
|
objreloc.Addend:=Data;
|
||||||
CurrObjSec.ObjRelocations.Add(objreloc);
|
CurrObjSec.ObjRelocations.Add(objreloc);
|
||||||
Data:=NtoLE(Data);
|
Data:=NtoLE(Data);
|
||||||
writebytes(Data,4);
|
writebytes(Data,4);
|
||||||
@ -904,8 +927,10 @@ implementation
|
|||||||
begin
|
begin
|
||||||
if not assigned(objrel.symbol) then
|
if not assigned(objrel.symbol) then
|
||||||
internalerror(2021092605);
|
internalerror(2021092605);
|
||||||
if objrel.symbol.bind<>AB_EXTERNAL then
|
if not (IsExternalFunction(objrel.symbol) or (objrel.symbol.typ=AT_FUNCTION) or (objrel.symbol.bind=AB_EXTERNAL)) then
|
||||||
begin
|
begin
|
||||||
|
Writeln('!!!', objrel.symbol.Name);
|
||||||
|
Writeln(assigned(objrel.symbol.objsection));
|
||||||
objsec.Data.seek(objrel.DataOffset);
|
objsec.Data.seek(objrel.DataOffset);
|
||||||
AddSleb5(objsec.Data,objrel.symbol.offset+TWasmObjSection(objrel.symbol.objsection).SegOfs);
|
AddSleb5(objsec.Data,objrel.symbol.offset+TWasmObjSection(objrel.symbol.objsection).SegOfs);
|
||||||
end;
|
end;
|
||||||
@ -914,6 +939,8 @@ implementation
|
|||||||
begin
|
begin
|
||||||
if not assigned(objrel.symbol) then
|
if not assigned(objrel.symbol) then
|
||||||
internalerror(2021092606);
|
internalerror(2021092606);
|
||||||
|
if IsExternalFunction(objrel.symbol) or (objrel.symbol.typ=AT_FUNCTION) then
|
||||||
|
internalerror(2021092628);
|
||||||
if objrel.symbol.bind<>AB_EXTERNAL then
|
if objrel.symbol.bind<>AB_EXTERNAL then
|
||||||
begin
|
begin
|
||||||
objsec.Data.seek(objrel.DataOffset);
|
objsec.Data.seek(objrel.DataOffset);
|
||||||
@ -921,7 +948,13 @@ implementation
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
RELOC_ABSOLUTE:
|
RELOC_ABSOLUTE:
|
||||||
;
|
begin
|
||||||
|
if not (IsExternalFunction(objrel.symbol) or (objrel.symbol.typ=AT_FUNCTION) or (objrel.symbol.bind=AB_EXTERNAL)) then
|
||||||
|
begin
|
||||||
|
objsec.Data.seek(objrel.DataOffset);
|
||||||
|
AddInt32(objsec.Data,objrel.symbol.offset+TWasmObjSection(objrel.symbol.objsection).SegOfs);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
RELOC_TYPE_INDEX_LEB:
|
RELOC_TYPE_INDEX_LEB:
|
||||||
;
|
;
|
||||||
else
|
else
|
||||||
@ -975,7 +1008,7 @@ implementation
|
|||||||
WriteByte(relout,Ord(R_WASM_MEMORY_ADDR_LEB));
|
WriteByte(relout,Ord(R_WASM_MEMORY_ADDR_LEB));
|
||||||
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
||||||
WriteUleb(relout,TWasmObjSymbol(objrel.symbol).SymbolIndex);
|
WriteUleb(relout,TWasmObjSymbol(objrel.symbol).SymbolIndex);
|
||||||
WriteUleb(relout,0); { addend to add to the address }
|
WriteSleb(relout,objrel.Addend); { addend to add to the address }
|
||||||
end;
|
end;
|
||||||
RELOC_MEMORY_ADDR_OR_TABLE_INDEX_SLEB:
|
RELOC_MEMORY_ADDR_OR_TABLE_INDEX_SLEB:
|
||||||
begin
|
begin
|
||||||
@ -993,7 +1026,7 @@ implementation
|
|||||||
WriteByte(relout,Ord(R_WASM_MEMORY_ADDR_SLEB));
|
WriteByte(relout,Ord(R_WASM_MEMORY_ADDR_SLEB));
|
||||||
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
||||||
WriteUleb(relout,TWasmObjSymbol(objrel.symbol).SymbolIndex);
|
WriteUleb(relout,TWasmObjSymbol(objrel.symbol).SymbolIndex);
|
||||||
WriteUleb(relout,0); { addend to add to the address }
|
WriteSleb(relout,objrel.Addend); { addend to add to the address }
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
RELOC_ABSOLUTE:
|
RELOC_ABSOLUTE:
|
||||||
@ -1013,7 +1046,7 @@ implementation
|
|||||||
WriteByte(relout,Ord(R_WASM_MEMORY_ADDR_I32));
|
WriteByte(relout,Ord(R_WASM_MEMORY_ADDR_I32));
|
||||||
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
||||||
WriteUleb(relout,TWasmObjSymbol(objrel.symbol).SymbolIndex);
|
WriteUleb(relout,TWasmObjSymbol(objrel.symbol).SymbolIndex);
|
||||||
WriteUleb(relout,0); { addend to add to the address }
|
WriteSleb(relout,objrel.Addend); { addend to add to the address }
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
RELOC_TYPE_INDEX_LEB:
|
RELOC_TYPE_INDEX_LEB:
|
||||||
|
Loading…
Reference in New Issue
Block a user