mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-24 03:19:17 +02:00
[PATCH 008/188] adding processing of link sections
From 8f3c9e9f94e2d6ffa3efd08b6d8015a3608e17d4 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Wed, 25 Sep 2019 17:03:45 -0400 git-svn-id: branches/wasm@46004 -
This commit is contained in:
parent
85267156f5
commit
50df4ac869
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -18982,3 +18982,4 @@ utils/wasmbin/wasmbindebug.pas svneol=native#text/plain
|
|||||||
utils/wasmbin/wasmld.lpi svneol=native#text/plain
|
utils/wasmbin/wasmld.lpi svneol=native#text/plain
|
||||||
utils/wasmbin/wasmld.lpr svneol=native#text/plain
|
utils/wasmbin/wasmld.lpr svneol=native#text/plain
|
||||||
utils/wasmbin/wasmlink.pas svneol=native#text/plain
|
utils/wasmbin/wasmlink.pas svneol=native#text/plain
|
||||||
|
utils/wasmbin/wasmlinkchange.pas svneol=native#text/plain
|
||||||
|
@ -7,7 +7,7 @@ uses
|
|||||||
cthreads,
|
cthreads,
|
||||||
{$ENDIF}{$ENDIF}
|
{$ENDIF}{$ENDIF}
|
||||||
{ you can add units after this }
|
{ you can add units after this }
|
||||||
Classes, SysUtils, wasmbin, lebutils, wasmbindebug, wasmlink;
|
Classes, SysUtils, wasmbin, lebutils, wasmbindebug, wasmlink, wasmlinkchange;
|
||||||
|
|
||||||
function ReadStream(st: TStream): Boolean;
|
function ReadStream(st: TStream): Boolean;
|
||||||
var
|
var
|
||||||
@ -49,18 +49,85 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure ReadWasmFile(const fn: string);
|
||||||
var
|
var
|
||||||
fs :TFileStream;
|
fs :TFileStream;
|
||||||
begin
|
begin
|
||||||
if ParamCount=0 then begin
|
fs := TFileStream.Create(fn, fmOpenRead or fmShareDenyNone);
|
||||||
writeln('please sepcify .wasm file');
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
fs := TFileStream.Create(ParamStr(1), fmOpenRead or fmShareDenyNone);
|
|
||||||
try
|
try
|
||||||
ReadStream(fs);
|
ReadStream(fs);
|
||||||
finally
|
finally
|
||||||
fs.Free;
|
fs.Free;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function WriteStream(st: TStream): Boolean;
|
||||||
|
var
|
||||||
|
dw : LongWord;
|
||||||
|
ofs : int64;
|
||||||
|
sc : TSection;
|
||||||
|
ps : int64;
|
||||||
|
nm : string;
|
||||||
|
begin
|
||||||
|
writeln('read: ');
|
||||||
|
dw := st.ReadDWord;
|
||||||
|
writeln('dw: ' ,dw);
|
||||||
|
Result := dw = WasmId_Int;
|
||||||
|
if not Result then begin
|
||||||
|
writeln('not a wasm file');
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
dw := st.ReadDWord;
|
||||||
|
writeln('version: ', dw);
|
||||||
|
while st.Position<st.Size do begin
|
||||||
|
ofs := st.Position;
|
||||||
|
sc.id := st.ReadByte;
|
||||||
|
sc.Size := ReadU(st);
|
||||||
|
writeln(ofs,': id=', sc.id,'(', SectionIdToStr(sc.id),') sz=', sc.size);
|
||||||
|
|
||||||
|
ps := st.Position+sc.size;
|
||||||
|
if sc.id=0 then begin
|
||||||
|
nm := GetName(st);
|
||||||
|
writeln(nm);
|
||||||
|
if nm = SectionName_Linking then begin
|
||||||
|
writeln('rewriting linking...');
|
||||||
|
ProcessLinkingSection(st);
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
//DumpLinking(st, sc.size - (st.Position - ofs));
|
||||||
|
end;
|
||||||
|
//if sc.id= 1 then DumpTypes(st);
|
||||||
|
|
||||||
|
if st.Position <> ps then
|
||||||
|
begin
|
||||||
|
//writeln('adjust stream targ=',ps,' actual: ', st.position);
|
||||||
|
st.Position := ps;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure ProcessWasmFile(const fn: string);
|
||||||
|
var
|
||||||
|
fs :TFileStream;
|
||||||
|
begin
|
||||||
|
writeln('proc: ', fn);
|
||||||
|
fs := TFileStream.Create(fn, fmOpenReadWrite or fmShareDenyNone);
|
||||||
|
try
|
||||||
|
writeln('size: ', fs.size);
|
||||||
|
WriteStream(fs);
|
||||||
|
finally
|
||||||
|
fs.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if ParamCount=0 then begin
|
||||||
|
writeln('please specify .wasm file');
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//ReadWasmFile(ParamStr(1));
|
||||||
|
ProcessWasmFile(ParamStr(1));
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
53
utils/wasmbin/wasmlinkchange.pas
Normal file
53
utils/wasmbin/wasmlinkchange.pas
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
unit wasmlinkchange;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses Classes, SysUtils, wasmlink, wasmbin, lebutils;
|
||||||
|
|
||||||
|
procedure ProcessLinkingSection(st: TStream);
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure ProcessLinkingSection(st: TStream);
|
||||||
|
var
|
||||||
|
mt : TLinkingMetadata;
|
||||||
|
//en : Int64;
|
||||||
|
sub : TLinkinSubSection;
|
||||||
|
cnt : LongWord;
|
||||||
|
nx : Int64;
|
||||||
|
i : integer;
|
||||||
|
si : TSymInfo;
|
||||||
|
ofs : Int64;
|
||||||
|
begin
|
||||||
|
//en := st.Position+secsize;
|
||||||
|
ReadMetadata(st, mt);
|
||||||
|
writeln('version: ', mt.version);
|
||||||
|
//while st.Position<en do begin
|
||||||
|
ReadLinkSubSect(st, sub);
|
||||||
|
nx := st.Position+sub.length;
|
||||||
|
|
||||||
|
writeln('subsec=',SubSecTypeToStr(sub.sectype),' ',sub.sectype);
|
||||||
|
cnt := ReadU(st);
|
||||||
|
writeln('- symbol table [count=', cnt,']');
|
||||||
|
for i:=0 to cnt-1 do begin
|
||||||
|
write(' - ',i,' ');
|
||||||
|
|
||||||
|
ofs := st.Position;
|
||||||
|
ReadSymInfo(st, si);
|
||||||
|
//write(SymKindToStr(si.kind),' ',IntToHex(si.flags,8));
|
||||||
|
//if si.hasSymName then write(' ',si.symname);
|
||||||
|
//writeln;
|
||||||
|
if si.flags and WASM_SYM_UNDEFINED = 0 then
|
||||||
|
si.flags := si.flags or WASM_SYM_BINDING_LOCAL;
|
||||||
|
|
||||||
|
st.Position := ofs;
|
||||||
|
WriteSymInfo(st, si);
|
||||||
|
|
||||||
|
//writeln(si.symname);
|
||||||
|
end;
|
||||||
|
|
||||||
|
st.Position:=nx;
|
||||||
|
//end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user