Skip to content

Commit c876bf9

Browse files
committed
cmd/internal/obj/wasm: use 64-bit instructions for indirect calls
Currently, on Wasm, an indirect call is compiled to // function index = PC>>16, PC is already on stack I32WrapI64 I32Const $16 ShrU // set PC_B to 0 ... // actual call CallIndirect Specifically, the function index is extracted from bits 16-31 of the "PC". When there are more than 65536 functions, this will overflow and wrap around, causing wrong function being called. This CL changes it to use 64-bit operations to extract the function index from the "PC", so there are enough bits to for it. For #64856. Change-Id: I83c11db4b78cf66250e88ac02a82bd13730a8914 Reviewed-on: https://go-review.googlesource.com/c/go/+/567896 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent b4309ec commit c876bf9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎src/cmd/internal/obj/wasm/wasmobj.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ func preprocess(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
465465

466466
case obj.TYPE_NONE:
467467
// (target PC is on stack)
468+
p = appendp(p, AI64Const, constAddr(16)) // only needs PC_F bits (16-63), PC_B bits (0-15) are zero
469+
p = appendp(p, AI64ShrU)
468470
p = appendp(p, AI32WrapI64)
469-
p = appendp(p, AI32Const, constAddr(16)) // only needs PC_F bits (16-31), PC_B bits (0-15) are zero
470-
p = appendp(p, AI32ShrU)
471471

472472
// Set PC_B parameter to function entry.
473473
// We need to push this before pushing the target PC_F,
@@ -521,9 +521,9 @@ func preprocess(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
521521

522522
case obj.TYPE_NONE:
523523
// (target PC is on stack)
524+
p = appendp(p, AI64Const, constAddr(16)) // only needs PC_F bits (16-63), PC_B bits (0-15) are zero
525+
p = appendp(p, AI64ShrU)
524526
p = appendp(p, AI32WrapI64)
525-
p = appendp(p, AI32Const, constAddr(16)) // only needs PC_F bits (16-31), PC_B bits (0-15) are zero
526-
p = appendp(p, AI32ShrU)
527527

528528
// Set PC_B parameter to function entry.
529529
// We need to push this before pushing the target PC_F,

0 commit comments

Comments
 (0)