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

CGO_ENABLED=0 build fails on go 1.12 #30986

Closed
wrdls opened this issue Mar 21, 2019 · 4 comments
Closed

CGO_ENABLED=0 build fails on go 1.12 #30986

wrdls opened this issue Mar 21, 2019 · 4 comments

Comments

@wrdls
Copy link

wrdls commented Mar 21, 2019

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

$ go version

go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

kernel version Output
$ uname -a

Linux thinkpad 5.0.3-arch1-1-ARCH #1 SMP PREEMPT Tue Mar 19 13:09:13 UTC 2019 x86_64 GNU/Linux

go env Output
$ go env

GOARCH="amd64"
GOBIN="/home/ward/go/bin"
GOCACHE="/home/ward/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ward/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ward/go/src/bitbucket.org/factionxyz/test-env/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build544707537=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ CGO_ENABLED=0 go build -a
# bitbucket.org/factionxyz/test-env
loadinternal: cannot find runtime/cgo

What did you expect to see?

Go compiles without issues like it did with 1.11.

$ CGO_ENABLED=0 ~/Downloads/go1.11.6.linux-amd64/bin/go build -a

What did you see instead?

Compilation exited with errors.

loadinternal: cannot find runtime/cgo
@agnivade
Copy link
Contributor

Please give us the exact steps to reproduce this issue. Thanks.

@wrdls
Copy link
Author

wrdls commented Mar 22, 2019

Ok, I found I actually have https://www.archlinux.org/packages/community/x86_64/go-pie/ installed. I must have missed the package change.

I guess this issue can be closed.

But as a follow-up question. Is a build with CGO_ENABLED=0 supposed to work when PIE is enabled?

Some info about PIE: https://wiki.gentoo.org/wiki/Hardened/Toolchain#Position_Independent_Executables_.28PIEs.29

@agnivade
Copy link
Contributor

/cc @ianlancetaylor for cgo

@ianlancetaylor
Copy link
Contributor

We don't currently support PIE when not using cgo. There is some background at #18968.

nya3jp added a commit to nya3jp/tast that referenced this issue Jun 28, 2019
Also disable PIE because it does not work without cgo:
golang/go#30986 (comment)

Consequently, we also end up disabling ASLR for Tast binaries.
This should be okay since Tast binaries are not shipped to users.

BUG=chromium:976196
TEST=fast_build.sh -T
TEST=fast_build.sh && ~/go/bin/tast run betty example.Pass

Cq-Depend: chromium:1663975
Change-Id: I0da6cfbe45622ec874f94e74bc3b5a0bc4661508
Reviewed-on: https://chromium-review.googlesource.com/1664194
Tested-by: Shuhei Takahashi <nya@chromium.org>
Commit-Ready: Shuhei Takahashi <nya@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
perj added a commit to perj/sebuild that referenced this issue Aug 30, 2019
As we call the similar C binary a module I went with that name for the
Go version as well. There's some trickery needed, Go does currently not
support nocgo for modules, as noted in
golang/go#30986
so that functionality has to be disabled. Also this triggers the CC
environment variable problem again so I had to change the test CC value
used.
perj added a commit to perj/sebuild that referenced this issue Sep 4, 2019
As we call the similar C binary a module I went with that name for the
Go version as well. There's some trickery needed, Go does currently not
support nocgo for modules, as noted in
golang/go#30986
so that functionality has to be disabled. Also this triggers the CC
environment variable problem again so I had to change the test CC value
used.
@golang golang locked and limited conversation to collaborators Mar 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants