1
0
mirror of https://github.com/golang/go synced 2024-11-14 17:30:29 -07:00

crypto/internal/fips: avoid some non-relocatable global initializers

In normal code,

	var x = []int{...}

will be laid out by the linker, but in FIPS packages, the slice
assignment has to be deferred to init time to avoid a global
data relocation. We can avoid the init time work by writing

	var x = [...]int{...}

instead. Do that.

For #69536.

Change-Id: Ie3c1d25af3f79182ee254014e49d3711038aa327
Reviewed-on: https://go-review.googlesource.com/c/go/+/625815
Reviewed-by: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Russ Cox 2024-11-05 13:50:00 -05:00
parent 5a9aeef9d5
commit 6051da46d0
8 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@ package sha256
import "math/bits"
var _K = []uint32{
var _K = [...]uint32{
0x428a2f98,
0x71374491,
0xb5c0fbcf,

View File

@ -16,7 +16,7 @@ TEXT ·blockSHA2(SB),NOSPLIT,$0
MOVD dig+0(FP), R0 // Hash value first address
MOVD p_base+8(FP), R1 // message first address
MOVD p_len+16(FP), R3 // message length
MOVD ·_K+0(SB), R2 // k constants first address
MOVD $·_K+0(SB), R2 // k constants first address
VLD1 (R0), [V0.S4, V1.S4] // load h(a,b,c,d,e,f,g,h)
VLD1.P 64(R2), [V16.S4, V17.S4, V18.S4, V19.S4]
VLD1.P 64(R2), [V20.S4, V21.S4, V22.S4, V23.S4]

View File

@ -151,7 +151,7 @@ TEXT ·block(SB),0,$64-32
ADD X29, X30, X28
BEQ X28, X29, end
MOV ·_K(SB), X18 // const table
MOV $·_K(SB), X18 // const table
ADD $8, X2, X19 // message schedule
MOV dig+0(FP), X20

View File

@ -438,7 +438,7 @@ func blockAVX2() {
func loop0() {
Label("loop0")
_K := NewDataAddr(Symbol{Name: ThatPeskyUnicodeDot + "_K"}, 0)
_K := NewDataAddr(Symbol{Name: "$" + ThatPeskyUnicodeDot + "_K"}, 0)
MOVQ(_K, RBP)
// byte swap first 16 dwords

View File

@ -10,7 +10,7 @@ package sha512
import "math/bits"
var _K = []uint64{
var _K = [...]uint64{
0x428a2f98d728ae22,
0x7137449123ef65cd,
0xb5c0fbcfec4d3b2f,

View File

@ -4526,7 +4526,7 @@ TEXT ·blockAVX2(SB), NOSPLIT, $56-32
VMOVDQU PSHUFFLE_BYTE_FLIP_MASK<>+0(SB), Y9
loop0:
MOVQ ·_K+0(SB), BP
MOVQ $·_K+0(SB), BP
VMOVDQU (DI), Y4
VPSHUFB Y9, Y4, Y4
VMOVDQU 32(DI), Y5

View File

@ -45,7 +45,7 @@ TEXT ·blockSHA512(SB),NOSPLIT,$0
MOVD dig+0(FP), R0
MOVD p_base+8(FP), R1
MOVD p_len+16(FP), R2
MOVD ·_K+0(SB), R3
MOVD $·_K+0(SB), R3
// long enough to prefetch
PRFM (R3), PLDL3KEEP

View File

@ -160,7 +160,7 @@ TEXT ·block(SB),0,$128-32
ADD X29, X30, X28
BEQ X28, X29, end
MOV ·_K(SB), X18 // const table
MOV $·_K(SB), X18 // const table
ADD $8, X2, X19 // message schedule
MOV dig+0(FP), X20