diff --git a/lld/test/wasm/pie.ll b/lld/test/wasm/pie.ll --- a/lld/test/wasm/pie.ll +++ b/lld/test/wasm/pie.ll @@ -88,8 +88,8 @@ ; DISASSEM: <__wasm_start>: ; DISASSEM-EMPTY: -; DISASSEM-NEXT: call 2 ; DISASSEM-NEXT: call 3 +; DISASSEM-NEXT: call 2 ; DISASSEM-NEXT: end ; Run the same test with threading support. In this mode @@ -107,8 +107,8 @@ ; DISASSEM-SHMEM: <__wasm_start>: ; DISASSEM-SHMEM-EMPTY: -; DISASSEM-SHMEM-NEXT: call 3 ; DISASSEM-SHMEM-NEXT: call 5 +; DISASSEM-SHMEM-NEXT: call 3 ; DISASSEM-SHMEM-NEXT: end ; SHMEM: FunctionNames: diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -1253,6 +1253,11 @@ { raw_string_ostream os(bodyContent); writeUleb128(os, 0, "num locals"); + if (WasmSym::applyGlobalRelocs) { + writeU8(os, WASM_OPCODE_CALL, "CALL"); + writeUleb128(os, WasmSym::applyGlobalRelocs->getFunctionIndex(), + "function index"); + } if (WasmSym::initMemory) { writeU8(os, WASM_OPCODE_CALL, "CALL"); writeUleb128(os, WasmSym::initMemory->getFunctionIndex(), @@ -1264,11 +1269,6 @@ writeUleb128(os, WasmSym::applyDataRelocs->getFunctionIndex(), "function index"); } - if (WasmSym::applyGlobalRelocs) { - writeU8(os, WASM_OPCODE_CALL, "CALL"); - writeUleb128(os, WasmSym::applyGlobalRelocs->getFunctionIndex(), - "function index"); - } writeU8(os, WASM_OPCODE_END, "END"); } createFunction(WasmSym::startFunction, bodyContent);