Skip to content

Commit 6051da4

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 5a9aeef commit 6051da4

8 files changed

+8
-8
lines changed

src/crypto/internal/fips/sha256/sha256block.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package sha256
1010

1111
import "math/bits"
1212

13-
var _K = []uint32{
13+
var _K = [...]uint32{
1414
0x428a2f98,
1515
0x71374491,
1616
0xb5c0fbcf,

src/crypto/internal/fips/sha256/sha256block_arm64.s

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

src/crypto/internal/fips/sha256/sha256block_riscv64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ TEXT ·block(SB),0,$64-32
151151
ADD X29, X30, X28
152152
BEQ X28, X29, end
153153

154-
MOV ·_K(SB), X18 // const table
154+
MOV $·_K(SB), X18 // const table
155155
ADD $8, X2, X19 // message schedule
156156

157157
MOV dig+0(FP), X20

src/crypto/internal/fips/sha512/_asm/sha512block_amd64_asm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func blockAVX2() {
438438
func loop0() {
439439
Label("loop0")
440440

441-
_K := NewDataAddr(Symbol{Name: ThatPeskyUnicodeDot + "_K"}, 0)
441+
_K := NewDataAddr(Symbol{Name: "$" + ThatPeskyUnicodeDot + "_K"}, 0)
442442
MOVQ(_K, RBP)
443443

444444
// byte swap first 16 dwords

src/crypto/internal/fips/sha512/sha512block.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package sha512
1010

1111
import "math/bits"
1212

13-
var _K = []uint64{
13+
var _K = [...]uint64{
1414
0x428a2f98d728ae22,
1515
0x7137449123ef65cd,
1616
0xb5c0fbcfec4d3b2f,

src/crypto/internal/fips/sha512/sha512block_amd64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -4526,7 +4526,7 @@ TEXT ·blockAVX2(SB), NOSPLIT, $56-32
45264526
VMOVDQU PSHUFFLE_BYTE_FLIP_MASK<>+0(SB), Y9
45274527

45284528
loop0:
4529-
MOVQ ·_K+0(SB), BP
4529+
MOVQ $·_K+0(SB), BP
45304530
VMOVDQU (DI), Y4
45314531
VPSHUFB Y9, Y4, Y4
45324532
VMOVDQU 32(DI), Y5

src/crypto/internal/fips/sha512/sha512block_arm64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ TEXT ·blockSHA512(SB),NOSPLIT,$0
4545
MOVD dig+0(FP), R0
4646
MOVD p_base+8(FP), R1
4747
MOVD p_len+16(FP), R2
48-
MOVD ·_K+0(SB), R3
48+
MOVD $·_K+0(SB), R3
4949

5050
// long enough to prefetch
5151
PRFM (R3), PLDL3KEEP

src/crypto/internal/fips/sha512/sha512block_riscv64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ TEXT ·block(SB),0,$128-32
160160
ADD X29, X30, X28
161161
BEQ X28, X29, end
162162

163-
MOV ·_K(SB), X18 // const table
163+
MOV $·_K(SB), X18 // const table
164164
ADD $8, X2, X19 // message schedule
165165

166166
MOV dig+0(FP), X20

0 commit comments

Comments
 (0)