1
0
mirror of https://github.com/golang/go synced 2024-11-22 10:44:41 -07:00

cmd/compile: avoid static init of strings in FIPS mode

Strings have relocations, and data relocations are bad.
Other literals are fine.

Fixes build failure in pending CL 628776.

Change-Id: I7a38bbff9776a365c5823d54c4a00e068dda5d9a
Reviewed-on: https://go-review.googlesource.com/c/go/+/628915
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Russ Cox <rsc@golang.org>
This commit is contained in:
Russ Cox 2024-11-17 19:53:18 -05:00 committed by Gopher Robot
parent 61790207f5
commit 5ec1457941
2 changed files with 6 additions and 1 deletions

View File

@ -332,6 +332,9 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
if ir.IsZero(r) {
return true
}
if disableGlobalAddrs && r.Type().IsString() {
return false
}
staticdata.InitConst(l, loff, r, int(typ.Size()))
return true

View File

@ -85,7 +85,9 @@ const (
func getdyn(n ir.Node, top bool) initGenType {
switch n.Op() {
default:
if ir.IsConstNode(n) {
// Handle constants in linker, except that linker cannot do
// the relocations necessary for string constants in FIPS packages.
if ir.IsConstNode(n) && (!n.Type().IsString() || !base.Ctxt.IsFIPS()) {
return initConst
}
return initDynamic