Skip to content

[lld][WebAssembly] Fix use of uninitialized stack data with --wasm64 #107780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Sep 8, 2024

In the case of -wasm64 we were setting the type of the init expression to be 64-bit but were only setting the low 32-bits of the value (by assigning to Int32).

Fixes: emscripten-core/emscripten#22538

In the case of `-wasm64` we were setting the type of the init expression
to be 64-bit but were only setting the low 32-bits of the value (by
assigning to Int32).

Fixes: emscripten-core/emscripten#22538
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-wasm

Author: Sam Clegg (sbc100)

Changes

In the case of -wasm64 we were setting the type of the init expression to be 64-bit but were only setting the low 32-bits of the value (by assigning to Int32).

Fixes: emscripten-core/emscripten#22538


Full diff: https://github.com/llvm/llvm-project/pull/107780.diff

1 Files Affected:

  • (modified) lld/wasm/SyntheticSections.cpp (+1-2)
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index f02f55519a2512..72d08b849d8e86 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -587,8 +587,7 @@ void ElemSection::writeBody() {
     initExpr.Inst.Value.Global = WasmSym::tableBase->getGlobalIndex();
   } else {
     bool is64 = config->is64.value_or(false);
-    initExpr.Inst.Opcode = is64 ? WASM_OPCODE_I64_CONST : WASM_OPCODE_I32_CONST;
-    initExpr.Inst.Value.Int32 = config->tableBase;
+    initExpr = intConst(config->tableBase, is64);
   }
   writeInitExpr(os, initExpr);
 

@sbc100 sbc100 requested a review from dschuff September 8, 2024 22:56
@sbc100 sbc100 merged commit 5c8fd1e into llvm:main Sep 9, 2024
11 checks passed
@sbc100 sbc100 deleted the fix_uninit branch September 9, 2024 16:28
@sbc100 sbc100 changed the title [lld][WebAssembly] Fix used of uninitialized stack data with -wasm64 [lld][WebAssembly] Fix use of uninitialized stack data with --wasm64 Sep 9, 2024
adambratschikaye pushed a commit to adambratschikaye/llvm-project that referenced this pull request Dec 12, 2024
…lvm#107780)

In the case of `--wasm64` we were setting the type of the init expression
to be 64-bit but were only setting the low 32-bits of the value (by
assigning to Int32).

Fixes: emscripten-core/emscripten#22538
dschuff pushed a commit to llvmbot/llvm-project that referenced this pull request Dec 16, 2024
…lvm#107780)

In the case of `--wasm64` we were setting the type of the init expression
to be 64-bit but were only setting the low 32-bits of the value (by
assigning to Int32).

Fixes: emscripten-core/emscripten#22538
(cherry picked from commit 5c8fd1e)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Dec 17, 2024
…lvm#107780)

In the case of `--wasm64` we were setting the type of the init expression
to be 64-bit but were only setting the low 32-bits of the value (by
assigning to Int32).

Fixes: emscripten-core/emscripten#22538
(cherry picked from commit 5c8fd1e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wasm MEMORY64: RuntimeError: WebAssembly.instantiate(): table index is out of bounds
3 participants