diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index b704677d36c93..3993fa249c13a 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -1366,6 +1366,14 @@ void Writer::createInitMemoryFunction() { writeUleb128(os, s->index, "segment index immediate"); writeU8(os, 0, "memory index immediate"); } + + // After initializing the TLS segment, we also need to apply TLS + // relocations in the same way __wasm_init_tls does. + if (s->isTLS() && ctx.sym.applyGlobalTLSRelocs) { + writeU8(os, WASM_OPCODE_CALL, "CALL"); + writeUleb128(os, ctx.sym.applyGlobalTLSRelocs->getFunctionIndex(), + "function index"); + } } } @@ -1518,8 +1526,8 @@ void Writer::createApplyGlobalRelocationsFunction() { } // Similar to createApplyGlobalRelocationsFunction but for -// TLS symbols. This cannot be run during the start function -// but must be delayed until __wasm_init_tls is called. +// TLS symbols. Can only be called after __tls_base is +// initialized. void Writer::createApplyGlobalTLSRelocationsFunction() { // First write the body's contents to a string. std::string bodyContent;