]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: add error check for move constant instructions on arm64
authorfanzha02 <fannie.zhang@arm.com>
Tue, 28 Sep 2021 05:46:14 +0000 (13:46 +0800)
committerfannie zhang <Fannie.Zhang@arm.com>
Thu, 30 Sep 2021 01:32:54 +0000 (01:32 +0000)
The current Go assembler encodes "MOVK $(0<<16|32|48), Rd" as the
same binary with "MOVK $0, Rd", but for arm64 move constant instructions
MOVK, MOVN and MOVZ, "op $0, Rd" and "op $(0<<16|32|48), Rd" have
different semantics. In order not to change the way the assembler
frontend parses constants, this patch adds a check for the zero shifts.

Change-Id: Ia844c419ce49f63605b549e3a2e98d9075dd1cf1
Reviewed-on: https://go-review.googlesource.com/c/go/+/275812
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: fannie zhang <Fannie.Zhang@arm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/asm/internal/asm/testdata/arm64error.s
src/cmd/internal/obj/arm64/asm7.go

index 7b006432c079394630c109a3f645c72c0e07122f..3d3de1d9b13770ba9efbd403359a7b0a1abac0d6 100644 (file)
@@ -430,4 +430,6 @@ TEXT errors(SB),$0
        STP     (R3, R4), 0x1234567(R27)                         // ERROR "REGTMP used in large offset store"
        LDP     0x1234567(R27), (R3, R4)                         // ERROR "REGTMP used in large offset load"
        STP     (R26, R27), 700(R2)                              // ERROR "cannot use REGTMP as source"
+       MOVK    $0, R10                                          // ERROR "zero shifts cannot be handled correctly"
+       MOVK    $(0<<32), R10                                    // ERROR "zero shifts cannot be handled correctly"
        RET
index 5d6caaed5f8e3c34cb5c33df0455bc90f28faf78..68f0921d4d9aa4cecb22122ab512bc9c867ef115 100644 (file)
@@ -3877,6 +3877,9 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
                o1 = c.opirr(p, p.As)
 
                d := p.From.Offset
+               if d == 0 {
+                       c.ctxt.Diag("zero shifts cannot be handled correctly: %v", p)
+               }
                s := movcon(d)
                if s < 0 || s >= 4 {
                        c.ctxt.Diag("bad constant for MOVK: %#x\n%v", uint64(d), p)