Skip to content

cmd/go: go build -i returning error if "net/http" is imported and clang set in CC and CXX #25138

Not planned
@tobiaswatzek

Description

@tobiaswatzek

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

Activity

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[/+] on Apr 27, 2018
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[/+] on Apr 27, 2018
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Apr 27, 2018
added this to the Go1.11 milestone on Apr 27, 2018
ianlancetaylor

ianlancetaylor commented on Apr 27, 2018

@ianlancetaylor
Contributor

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

ianlancetaylor

ianlancetaylor commented on Apr 27, 2018

@ianlancetaylor
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

tms320 commented on May 27, 2018

@tms320

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

tms320 commented on Jun 6, 2018

@tms320

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.

modified the milestones: Go1.11, Go1.12 on Jul 6, 2018
mahnve

mahnve commented on Sep 23, 2018

@mahnve

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"

5 remaining items

removed
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Nov 13, 2018
modified the milestones: Go1.12, Go1.13 on Feb 12, 2019
bcmills

bcmills commented on May 8, 2019

@bcmills
Contributor

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.

modified the milestones: Go1.13, Go1.14 on May 8, 2019
modified the milestones: Go1.14, Backlog on Oct 9, 2019
bcmills

bcmills commented on Feb 24, 2023

@bcmills
Contributor

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.

locked and limited conversation to collaborators on Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeGoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mahnve@rsc@andybons@ianlancetaylor@bcmills

        Issue actions

          cmd/go: go build -i returning error if "net/http" is imported and clang set in CC and CXX · Issue #25138 · golang/go