aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2025-07-23 14:46:22 -0400
committerGopher Robot <gobot@golang.org>2025-08-05 09:52:44 -0700
commita2c45f0eb1f281ed39c5111dd0fe4b2728f11cf3 (patch)
tree65ebc95b25980441e184fda464a45d2683f9f317 /src/runtime
parentcd55f86b8dcfc139ee5c17d32530ac9e758c8bc0 (diff)
downloadgo-a2c45f0eb1f281ed39c5111dd0fe4b2728f11cf3.tar.xz
runtime: test VDSO symbol hash values
In addition to verifying existing values, this makes it easier to add a new one by adding an invalid entry and running the test. Change-Id: I6a6a636c9c413add29884e4f6759196f4db34de7 Reviewed-on: https://go-review.googlesource.com/c/go/+/693276 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/export_vdso_linux_test.go29
-rw-r--r--src/runtime/vdso_linux_test.go52
2 files changed, 81 insertions, 0 deletions
diff --git a/src/runtime/export_vdso_linux_test.go b/src/runtime/export_vdso_linux_test.go
new file mode 100644
index 0000000000..cd339c6038
--- /dev/null
+++ b/src/runtime/export_vdso_linux_test.go
@@ -0,0 +1,29 @@
+// Copyright 2025 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.
+
+//go:build linux && (386 || amd64 || arm || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x)
+
+package runtime
+
+type VDSOSymbolKey vdsoSymbolKey
+
+func (v VDSOSymbolKey) Name() string {
+ return v.name
+}
+
+func (v VDSOSymbolKey) SymHash() uint32 {
+ return v.symHash
+}
+
+func (v VDSOSymbolKey) GNUHash() uint32 {
+ return v.gnuHash
+}
+
+func VDSOSymbolKeys() []VDSOSymbolKey {
+ keys := make([]VDSOSymbolKey, 0, len(vdsoSymbolKeys))
+ for _, k := range vdsoSymbolKeys {
+ keys = append(keys, VDSOSymbolKey(k))
+ }
+ return keys
+}
diff --git a/src/runtime/vdso_linux_test.go b/src/runtime/vdso_linux_test.go
new file mode 100644
index 0000000000..313dd6e718
--- /dev/null
+++ b/src/runtime/vdso_linux_test.go
@@ -0,0 +1,52 @@
+// Copyright 2025 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.
+
+//go:build linux && (386 || amd64 || arm || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x)
+
+package runtime_test
+
+import (
+ "runtime"
+ "testing"
+)
+
+// DT_GNU_HASH hash function.
+func gnuHash(s string) uint32 {
+ h := uint32(5381)
+ for _, r := range s {
+ h = (h << 5) + h + uint32(r)
+ }
+ return h
+}
+
+// DT_HASH hash function.
+func symHash(s string) uint32 {
+ var h, g uint32
+ for _, r := range s {
+ h = (h << 4) + uint32(r)
+ g = h & 0xf0000000
+ if g != 0 {
+ h ^= g >> 24
+ }
+ h &^= g
+ }
+ return h
+}
+
+func TestVDSOHash(t *testing.T) {
+ for _, sym := range runtime.VDSOSymbolKeys() {
+ name := sym.Name()
+ t.Run(name, func(t *testing.T) {
+ want := symHash(name)
+ if sym.SymHash() != want {
+ t.Errorf("SymHash got %#x want %#x", sym.SymHash(), want)
+ }
+
+ want = gnuHash(name)
+ if sym.GNUHash() != want {
+ t.Errorf("GNUHash got %#x want %#x", sym.GNUHash(), want)
+ }
+ })
+ }
+}