Commit ef26021d authored by Ben Shi's avatar Ben Shi Committed by Cherry Zhang

cmd/internal/obj/arm: check illegal base registers in ARM instructions

Wrong instructions "MOVW 8(F0), R1" and "MOVW R0<<0(F1), R1"
are silently accepted, and all Fx are treated as Rx.

The patch checks all those illegal base registers.

fixes #20724

Change-Id: I05d41bb43fe774b023205163b7daf4a846e9dc88
Reviewed-on: https://go-review.googlesource.com/46132
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 4b8bfa63
...@@ -3,6 +3,32 @@ ...@@ -3,6 +3,32 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
TEXT errors(SB),$0 TEXT errors(SB),$0
MOVW (F0), R1 // ERROR "illegal base register"
MOVB (F0), R1 // ERROR "illegal base register"
MOVH (F0), R1 // ERROR "illegal base register"
MOVF (F0), F1 // ERROR "illegal base register"
MOVD (F0), F1 // ERROR "illegal base register"
MOVW R1, (F0) // ERROR "illegal base register"
MOVB R2, (F0) // ERROR "illegal base register"
MOVH R3, (F0) // ERROR "illegal base register"
MOVF F4, (F0) // ERROR "illegal base register"
MOVD F5, (F0) // ERROR "illegal base register"
MOVM.IA (F1), [R0-R4] // ERROR "illegal base register"
MOVM.DA (F1), [R0-R4] // ERROR "illegal base register"
MOVM.IB (F1), [R0-R4] // ERROR "illegal base register"
MOVM.DB (F1), [R0-R4] // ERROR "illegal base register"
MOVM.IA [R0-R4], (F1) // ERROR "illegal base register"
MOVM.DA [R0-R4], (F1) // ERROR "illegal base register"
MOVM.IB [R0-R4], (F1) // ERROR "illegal base register"
MOVM.DB [R0-R4], (F1) // ERROR "illegal base register"
MOVW R0<<0(F1), R1 // ERROR "illegal base register"
MOVB R0<<0(F1), R1 // ERROR "illegal base register"
MOVW R1, R0<<0(F1) // ERROR "illegal base register"
MOVB R2, R0<<0(F1) // ERROR "illegal base register"
MOVF 0x00ffffff(F2), F1 // ERROR "illegal base register"
MOVD 0x00ffffff(F2), F1 // ERROR "illegal base register"
MOVF F2, 0x00ffffff(F2) // ERROR "illegal base register"
MOVD F2, 0x00ffffff(F2) // ERROR "illegal base register"
MULS.S R1, R2, R3, R4 // ERROR "invalid .S suffix" MULS.S R1, R2, R3, R4 // ERROR "invalid .S suffix"
ADD.P R1, R2, R3 // ERROR "invalid .P suffix" ADD.P R1, R2, R3 // ERROR "invalid .P suffix"
SUB.W R2, R3 // ERROR "invalid .W suffix" SUB.W R2, R3 // ERROR "invalid .W suffix"
......
...@@ -1343,6 +1343,27 @@ func (c *ctxt5) oplook(p *obj.Prog) *Optab { ...@@ -1343,6 +1343,27 @@ func (c *ctxt5) oplook(p *obj.Prog) *Optab {
} }
} }
// check illegal base register
switch a1 {
case C_SHIFT:
if p.From.Reg == 0 { // no base register
break
}
fallthrough
case C_SOREG, C_LOREG, C_HOREG, C_FOREG, C_ROREG, C_HFOREG, C_SROREG:
if p.From.Reg < REG_R0 || REG_R15 < p.From.Reg {
c.ctxt.Diag("illegal base register: %v", p)
}
default:
}
switch a3 {
case C_SOREG, C_LOREG, C_HOREG, C_FOREG, C_ROREG, C_HFOREG, C_SROREG, C_SHIFT:
if p.To.Reg < REG_R0 || REG_R15 < p.To.Reg {
c.ctxt.Diag("illegal base register: %v", p)
}
default:
}
// If current instruction has a .S suffix (flags update), // If current instruction has a .S suffix (flags update),
// we must use the constant pool instead of splitting it. // we must use the constant pool instead of splitting it.
if (a1 == C_RCON2A || a1 == C_RCON2S) && p.Scond&C_SBIT != 0 { if (a1 == C_RCON2A || a1 == C_RCON2S) && p.Scond&C_SBIT != 0 {
......
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