cmd/compile: allow static init for unsafe.Pointer(&x) where x is global
This avoids both a write barrier and then dynamic initialization
globals of the form
var x something
var xp = unsafe.Pointer(&x)
Using static initialization avoids emitting a relocation for &x,
which helps cgo.
Fixes #9411.
Change-Id: I0dbf480859cce6ab57ab805d1b8609c45b48f156
Reviewed-on: https://go-review.googlesource.com/11693
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
diff --git a/test/sinit.go b/test/sinit.go
index df1a4cc..188a530 100644
--- a/test/sinit.go
+++ b/test/sinit.go
@@ -10,6 +10,8 @@
package p
+import "unsafe"
+
// Should be no init func in the assembly.
// All these initializations should be done at link time.
@@ -284,3 +286,6 @@
}
var _ Mer = (*T1)(nil)
+
+var Byte byte
+var PtrByte unsafe.Pointer = unsafe.Pointer(&Byte)