Skip to content

Commit 7b6c94d

Browse files
committed
cmd/go: drop fips140 build ID hacks
We were trying to keep all binaries stale in fips140 mode so that every build would write and leave behind a fips.o in the work directory for use by validating labs. That breaks various staleness checks, including the one in cmd/dist during GOFIPS140=latest ./make.bash. Revert the fips140 hack. Validating labs will still be able to find the fips.o when building against a clean cache. Add the default godebug to the link hash though, so that it is clear that GOFIPS140=latest and GOFIPS140=off binaries have different hashes. (The only effect is the default GODEBUG setting.) They already had different hashes, because the default GODEBUG ends up in p.Internal.BuildInfo, and that gets hashed in a "modinfo" line, but better to be explicit. Fixes #70873. Change-Id: I49a38c180208098c2b6720facef48f4e96d44c54 Reviewed-on: https://go-review.googlesource.com/c/go/+/637116 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent cb72406 commit 7b6c94d

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

src/cmd/go/internal/fips140/fips140.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@
4040
//
4141
// GOFIPS140=latest go build -work my/binary
4242
//
43-
// will leave fips.o behind in $WORK/b001. Auditors like to be able to
44-
// see that file. Accordingly, when [Enabled] returns true,
45-
// [cmd/go/internal/work.Builder.useCache] arranges never to cache linker
46-
// output, so that the link step always runs, and fips.o is always left
47-
// behind in the link step. If this proves too slow, we could always
48-
// cache fips.o as an extra link output and then restore it when -work is
49-
// set, but we went a very long time never caching link steps at all, so
50-
// not caching them in FIPS mode seems perfectly fine.
43+
// will leave fips.o behind in $WORK/b001
44+
// (unless the build result is cached, of course).
5145
//
5246
// When GOFIPS140 is set to something besides off and latest, [Snapshot]
5347
// returns true, indicating that the build should replace the latest copy

src/cmd/go/internal/work/buildid.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"cmd/go/internal/base"
1616
"cmd/go/internal/cache"
1717
"cmd/go/internal/cfg"
18-
"cmd/go/internal/fips140"
1918
"cmd/go/internal/fsys"
2019
"cmd/go/internal/str"
2120
"cmd/internal/buildid"
@@ -447,19 +446,6 @@ func (b *Builder) useCache(a *Action, actionHash cache.ActionID, target string,
447446
a.buildID = actionID + buildIDSeparator + mainpkg.buildID + buildIDSeparator + contentID
448447
}
449448

450-
// In FIPS mode, we disable any link caching,
451-
// so that we always leave fips.o in $WORK/b001.
452-
// This makes sure that labs validating the FIPS
453-
// implementation can always run 'go build -work'
454-
// and then find fips.o in $WORK/b001/fips.o.
455-
// We could instead also save the fips.o and restore it
456-
// to $WORK/b001 from the cache,
457-
// but we went years without caching binaries anyway,
458-
// so not caching them for FIPS will be fine, at least to start.
459-
if a.Mode == "link" && fips140.Enabled() && a.Package != nil && !strings.HasSuffix(a.Package.ImportPath, ".test") {
460-
return false
461-
}
462-
463449
// If user requested -a, we force a rebuild, so don't use the cache.
464450
if cfg.BuildA {
465451
if p := a.Package; p != nil && !p.Stale {
@@ -519,7 +505,7 @@ func (b *Builder) useCache(a *Action, actionHash cache.ActionID, target string,
519505
oldBuildID := a.buildID
520506
a.buildID = id[1] + buildIDSeparator + id[2]
521507
linkID := buildid.HashToString(b.linkActionID(a.triggers[0]))
522-
if id[0] == linkID && !fips140.Enabled() {
508+
if id[0] == linkID {
523509
// Best effort attempt to display output from the compile and link steps.
524510
// If it doesn't work, it doesn't work: reusing the cached binary is more
525511
// important than reprinting diagnostic information.

src/cmd/go/internal/work/exec.go

+1
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ func (b *Builder) linkActionID(a *Action) cache.ActionID {
13741374
fmt.Fprintf(h, "buildmode %s goos %s goarch %s\n", cfg.BuildBuildmode, cfg.Goos, cfg.Goarch)
13751375
fmt.Fprintf(h, "import %q\n", p.ImportPath)
13761376
fmt.Fprintf(h, "omitdebug %v standard %v local %v prefix %q\n", p.Internal.OmitDebug, p.Standard, p.Internal.Local, p.Internal.LocalPrefix)
1377+
fmt.Fprintf(h, "defaultgodebug %q\n", p.DefaultGODEBUG)
13771378
if cfg.BuildTrimpath {
13781379
fmt.Fprintln(h, "trimpath")
13791380
}

src/cmd/go/testdata/script/fips.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ go build -x -o x.exe
2020
go build -x -o x.exe
2121
! stderr link
2222

23-
# build with GOFIPS140=latest is NOT cached (need fipso)
23+
# build with GOFIPS140=latest is cached too
2424
env GOFIPS140=latest
2525
go build -x -o x.exe
2626
stderr link.*-fipso
2727
go build -x -o x.exe
28-
stderr link.*-fipso
28+
! stderr link.*-fipso
2929

3030
# build test with GOFIPS140=off is cached
3131
env GOFIPS140=off
@@ -41,8 +41,6 @@ stderr link.*-fipso
4141
go test -x -c
4242
! stderr link
4343

44-
45-
4644
-- go.mod --
4745
module m
4846
-- x.go --

src/cmd/go/testdata/script/fipssnap.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ stdout crypto/internal/fips140/$snap/sha256
4747

4848
[short] skip
4949

50-
# build with GOFIPS140=snap is NOT cached (need fipso)
50+
# build with GOFIPS140=snap is cached
5151
go build -x -o x.exe
5252
stderr link.*-fipso
5353
go build -x -o x.exe
54-
stderr link.*-fipso
54+
! stderr link.*-fipso
5555

5656
# build test with GOFIPS140=snap is cached
5757
go test -x -c

0 commit comments

Comments
 (0)