Skip to content

Commit 301499f

Browse files
committed
cmd/go: explicitly add default GODEBUG to linker config
Previously we expected the default GODEBUG that's embedded in the binary to be taken into account for build actionIDs through the build info. The build info contains the default GODEBUG for a package main, and then that build info is used to generate the action id. But tests of packages other than main do not have buildinfo set on them. So the default GODEBUG isn't taken into account in the action id for those tests. Explicitly include GODEBUG when generating all link actions' action ids to make sure it's always present. Fixes #69203 Change-Id: Ifbc58482454ecfb51ba09cfcff02972cac3270c1 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/610875 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]>
1 parent c1fe637 commit 301499f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,14 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
14251425
fmt.Fprintf(h, "GOEXPERIMENT=%q\n", cfg.CleanGOEXPERIMENT)
14261426
}
14271427

1428+
// The default godebug is embedded in the binary. For main packages it's
1429+
// already taken into account for the action id through the build info. But
1430+
// to make sure it's included for tests of other packages, where there's no
1431+
// build info, use it as part of the action id. See issue #69203.
1432+
if p != nil {
1433+
fmt.Fprintf(h, "default GODEBUG %q\n", p.DefaultGODEBUG)
1434+
}
1435+
14281436
// The linker writes source file paths that refer to GOROOT,
14291437
// but only if -trimpath is not specified (see [gctoolchain.ld] in gc.go).
14301438
gorootFinal := cfg.GOROOT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is the case reported in issue #69203. Setting GO111MODULE
2+
# off sets the Go version used to determine default GODEBUG settings
3+
# to Go 1.20, flipping the httplaxcontentlength godebug's value to "1".
4+
# Doing so causes net/http.TestReadResponseErrors to fail.
5+
# Before CL 610875, the default GODEBUG was only sometimes used to generate the actionID
6+
# for a link: if the binary being linked was package main, the default GODEBUG would be
7+
# embedded in the build info, which is in turn used for the action id. But for a test
8+
# of a non-main package, there would be no build info set and the default godebug would not
9+
# be taken into account in the action id. So if the only difference between a test run was the
10+
# default GODEBUG setting, the cached test result would be used (even though the
11+
# binaries were different because they contained different default GODEBUG values).
12+
# Now we explicitly add the default GODEBUG to the action id, so the test binaries' link actions
13+
# have different actionIDs. That means that the cached test results (whose action ids
14+
# are based on the test binaries' action ids) should only be used when the default GODEBUG matches.
15+
16+
[short] skip 'runs go test'
17+
18+
# Baseline: ensure TestReadResponseErrors fails with GODEBUG httplaxcontentlength=1.
19+
env GO111MODULE=off
20+
! go test net/http -run=^TestReadResponseErrors$
21+
22+
# Ensure that it passes without httplaxcontentlength=1.
23+
env GO111MODULE=on
24+
go test net/http -run=^TestReadResponseErrors$
25+
26+
# Make sure that the previous cached pass isn't reused when setting httplaxcontentlength=1.
27+
env GO111MODULE=off
28+
! go test net/http -run=^TestReadResponseErrors$

0 commit comments

Comments
 (0)