From 80a6fedea05dbdab2e55b2ba922faeaf4155a981 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 12 Feb 2019 19:40:42 -0800 Subject: cmd/compile: add -d=checkptr to validate unsafe.Pointer rules This CL adds -d=checkptr as a compile-time option for adding instrumentation to check that Go code is following unsafe.Pointer safety rules dynamically. In particular, it currently checks two things: 1. When converting unsafe.Pointer to *T, make sure the resulting pointer is aligned appropriately for T. 2. When performing pointer arithmetic, if the result points to a Go heap object, make sure we can find an unsafe.Pointer-typed operand that pointed into the same object. These checks are currently disabled for the runtime, and can also be disabled through a new //go:nocheckptr annotation. The latter is necessary for functions like strings.noescape, which intentionally violate safety rules to workaround escape analysis limitations. Fixes #22218. Change-Id: If5a51273881d93048f74bcff10a3275c9c91da6a Reviewed-on: https://go-review.googlesource.com/c/go/+/162237 Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/strings/builder.go | 1 + 1 file changed, 1 insertion(+) (limited to 'src/strings') diff --git a/src/strings/builder.go b/src/strings/builder.go index 3f33a87508..6ff151d74b 100644 --- a/src/strings/builder.go +++ b/src/strings/builder.go @@ -24,6 +24,7 @@ type Builder struct { // USE CAREFULLY! // This was copied from the runtime; see issues 23382 and 7921. //go:nosplit +//go:nocheckptr func noescape(p unsafe.Pointer) unsafe.Pointer { x := uintptr(p) return unsafe.Pointer(x ^ 0) -- cgit v1.3