[lld] dabbab6 - [lld][WebAssembly] Apply global relocs before data relocs
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 16 14:31:24 PST 2022
Author: Sam Clegg
Date: 2022-02-16T14:30:39-08:00
New Revision: dabbab6861512453aa8f864ef863d31c1d57aa3e
URL: https://github.com/llvm/llvm-project/commit/dabbab6861512453aa8f864ef863d31c1d57aa3e
DIFF: https://github.com/llvm/llvm-project/commit/dabbab6861512453aa8f864ef863d31c1d57aa3e.diff
LOG: [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
Added:
Modified:
lld/test/wasm/pie.ll
lld/wasm/Writer.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/pie.ll b/lld/test/wasm/pie.ll
index 40159e79cdcae..0ae1c9ed416cf 100644
--- a/lld/test/wasm/pie.ll
+++ b/lld/test/wasm/pie.ll
@@ -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:
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 95f6483e9e591..621e48e7f273a 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -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);
More information about the llvm-commits
mailing list