Skip to content

cmd/go: 'go build -race' with a cross-compiled GOOS should not suggest setting CGO_ENABLED #37021

Closed
@MasterDimmy

Description

@MasterDimmy
$ 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions