+ WebAssembly internal linker: write the global section in the linker map file

This commit is contained in:
Nikolay Nikolov 2025-02-16 02:11:37 +02:00
parent 5a07867d20
commit c005544f3d
2 changed files with 18 additions and 2 deletions
compiler

View File

@ -5015,7 +5015,10 @@ implementation
exesec: TExeSection;
globals_count, i: Integer;
objsec: TWasmObjSection;
mapstr: string;
begin
if assigned(exemap) then
exemap.AddHeader('Global section');
exesec:=FindExeSection('.wasm_globals');
if not assigned(exesec) then
internalerror(2024010112);
@ -5031,6 +5034,8 @@ implementation
WriteByte(FWasmSections[wsiGlobal],1)
else
WriteByte(FWasmSections[wsiGlobal],0);
if assigned(exemap) then
WriteStr(mapstr,' Global[',i,'] ',wasm_basic_type_str[objsec.MainFuncSymbol.LinkingData.GlobalType],' mutable=',objsec.MainFuncSymbol.LinkingData.GlobalIsMutable,' <',objsec.MainFuncSymbol.Name,'> - init ');
{ initializer expr }
with objsec.MainFuncSymbol.LinkingData.GlobalInitializer do
case typ of
@ -5038,27 +5043,37 @@ implementation
begin
WriteByte(FWasmSections[wsiGlobal],$41); { i32.const }
WriteSleb(FWasmSections[wsiGlobal],init_i32);
if assigned(exemap) then
mapstr:=mapstr+'i32='+tostr(init_i32);
end;
wbt_i64:
begin
WriteByte(FWasmSections[wsiGlobal],$42); { i64.const }
WriteSleb(FWasmSections[wsiGlobal],init_i64);
if assigned(exemap) then
mapstr:=mapstr+'i64='+tostr(init_i64);
end;
wbt_f32:
begin
WriteByte(FWasmSections[wsiGlobal],$43); { f32.const }
WriteF32LE(FWasmSections[wsiGlobal],init_f32);
if assigned(exemap) then
WriteStr(mapstr,mapstr+'f32=',init_f32);
end;
wbt_f64:
begin
WriteByte(FWasmSections[wsiGlobal],$44); { f64.const }
WriteF64LE(FWasmSections[wsiGlobal],init_f64);
if assigned(exemap) then
WriteStr(mapstr,mapstr+'f64=',init_f64);
end;
wbt_funcref,
wbt_externref:
begin
WriteByte(FWasmSections[wsiGlobal],$D0); { ref.null }
WriteByte(FWasmSections[wsiGlobal],encode_wasm_basic_type(typ));
if assigned(exemap) then
mapstr:=mapstr+'ref.null '+wasm_basic_type_str[typ];
end;
else
internalerror(2024010114);
@ -5066,6 +5081,8 @@ implementation
WriteByte(FWasmSections[wsiGlobal],$0B); { end }
{ add entry for the name section }
AddToGlobalNameMap(i,objsec.MainFuncSymbol.Name);
if assigned(exemap) then
exemap.Add(mapstr);
end;
end;

View File

@ -163,6 +163,7 @@ uses
WasmNumberTypes = [wbt_i32, wbt_i64, wbt_f32, wbt_f64];
WasmReferenceTypes = [wbt_funcref, wbt_externref];
WasmVectorTypes = [wbt_v128];
wasm_basic_type_str : array [TWasmBasicType] of string = ('unknown','i32','i64','f32','f64','funcref','externref','v128');
{# First value of opcode enumeration }
firstop = low(tasmop);
@ -690,8 +691,6 @@ uses
end;
function TWasmFuncType.ToString: ansistring;
const
wasm_basic_type_str : array [TWasmBasicType] of string = ('unknown','i32','i64','f32','f64','funcref','externref','v128');
var
i: Integer;
begin