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: 'go build -race' with a cross-compiled GOOS should not suggest setting CGO_ENABLED #37021

Open
MasterDimmy opened this issue Feb 4, 2020 · 5 comments
Milestone

Comments

@MasterDimmy
Copy link

@MasterDimmy MasterDimmy commented Feb 4, 2020

$ go version
go version go1.13.7 windows/amd64

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

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\8\AppData\Local\go-build
set GOENV=C:\Users\8\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\gopath
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Go\src\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=d:\TEMP\go-build345576314=/tmp/go-build -gno-record-gcc-switches

What did you do?

i compile this file for test:

package main

import (
"fmt"
)

func main() {
c := make(chan bool)
m := make(map[string]string)
go func() {
m["1"] = "a" // First conflicting access.
c <- true
}()
m["2"] = "b" // Second conflicting access.
<-c
for k, v := range m {
fmt.Println(k, v)
}
}

with

set CGO_ENABLED=1
set GOOS=linux
set GO_ARCH=amd64
go build -race

What did you expect to see?

success compile

What did you see instead?

# runtime/cgo
gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
gcc_linux_amd64.c:66:2: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
   66 |  sigfillset(&ign);
      |  ^~~~~~~~~~
cc1.exe: all warnings being treated as errors

Note, that

set CGO_ENABLED=1
set GOOS=linux
go build 

is succecced, but i need to compile with "-race" detector. If CGO_ENABLED=0

set CGO_ENABLED=0
set GOOS=linux
go build -race

then i got

go build: -race requires cgo; enable cgo by setting CGO_ENABLED=1
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Feb 4, 2020

Cross-compiling programs with C dependencies is generally not supported, and the runtime support for -race mode relies on C dependencies.

If you want to build a race-enabled binary, you need to either compile for GOOS=windows or build the binary on a Linux machine.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Feb 4, 2020

Probably the best we can do here is emit a clearer diagnostic for cross-compiled -race builds. (We should not prompt the user to “enable cgo” if we don't have reason to believe that such a build would succeed.)

CC @jayconrod @matloob

@bcmills bcmills changed the title cannot compile go build -race with GOOS=linux on windows cmd/go: 'go build -race' with a cross-compiled GOOS should not suggest setting CGO_ENABLED Feb 4, 2020
@bcmills bcmills added this to the Backlog milestone Feb 4, 2020
@MasterDimmy

This comment has been minimized.

Copy link
Author

@MasterDimmy MasterDimmy commented Feb 4, 2020

just try to cross compile this:

package main

import (
"fmt"
)

func main() {
c := make(chan bool)
m := make(map[string]string)
go func() {
m["1"] = "a" // First conflicting access.
c <- true
}()
m["2"] = "b" // Second conflicting access.
<-c
for k, v := range m {
fmt.Println(k, v)
}
}

from windows\amd64 to linux\amd64 with gox

@MasterDimmy

This comment has been minimized.

Copy link
Author

@MasterDimmy MasterDimmy commented Feb 4, 2020

I think "'go build -race' with a cross-compiled GOOS should not suggest setting CGO_ENABLED" is not what this issue is for, that is another issue\suggestion.

Current issue is unavailability to crosscompile "-race" with gox.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Feb 4, 2020

@MasterDimmy, the fact that go test -race has C dependencies is not something we can feasibly fix. (The race detector uses a fairly extensive C library, and the folks on the Go team are not in a position to rewrite it from scratch in pure Go.)

If you want to volunteer to rewrite the race-detector library in pure Go, you're welcome to do so, but as far as “things we can feasibly plan to fix” are concerned, a better error message for this case is about the limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.