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: link should stop when cgo is required but disabled #46330

Open
perillo opened this issue May 23, 2021 · 3 comments
Open

cmd/go: link should stop when cgo is required but disabled #46330

perillo opened this issue May 23, 2021 · 3 comments

Comments

@perillo
Copy link
Contributor

@perillo perillo commented May 23, 2021

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

$ go version
go version go1.16.4 linux/amd64

Does this issue reproduce with the latest release?

Yes.
It also reproduces with go1.17 devel.

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE="*.local"
GOMODCACHE="/home/manlio/.local/lib/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="*.local"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2831720649=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.16.4 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.16.4
uname -sr: Linux 5.12.5-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) release release version 2.33.
gdb --version: GNU gdb (GDB) 10.2

What did you do?

Using https://play.golang.org/p/LqHgq34kmVq:

$ CGO_ENABLED=0 GOOS=android GOARCH=386 go build

What I'm doing is to check if my package is buildable for the specified platform.

What did you expect to see?

An error, reporting that cgo is required for the platform but explicitly disabled by the user. The program should exit, instead of continuing.

What did you see instead?

loadinternal: cannot find runtime/cgo
/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: cannot find libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
collect2: error: ld returned 1 exit status
  • android/arm reports:

    loadinternal: cannot find runtime/cgo
    /usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
    gcc: error: unrecognized command-line option ‘-marm’; did you mean ‘-mabm’?
    
  • android/amd64 and android/arm64 works

  • ios/amd64 and ios/arm64 reports:

    loadinternal: cannot find runtime/cgo
    /usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
    /usr/bin/ld: cannot find 1144: No such file or directory
    /tmp/go-link-897956511/go.o: file not recognized: file format not recognized
    collect2: error: ld returned 1 exit status
    
@perillo perillo changed the title cmd/go: build should stop when cgo is required but disabled by the user cmd/go: link should stop when cgo is required but disabled by the user May 23, 2021
@perillo
Copy link
Contributor Author

@perillo perillo commented May 23, 2021

@perillo perillo changed the title cmd/go: link should stop when cgo is required but disabled by the user cmd/link: link should stop when cgo is required but disabled by the user May 23, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented May 23, 2021

Change https://golang.org/cl/321935 mentions this issue: cmd/link: exit if cgo is required for external linking but is disabled

@perillo perillo changed the title cmd/link: link should stop when cgo is required but disabled by the user cmd/link: link should stop when cgo is required but disabled May 23, 2021
@perillo
Copy link
Contributor Author

@perillo perillo commented May 23, 2021

The go tool disables cgo automatically when cross compiling, so it is not necessary to explicitly disable it.

@mknyszek mknyszek added this to the Backlog milestone May 24, 2021
@cherrymui cherrymui removed this from the Backlog milestone May 24, 2021
@cherrymui cherrymui added this to the Unplanned milestone May 24, 2021
@cherrymui cherrymui changed the title cmd/link: link should stop when cgo is required but disabled cmd/go: link should stop when cgo is required but disabled May 24, 2021
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
4 participants