[lld] [WebAssembly] Generate a call to __wasm_apply_global_tls_relocs in __wasm_init_memory (PR #149832)
    Sam Clegg via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Oct 21 14:01:53 PDT 2025
    
    
  
sbc100 wrote:
> > Bug in lld: memory.init is called twice for the TLS region of the main thread.
> 
> This is only a bug if you require that `__wasm_tls_init` be called on the main thread; does that have to be the case?
> 
> I don't know of any cases where `__wasm_apply_global_tls_relocs` accesses globals pointing to non-DSO-local variables. If it is the case that only globals corresponding to DSO-local variables are accessed/initialized, then all that's needed for `__wasm_apply_global_tls_relocs` to work is `__tls_base`, which can be initialized before instantiation. As I understand, relocations involving symbols from other DL modules are performed entirely by the linker.
I feel like we've been over this already above. 
What you are saying may be true of `__wasm_apply_global_tls_relocs` but it is not true of `__wasm_apply_tls_relocs`.  `__wasm_tls_init` needs to be called after instantiation because of this latter function, even if technically the former could run during instantiation.
> Indeed, this is how it's done today in wasix-libc and our fork of clang, and we have not run into any issues with unintiailized globals. However, you mentioned:
> 
> > in particular applies relocations which must happen after the start function.
> 
> Is there something I'm missing? I don't know of any such relocations.
Perhaps none of the programs are you running have any relocation in `__wasm_apply_tls_relocs`?
Perhaps we need to construct construct such as program so show that `__wasm_tls_init` does need to be called after initialization on the main thread?  Presumably any such program would fail on your runtime today?
https://github.com/llvm/llvm-project/pull/149832
    
    
More information about the llvm-commits
mailing list