From b7ec33b4698b0ba8190b088aca811932f2d473a5 Mon Sep 17 00:00:00 2001 From: Yu Yin Date: Wed, 25 Sep 2019 15:54:06 +0800 Subject: [PATCH] [mips][wasm-c-api] Fix unaligned store. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when wasm have multiple returns but not aligned such as return {kWasmI32, kWasmI64, kWasmI64, kWasmI32 } like test/wasm-api-tests/multi-return.cc do, wasm compiler will generate store instructions but not unaligned store instructions to store the return values, this will cause check failed on mips simulator, the test maybe will successful on mips native machine if the host kernel can handle the unaligend stores. This patch also fix the return address offset. Change-Id: I7de93fdbef3341e7d0057f6ecbc95a9d2f86c943 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1824309 Commit-Queue: Clemens Backes [né Hammacher] Reviewed-by: Clemens Backes [né Hammacher] Reviewed-by: Jakob Kummerow Cr-Commit-Position: refs/heads/master@{#63963} --- src/compiler/backend/mips/code-generator-mips.cc | 5 +++-- src/compiler/backend/mips64/code-generator-mips64.cc | 3 ++- src/compiler/wasm-compiler.cc | 6 ++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/backend/mips/code-generator-mips.cc b/src/compiler/backend/mips/code-generator-mips.cc index 7d90873b41..7b922e7bc6 100644 --- a/src/compiler/backend/mips/code-generator-mips.cc +++ b/src/compiler/backend/mips/code-generator-mips.cc @@ -782,7 +782,8 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( Label start_call; bool isWasmCapiFunction = linkage()->GetIncomingDescriptor()->IsWasmCapiFunction(); - int offset = 48; + // from start_call to return address. + int offset = 40; #if V8_HOST_ARCH_MIPS if (__ emit_debug_code()) { offset += 16; @@ -794,7 +795,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( __ bind(&start_call); __ nal(); __ nop(); - __ Addu(ra, ra, offset); + __ Addu(ra, ra, offset - 8); // 8 = nop + nal __ sw(ra, MemOperand(fp, WasmExitFrameConstants::kCallingPCOffset)); __ mov(ra, kScratchReg); } diff --git a/src/compiler/backend/mips64/code-generator-mips64.cc b/src/compiler/backend/mips64/code-generator-mips64.cc index 7ff7053360..170b79390f 100644 --- a/src/compiler/backend/mips64/code-generator-mips64.cc +++ b/src/compiler/backend/mips64/code-generator-mips64.cc @@ -760,6 +760,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( Label start_call; bool isWasmCapiFunction = linkage()->GetIncomingDescriptor()->IsWasmCapiFunction(); + // from start_call to return address. int offset = 48; #if V8_HOST_ARCH_MIPS64 if (__ emit_debug_code()) { @@ -772,7 +773,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( __ bind(&start_call); __ nal(); __ nop(); - __ Daddu(ra, ra, offset); + __ Daddu(ra, ra, offset - 8); // 8 = nop + nal __ sd(ra, MemOperand(fp, WasmExitFrameConstants::kCallingPCOffset)); __ mov(ra, kScratchReg); } diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index 59da26b0f8..1568ba639c 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -6206,14 +6206,12 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { pos = 0; offset = 0; for (wasm::ValueType type : sig_->returns()) { - StoreRepresentation store_rep( - wasm::ValueTypes::MachineRepresentationFor(type), kNoWriteBarrier); Node* value = sig_->return_count() == 1 ? call : graph()->NewNode(mcgraph()->common()->Projection(pos), call, Control()); - SetEffect(graph()->NewNode(mcgraph()->machine()->Store(store_rep), - arg_buffer, Int32Constant(offset), value, + SetEffect(graph()->NewNode(GetSafeStoreOperator(offset, type), arg_buffer, + Int32Constant(offset), value, Effect(), Control())); offset += wasm::ValueTypes::ElementSizeInBytes(type); pos++;