File tree Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2025 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ //go:build linux && (386 || amd64 || arm || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x)
6
+
7
+ package runtime
8
+
9
+ type VDSOSymbolKey vdsoSymbolKey
10
+
11
+ func (v VDSOSymbolKey ) Name () string {
12
+ return v .name
13
+ }
14
+
15
+ func (v VDSOSymbolKey ) SymHash () uint32 {
16
+ return v .symHash
17
+ }
18
+
19
+ func (v VDSOSymbolKey ) GNUHash () uint32 {
20
+ return v .gnuHash
21
+ }
22
+
23
+ func VDSOSymbolKeys () []VDSOSymbolKey {
24
+ keys := make ([]VDSOSymbolKey , 0 , len (vdsoSymbolKeys ))
25
+ for _ , k := range vdsoSymbolKeys {
26
+ keys = append (keys , VDSOSymbolKey (k ))
27
+ }
28
+ return keys
29
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2025 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ //go:build linux && (386 || amd64 || arm || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x)
6
+
7
+ package runtime_test
8
+
9
+ import (
10
+ "runtime"
11
+ "testing"
12
+ )
13
+
14
+ // DT_GNU_HASH hash function.
15
+ func gnuHash (s string ) uint32 {
16
+ h := uint32 (5381 )
17
+ for _ , r := range s {
18
+ h = (h << 5 ) + h + uint32 (r )
19
+ }
20
+ return h
21
+ }
22
+
23
+ // DT_HASH hash function.
24
+ func symHash (s string ) uint32 {
25
+ var h , g uint32
26
+ for _ , r := range s {
27
+ h = (h << 4 ) + uint32 (r )
28
+ g = h & 0xf0000000
29
+ if g != 0 {
30
+ h ^= g >> 24
31
+ }
32
+ h &^= g
33
+ }
34
+ return h
35
+ }
36
+
37
+ func TestVDSOHash (t * testing.T ) {
38
+ for _ , sym := range runtime .VDSOSymbolKeys () {
39
+ name := sym .Name ()
40
+ t .Run (name , func (t * testing.T ) {
41
+ want := symHash (name )
42
+ if sym .SymHash () != want {
43
+ t .Errorf ("SymHash got %#x want %#x" , sym .SymHash (), want )
44
+ }
45
+
46
+ want = gnuHash (name )
47
+ if sym .GNUHash () != want {
48
+ t .Errorf ("GNUHash got %#x want %#x" , sym .GNUHash (), want )
49
+ }
50
+ })
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments