Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: cross-compiling package tests emits errors to stderr yet 0 exit code #62123

Closed
dmitshur opened this issue Aug 17, 2023 · 5 comments
Closed
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Aug 17, 2023

What version of Go are you using (go version)?

$ go version
go version devel go1.22-6a1182027c Thu Aug 17 21:40:36 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes, with Go 1.21.0. (See #61960 (comment).)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/gopher/.cache/go-build'
GOENV='/home/gopher/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/gopher/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/gopher/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/gopher/gotip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/gopher/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.22-6a1182027c Thu Aug 17 21:40:36 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/tmp.mTNFgITEiU/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4223926392=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I used a linux/amd64 host and attempted to cross-compile a simple Go package and its tests to android/amd64, one of Go's ports. Here's a somewhat minified way to reproduce the issue:

$ cd $(mktemp -d)
$ go mod init example.com/m
$ echo "package p; import "testing"; func Test(t *testing.T) {}" > p_test.go
$ GOOS=android GOARCH=amd64 go test -c -o=/dev/null

What did you expect to see?

Either successful compilation, no output to stderr, and 0 exit code,
or a clearly failed compilation and a non-zero exit code.

What did you see instead?

Output to stderr that looks like an error, but exit code 0.

$ GOOS=android GOARCH=amd64 go test -c -o=/dev/null
# example.com/m.test
loadinternal: cannot find runtime/cgo
$ echo $?
0

I spotted this in LUCI (#61960), where we try to rely on go test -c -o=/dev/null to catch compilation errors on all supported Go ports.

CC @bcmills, @ianlancetaylor.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 17, 2023
@dmitshur dmitshur added this to the Backlog milestone Aug 17, 2023
@bcmills
Copy link
Contributor

bcmills commented Aug 18, 2023

@bcmills bcmills added GoCommand cmd/go compiler/runtime Issues related to the Go compiler and/or runtime. labels Aug 23, 2023
@mknyszek
Copy link
Contributor

@cherrymui says that this is actually a successful (well, probably :)) compilation, just some additional (possibly confusing) output is printed.

@cherrymui
Copy link
Member

cherrymui commented Aug 23, 2023

See also #31544. loadinternal: cannot find runtime/cgo is just a print in the linker, not an error. The build actually succeeds, and you should get a binary that is (very likely) working.

Maybe the fix for #31544 didn't include this case, i.e. Android?

@bcmills
Copy link
Contributor

bcmills commented Aug 23, 2023

The fix for #31544 apparently didn't cover the case of CGO_ENABLED=0 at all. 😅

(This issue is a symptom of exactly #46330.)

@bcmills bcmills self-assigned this Aug 23, 2023
@bcmills bcmills modified the milestones: Backlog, Go1.22 Aug 23, 2023
@gopherbot
Copy link

Change https://go.dev/cl/522239 mentions this issue: cmd/go: error out of linking package main if cgo is required but not enabled

cellularmitosis pushed a commit to cellularmitosis/go that referenced this issue Aug 24, 2023
…enabled

Fixes golang#46330.
Fixes golang#62123.
Updates golang#31544.

Change-Id: I023aa2bdb5a24e126a0de5192a077e8cf1a0a67c
Reviewed-on: https://go-review.googlesource.com/c/go/+/522239
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants