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: build constraints sometimes ineffective for net/cgo_resnew.go on FreeBSD #33101

Closed
ohmantics opened this issue Jul 14, 2019 · 10 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-FreeBSD WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@ohmantics
Copy link

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

$ go version
go version go1.12.6 freebsd/amd64

Does this issue reproduce with the latest release?

Yes. (Bumped to 1.12.7 by changing pkg repos over to latest and tried again.)

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GOPATH="/home/xxx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/freebsd_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/home/xxx/Projects/sshcode/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build447432705=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Downloaded sshcode and was in progress patching it for FreeBSD. Ran ci/build.sh.

What did you expect to see?

Build success.

What did you see instead?

A few repeats of the below:

# net
/usr/local/go/src/net/cgo_resnew.go:21:87: cannot use _Ctype_uint(len(b)) (type _Ctype_uint) as type _Ctype_ulong in argument to _C2func_getnameinfo
@bcmills
Copy link
Contributor

bcmills commented Jul 15, 2019

The +build constraints on cgo_resnew.go do not appear to allow freebsd: it should be using cgo_resold.go instead.

Can you reproduce this failure using a sequence of go commands rather than the ci/build.sh wrapper?

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 15, 2019
@bcmills bcmills changed the title Build issue with cgo_resnew.go on FreeBSD net: Build issue with cgo_resnew.go on FreeBSD Jul 15, 2019
@bcmills
Copy link
Contributor

bcmills commented Jul 15, 2019

Ah, yeah: ci/build.sh is explicitly cross-compiling, so presumably you don't have the correct C headers for the target platforms.

Cross-compiles don't enable cgo by default, for that exact reason. Do you have CGO_ENABLED explicitly set in your environment? If so, what happens if you unset it?

@cuonglm
Copy link
Member

cuonglm commented Jul 31, 2019

@bcmills
Copy link
Contributor

bcmills commented Jul 31, 2019

@cuonglm, was that a flake, or did you find a workaround?

@cuonglm
Copy link
Member

cuonglm commented Aug 1, 2019

@bcmills it does not seem to be a flake, it occrurred when I cross-compile with cgo enable on freebsd.

In my CL, I change the test to run on Linux only.

@bcmills bcmills removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 1, 2019
@bcmills bcmills added this to the Go1.14 milestone Aug 1, 2019
@bcmills bcmills changed the title net: Build issue with cgo_resnew.go on FreeBSD cmd/go: build constraints sometimes ineffective for net/cgo_resnew.go on FreeBSD Aug 1, 2019
@stevenh
Copy link
Contributor

stevenh commented Aug 27, 2019

Have the same problem here building one of our packages, confirmed on:
go version go1.12.9 freebsd/amd64

Setting CGO_ENABLED=0 fixed it but I thought cross-compile did this by default?

@bcmills
Copy link
Contributor

bcmills commented Sep 16, 2019

@stevenh, @cuonglm, if you can reproduce this reliably please post exact instructions, including the output of go env and uname -sv.

@bcmills
Copy link
Contributor

bcmills commented Sep 16, 2019

I can reproduce the observed symptom on FreeBSD 12.1 by running:

CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build net

Without the explicit CGO_ENABLED=1, that command succeeds.

I note that sshcode/build.sh explicitly sets GOOS=linux, so all that would be required to reproduce it there is CGO_ENABLED=1.

So my question to all of you is: have you seen this issue with CGO_ENABLED unset in the environment of the go command in which you observed the failure?

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed help wanted labels Sep 16, 2019
@stevenh
Copy link
Contributor

stevenh commented Sep 17, 2019

With 1.12.9 I get

go build
# net
/usr/local/go/src/net/cgo_resnew.go:21:87: cannot use _Ctype_uint(len(b)) (type _Ctype_uint) as type _Ctype_ulong in argument to _C2func_getnameinfo
go env
GOARCH="amd64"
GOBIN="/data/go/bin"
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="linux"
GOPATH="/data/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/freebsd_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build371148949=/tmp/go-build -gno-record-gcc-switches"
uname -sv
FreeBSD FreeBSD 12.0-RELEASE-p10 MULTIPLAY-r5
env |grep GO
GOPATH=/data/go
GOHOME=/data/go
GOBIN=/data/go/bin
GOOS=linux

With 1.13 it doesn't exhibit the same behaviour, and notably go env has changed to CGO_ENABLED="0" which under 1.12.9 was CGO_ENABLED="1" even though its not set in my environment.

go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/data/go/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/data/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/freebsd_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build722621377=/tmp/go-build -gno-record-gcc-switches"

In addition removing GOOS=linux from my env makes 1.13 automatically set CGO_ENABLED="1" so it looks like 1.12 had an issue correctly configuring CGO_ENABLED when cross compiling.

So to confirm looks like this is fixed in 1.13.

@bcmills
Copy link
Contributor

bcmills commented Oct 3, 2019

Thanks for the followup.

#33673 seems closely related. The report there suggests that the default value of CGO_ENABLED for cross-compiled builds may have changed back to 0 (as intended) in CL 171137.

So I'm going to call this “fixed in 1.13”, but please open a new issue if it crops up again!

@bcmills bcmills closed this as completed Oct 3, 2019
@golang golang locked and limited conversation to collaborators Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-FreeBSD WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants