mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 15:49:18 +02:00
+ write the linking section (empty for now)
This commit is contained in:
parent
8295173f86
commit
8c57d20abc
@ -95,12 +95,14 @@ interface
|
|||||||
private
|
private
|
||||||
FData: TWasmObjData;
|
FData: TWasmObjData;
|
||||||
FWasmSections: array [TWasmSectionID] of tdynamicarray;
|
FWasmSections: array [TWasmSectionID] of tdynamicarray;
|
||||||
|
FWasmCustomSections: array [TWasmCustomSectionType] of tdynamicarray;
|
||||||
procedure WriteUleb(d: tdynamicarray; v: uint64);
|
procedure WriteUleb(d: tdynamicarray; v: uint64);
|
||||||
procedure WriteUleb(w: TObjectWriter; v: uint64);
|
procedure WriteUleb(w: TObjectWriter; v: uint64);
|
||||||
procedure WriteSleb(d: tdynamicarray; v: int64);
|
procedure WriteSleb(d: tdynamicarray; v: int64);
|
||||||
procedure WriteByte(d: tdynamicarray; b: byte);
|
procedure WriteByte(d: tdynamicarray; b: byte);
|
||||||
procedure WriteName(d: tdynamicarray; const s: string);
|
procedure WriteName(d: tdynamicarray; const s: string);
|
||||||
procedure WriteWasmSection(wsid: TWasmSectionID);
|
procedure WriteWasmSection(wsid: TWasmSectionID);
|
||||||
|
procedure WriteWasmCustomSection(wcst: TWasmCustomSectionType);
|
||||||
procedure CopyDynamicArray(src, dest: tdynamicarray; size: QWord);
|
procedure CopyDynamicArray(src, dest: tdynamicarray; size: QWord);
|
||||||
procedure WriteZeros(dest: tdynamicarray; size: QWord);
|
procedure WriteZeros(dest: tdynamicarray; size: QWord);
|
||||||
procedure WriteWasmResultType(dest: tdynamicarray; wrt: TWasmResultType);
|
procedure WriteWasmResultType(dest: tdynamicarray; wrt: TWasmResultType);
|
||||||
@ -487,6 +489,16 @@ implementation
|
|||||||
Writer.writearray(FWasmSections[wsid]);
|
Writer.writearray(FWasmSections[wsid]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TWasmObjOutput.WriteWasmCustomSection(wcst: TWasmCustomSectionType);
|
||||||
|
var
|
||||||
|
b: byte;
|
||||||
|
begin
|
||||||
|
b:=0;
|
||||||
|
Writer.write(b,1);
|
||||||
|
WriteUleb(Writer,FWasmCustomSections[wcst].size);
|
||||||
|
Writer.writearray(FWasmCustomSections[wcst]);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TWasmObjOutput.CopyDynamicArray(src, dest: tdynamicarray; size: QWord);
|
procedure TWasmObjOutput.CopyDynamicArray(src, dest: tdynamicarray; size: QWord);
|
||||||
var
|
var
|
||||||
buf: array [0..4095] of byte;
|
buf: array [0..4095] of byte;
|
||||||
@ -619,8 +631,16 @@ implementation
|
|||||||
import_functions_count: Integer = 0;
|
import_functions_count: Integer = 0;
|
||||||
functions_count: Integer = 0;
|
functions_count: Integer = 0;
|
||||||
objsym: TObjSymbol;
|
objsym: TObjSymbol;
|
||||||
|
cust_sec: TWasmCustomSectionType;
|
||||||
begin
|
begin
|
||||||
FData:=TWasmObjData(Data);
|
FData:=TWasmObjData(Data);
|
||||||
|
|
||||||
|
{ each custom sections starts with its name }
|
||||||
|
for cust_sec in TWasmCustomSectionType do
|
||||||
|
WriteName(FWasmCustomSections[cust_sec],WasmCustomSectionName[cust_sec]);
|
||||||
|
|
||||||
|
WriteUleb(FWasmCustomSections[wcstLinking],2); { linking metadata version }
|
||||||
|
|
||||||
for i:=0 to Data.ObjSymbolList.Count-1 do
|
for i:=0 to Data.ObjSymbolList.Count-1 do
|
||||||
begin
|
begin
|
||||||
objsym:=TObjSymbol(Data.ObjSymbolList[i]);
|
objsym:=TObjSymbol(Data.ObjSymbolList[i]);
|
||||||
@ -734,6 +754,7 @@ implementation
|
|||||||
WriteWasmSection(wsiDataCount);
|
WriteWasmSection(wsiDataCount);
|
||||||
WriteWasmSection(wsiCode);
|
WriteWasmSection(wsiCode);
|
||||||
WriteWasmSection(wsiData);
|
WriteWasmSection(wsiData);
|
||||||
|
WriteWasmCustomSection(wcstLinking);
|
||||||
|
|
||||||
Writeln('ObjSymbolList:');
|
Writeln('ObjSymbolList:');
|
||||||
for i:=0 to Data.ObjSymbolList.Count-1 do
|
for i:=0 to Data.ObjSymbolList.Count-1 do
|
||||||
@ -760,19 +781,25 @@ implementation
|
|||||||
constructor TWasmObjOutput.create(AWriter: TObjectWriter);
|
constructor TWasmObjOutput.create(AWriter: TObjectWriter);
|
||||||
var
|
var
|
||||||
i: TWasmSectionID;
|
i: TWasmSectionID;
|
||||||
|
j: TWasmCustomSectionType;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
cobjdata:=TWasmObjData;
|
cobjdata:=TWasmObjData;
|
||||||
for i in TWasmSectionID do
|
for i in TWasmSectionID do
|
||||||
FWasmSections[i] := tdynamicarray.create(SectionDataMaxGrow);
|
FWasmSections[i] := tdynamicarray.create(SectionDataMaxGrow);
|
||||||
|
for j in TWasmCustomSectionType do
|
||||||
|
FWasmCustomSections[j] := tdynamicarray.create(SectionDataMaxGrow);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TWasmObjOutput.destroy;
|
destructor TWasmObjOutput.destroy;
|
||||||
var
|
var
|
||||||
i: TWasmSectionID;
|
i: TWasmSectionID;
|
||||||
|
j: TWasmCustomSectionType;
|
||||||
begin
|
begin
|
||||||
for i in TWasmSectionID do
|
for i in TWasmSectionID do
|
||||||
FWasmSections[i].Free;
|
FWasmSections[i].Free;
|
||||||
|
for j in TWasmCustomSectionType do
|
||||||
|
FWasmCustomSections[j].Free;
|
||||||
inherited destroy;
|
inherited destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -45,6 +45,18 @@ type
|
|||||||
wsiData = 11,
|
wsiData = 11,
|
||||||
wsiDataCount = 12);
|
wsiDataCount = 12);
|
||||||
|
|
||||||
|
TWasmCustomSectionType = (
|
||||||
|
wcstLinking,
|
||||||
|
wcstRelocCode,
|
||||||
|
wcstRelocData);
|
||||||
|
|
||||||
|
const
|
||||||
|
WasmCustomSectionName: array [TWasmCustomSectionType] of string =
|
||||||
|
('linking',
|
||||||
|
'reloc.CODE',
|
||||||
|
'reloc.DATA');
|
||||||
|
|
||||||
|
type
|
||||||
TWasmRelocationType = (
|
TWasmRelocationType = (
|
||||||
R_WASM_FUNCTION_INDEX_LEB = 0,
|
R_WASM_FUNCTION_INDEX_LEB = 0,
|
||||||
R_WASM_TABLE_INDEX_SLEB = 1,
|
R_WASM_TABLE_INDEX_SLEB = 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user