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

Closed
tobiaswatzek opened this issue Apr 27, 2018 · 9 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tobiaswatzek
Copy link

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 go build -i returning error if "net/http" is imported and clang set in CC and CXX 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 cmd/cgo: go build -i returning error if "net/http" is imported and clang set in CC and CXX 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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 27, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Apr 27, 2018
@ianlancetaylor
Copy link
Contributor

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

@ianlancetaylor
Copy link
Contributor

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link
Contributor

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.

@bcmills bcmills added GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. labels Nov 13, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 13, 2018
@andybons andybons modified the milestones: Go1.12, Go1.13 Feb 12, 2019
@bcmills
Copy link
Contributor

bcmills commented May 8, 2019

we probably shouldn't even try to install standard-library dependencies even with the -i flag

We should make this change, but not during the freeze. It'll have to slip another release.

@bcmills bcmills modified the milestones: Go1.13, Go1.14 May 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 24, 2023

As of Go 1.20, standard-library packages no longer have an install target, and go build no longer accepts the -i flag. I think this issue is now moot, but please let me know if there's still something to do here.

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2023
@golang golang locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

9 participants