1 // Copyright 2024 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 // Package checktest defines some code and data for use in
6 // the crypto/internal/fips140/check test.
7 package checktest
8 9 import (
10 _ "crypto/internal/fips140/check"
11 "runtime"
12 _ "unsafe" // go:linkname
13 )
14 15 var NOPTRDATA int = 1
16 17 // The linkname here disables asan registration of this global,
18 // because asan gets mad about rodata globals.
19 //
20 //go:linkname RODATA crypto/internal/fips140/check/checktest.RODATA
21 var RODATA int32 // set to 2 in asm.s
22 23 // DATA needs to have both a pointer and an int so that _some_ of it gets
24 // initialized at link time, so it is treated as DATA and not BSS.
25 // The pointer is deferred to init time.
26 var DATA = struct {
27 P *int
28 X int
29 }{&NOPTRDATA, 3}
30 31 var NOPTRBSS int
32 33 var BSS *int
34 35 func TEXT() {}
36 37 var (
38 globl12 [12]byte
39 globl8 [8]byte
40 )
41 42 func init() {
43 globl8 = [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
44 globl12 = [12]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
45 runtime.Gosched()
46 47 sum := byte(0)
48 for _, x := range globl12 {
49 sum += x
50 }
51 if sum != 78 {
52 panic("globl12 did not sum properly")
53 }
54 55 sum = byte(0)
56 for _, x := range globl8 {
57 sum += x
58 }
59 if sum != 36 {
60 panic("globl8 did not sum properly")
61 }
62 }
63