aboutsummaryrefslogtreecommitdiff
path: root/src/internal/bytealg
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2018-10-31 15:04:04 -0400
committerAustin Clements <austin@google.com>2018-11-12 20:27:16 +0000
commitef7ce57ac2da02aeceada27761c282e0718c6e14 (patch)
treebfde4649e9e2d40fd66b9c1138552e3a32488996 /src/internal/bytealg
parent4f3604d3f2b25905907742f48cd0feeec5b458e1 (diff)
downloadgo-ef7ce57ac2da02aeceada27761c282e0718c6e14.tar.xz
internal/bytealg, runtime: provide linknames for pushed symbols
The internal/bytealg package defines several symbols in the runtime, bytes, and strings packages in assembly, and the runtime package defines symbols in reflect and sync/atomic. Currently, there's no corresponding Go prototype for these symbols in the defining package. We're going to start depending on Go prototypes in the same package as their assembly definitions in order to provide ABI wrappers. Plus, these are good documentation and colocate type information with definitions, which could be useful for vet if it learned a little about linkname. This CL adds linknamed Go prototypes for all pushed symbols in internal/bytealg and runtime. For #27539. Change-Id: I9b0c12d935a75bb6af46b6761180d451c00f11b8 Reviewed-on: https://go-review.googlesource.com/c/146820 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/internal/bytealg')
-rw-r--r--src/internal/bytealg/compare_native.go9
-rw-r--r--src/internal/bytealg/equal_native.go12
2 files changed, 21 insertions, 0 deletions
diff --git a/src/internal/bytealg/compare_native.go b/src/internal/bytealg/compare_native.go
index d4ff61938c..b14aa8c72c 100644
--- a/src/internal/bytealg/compare_native.go
+++ b/src/internal/bytealg/compare_native.go
@@ -6,5 +6,14 @@
package bytealg
+import _ "unsafe" // For go:linkname
+
//go:noescape
func Compare(a, b []byte) int
+
+// The declaration below generates ABI wrappers for functions
+// implemented in assembly in this package but declared in another
+// package.
+
+//go:linkname abigen_runtime_cmpstring runtime.cmpstring
+func abigen_runtime_cmpstring(a, b string) int
diff --git a/src/internal/bytealg/equal_native.go b/src/internal/bytealg/equal_native.go
index b5c453086c..995f0749d4 100644
--- a/src/internal/bytealg/equal_native.go
+++ b/src/internal/bytealg/equal_native.go
@@ -4,11 +4,23 @@
package bytealg
+import "unsafe"
+
// Note: there's no equal_generic.go because every platform must implement at least memequal_varlen in assembly.
//go:noescape
func Equal(a, b []byte) bool
+// The declarations below generate ABI wrappers for functions
+// implemented in assembly in this package but declared in another
+// package.
+
// The compiler generates calls to runtime.memequal and runtime.memequal_varlen.
// In addition, the runtime calls runtime.memequal explicitly.
// Those functions are implemented in this package.
+
+//go:linkname abigen_runtime_memequal runtime.memequal
+func abigen_runtime_memequal(a, b unsafe.Pointer, size uintptr) bool
+
+//go:linkname abigen_runtime_memequal_varlen runtime.memequal_varlen
+func abigen_runtime_memequal_varlen(a, b unsafe.Pointer) bool