From 961042356ccf45e7d6247aa334323c44230586f6 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Sat, 10 Aug 2024 19:43:52 +0300 Subject: [PATCH] * WebAssembly threads internal linker: fix validation of R_WASM_GLOBAL_INDEX_LEB relocations in modules that support threads --- compiler/ogwasm.pas | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index f78e0612d9..8e76cf0dac 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -2700,9 +2700,16 @@ implementation InputError('R_WASM_SECTION_OFFSET_I32 must point to a SYMTAB_SECTION symbol'); exit; end; - if (RelocType=R_WASM_GLOBAL_INDEX_LEB) and (SymbolTable[RelocIndex].SymKind<>SYMTAB_GLOBAL) then + if (RelocType=R_WASM_GLOBAL_INDEX_LEB) and + not ((SymbolTable[RelocIndex].SymKind=SYMTAB_GLOBAL) or + ((ts_wasm_threads in current_settings.targetswitches) and + (SymbolTable[RelocIndex].SymKind=SYMTAB_DATA) and + ((SymbolTable[RelocIndex].SymFlags and WASM_SYM_TLS)<>0))) then begin - InputError('Relocation must point to a SYMTAB_GLOBAL symbol'); + if ts_wasm_threads in current_settings.targetswitches then + InputError('Relocation must point to a SYMTAB_GLOBAL symbol or a SYMTAB_DATA symbol with the WASM_SYM_TLS flag set') + else + InputError('Relocation must point to a SYMTAB_GLOBAL symbol'); exit; end; if (RelocType=R_WASM_TAG_INDEX_LEB) and (SymbolTable[RelocIndex].SymKind<>SYMTAB_EVENT) then