Go version
go version go1.25.0 linux/arm64
Output of go env
in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build163042255=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/w/src/go.mod'
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/w'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/w/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
cd src
CGO_ENABLED=1 ./all.bash
What did you see happen?
##### Testing packages.
# go tool dist test -run=^cmd/go$
vcs-test.golang.org rerouted to http://127.0.0.1:45751
https://vcs-test.golang.org rerouted to https://127.0.0.1:45827
go test proxy running at GOPROXY=http://127.0.0.1:35641/mod
--- FAIL: TestScript (0.48s)
--- FAIL: TestScript/autocgo (0.03s)
script_test.go:139: 2025-09-09T18:13:20Z
script_test.go:141: $WORK=/tmp/cmd-go-test-976430197/tmpdir4240751195/autocgo3125866786
script_test.go:163:
# Test automatic setting of CGO_ENABLED based on $CC and what's in $PATH. (0.000s)
# Assume we're on a system that can enable cgo normally. (0.009s)
# Clearing CC and removing everything but Go from the PATH should usually
# disable cgo: no C compiler anymore (unless the baked-in defaultCC is an
# absolute path and exists. (0.015s)
> env CC=
> env PATH=$GOROOT/bin
> go env CGO_ENABLED
[stdout]
1
> [!abscc] stdout 0
script_test.go:163: FAIL: testdata/script/autocgo.txt:17: stdout 0: no match for `(?m)0` in stdout
FAIL
FAIL cmd/go 23.070s
What did you expect to see?
Tests should pass.
Reverting commit 8cd6d68a0881d2bc0081081a847bb36fc314e761 (#69994) fixes the problem as does removing CGO_ENABLED=1
at build time. The documentation in src/cmd/cgo/doc.go also became out-of-date with the offending commit. It currently still says:
The cgo tool is enabled by default for native builds on systems where it is expected to work. It is disabled by default when cross-compiling as well as when the CC environment variable is unset and the default C compiler (typically gcc or clang) cannot be found on the system PATH. You can override the default by setting the CGO_ENABLED environment variable when running the go tool: set it to 1 to enable the use of cgo, and to 0 to disable it.
After the commit, the default CGO_ENABLED
state can be set while building the toolchain, making it invariant of cross-compilation. That seems somewhat reasonable when CC_FOR_${GOOS}_${GOARCH}
is set. It is however not matching the current documentation.
I expected:
- Tests should not fail with CGO_ENABLED
set during the toolchain build.
- Documentation should ideally match actual behavior with CGO_ENABLED
set during the toolchain. To be fair, this is a very special case that does not affect the majority of users using the standard toolchain builds where CGO_ENABLED
is not set at build time.
Comment From: Lekensteyn
CC @qiulaidongfeng due to a regression through commit 8cd6d68a0881 ("cmd/go: fix incorrect determining default value of CGO_ENABLED").
Comment From: mrkfrmn
cc @golang/command-line
Comment From: gabyhelp
Related Issues
- cmd/go: regression on the default of CGO_ENABLED to 0 for cross builds #33673 (closed)
- go test does not work without CGO_ENABLED=1 #32287 (closed)
- affected/package: toolchain test/fixedbugs/10607 #62399 (closed)
- cmd/go: GOOS=android requires explicitly setting CGO_ENABLED=1 #30216 (closed)
- cmd/build: cgo cross build need to explictly set `CGO_ENABLED=1` #72988 (closed)
- The `go build` cross compilate failed #55033 (closed)
- `go build` produces bad error message when CGO_ENABLED=0 but need to build using cgo #69288 (closed)
Related Code Changes
- cmd/dist, go/build: make CGO_ENABLED during make.bash sticky
- cmd/go: run tests when cmd/go is cross-compiled
- cmd/go: fix incorrect determining default value of CGO_ENABLED
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: qiulaidongfeng
Thanks report, I will send fix.
Comment From: gopherbot
Change https://go.dev/cl/703555 mentions this issue: cmd/go: disable cgo by default if CC unset and DefaultCC doesn't exist