diff --git a/compiler/wasm32/cpubase.pas b/compiler/wasm32/cpubase.pas index 9c340da361..ba4865bb29 100644 --- a/compiler/wasm32/cpubase.pas +++ b/compiler/wasm32/cpubase.pas @@ -350,6 +350,17 @@ uses STACK_POINTER_SYM = '__stack_pointer'; { The exception tag symbol, used for FPC exceptions } FPC_EXCEPTION_TAG_SYM = '__FPC_exception'; + { Immutable global variable, created by the linker, when multithreading + support is enabled. Contains the total size (plus padding) of all the + threadvars, used by the program. } + TLS_SIZE_SYM = '__tls_size'; + { Immutable global variable, created by the linker, when multithreading + support is enabled. Contains the alignment requirement for the thread + local block. } + TLS_ALIGN_SYM = '__tls_align'; + { Mutable global variable, created by the linker, when multithreading + support is enabled. } + TLS_BASE_SYM = '__tls_base'; {***************************************************************************** Helpers diff --git a/compiler/wasm32/nwasmutil.pas b/compiler/wasm32/nwasmutil.pas index a02ecca0dd..f16027eb8e 100644 --- a/compiler/wasm32/nwasmutil.pas +++ b/compiler/wasm32/nwasmutil.pas @@ -98,6 +98,13 @@ implementation list.Concat(tai_globaltype.create(STACK_POINTER_SYM,wbt_i32,false)); + if ts_wasm_threads in current_settings.targetswitches then + begin + list.Concat(tai_globaltype.create(TLS_SIZE_SYM,wbt_i32,true)); + list.Concat(tai_globaltype.create(TLS_ALIGN_SYM,wbt_i32,true)); + list.Concat(tai_globaltype.create(TLS_BASE_SYM,wbt_i32,false)); + end; + if ts_wasm_native_exceptions in current_settings.targetswitches then begin list.Concat(tai_tagtype.create(FPC_EXCEPTION_TAG_SYM, []));