mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 08:09:18 +02:00
[PATCH 057/188] adding an option to mark global variable as weak
From a6d126af643ab89eef0298482a9bc6d832d5a77d Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Tue, 26 Nov 2019 09:16:47 -0500 git-svn-id: branches/wasm@46053 -
This commit is contained in:
parent
8b1d615a77
commit
7029fd383a
@ -15,8 +15,9 @@ const
|
|||||||
ACT_EXPORTRENAME = 'exportrename';
|
ACT_EXPORTRENAME = 'exportrename';
|
||||||
ACT_SYMBOLFLAG = 'symbolflag';
|
ACT_SYMBOLFLAG = 'symbolflag';
|
||||||
ACT_SYMBOLAUTO = 'symbolauto';
|
ACT_SYMBOLAUTO = 'symbolauto';
|
||||||
|
ACT_WEAK = 'weak';
|
||||||
|
|
||||||
VERSION = '1.0';
|
VERSION = '1.1';
|
||||||
|
|
||||||
procedure PrintHelp;
|
procedure PrintHelp;
|
||||||
begin
|
begin
|
||||||
@ -27,14 +28,19 @@ begin
|
|||||||
writeln('options:');
|
writeln('options:');
|
||||||
writeln(' --exportrename @inputfile - renaming export names');
|
writeln(' --exportrename @inputfile - renaming export names');
|
||||||
writeln(' --symbolflag @inputfile - update symbol flags as specified in input');
|
writeln(' --symbolflag @inputfile - update symbol flags as specified in input');
|
||||||
writeln(' --symbolauto - update symbol by the use');
|
writeln(' --symbolauto - update symbol by the use ');
|
||||||
writeln(' --verbose - enabling verbose mode');
|
writeln(' --weak %name% - specify symbol names for global variables to be marked weak reference');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TToolActions }
|
{ TToolActions }
|
||||||
|
|
||||||
|
// it's assumed that the wasmtool will be instructed
|
||||||
|
// to take mulitple actions on the same file.
|
||||||
|
// thus every action is recorded as TToolActions
|
||||||
|
// Those are created during the parameters parsing
|
||||||
|
|
||||||
TToolActions = class(TObject)
|
TToolActions = class(TObject)
|
||||||
action : string; // action to take place
|
action : string; // action to take place
|
||||||
paramsFn : string; // input file name
|
paramsFn : string; // input file name
|
||||||
@ -53,7 +59,9 @@ end;
|
|||||||
procedure ProcessParams(acts: TList; const inputFn: string; doVerbose: Boolean);
|
procedure ProcessParams(acts: TList; const inputFn: string; doVerbose: Boolean);
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
|
j : integer;
|
||||||
ta : TToolActions;
|
ta : TToolActions;
|
||||||
|
wk : TStringList;
|
||||||
begin
|
begin
|
||||||
for i:=0 to acts.Count-1 do begin
|
for i:=0 to acts.Count-1 do begin
|
||||||
ta := TToolActions(acts[i]);
|
ta := TToolActions(acts[i]);
|
||||||
@ -66,8 +74,14 @@ begin
|
|||||||
ExportRename(inputFn, ta.paramsFn, doVerbose);
|
ExportRename(inputFn, ta.paramsFn, doVerbose);
|
||||||
end else if ta.action = ACT_SYMBOLFLAG then begin
|
end else if ta.action = ACT_SYMBOLFLAG then begin
|
||||||
ChangeSymbolFlag(inputFn, ta.paramsFn);
|
ChangeSymbolFlag(inputFn, ta.paramsFn);
|
||||||
end else if ta.action = ACT_SYMBOLAUTO then begin
|
end else if (ta.action = ACT_SYMBOLAUTO) then begin
|
||||||
PredictSymbolsFromLink(inputFn, doVerbose);
|
wk := TStringList.Create;
|
||||||
|
for j:=0 to acts.Count-1 do begin
|
||||||
|
if TToolActions(acts[j]).action = ACT_WEAK then
|
||||||
|
wk.Add( TToolActions(acts[j]).paramsFn );
|
||||||
|
end;
|
||||||
|
PredictSymbolsFromLink(inputFn, wk, doVerbose);
|
||||||
|
wk.free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -9,7 +9,7 @@ uses
|
|||||||
|
|
||||||
function ChangeSymbolFlagStream(st: TStream; syms: TStrings): Boolean;
|
function ChangeSymbolFlagStream(st: TStream; syms: TStrings): Boolean;
|
||||||
procedure ChangeSymbolFlag(const fn, symfn: string);
|
procedure ChangeSymbolFlag(const fn, symfn: string);
|
||||||
function PredictSymbolsFromLink(const wasmfn: string; doVerbose: Boolean = false): Boolean;
|
function PredictSymbolsFromLink(const wasmfn: string; weakList: TStrings; doVerbose: Boolean = false): Boolean;
|
||||||
|
|
||||||
procedure MatchExportNameToSymName(const x: TExportSection; const l: TLinkingSection; dst: TStrings);
|
procedure MatchExportNameToSymName(const x: TExportSection; const l: TLinkingSection; dst: TStrings);
|
||||||
function ExportRenameSym(var x: TExportSection; syms: TStrings): Integer;
|
function ExportRenameSym(var x: TExportSection; syms: TStrings): Integer;
|
||||||
@ -68,7 +68,9 @@ procedure MatchExportNameToSymFlag(
|
|||||||
const c: TCodeSection;
|
const c: TCodeSection;
|
||||||
const e: TElementSection;
|
const e: TElementSection;
|
||||||
const x: TExportSection;
|
const x: TExportSection;
|
||||||
var l: TLinkingSection; doVerbose: Boolean);
|
var l: TLinkingSection;
|
||||||
|
weakList: TStrings; // do known set of globals weak
|
||||||
|
doVerbose: Boolean);
|
||||||
type
|
type
|
||||||
TFuncType = (ftImpl = 0, ftIntf, ftStub, ftExport);
|
TFuncType = (ftImpl = 0, ftIntf, ftStub, ftExport);
|
||||||
|
|
||||||
@ -155,13 +157,19 @@ begin
|
|||||||
writeln;
|
writeln;
|
||||||
end;
|
end;
|
||||||
//if l.symbols[i].symindex>mx then mx := ;
|
//if l.symbols[i].symindex>mx then mx := ;
|
||||||
|
end else if (l.symbols[i].kind = SYMTAB_GLOBAL) and Assigned(weakList) then begin
|
||||||
|
if l.symbols[i].hasSymName and (weakList.IndexOf(l.symbols[i].symname)>=0) then begin
|
||||||
|
if doVerbose then
|
||||||
|
writeln('weakining: ',l.symbols[i].symname);
|
||||||
|
l.symbols[i].flags := l.symbols[i].flags or WASM_SYM_BINDING_WEAK or WASM_SYM_VISIBILITY_HIDDEN;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function PredictSymbolsFromLink(const wasmfn: string; doVerbose: Boolean = false): Boolean;
|
function PredictSymbolsFromLink(const wasmfn: string; weakList: TStrings; doVerbose: Boolean = false): Boolean;
|
||||||
var
|
var
|
||||||
st : TFileStream;
|
st : TFileStream;
|
||||||
dw : LongWord;
|
dw : LongWord;
|
||||||
@ -246,7 +254,7 @@ begin
|
|||||||
|
|
||||||
if Result then begin
|
if Result then begin
|
||||||
if doVerbose then writeln('detecting symbols');
|
if doVerbose then writeln('detecting symbols');
|
||||||
MatchExportNameToSymFlag(imp, c, e, x, l, doVerbose);
|
MatchExportNameToSymFlag(imp, c, e, x, l, weakList, doVerbose);
|
||||||
mem:=TMemoryStream.Create;
|
mem:=TMemoryStream.Create;
|
||||||
mem2:=TMemoryStream.Create;
|
mem2:=TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user