From a7a7f2991a8650f93ed9fdeae4cf22c47477d909 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 6 Mar 2018 10:00:56 -0800 Subject: [PATCH] [wasm] enable kRetpoline on call_indirect Change-Id: If97eda2cc2da4501da7f4a753107f58c2797f237 Reviewed-on: https://chromium-review.googlesource.com/885181 Commit-Queue: Eric Holk Reviewed-by: Ben Titzer Cr-Commit-Position: refs/heads/master@{#51775} --- src/compiler/wasm-compiler.cc | 11 +++++++---- src/compiler/wasm-compiler.h | 4 ++-- src/compiler/wasm-linkage.cc | 24 +++++++++++++----------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index f43dfa7cf14b..f53ccd4112cd 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -2530,7 +2530,7 @@ Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node* function, Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args, Node*** rets, wasm::WasmCodePosition position, - Node* wasm_context) { + Node* wasm_context, bool use_retpoline) { if (wasm_context == nullptr) { DCHECK_NOT_NULL(wasm_context_); wasm_context = wasm_context_.get(); @@ -2551,7 +2551,8 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args, args[params + 2] = *effect_; args[params + 3] = *control_; - auto call_descriptor = GetWasmCallDescriptor(jsgraph()->zone(), sig); + auto call_descriptor = + GetWasmCallDescriptor(jsgraph()->zone(), sig, use_retpoline); const Operator* op = jsgraph()->common()->Call(call_descriptor); Node* call = graph()->NewNode(op, static_cast(count), args); SetSourcePosition(call, position); @@ -2697,8 +2698,10 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args, graph()->NewNode(machine->Int32Add(), key_offset, Uint32Constant(fixed_offset + kPointerSize)), *effect_, *control_); - args[0] = entry; - return BuildWasmCall(sig, args, rets, position); + args[0] = entry; + constexpr Node* wasm_context = nullptr; + const bool use_retpoline = FLAG_untrusted_code_mitigations; + return BuildWasmCall(sig, args, rets, position, wasm_context, use_retpoline); } Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { diff --git a/src/compiler/wasm-compiler.h b/src/compiler/wasm-compiler.h index e23fd4fe14c3..a4dcb7d83179 100644 --- a/src/compiler/wasm-compiler.h +++ b/src/compiler/wasm-compiler.h @@ -508,7 +508,7 @@ class WasmGraphBuilder { Node* BuildCCall(MachineSignature* sig, Node* function, Args... args); Node* BuildWasmCall(wasm::FunctionSig* sig, Node** args, Node*** rets, wasm::WasmCodePosition position, - Node* wasm_context = nullptr); + Node* wasm_context = nullptr, bool use_retpoline = false); Node* BuildF32CopySign(Node* left, Node* right); Node* BuildF64CopySign(Node* left, Node* right); @@ -631,7 +631,7 @@ class WasmGraphBuilder { constexpr int kWasmContextParameterIndex = 0; V8_EXPORT_PRIVATE CallDescriptor* GetWasmCallDescriptor( - Zone* zone, wasm::FunctionSig* signature); + Zone* zone, wasm::FunctionSig* signature, bool use_retpoline = false); V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptor( Zone* zone, CallDescriptor* call_descriptor); V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptorForSimd( diff --git a/src/compiler/wasm-linkage.cc b/src/compiler/wasm-linkage.cc index cef127f334d4..43f7c8f7a00b 100644 --- a/src/compiler/wasm-linkage.cc +++ b/src/compiler/wasm-linkage.cc @@ -223,7 +223,8 @@ static constexpr Allocator parameter_registers(kGPParamRegisters, } // namespace // General code uses the above configuration data. -CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig) { +CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig, + bool use_retpoline) { // The '+ 1' here is to accomodate the wasm_context as first parameter. LocationSignature::Builder locations(zone, fsig->return_count(), fsig->parameter_count() + 1); @@ -264,16 +265,17 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig) { ? CallDescriptor::kCallWasmFunction : CallDescriptor::kCallCodeObject; - return new (zone) CallDescriptor( // -- - kind, // kind - target_type, // target MachineType - target_loc, // target location - locations.Build(), // location_sig - params.stack_offset, // stack_parameter_count - compiler::Operator::kNoProperties, // properties - kCalleeSaveRegisters, // callee-saved registers - kCalleeSaveFPRegisters, // callee-saved fp regs - CallDescriptor::kNoFlags, // flags + return new (zone) CallDescriptor( // -- + kind, // kind + target_type, // target MachineType + target_loc, // target location + locations.Build(), // location_sig + params.stack_offset, // stack_parameter_count + compiler::Operator::kNoProperties, // properties + kCalleeSaveRegisters, // callee-saved registers + kCalleeSaveFPRegisters, // callee-saved fp regs + use_retpoline ? CallDescriptor::kRetpoline + : CallDescriptor::kNoFlags, // flags "wasm-call", // debug name 0, // allocatable registers rets.stack_offset - params.stack_offset); // stack_return_count