[wasm]: Load and store globals properly on big-endian

TEST=wasm-spec-tests/tests/exports,wasm-spec-tests/tests/data

Change-Id: I5c1001b00f2a7eab41e6e143afa19803969c0fe4
Reviewed-on: https://chromium-review.googlesource.com/1181022
Reviewed-by: Junliang Yan <jyan@ca.ibm.com>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Sreten Kovacevic <skovacevic@wavecomp.com>
Cr-Commit-Position: refs/heads/master@{#55274}
This commit is contained in:
Ivica Bogosavljevic 2018-08-20 13:46:26 +02:00 committed by Commit Bot
parent 4f0e9d6cb7
commit a4211ad6ee
2 changed files with 18 additions and 9 deletions

View File

@ -1294,7 +1294,8 @@ uint32_t InstanceBuilder::EvalUint32InitExpr(const WasmInitExpr& expr) {
return expr.val.i32_const;
case WasmInitExpr::kGlobalIndex: {
uint32_t offset = module_->globals[expr.val.global_index].offset;
return *reinterpret_cast<uint32_t*>(raw_buffer_ptr(globals_, offset));
return ReadLittleEndianValue<uint32_t>(
reinterpret_cast<Address>(raw_buffer_ptr(globals_, offset)));
}
default:
UNREACHABLE();

View File

@ -108,28 +108,36 @@ Address WasmGlobalObject::address() const {
return Address(array_buffer()->backing_store()) + offset();
}
int32_t WasmGlobalObject::GetI32() { return Memory::int32_at(address()); }
int32_t WasmGlobalObject::GetI32() {
return ReadLittleEndianValue<int32_t>(address());
}
int64_t WasmGlobalObject::GetI64() { return Memory::int64_at(address()); }
int64_t WasmGlobalObject::GetI64() {
return ReadLittleEndianValue<int64_t>(address());
}
float WasmGlobalObject::GetF32() { return Memory::float_at(address()); }
float WasmGlobalObject::GetF32() {
return ReadLittleEndianValue<float>(address());
}
double WasmGlobalObject::GetF64() { return Memory::double_at(address()); }
double WasmGlobalObject::GetF64() {
return ReadLittleEndianValue<double>(address());
}
void WasmGlobalObject::SetI32(int32_t value) {
Memory::int32_at(address()) = value;
WriteLittleEndianValue<int32_t>(address(), value);
}
void WasmGlobalObject::SetI64(int64_t value) {
Memory::int64_at(address()) = value;
WriteLittleEndianValue<int64_t>(address(), value);
}
void WasmGlobalObject::SetF32(float value) {
Memory::float_at(address()) = value;
WriteLittleEndianValue<float>(address(), value);
}
void WasmGlobalObject::SetF64(double value) {
Memory::double_at(address()) = value;
WriteLittleEndianValue<double>(address(), value);
}
// WasmInstanceObject