[mips][wasm-c-api] Fix unaligned store.

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] <clemensh@chromium.org>
Reviewed-by: Clemens Backes [né Hammacher] <clemensh@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63963}
This commit is contained in:
Yu Yin 2019-09-25 15:54:06 +08:00 committed by Commit Bot
parent db90b8d644
commit b7ec33b469
3 changed files with 7 additions and 7 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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++;