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: go build -i returning error if "net/http" is imported and clang set in CC and CXX #25138

Open
spitzfaust opened this Issue Apr 27, 2018 · 7 comments

Comments

Projects
None yet
7 participants
@spitzfaust

spitzfaust commented Apr 27, 2018

What did you do?

I updated my Go installation from 1.8 to 1.10.1. I used the officially provided archive (go1.10.1.linux-amd64.tar.gz) for Linux x86-64 from https://golang.org/dl/.
When I try to use the "net/http" package in a file go build -i prints the following error go build runtime/cgo: open /usr/local/go/pkg/linux_amd64/runtime/cgo.a: permission denied. If I just run go build without -i or if I downgrade to Go 1.9.5 and run the command the error does not appear and everything builds without errors.

The following code can be used to reproduce the issue:

package main

import (
	"fmt"
	"net/http"
)

func main() {
	s := http.StatusOK
	fmt.Println(s)
}

Code on The Go Playground

I further investigated this issue and tried to reproduce it on the Linux machines of two friends. We discovered that the issue only occurs if the following environment variable values are set: CC="clang" and CXX="clang++". If those variables are set to CC="gcc" and CXX="g++" the command runs as expected without errors.

What did you expect to see?

No error and a compiled binary.

What did you see instead?

The following error message and no binary.
go build runtime/cgo: open /usr/local/go/pkg/linux_amd64/runtime/cgo.a: permission denied

System details

go version go1.10.1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tobias/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tobias/Code/GoWorkspace"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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-build742161429=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.10.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.10.1
uname -sr: Linux 4.15.17-300.fc27.x86_64
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 27 (Twenty Seven)
Release:	27
Codename:	TwentySeven
/lib64/libc.so.6: GNU C Library (GNU libc) stable release version 2.26, by Roland McGrath et al.
lldb --version: lldb version 5.0.1
gdb --version: GNU gdb (GDB) Fedora 8.0.1-36.fc27

@ianlancetaylor ianlancetaylor changed the title from go build -i returning error if "net/http" is imported and clang set in CC and CXX to cmd/cgo: go build -i returning error if "net/http" is imported and clang set in CC and CXX Apr 27, 2018

@ianlancetaylor ianlancetaylor changed the title from cmd/cgo: go build -i returning error if "net/http" is imported and clang set in CC and CXX to cmd/go: go build -i returning error if "net/http" is imported and clang set in CC and CXX Apr 27, 2018

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Apr 27, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Apr 27, 2018

It would be nice to fix this, though at the moment I don't see how.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Apr 27, 2018

Note that there isn't much reason to use go build -i with 1.10, so I certainly recommend omitting the -i option as a workaround.

@tms320

This comment has been minimized.

tms320 commented May 27, 2018

I have the same problem on Raspbian. I use LiteIDE. To eliminate the problem I had to modify the file:
~/liteide/build/liteide/share/liteide/litebuild/gosrc.xml
I removed '-i' option in these lines:
<custom id="BuildArgsi" name="BUILDARGS" value="-i" shared-value="$(BUILDFLAGS)"/>
<custom id="ForceBuildArgsi" name="FORCEBUILDARGS" value="-i -a -v" shared-value="$(BUILDFLAGS)"/>

@tms320

This comment has been minimized.

tms320 commented Jun 6, 2018

The author of Lite IDE helped me to solve the problem on Raspberry Pi 3:
visualfc/liteide#946
I built and installed 'std ' using the following command:
sudo GOOS=linux GOARCH=arm GOARM=6 go install std
And the problem was eliminated.

@mahnve

This comment has been minimized.

mahnve commented Sep 23, 2018

I have the same problem, even with CC="gcc" and CXX="g++"

$ go env             
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mahnve/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mahnve/src/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=""
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-build973526131=/tmp/go-build -gno-record-gcc-switches"
@dobegor

This comment has been minimized.

dobegor commented Oct 24, 2018

This error reproduces itself on macOS High Sierra 10.14 with XCode command-line tools installed.

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dobegor/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dobegor/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/dobegor/coding/buzztalk/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=/var/folders/9h/8ghw84gx02l6__ryvxp4yzwh0000gn/T/go-build605292635=/tmp/go-build -gno-record-gcc-switches -fno-common"
@bcmills

This comment has been minimized.

Member

bcmills commented Nov 13, 2018

This is similar to #27285. Since GOCACHE is enabled, we probably shouldn't even try to install standard-library dependencies even with the -i flag: it's fine for them to exist only in the build cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment