|
@@ -86,6 +86,7 @@ interface
|
|
SegSymIdx: Integer;
|
|
SegSymIdx: Integer;
|
|
SegOfs: qword;
|
|
SegOfs: qword;
|
|
FileSectionOfs: qword;
|
|
FileSectionOfs: qword;
|
|
|
|
+ MainFuncSymbol: TWasmObjSymbol;
|
|
constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:longint;Aoptions:TObjSectionOptions);override;
|
|
constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:longint;Aoptions:TObjSectionOptions);override;
|
|
function IsCode: Boolean;
|
|
function IsCode: Boolean;
|
|
function IsData: Boolean;
|
|
function IsData: Boolean;
|
|
@@ -171,6 +172,7 @@ interface
|
|
procedure WriteLinkingSubsection(wlst: TWasmLinkingSubsectionType);
|
|
procedure WriteLinkingSubsection(wlst: TWasmLinkingSubsectionType);
|
|
procedure DoRelocations;
|
|
procedure DoRelocations;
|
|
procedure WriteRelocations;
|
|
procedure WriteRelocations;
|
|
|
|
+ function FindFunctionSymbol(Symbol: TWasmObjSymbol): TWasmObjSymbol;
|
|
protected
|
|
protected
|
|
function writeData(Data:TObjData):boolean;override;
|
|
function writeData(Data:TObjData):boolean;override;
|
|
public
|
|
public
|
|
@@ -402,6 +404,7 @@ implementation
|
|
inherited create(AList, Aname, Aalign, Aoptions);
|
|
inherited create(AList, Aname, Aalign, Aoptions);
|
|
SegIdx:=-1;
|
|
SegIdx:=-1;
|
|
SegSymIdx:=-1;
|
|
SegSymIdx:=-1;
|
|
|
|
+ MainFuncSymbol:=nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TWasmObjSection.IsCode: Boolean;
|
|
function TWasmObjSection.IsCode: Boolean;
|
|
@@ -1166,6 +1169,7 @@ implementation
|
|
objrel: TWasmObjRelocation;
|
|
objrel: TWasmObjRelocation;
|
|
relout: tdynamicarray;
|
|
relout: tdynamicarray;
|
|
relcount: PInteger;
|
|
relcount: PInteger;
|
|
|
|
+ FuncSym: TWasmObjSymbol;
|
|
begin
|
|
begin
|
|
for si:=0 to FData.ObjSectionList.Count-1 do
|
|
for si:=0 to FData.ObjSectionList.Count-1 do
|
|
begin
|
|
begin
|
|
@@ -1293,7 +1297,15 @@ implementation
|
|
end
|
|
end
|
|
else if assigned(objrel.symbol) and assigned(objrel.symbol.objsection) and TWasmObjSection(objrel.symbol.objsection).IsCode then
|
|
else if assigned(objrel.symbol) and assigned(objrel.symbol.objsection) and TWasmObjSection(objrel.symbol.objsection).IsCode then
|
|
begin
|
|
begin
|
|
- //Writeln('todo: relocation to code: ', objrel.symbol.name);
|
|
|
|
|
|
+ Inc(relcount^);
|
|
|
|
+ WriteByte(relout,Ord(R_WASM_FUNCTION_OFFSET_I32));
|
|
|
|
+ WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
|
|
|
+ FuncSym:=FindFunctionSymbol(TWasmObjSymbol(objrel.Symbol));
|
|
|
|
+ if FuncSym.SymbolIndex<0 then
|
|
|
|
+ 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 }
|
|
end
|
|
end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
@@ -1348,6 +1360,11 @@ implementation
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ function TWasmObjOutput.FindFunctionSymbol(Symbol: TWasmObjSymbol): TWasmObjSymbol;
|
|
|
|
+ begin
|
|
|
|
+ Result:=TWasmObjSection(Symbol.objsection).MainFuncSymbol;
|
|
|
|
+ end;
|
|
|
|
+
|
|
function TWasmObjOutput.writeData(Data:TObjData):boolean;
|
|
function TWasmObjOutput.writeData(Data:TObjData):boolean;
|
|
var
|
|
var
|
|
section_nr: Integer;
|
|
section_nr: Integer;
|
|
@@ -1425,7 +1442,10 @@ implementation
|
|
if IsExternalFunction(objsym) then
|
|
if IsExternalFunction(objsym) then
|
|
Inc(import_functions_count);
|
|
Inc(import_functions_count);
|
|
if (objsym.typ=AT_FUNCTION) and not objsym.IsAlias then
|
|
if (objsym.typ=AT_FUNCTION) and not objsym.IsAlias then
|
|
- Inc(functions_count);
|
|
|
|
|
|
+ begin
|
|
|
|
+ TWasmObjSection(objsym.objsection).MainFuncSymbol:=objsym;
|
|
|
|
+ Inc(functions_count);
|
|
|
|
+ end;
|
|
if IsExportedFunction(objsym) then
|
|
if IsExportedFunction(objsym) then
|
|
Inc(export_functions_count);
|
|
Inc(export_functions_count);
|
|
end;
|
|
end;
|