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

doc: document race detector cgo requirements #51235

Closed
andig opened this issue Feb 17, 2022 · 13 comments
Closed

doc: document race detector cgo requirements #51235

andig opened this issue Feb 17, 2022 · 13 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@andig
Copy link
Contributor

andig commented Feb 17, 2022

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

$ go version
go version go1.17.6 darwin/arm64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/andig/Library/Caches/go-build"
GOENV="/Users/andig/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/andig/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/andig/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.17.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.6/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sv/rs_453y57xj86xsbz3kw1mbc0000gn/T/go-build3031970245=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.17.6 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.17.6
uname -v: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
ProductName:	macOS
ProductVersion:	12.2
BuildVersion:	21D49
lldb --version: lldb-1300.0.42.3
Swift version 5.5.2-dev

What did you do?

Use goreleaser to create multi-platform release. Amongst others, goreleaser executes:

CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -race  main.go

What did you expect to see?

Sucess

What did you see instead?

go build: -race requires cgo

I would like to request documenting the cgo requirements per platform as part of https://go.dev/doc/articles/race_detector.

@andig andig changed the title document race detector requirements document race detector cgo requirements Feb 17, 2022
@mengzhuo
Copy link
Contributor

@ianlancetaylor How about this doc?

Requirements

The race detector require cgo and support the os/arch below:

  • linux/amd64
  • linux/ppc64le
  • linux/arm64
  • freebsd/amd64
  • netbsd/amd64
  • darwin/amd64
  • darwin/arm64
  • windows/amd64

@mengzhuo mengzhuo added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 17, 2022
@ALTree
Copy link
Member

ALTree commented Feb 17, 2022

@ianlancetaylor How about this doc?

Requirements

The race detector require cgo and support the os/arch below:

* linux/amd64

* linux/ppc64le

* linux/arm64

* freebsd/amd64

* netbsd/amd64

* darwin/amd64

* darwin/arm64

* windows/amd64

I would keep the list inline, also "s" missing on the verb, my proposal:

The race detector requires cgo to be enabled, and supports linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64, darwin/arm64, and windows/amd64.

@ALTree ALTree changed the title document race detector cgo requirements doc: document race detector cgo requirements Feb 17, 2022
@andig
Copy link
Contributor Author

andig commented Feb 17, 2022

Thank you @ALTree I was under the impression that it didn't need cgo on all platforms, but if it's helpful to mention that it does!

@ALTree
Copy link
Member

ALTree commented Feb 17, 2022

@andig I think #6508 and #9918 still apply.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/386454 mentions this issue: _content: cgo requirement for race detector

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Feb 25, 2022
@dmitshur dmitshur added this to the Unreleased milestone Feb 25, 2022
passionSeven added a commit to passionSeven/website that referenced this issue Oct 18, 2022
The race detector doc doesn't state cgo,
the content is basically as ALTree suggested in issue 51235.

Fixes golang/go#51235

Change-Id: I03356c01f4542e69a02c712063afb77ae68cc90f
Reviewed-on: https://go-review.googlesource.com/c/website/+/386454
Reviewed-by: DO NOT USE <[email protected]>
Trust: Dmitri Shuralyov <[email protected]>
@inliquid
Copy link

inliquid commented Feb 8, 2023

Could anyone please explain why this was working perfectly on Windows with go1.19, and suddenly started to complain about CGO in go1.20? What's changed which made it effectively malfunct on Windows?

@ianlancetaylor
Copy link
Member

As far as I can tell using the race detector has required cgo on Windows for several releases. What does go env CGO_ENABLED print for both of the releases you are testing.

@inliquid
Copy link

inliquid commented Feb 8, 2023

@ianlancetaylor I could pass vet=off and it did the trick.

So this works:

>go1.19.5 test -v -count=1 -race -vet=off .
<...>

This doesn't:

>go test -v -count=1 -race -vet=off .
go: -race requires cgo; enable cgo by setting CGO_ENABLED=1

But w/o vet=off go1.19 also breaks:

>go1.19.5 test -v -count=1 -race .          
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%
FAIL    gitlab.ptsecurity.com/ptcs/policy-enforcer/cmd/policy-enforcer [build failed]
FAIL

Despite this fancy trick everything worked until go1.20 and now it looks like a regression.

@ianlancetaylor
Copy link
Member

I don't know why -vet=off would make any difference here. That sounds like a bug. It makes me think that something got into your build cache somehow. What happens if you run go1.19.5 test -a -v -count=1 -race -vet=off ?

@inliquid
Copy link

inliquid commented Feb 9, 2023

@ianlancetaylor

I don't know why -vet=off would make any difference here.

Initially I found this was mentioned here: #27089 (comment)

What happens if you run go1.19.5 test -a -v -count=1 -race -vet=off ?

>go1.19.5 test -a -v -count=1 -race -vet=off
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

@ianlancetaylor
Copy link
Member

OK, so forcing the rebuild demonstrates the problem even if you use -vet=off. I think that means that it was only working with 1.19 because the of the prebuilt packages. In Go 1.20 we no longer include those with binary releases (https://go.dev/doc/go1.20#go-command). So it's possible that this is a bit of a regression for people using binary releases. It's possible that in Go 1.19 the race detector would work out of the box for programs that do not require cgo even if there is no C compiler installed, because the C compiler was run when building the packages. In Go 1.20 that is no longer true. This is just a guess, though. If you want to pursue this further, please open a new issue with this possibility. Thanks.

@elafontaine
Copy link

Thanks Ian, it makes sense (at least on my setup (I was going mad)). I had a project that I compiled on go 1.17 and I've just now started on a new project in VS code and I had different behaviour until tonight when I rebuilt the old binary. Now it keeps failing as mention. I had passed a flag for the test environment which is -race and was wondering why the old project was able to run the debug mode of tests with cgo_enabled=0 while the new one required gcc to be present.

Thanks a lot for this issue. I will install gcc now.

@d0vgan
Copy link

d0vgan commented Jun 20, 2023

Guys, I'm a Windows user and I still have this problem with the recent versions of Go (1.20.5; 1.20.3). An attempt to run the race detector leads to:

# runtime/cgo
cgo-builtin-prolog:1: stddef.h: No such file or directory

So I'm having a proposal: could you add a hint for Windows users, mentioning this issue on the download page and explaining what this CGO is and how to install it?

@golang golang locked and limited conversation to collaborators Jun 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

9 participants