forked from OSchip/llvm-project
[lld][WebAssembly] Apply global relocs before data relocs
Since the code for apply data relocations can sometimes use the values stored in he globals, they need to be relocated before the data relocations can be run. Fixes: https://github.com/emscripten-core/emscripten/issues/13398 Differential Revision: https://reviews.llvm.org/D119666
This commit is contained in:
parent
ef39235cb9
commit
dabbab6861
|
@ -88,8 +88,8 @@ declare void @external_func()
|
|||
|
||||
; 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 @@ declare void @external_func()
|
|||
|
||||
; 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:
|
||||
|
|
|
@ -1253,6 +1253,11 @@ void Writer::createStartFunction() {
|
|||
{
|
||||
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 @@ void Writer::createStartFunction() {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue