{ This file is part of wasmbin - a collection of WebAssembly binary utils. Copyright (C) 2019, 2020 Dmitry Boyarintsev Copyright (C) 2020 by the Free Pascal development team This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the GNU General Public License is available on the World Wide Web at . You can also obtain it by writing to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. } unit wasmlinkchange; {$mode objfpc}{$H+} interface uses Classes, SysUtils, wasmlink, wasmbin, lebutils; type TSymbolType = ( st_Nochange, st_Local, // 'L' st_Weak, // 'W' st_VisHidden, // 'H' visibility-local st_VisDefault // 'D' visibility default (not-hidden) ); TSymbolTypes = set of TSymbolType; TSymbolConfigure = class(TObject) symname : string; needtype : TSymbolType; end; procedure ReadSymbolsConf(const fn: string; dst: TStrings); procedure ReadSymbolsConf(src: TStream; dst: TStrings); procedure ProcessLinkingSection(st: TStream; syms: TStrings); implementation procedure ReadSymbolsConf(const fn: string; dst: TStrings); var fs: TFileStream; begin fs:=TFileStream.Create(fn, fmOpenRead or fmShareDenyNone); try ReadSymbolsConf(fs, dst); finally fs.Free; end; end; function StrToSymType(const s: string): TSymbolType; begin if length(s)=0 then Result:=st_Nochange else case upCase(s[1]) of 'L': Result:=st_Local; 'H': Result:=st_VisHidden; 'W': Result:=st_Weak; 'D': Result:=st_VisDefault; else Result:=st_Nochange; end; end; function StrToSymTypes(const s: string): TSymbolTypes; var i: integer; tt : TSymbolType; begin Result := []; for i:=1 to length(s) do begin tt := StrToSymType(s[i]); if tt <> st_Nochange then Include(Result, tt); end; end; procedure ReadSymbolsConf(src: TStream; dst: TStrings); begin dst.LoadFromStream(src); end; procedure ProcessLinkingSection(st: TStream; syms: TStrings); var mt : TLinkingMetadata; //en : Int64; sub : TLinkingSubSection; cnt : LongWord; nx : Int64; i : integer; si : TSymInfo; ofs : Int64; v : string; tt : TSymbolType; tts : TSymbolTypes; fl : LongWord; begin //en := st.Position+secsize; ReadMetadata(st, mt); writeln('version: ', mt.version); //while st.Position si.flags then begin st.Position := ofs; WriteSymInfo(st, si); end; end; //writeln(si.symname); end; st.Position:=nx; //end; end; end.