Commit a9d90018 authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Fix up mips & WasmCodeManager

Corrected mips code generation for WASM_CALL and JS_TO_WASM_CALL.

The logic for fetching raw call sites needed changing, too, in light
of mips' 2-instruction calls, where using target_address_address is
incorrect. The CL adds platform-specific accessors.

Bug: chromium:793292 chromium:793282
Change-Id: I879ea6bffdad60791d88a6f5ea15087cdcd3f2e9
Reviewed-on: https://chromium-review.googlesource.com/818460Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarIvica Bogosavljevic <ivica.bogosavljevic@mips.com>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50037}
parent 62f09de9
...@@ -787,7 +787,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -787,7 +787,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
__ Call(wasm_code, info()->IsWasm() ? RelocInfo::WASM_CALL __ Call(wasm_code, info()->IsWasm() ? RelocInfo::WASM_CALL
: RelocInfo::JS_TO_WASM_CALL); : RelocInfo::JS_TO_WASM_CALL);
} else { } else {
__ Call(at, i.InputRegister(0), 0); __ Call(i.InputRegister(0));
} }
RecordCallPosition(instr); RecordCallPosition(instr);
frame_access_state()->ClearSPDelta(); frame_access_state()->ClearSPDelta();
...@@ -816,7 +816,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -816,7 +816,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
__ Jump(wasm_code, info()->IsWasm() ? RelocInfo::WASM_CALL __ Jump(wasm_code, info()->IsWasm() ? RelocInfo::WASM_CALL
: RelocInfo::JS_TO_WASM_CALL); : RelocInfo::JS_TO_WASM_CALL);
} else { } else {
__ Jump(at, i.InputRegister(0), 0); __ Jump(i.InputRegister(0));
} }
frame_access_state()->ClearSPDelta(); frame_access_state()->ClearSPDelta();
frame_access_state()->SetFrameAccessToDefault(); frame_access_state()->SetFrameAccessToDefault();
......
...@@ -77,15 +77,13 @@ void RelocInfo::apply(intptr_t delta) { ...@@ -77,15 +77,13 @@ void RelocInfo::apply(intptr_t delta) {
Address RelocInfo::target_address() { Address RelocInfo::target_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) || IsWasmCall(rmode_));
return Assembler::target_address_at(pc_, host_); return Assembler::target_address_at(pc_, host_);
} }
Address RelocInfo::target_address_address() { Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) || DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) || IsWasmCall(rmode_) ||
IsRuntimeEntry(rmode_) || rmode_ == EMBEDDED_OBJECT || rmode_ == EXTERNAL_REFERENCE);
rmode_ == EMBEDDED_OBJECT ||
rmode_ == EXTERNAL_REFERENCE);
// Read the address of the word containing the target_address in an // Read the address of the word containing the target_address in an
// instruction stream. // instruction stream.
// The only architecture-independent user of this function is the serializer. // The only architecture-independent user of this function is the serializer.
......
...@@ -77,7 +77,7 @@ void RelocInfo::apply(intptr_t delta) { ...@@ -77,7 +77,7 @@ void RelocInfo::apply(intptr_t delta) {
Address RelocInfo::target_address() { Address RelocInfo::target_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) || IsWasmCall(rmode_));
return Assembler::target_address_at(pc_, host_); return Assembler::target_address_at(pc_, host_);
} }
......
...@@ -506,8 +506,7 @@ void NativeModule::Link(uint32_t index) { ...@@ -506,8 +506,7 @@ void NativeModule::Link(uint32_t index) {
for (RelocIterator it(code->instructions(), code->reloc_info(), for (RelocIterator it(code->instructions(), code->reloc_info(),
code->constant_pool(), mode_mask); code->constant_pool(), mode_mask);
!it.done(); it.next()) { !it.done(); it.next()) {
uint32_t index = uint32_t index = GetWasmCalleeTag(it.rinfo());
*(reinterpret_cast<uint32_t*>(it.rinfo()->target_address_address()));
const WasmCode* target = GetCode(index); const WasmCode* target = GetCode(index);
if (target == nullptr) continue; if (target == nullptr) continue;
Address target_addr = target->instructions().start(); Address target_addr = target->instructions().start();
...@@ -976,6 +975,29 @@ NativeModuleModificationScope::~NativeModuleModificationScope() { ...@@ -976,6 +975,29 @@ NativeModuleModificationScope::~NativeModuleModificationScope() {
} }
} }
// On Intel, call sites are encoded as a displacement. For linking
// and for serialization/deserialization, we want to store/retrieve
// a tag (the function index). On Intel, that means accessing the
// raw displacement. Everywhere else, that simply means accessing
// the target address.
void SetWasmCalleeTag(RelocInfo* rinfo, uint32_t tag) {
#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
*(reinterpret_cast<uint32_t*>(rinfo->target_address_address())) = tag;
#else
rinfo->set_target_address(nullptr, reinterpret_cast<Address>(tag),
SKIP_WRITE_BARRIER, SKIP_ICACHE_FLUSH);
#endif
}
uint32_t GetWasmCalleeTag(RelocInfo* rinfo) {
#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
return *(reinterpret_cast<uint32_t*>(rinfo->target_address_address()));
#else
return static_cast<uint32_t>(
reinterpret_cast<size_t>(rinfo->target_address()));
#endif
}
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -414,6 +414,13 @@ class NativeModuleModificationScope final { ...@@ -414,6 +414,13 @@ class NativeModuleModificationScope final {
NativeModule* native_module_; NativeModule* native_module_;
}; };
// Utilities specific to wasm code generation. We embed a tag for call sites -
// the index of the called function - when serializing and when creating the
// code, initially. These APIs offer accessors. The implementation has platform
// specific nuances.
void SetWasmCalleeTag(RelocInfo* rinfo, uint32_t tag);
uint32_t GetWasmCalleeTag(RelocInfo* rinfo);
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -24,18 +24,6 @@ namespace internal { ...@@ -24,18 +24,6 @@ namespace internal {
namespace wasm { namespace wasm {
namespace { namespace {
void SetRawTargetData(RelocInfo* rinfo, uint32_t value) {
if (rinfo->target_address_size() == sizeof(uint32_t)) {
*(reinterpret_cast<uint32_t*>(rinfo->target_address_address())) = value;
return;
} else {
DCHECK_EQ(rinfo->target_address_size(), sizeof(intptr_t));
DCHECK_EQ(rinfo->target_address_size(), 8);
*(reinterpret_cast<intptr_t*>(rinfo->target_address_address())) =
static_cast<intptr_t>(value);
return;
}
}
class Writer { class Writer {
public: public:
...@@ -373,17 +361,17 @@ void NativeModuleSerializer::BufferCodeInAllocatedScratch( ...@@ -373,17 +361,17 @@ void NativeModuleSerializer::BufferCodeInAllocatedScratch(
case RelocInfo::CODE_TARGET: { case RelocInfo::CODE_TARGET: {
Address orig_target = orig_iter.rinfo()->target_address(); Address orig_target = orig_iter.rinfo()->target_address();
uint32_t tag = EncodeBuiltinOrStub(orig_target); uint32_t tag = EncodeBuiltinOrStub(orig_target);
SetRawTargetData(iter.rinfo(), tag); SetWasmCalleeTag(iter.rinfo(), tag);
} break; } break;
case RelocInfo::WASM_CALL: { case RelocInfo::WASM_CALL: {
Address orig_target = orig_iter.rinfo()->wasm_call_address(); Address orig_target = orig_iter.rinfo()->wasm_call_address();
uint32_t tag = wasm_targets_lookup_[orig_target]; uint32_t tag = wasm_targets_lookup_[orig_target];
SetRawTargetData(iter.rinfo(), tag); SetWasmCalleeTag(iter.rinfo(), tag);
} break; } break;
case RelocInfo::RUNTIME_ENTRY: { case RelocInfo::RUNTIME_ENTRY: {
Address orig_target = orig_iter.rinfo()->target_address(); Address orig_target = orig_iter.rinfo()->target_address();
uint32_t tag = reference_table_lookup_[orig_target]; uint32_t tag = reference_table_lookup_[orig_target];
SetRawTargetData(iter.rinfo(), tag); SetWasmCalleeTag(iter.rinfo(), tag);
} break; } break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -579,8 +567,7 @@ bool NativeModuleDeserializer::ReadCode() { ...@@ -579,8 +567,7 @@ bool NativeModuleDeserializer::ReadCode() {
SKIP_WRITE_BARRIER); SKIP_WRITE_BARRIER);
} }
case RelocInfo::CODE_TARGET: { case RelocInfo::CODE_TARGET: {
uint32_t tag = *(reinterpret_cast<uint32_t*>( uint32_t tag = GetWasmCalleeTag(iter.rinfo());
iter.rinfo()->target_address_address()));
Address target = GetTrampolineOrStubFromTag(tag); Address target = GetTrampolineOrStubFromTag(tag);
iter.rinfo()->set_target_address(nullptr, target, SKIP_WRITE_BARRIER, iter.rinfo()->set_target_address(nullptr, target, SKIP_WRITE_BARRIER,
SKIP_ICACHE_FLUSH); SKIP_ICACHE_FLUSH);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment