Skip to content

Commit

Permalink
cmd/internal/obj/arm: check illegal base registers in ARM instructions
Browse files Browse the repository at this point in the history
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 golang#20724

Change-Id: I05d41bb43fe774b023205163b7daf4a846e9dc88
Reviewed-on: https://go-review.googlesource.com/46132
Run-TryBot: Cherry Zhang <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
benshi001 authored and cherrymui committed Jun 30, 2017
1 parent 4b8bfa6 commit ef26021
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/cmd/asm/internal/asm/testdata/armerror.s
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions src/cmd/internal/obj/arm/asm5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ef26021

Please sign in to comment.