From 50df4ac8690641f4d9aafcab90ee2e41d6c2aa46 Mon Sep 17 00:00:00 2001 From: nickysn Date: Mon, 3 Aug 2020 12:58:51 +0000 Subject: [PATCH] [PATCH 008/188] adding processing of link sections From 8f3c9e9f94e2d6ffa3efd08b6d8015a3608e17d4 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev Date: Wed, 25 Sep 2019 17:03:45 -0400 git-svn-id: branches/wasm@46004 - --- .gitattributes | 1 + utils/wasmbin/wasmld.lpr | 79 +++++++++++++++++++++++++++++--- utils/wasmbin/wasmlinkchange.pas | 53 +++++++++++++++++++++ 3 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 utils/wasmbin/wasmlinkchange.pas diff --git a/.gitattributes b/.gitattributes index 873aacb55a..1d9d8d5f25 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18982,3 +18982,4 @@ utils/wasmbin/wasmbindebug.pas svneol=native#text/plain utils/wasmbin/wasmld.lpi svneol=native#text/plain utils/wasmbin/wasmld.lpr svneol=native#text/plain utils/wasmbin/wasmlink.pas svneol=native#text/plain +utils/wasmbin/wasmlinkchange.pas svneol=native#text/plain diff --git a/utils/wasmbin/wasmld.lpr b/utils/wasmbin/wasmld.lpr index cf704d9075..1aa72c19d8 100644 --- a/utils/wasmbin/wasmld.lpr +++ b/utils/wasmbin/wasmld.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} { you can add units after this } - Classes, SysUtils, wasmbin, lebutils, wasmbindebug, wasmlink; + Classes, SysUtils, wasmbin, lebutils, wasmbindebug, wasmlink, wasmlinkchange; function ReadStream(st: TStream): Boolean; var @@ -49,18 +49,85 @@ begin end; +procedure ReadWasmFile(const fn: string); var fs :TFileStream; begin - if ParamCount=0 then begin - writeln('please sepcify .wasm file'); - exit; - end; - fs := TFileStream.Create(ParamStr(1), fmOpenRead or fmShareDenyNone); + fs := TFileStream.Create(fn, fmOpenRead or fmShareDenyNone); try ReadStream(fs); finally fs.Free; 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 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. diff --git a/utils/wasmbin/wasmlinkchange.pas b/utils/wasmbin/wasmlinkchange.pas new file mode 100644 index 0000000000..83eff72e3a --- /dev/null +++ b/utils/wasmbin/wasmlinkchange.pas @@ -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