Skip to content

Commit 5c5a93e

Browse files
committed
deps: V8: cherry-pick 2b77ca200c56
Original commit message: [wasm][liftoff] Always zero-extend 32 bit offsets The upper 32 bits of the 64 bit offset register are not guaranteed to be cleared, so a zero-extension is needed. We already do the zero-extension in the case of explicit bounds checking, but this should also be done if the trap handler is enabled. [email protected] [email protected] Bug: v8:11809 Change-Id: I21e2535c701041d11fa06c176fa683d82db0a3f1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2917612 Commit-Queue: Thibaud Michaud <[email protected]> Reviewed-by: Clemens Backes <[email protected]> Cr-Commit-Position: refs/heads/master@{#74881} Refs: v8/v8@2b77ca2 PR-URL: #39337 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent cf49ebb commit 5c5a93e

File tree

8 files changed

+84
-13
lines changed

8 files changed

+84
-13
lines changed

Diff for: common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.15',
39+
'v8_embedder_string': '-node.16',
4040

4141
##### V8 defaults for Node.js #####
4242

Diff for: deps/v8/src/wasm/baseline/arm/liftoff-assembler-arm.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,8 @@ void LiftoffAssembler::StoreTaggedPointer(Register dst_addr,
766766
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
767767
Register offset_reg, uint32_t offset_imm,
768768
LoadType type, LiftoffRegList pinned,
769-
uint32_t* protected_load_pc, bool is_load_mem) {
769+
uint32_t* protected_load_pc, bool is_load_mem,
770+
bool i64_offset) {
770771
// Offsets >=2GB are statically OOB on 32-bit systems.
771772
DCHECK_LE(offset_imm, std::numeric_limits<int32_t>::max());
772773
liftoff::LoadInternal(this, dst, src_addr, offset_reg,

Diff for: deps/v8/src/wasm/baseline/arm64/liftoff-assembler-arm64.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,13 @@ inline CPURegister AcquireByType(UseScratchRegisterScope* temps,
126126
template <typename T>
127127
inline MemOperand GetMemOp(LiftoffAssembler* assm,
128128
UseScratchRegisterScope* temps, Register addr,
129-
Register offset, T offset_imm) {
129+
Register offset, T offset_imm,
130+
bool i64_offset = false) {
130131
if (offset.is_valid()) {
131-
if (offset_imm == 0) return MemOperand(addr.X(), offset.X());
132+
if (offset_imm == 0) {
133+
return i64_offset ? MemOperand(addr.X(), offset.X())
134+
: MemOperand(addr.X(), offset.W(), UXTW);
135+
}
132136
Register tmp = temps->AcquireX();
133137
DCHECK_GE(kMaxUInt32, offset_imm);
134138
assm->Add(tmp, offset.X(), offset_imm);
@@ -490,10 +494,11 @@ void LiftoffAssembler::StoreTaggedPointer(Register dst_addr,
490494
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
491495
Register offset_reg, uintptr_t offset_imm,
492496
LoadType type, LiftoffRegList pinned,
493-
uint32_t* protected_load_pc, bool is_load_mem) {
497+
uint32_t* protected_load_pc, bool is_load_mem,
498+
bool i64_offset) {
494499
UseScratchRegisterScope temps(this);
495-
MemOperand src_op =
496-
liftoff::GetMemOp(this, &temps, src_addr, offset_reg, offset_imm);
500+
MemOperand src_op = liftoff::GetMemOp(this, &temps, src_addr, offset_reg,
501+
offset_imm, i64_offset);
497502
if (protected_load_pc) *protected_load_pc = pc_offset();
498503
switch (type.value()) {
499504
case LoadType::kI32Load8U:

Diff for: deps/v8/src/wasm/baseline/ia32/liftoff-assembler-ia32.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ void LiftoffAssembler::StoreTaggedPointer(Register dst_addr,
388388
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
389389
Register offset_reg, uint32_t offset_imm,
390390
LoadType type, LiftoffRegList pinned,
391-
uint32_t* protected_load_pc, bool is_load_mem) {
391+
uint32_t* protected_load_pc, bool is_load_mem,
392+
bool i64_offset) {
392393
// Offsets >=2GB are statically OOB on 32-bit systems.
393394
DCHECK_LE(offset_imm, std::numeric_limits<int32_t>::max());
394395
DCHECK_EQ(type.value_type() == kWasmI64, dst.is_gp_pair());

Diff for: deps/v8/src/wasm/baseline/liftoff-assembler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class LiftoffAssembler : public TurboAssembler {
669669
inline void Load(LiftoffRegister dst, Register src_addr, Register offset_reg,
670670
uintptr_t offset_imm, LoadType type, LiftoffRegList pinned,
671671
uint32_t* protected_load_pc = nullptr,
672-
bool is_load_mem = false);
672+
bool is_load_mem = false, bool i64_offset = false);
673673
inline void Store(Register dst_addr, Register offset_reg,
674674
uintptr_t offset_imm, LiftoffRegister src, StoreType type,
675675
LiftoffRegList pinned,

Diff for: deps/v8/src/wasm/baseline/liftoff-compiler.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -2798,14 +2798,16 @@ class LiftoffCompiler {
27982798
// Only look at the slot, do not pop it yet (will happen in PopToRegister
27992799
// below, if this is not a statically-in-bounds index).
28002800
auto& index_slot = __ cache_state()->stack_state.back();
2801+
bool i64_offset = index_val.type == kWasmI64;
28012802
if (IndexStaticallyInBounds(index_slot, type.size(), &offset)) {
28022803
__ cache_state()->stack_state.pop_back();
28032804
DEBUG_CODE_COMMENT("load from memory (constant offset)");
28042805
LiftoffRegList pinned;
28052806
Register mem = pinned.set(__ GetUnusedRegister(kGpReg, pinned)).gp();
28062807
LOAD_INSTANCE_FIELD(mem, MemoryStart, kSystemPointerSize, pinned);
28072808
LiftoffRegister value = pinned.set(__ GetUnusedRegister(rc, pinned));
2808-
__ Load(value, mem, no_reg, offset, type, pinned, nullptr, true);
2809+
__ Load(value, mem, no_reg, offset, type, pinned, nullptr, true,
2810+
i64_offset);
28092811
__ PushRegister(kind, value);
28102812
} else {
28112813
LiftoffRegister full_index = __ PopToRegister();
@@ -2824,8 +2826,8 @@ class LiftoffCompiler {
28242826
LiftoffRegister value = pinned.set(__ GetUnusedRegister(rc, pinned));
28252827

28262828
uint32_t protected_load_pc = 0;
2827-
__ Load(value, mem, index, offset, type, pinned, &protected_load_pc,
2828-
true);
2829+
__ Load(value, mem, index, offset, type, pinned, &protected_load_pc, true,
2830+
i64_offset);
28292831
if (env_->use_trap_handler) {
28302832
AddOutOfLineTrap(decoder, WasmCode::kThrowWasmTrapMemOutOfBounds,
28312833
protected_load_pc);

Diff for: deps/v8/src/wasm/baseline/x64/liftoff-assembler-x64.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,11 @@ void LiftoffAssembler::AtomicLoad(LiftoffRegister dst, Register src_addr,
389389
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
390390
Register offset_reg, uintptr_t offset_imm,
391391
LoadType type, LiftoffRegList pinned,
392-
uint32_t* protected_load_pc, bool is_load_mem) {
392+
uint32_t* protected_load_pc, bool is_load_mem,
393+
bool i64_offset) {
394+
if (offset_reg != no_reg && !i64_offset) {
395+
AssertZeroExtended(offset_reg);
396+
}
393397
Operand src_op = liftoff::GetMemOp(this, src_addr, offset_reg, offset_imm);
394398
if (protected_load_pc) *protected_load_pc = pc_offset();
395399
switch (type.value()) {

Diff for: deps/v8/test/mjsunit/regress/wasm/regress-11809.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2021 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
//
5+
// Flags: --enable-testing-opcode-in-wasm --nowasm-tier-up --wasm-tier-mask-for-testing=2
6+
7+
load("test/mjsunit/wasm/wasm-module-builder.js");
8+
9+
var instance = (function () {
10+
var builder = new WasmModuleBuilder();
11+
builder.addMemory(1, 1, false /* exported */);
12+
13+
var sig_index = builder.addType(makeSig(
14+
[kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32,
15+
kWasmI32],
16+
[kWasmI32]));
17+
var sig_three = builder.addType(makeSig(
18+
[kWasmI64, kWasmI64, kWasmI64, kWasmI64, kWasmI64, kWasmI64, kWasmI64,
19+
kWasmI64],
20+
[]));
21+
22+
var zero = builder.addFunction("zero", kSig_i_i);
23+
var one = builder.addFunction("one", sig_index);
24+
var two = builder.addFunction("two", kSig_v_i);
25+
var three = builder.addFunction("three", sig_three).addBody([]);
26+
27+
zero.addBody([kExprLocalGet, 0, kExprI32LoadMem, 0, 0]);
28+
29+
one.addBody([
30+
kExprLocalGet, 7,
31+
kExprCallFunction, zero.index]);
32+
33+
two.addBody([
34+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
35+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
36+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
37+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
38+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
39+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
40+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
41+
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
42+
kExprCallFunction, three.index,
43+
kExprI32Const, 0,
44+
kExprI32Const, 0,
45+
kExprI32Const, 0,
46+
kExprI32Const, 0,
47+
kExprI32Const, 0,
48+
kExprI32Const, 0,
49+
kExprI32Const, 0,
50+
kExprI32Const, 0,
51+
kExprCallFunction, one.index,
52+
kExprDrop,
53+
]).exportFunc();
54+
55+
return builder.instantiate({});
56+
})();
57+
58+
instance.exports.two()

0 commit comments

Comments
 (0)