[PATCH] D119666: [lld][WebAssembly] Apply global relocs before data relocs
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 13 08:02:35 PST 2022
sbc100 created this revision.
Herald added subscribers: wingo, ecnelises, sunfish, jgravelle-google, dschuff.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119666
Files:
lld/test/wasm/pie.ll
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ 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);
Index: lld/test/wasm/pie.ll
===================================================================
--- lld/test/wasm/pie.ll
+++ 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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119666.408264.patch
Type: text/x-patch
Size: 1725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220213/24593a46/attachment.bin>
More information about the llvm-commits
mailing list