Commit f16c5f8d authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[arm] Don't allow use of SP as a scratch register

This would allow SP to be a nonsense value, which would confuse the CPU
profiler when the signal handler read the SP before it was restored.

Bug: v8:8355
Change-Id: If108c8cf00467904fe0f4f26fddc2e3122afcd93
Reviewed-on: https://chromium-review.googlesource.com/c/1298032Reviewed-by: 's avatarMartyn Capewell <martyn.capewell@arm.com>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56967}
parent 840242f4
......@@ -1167,7 +1167,7 @@ void Assembler::Move32BitImmediate(Register rd, const Operand& x,
DCHECK(!x.MustOutputRelocInfo(this));
UseScratchRegisterScope temps(this);
// Re-use the destination register as a scratch if possible.
Register target = rd != pc ? rd : temps.Acquire();
Register target = rd != pc && rd != sp ? rd : temps.Acquire();
uint32_t imm32 = static_cast<uint32_t>(x.immediate());
movw(target, imm32 & 0xFFFF, cond);
movt(target, imm32 >> 16, cond);
......@@ -1241,8 +1241,9 @@ void Assembler::AddrMode1(Instr instr, Register rd, Register rn,
// it first to a scratch register and change the original instruction to
// use it.
// Re-use the destination register if possible.
Register scratch =
(rd.is_valid() && rd != rn && rd != pc) ? rd : temps.Acquire();
Register scratch = (rd.is_valid() && rd != rn && rd != pc && rd != sp)
? rd
: temps.Acquire();
mov(scratch, x, LeaveCC, cond);
AddrMode1(instr, rd, rn, Operand(scratch));
}
......@@ -1307,8 +1308,9 @@ void Assembler::AddrMode2(Instr instr, Register rd, const MemOperand& x) {
UseScratchRegisterScope temps(this);
// Allow re-using rd for load instructions if possible.
bool is_load = (instr & L) == L;
Register scratch =
(is_load && rd != x.rn_ && rd != pc) ? rd : temps.Acquire();
Register scratch = (is_load && rd != x.rn_ && rd != pc && rd != sp)
? rd
: temps.Acquire();
mov(scratch, Operand(x.offset_), LeaveCC,
Instruction::ConditionField(instr));
AddrMode2(instr, rd, MemOperand(x.rn_, scratch, x.am_));
......@@ -1347,8 +1349,9 @@ void Assembler::AddrMode3(Instr instr, Register rd, const MemOperand& x) {
// register.
UseScratchRegisterScope temps(this);
// Allow re-using rd for load instructions if possible.
Register scratch =
(is_load && rd != x.rn_ && rd != pc) ? rd : temps.Acquire();
Register scratch = (is_load && rd != x.rn_ && rd != pc && rd != sp)
? rd
: temps.Acquire();
mov(scratch, Operand(x.offset_), LeaveCC,
Instruction::ConditionField(instr));
AddrMode3(instr, rd, MemOperand(x.rn_, scratch, x.am_));
......@@ -1362,7 +1365,7 @@ void Assembler::AddrMode3(Instr instr, Register rd, const MemOperand& x) {
UseScratchRegisterScope temps(this);
// Allow re-using rd for load instructions if possible.
Register scratch =
(is_load && rd != x.rn_ && rd != pc) ? rd : temps.Acquire();
(is_load && rd != x.rn_ && rd != pc && rd != sp) ? rd : temps.Acquire();
mov(scratch, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC,
Instruction::ConditionField(instr));
AddrMode3(instr, rd, MemOperand(x.rn_, scratch, x.am_));
......
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