+ produce a target_features section when compiling with -CTwasmthreads

This commit is contained in:
Nikolay Nikolov 2022-05-28 04:04:02 +03:00
parent 1dd80d596d
commit 7cd082ba5f
2 changed files with 23 additions and 3 deletions

View File

@ -169,7 +169,7 @@ interface
implementation implementation
uses uses
verbose,version; verbose,version,globals;
procedure WriteUleb5(d: tdynamicarray; v: uint64); procedure WriteUleb5(d: tdynamicarray; v: uint64);
var var
@ -1655,6 +1655,19 @@ implementation
Writer.write(WasmModuleMagic,SizeOf(WasmModuleMagic)); Writer.write(WasmModuleMagic,SizeOf(WasmModuleMagic));
Writer.write(WasmVersion,SizeOf(WasmVersion)); Writer.write(WasmVersion,SizeOf(WasmVersion));
if ts_wasm_threads in current_settings.targetswitches then
begin
WriteUleb(FWasmCustomSections[wcstTargetFeatures],4);
WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
WriteName(FWasmCustomSections[wcstTargetFeatures],'atomics');
WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
WriteName(FWasmCustomSections[wcstTargetFeatures],'bulk-memory');
WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
WriteName(FWasmCustomSections[wcstTargetFeatures],'mutable-globals');
WriteUleb(FWasmCustomSections[wcstTargetFeatures],$2B);
WriteName(FWasmCustomSections[wcstTargetFeatures],'sign-ext');
end;
{ Write the producers section: { Write the producers section:
https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md } https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md }
WriteUleb(FWasmCustomSections[wcstProducers],2); WriteUleb(FWasmCustomSections[wcstProducers],2);
@ -1722,6 +1735,11 @@ implementation
end; end;
WriteWasmCustomSection(wcstProducers); WriteWasmCustomSection(wcstProducers);
Inc(section_nr); Inc(section_nr);
if ts_wasm_threads in current_settings.targetswitches then
begin
WriteWasmCustomSection(wcstTargetFeatures);
Inc(section_nr);
end;
result:=true; result:=true;
end; end;

View File

@ -50,14 +50,16 @@ type
wcstLinking, wcstLinking,
wcstRelocCode, wcstRelocCode,
wcstRelocData, wcstRelocData,
wcstProducers); wcstProducers,
wcstTargetFeatures);
const const
WasmCustomSectionName: array [TWasmCustomSectionType] of string = WasmCustomSectionName: array [TWasmCustomSectionType] of string =
('linking', ('linking',
'reloc.CODE', 'reloc.CODE',
'reloc.DATA', 'reloc.DATA',
'producers'); 'producers',
'target_features');
type type
TWasmRelocationType = ( TWasmRelocationType = (