1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:10:12 -07:00

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: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Ben Shi 2017-06-20 03:03:12 +00:00 committed by Cherry Zhang
parent 4b8bfa6352
commit ef26021d30
2 changed files with 47 additions and 0 deletions

View File

@ -3,6 +3,32 @@
// license that can be found in the LICENSE file.
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"
ADD.P R1, R2, R3 // ERROR "invalid .P suffix"
SUB.W R2, R3 // ERROR "invalid .W suffix"

View File

@ -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),
// we must use the constant pool instead of splitting it.
if (a1 == C_RCON2A || a1 == C_RCON2S) && p.Scond&C_SBIT != 0 {