]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: avoid static init of strings in FIPS mode
authorRuss Cox <rsc@golang.org>
Mon, 18 Nov 2024 00:53:18 +0000 (19:53 -0500)
committerGopher Robot <gobot@golang.org>
Mon, 18 Nov 2024 17:29:51 +0000 (17:29 +0000)
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>

src/cmd/compile/internal/staticinit/sched.go
src/cmd/compile/internal/walk/complit.go

index fae4eb0d8b7d4c5e2d5727d4d2ed2f22b3cb4df1..ce2e921771ed941a05a3780ea6af72f3bb49f2fc 100644 (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
 
index 70750ab0373b66c9ccb7e38c917c29d243379b3f..6452618f6cead70ff2ccfc19b66e89c3eb329fde 100644 (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