]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/7g: reserve registers R26 to R32
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 3 Apr 2015 16:43:43 +0000 (12:43 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 3 Apr 2015 18:25:09 +0000 (18:25 +0000)
These registers are not available for programs to use. Prior to this
change, the compiler would crash attempting to use ZR as a general
purpose register. Other programs would compile but on execution would
overwrite the G register and cause havoc.

Fixes linux/arm64 build.
Fixes #10304
Fixes #10320

Change-Id: I5cf51d3b77cfe3db7dd6377324950cafb02f8d8b
Reviewed-on: https://go-review.googlesource.com/8456
Reviewed-by: Minux Ma <minux@golang.org>
src/cmd/7g/reg.go
test/fixedbugs/issue10320.go [new file with mode: 0644]

index c8035f5663769092ebd16a8a0061a7d76e8dcbca..bf957c59683d34cbbd327c77ae6495d8940bf287 100644 (file)
@@ -115,6 +115,11 @@ func excludedregs() uint64 {
        // Exclude registers with fixed functions
        regbits := uint64(RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2) | RtoB(arm64.REGPR))
 
+       // Exclude R26 - R31.
+       for r := arm64.REGMAX + 1; r <= arm64.REGZERO; r++ {
+               regbits |= RtoB(r)
+       }
+
        // Also exclude floating point registers with fixed constants
        regbits |= RtoB(arm64.REG_F27) | RtoB(arm64.REG_F28) | RtoB(arm64.REG_F29) | RtoB(arm64.REG_F30) | RtoB(arm64.REG_F31)
 
diff --git a/test/fixedbugs/issue10320.go b/test/fixedbugs/issue10320.go
new file mode 100644 (file)
index 0000000..697aad1
--- /dev/null
@@ -0,0 +1,55 @@
+// run
+
+// Copyright 2015 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.
+
+// Issue 10320: 7g failed to compile a program because it attempted
+// to use ZR as register. Other programs compiled but failed to
+// execute correctly because they clobbered the g register.
+
+package main
+
+func main() {
+       var x00, x01, x02, x03, x04, x05, x06, x07, x08, x09 int
+       var x10, x11, x12, x13, x14, x15, x16, x17, x18, x19 int
+       var x20, x21, x22, x23, x24, x25, x26, x27, x28, x29 int
+       var x30, x31, x32 int
+
+       _ = x00
+       _ = x01
+       _ = x02
+       _ = x03
+       _ = x04
+       _ = x05
+       _ = x06
+       _ = x07
+       _ = x08
+       _ = x09
+
+       _ = x10
+       _ = x11
+       _ = x12
+       _ = x13
+       _ = x14
+       _ = x15
+       _ = x16
+       _ = x17
+       _ = x18
+       _ = x19
+
+       _ = x20
+       _ = x21
+       _ = x22
+       _ = x23
+       _ = x24
+       _ = x25
+       _ = x26
+       _ = x27
+       _ = x28
+       _ = x29
+
+       _ = x30
+       _ = x31
+       _ = x32
+}