From cafb36bf11c0ec30a5650a6f1200b0f046fc67a7 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Tue, 16 Jan 2018 03:00:04 +0000 Subject: [PATCH] cmd/internal/obj/arm64: fix assemble VLD1/VST1 bug The current code misassembles VLD1/VST1 instruction with non-zero offset. The offset is dropped silently without any error message. The cause of the misassembling is the current code treats argument (Rn)(Rm) as ZOREG type. The fix changes the matching rules and considers (Rn)(Rm) as ROFF type. The fix will report error information when assembles VLD1/VST1 (R8)(R13), [V1.16B]. The fix enables the ARM64Errors test. Fixes #23448 Change-Id: I3dd518b91e9960131ffb8efcb685cb8df84b70eb Reviewed-on: https://go-review.googlesource.com/87956 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/asm/internal/asm/endtoend_test.go | 4 ++++ src/cmd/asm/internal/asm/testdata/arm64error.s | 13 +++++++++++++ src/cmd/internal/obj/arm64/asm7.go | 14 +++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/cmd/asm/internal/asm/testdata/arm64error.s diff --git a/src/cmd/asm/internal/asm/endtoend_test.go b/src/cmd/asm/internal/asm/endtoend_test.go index e877a53178..d8a447d958 100644 --- a/src/cmd/asm/internal/asm/endtoend_test.go +++ b/src/cmd/asm/internal/asm/endtoend_test.go @@ -385,6 +385,10 @@ func TestARM64Encoder(t *testing.T) { testEndToEnd(t, "arm64", "arm64enc") } +func TestARM64Errors(t *testing.T) { + testErrors(t, "arm64", "arm64error") +} + func TestAMD64EndToEnd(t *testing.T) { testEndToEnd(t, "amd64", "amd64") } diff --git a/src/cmd/asm/internal/asm/testdata/arm64error.s b/src/cmd/asm/internal/asm/testdata/arm64error.s new file mode 100644 index 0000000000..97af09c4dd --- /dev/null +++ b/src/cmd/asm/internal/asm/testdata/arm64error.s @@ -0,0 +1,13 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +TEXT errors(SB),$0 + MOVD.P 300(R2), R3 // ERROR "offset out of range [-255,254]" + MOVD.P R3, 344(R2) // ERROR "offset out of range [-255,254]" + VLD1 (R8)(R13), [V2.B16] // ERROR "illegal combination" + VLD1 8(R9), [V2.B16] // ERROR "illegal combination" + VST1 [V1.B16], (R8)(R13) // ERROR "illegal combination" + VST1 [V1.B16], 9(R2) // ERROR "illegal combination" + VLD1 8(R8)(R13), [V2.B16] // ERROR "illegal combination" + RET diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 824fece550..fdf1fb565d 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -584,6 +584,7 @@ var optab = []Optab{ {AVADD, C_VREG, C_NONE, C_VREG, 89, 4, 0, 0, 0}, {AVLD1, C_ZOREG, C_NONE, C_LIST, 81, 4, 0, 0, 0}, {AVLD1, C_LOREG, C_NONE, C_LIST, 81, 4, 0, 0, C_XPOST}, + {AVLD1, C_ROFF, C_NONE, C_LIST, 81, 4, 0, 0, C_XPOST}, {AVMOV, C_ELEM, C_NONE, C_REG, 73, 4, 0, 0, 0}, {AVMOV, C_REG, C_NONE, C_ARNG, 82, 4, 0, 0, 0}, {AVMOV, C_ARNG, C_NONE, C_ARNG, 83, 4, 0, 0, 0}, @@ -592,6 +593,7 @@ var optab = []Optab{ {AVREV32, C_ARNG, C_NONE, C_ARNG, 83, 4, 0, 0, 0}, {AVST1, C_LIST, C_NONE, C_ZOREG, 84, 4, 0, 0, 0}, {AVST1, C_LIST, C_NONE, C_LOREG, 84, 4, 0, 0, C_XPOST}, + {AVST1, C_LIST, C_NONE, C_ROFF, 84, 4, 0, 0, C_XPOST}, {AVDUP, C_ELEM, C_NONE, C_ARNG, 79, 4, 0, 0, 0}, {AVADDV, C_ARNG, C_NONE, C_VREG, 85, 4, 0, 0, 0}, {AVMOVI, C_ADDCON, C_NONE, C_ARNG, 86, 4, 0, 0, 0}, @@ -1268,6 +1270,12 @@ func (c *ctxt7) aclass(a *obj.Addr) int { return autoclass(c.instoffset) case obj.NAME_NONE: + if a.Index != 0 { + if a.Offset != 0 { + return C_GOK + } + return C_ROFF + } c.instoffset = a.Offset return oregclass(c.instoffset) } @@ -1417,7 +1425,7 @@ func (c *ctxt7) oplook(p *obj.Prog) *Optab { } } - c.ctxt.Diag("illegal combination %v %v %v %v, %d %d", p, DRconv(a1), DRconv(a2), DRconv(a3), p.From.Type, p.To.Type) + c.ctxt.Diag("illegal combination: %v %v %v %v, %d %d", p, DRconv(a1), DRconv(a2), DRconv(a3), p.From.Type, p.To.Type) if ops == nil { ops = optab } @@ -2523,7 +2531,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { v := int32(p.From.Offset) if v < -256 || v > 255 { - c.ctxt.Diag("offset out of range\n%v", p) + c.ctxt.Diag("offset out of range [-255,254]: %v", p) } o1 = c.opldrpp(p, p.As) if o.scond == C_XPOST { @@ -2537,7 +2545,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { v := int32(p.To.Offset) if v < -256 || v > 255 { - c.ctxt.Diag("offset out of range\n%v", p) + c.ctxt.Diag("offset out of range [-255,254]: %v", p) } o1 = LD2STR(c.opldrpp(p, p.As)) if o.scond == C_XPOST { -- 2.50.0