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: GOOS=android requires explicitly setting CGO_ENABLED=1 #30216

Open
saleemrashid opened this Issue Feb 13, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@saleemrashid
Copy link

saleemrashid commented Feb 13, 2019

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

$ go version
go version go1.11.5 linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ GOOS=android GOARCH=arm GOARM=7 CC=arm-linux-androideabi-gcc CXX=false go env
GOARCH="arm"
GOBIN=""
GOCACHE="/home/saleem/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="android"
GOPATH="/home/saleem/.local/lib/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
GOARM="7"
CC="arm-linux-androideabi-gcc"
CXX="false"
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 -marm -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build669201380=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, World!")
}

What did you expect to see?

The command should succeed without explicitly setting CGO_ENABLED=1

What did you see instead?

Without explicitly setting CGO_ENABLED (go env shows it defaults to CGO_ENABLED=0)

$ GOOS=android GOARCH=arm GOARM=7 CC=arm-linux-androideabi-gcc CXX=false go build
/usr/lib/go/pkg/tool/linux_amd64/link: running arm-linux-androideabi-gcc failed: exit status 1
/tmp/go-link-934544495/go.o:go.go:_cgo_init: error: undefined reference to 'x_cgo_init'
/tmp/go-link-934544495/go.o:go.go:_cgo_notify_runtime_init_done: error: undefined reference to 'x_cgo_notify_runtime_init_done'
/tmp/go-link-934544495/go.o:go.go:_cgo_thread_start: error: undefined reference to 'x_cgo_thread_start'
/tmp/go-link-934544495/go.o:go.go:runtime._cgo_setenv: error: undefined reference to 'x_cgo_setenv'
/tmp/go-link-934544495/go.o:go.go:runtime._cgo_unsetenv: error: undefined reference to 'x_cgo_unsetenv'
/tmp/go-link-934544495/go.o:go.go:runtime.cgo_yield: error: undefined reference to '_cgo_yield'
collect2: error: ld returned 1 exit status

Explicitly setting CGO_ENABLED=1 leads to a successful build

$ GOOS=android GOARCH=arm GOARM=7 CC=arm-linux-androideabi-gcc CXX=false CGO_ENABLED=1 go build
$ 
@saleemrashid

This comment has been minimized.

Copy link
Author

saleemrashid commented Feb 13, 2019

See also #25963

@bcmills bcmills added the mobile label Feb 13, 2019

@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Feb 13, 2019

@bcmills bcmills added this to the Go1.13 milestone Feb 13, 2019

@eliasnaur

This comment has been minimized.

Copy link
Contributor

eliasnaur commented Feb 13, 2019

The go tool disables CGO_ENABLED when cross-compiling:

$ go env CGO_ENABLED
1
$ GOOS=android go env CGO_ENABLED
0

I suppose we could keep CGO_ENABLED when CC or CXX is set?

@ianlancetaylor ianlancetaylor changed the title GOOS=android requires explicitly setting CGO_ENABLED=1 cmd/go: GOOS=android requires explicitly setting CGO_ENABLED=1 Feb 13, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Feb 13, 2019

It would be nice to figure out when we can safely set CGO_ENABLED, but I'm not sure it should be simply because CC is set. We have a corresponding set of bug reports from people who set CC to the wrong compiler. But I don't have a better suggestion.

@eliasnaur

This comment has been minimized.

Copy link
Contributor

eliasnaur commented Feb 14, 2019

How about keeping CGO_ENABLED for geese that don't support internal linking?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.