From: Russ Cox Date: Mon, 18 Nov 2024 00:53:18 +0000 (-0500) Subject: cmd/compile: avoid static init of strings in FIPS mode X-Git-Tag: go1.24rc1~336 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5ec1457941d1754a583a745259b9c308749c0bd1;p=gostls13.git 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 Reviewed-by: Robert Griesemer Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Auto-Submit: Russ Cox --- diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go index fae4eb0d8b..ce2e921771 100644 --- a/src/cmd/compile/internal/staticinit/sched.go +++ b/src/cmd/compile/internal/staticinit/sched.go @@ -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 diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go index 70750ab037..6452618f6c 100644 --- a/src/cmd/compile/internal/walk/complit.go +++ b/src/cmd/compile/internal/walk/complit.go @@ -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