From 109ccdab2a7032d09b1d6a04aeb6ea214217fbd5 Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Sun, 26 May 2024 14:27:02 +0200 Subject: [PATCH] fix: remove go linkname (#406) --- noescape.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/noescape.go b/noescape.go index 09afed28..89078463 100644 --- a/noescape.go +++ b/noescape.go @@ -4,6 +4,18 @@ import ( "unsafe" ) -//go:linkname noescape runtime.noescape -//go:noescape -func noescape(p unsafe.Pointer) unsafe.Pointer +// noescape hides a pointer from escape analysis. noescape is +// the identity function but escape analysis doesn't think the +// output depends on the input. noescape is inlined and currently +// compiles down to zero instructions. +// USE CAREFULLY! +// +// This function is taken from Go std lib: +// https://github.com/golang/go/blob/master/src/runtime/stubs.go#L178 +// +//nolint:govet,staticcheck +//go:nosplit +func noescape(p unsafe.Pointer) unsafe.Pointer { + x := uintptr(p) + return unsafe.Pointer(x ^ 0) +}