go: cmd/go: `go install` with CGO_ENABLED=0 tries to install standard packages, which can fail

Please answer these questions before submitting your issue. Thanks!

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

[jaten@biggie tmp]$ go version
go version go1.8rc3 linux/amd64 ## also happens on go1.7.4
[jaten@biggie tmp]$

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

[jaten@biggie tmp]$ go env
GOARCH=“amd64”
GOBIN=“”
GOEXE=“”
GOHOSTARCH=“amd64”
GOHOSTOS=“linux”
GOOS=“linux”
GOPATH=“/home/jaten/go”
GORACE=“”
GOROOT=“/usr/local/go”
GOTOOLDIR=“/usr/local/go/pkg/tool/linux_amd64”
GCCGO=“gccgo”
CC=“gcc”
GOGCCFLAGS=“-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build885638224=/tmp/go-build -gno-record-gcc-switches”
CXX=“g++”
CGO_ENABLED=“0”
PKG_CONFIG=“pkg-config”
CGO_CFLAGS=“-g -O2”
CGO_CPPFLAGS=“”
CGO_CXXFLAGS=“-g -O2”
CGO_FFLAGS=“-g -O2”
CGO_LDFLAGS=“-g -O2”
[jaten@biggie tmp]$

What did you do?

I ran make for https://github.com/glycerine/vhaline Makefile does go install on the library github.com/glycerine/vhaline/vhaline and then on a test executable; github.com/glycerine/vhaline/cmd/vhaline

What did you expect to see?

successful build. build is successful without CGO_ENABLED=0

What did you see instead?

[jaten@biggie vhaline]$ make                                                                                                  
cd vhaline && go install && cd ../cmd/vhaline && go install                                                                   
go install net: open /usr/local/go/pkg/linux_amd64/net.a: permission denied                  ### problem!                                 
make: *** [build] Error 1                                                                                                     
[jaten@biggie vhaline]$ go version                                                                                            
go version go1.8rc3 linux/amd64                                                                                               
[jaten@biggie vhaline]$ env|grep GO                                                                                           
CGO_ENABLED=0                                                                                                                 
GOROOT=/usr/local/go                                                                                                          
GODEBUG=netdns=go                                                                                                             
GOPATH=/home/jaten/go                                                                                                         
[jaten@biggie vhaline]$ ls -al /usr/local/go/pkg/linux_amd64/net.a                                                            
-rw-r--r-- 1 root root 1209910 Jan 26 18:55 /usr/local/go/pkg/linux_amd64/net.a                                               
[jaten@biggie vhaline]$ file /usr/local/go/pkg/linux_amd64/net.a                                                              
/usr/local/go/pkg/linux_amd64/net.a: current ar archive                                                                       
[jaten@biggie vhaline]$ mkdir tmp                                                                                             
[jaten@biggie vhaline]$ cd tmp                                                                                                
[jaten@biggie tmp]$ ar x /usr/local/go/pkg/linux_amd64/net.a                                                                  
[jaten@biggie tmp]$ ls -al                                                                                                    
total 1192                                                                                                                    
drwxrwxr-x 2 jaten jaten      48 Feb  7 16:57 .                                                                               
drwxrwxr-x 7 jaten jaten    4096 Feb  7 16:57 ..                                                                              
-rw-r--r-- 1 jaten jaten   19172 Feb  7 16:57 _all.o                                                                          
-rw-r--r-- 1 jaten jaten 1169185 Feb  7 16:57 _go_.o                                                                          
-rw-r--r-- 1 jaten jaten   21364 Feb  7 16:57 __.PKGDEF                                                                       
[jaten@biggie tmp]$ go env    
GOARCH="amd64"                                                                                                                
GOBIN=""                                                                                                                      
GOEXE=""                                                                                                                      
GOHOSTARCH="amd64"                                                                                                            
GOHOSTOS="linux"                                                                                                              
GOOS="linux"                                                                                                                  
GOPATH="/home/jaten/go"                                                                                                       
GORACE=""                                                                                                                     
GOROOT="/usr/local/go"                                                                                                        
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"                                                                                
GCCGO="gccgo"                                                                                                                 
CC="gcc"                                                                                                                      
GOGCCFLAGS="-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build885638224=/tmp/go-build -gno-record-gcc-switches"   
CXX="g++"                                                                                                                     
CGO_ENABLED="0"                                                                                                               
PKG_CONFIG="pkg-config"                                                                                                       
CGO_CFLAGS="-g -O2"                                                                                                           
CGO_CPPFLAGS=""                                                                                                               
CGO_CXXFLAGS="-g -O2"                                                                                                         
CGO_FFLAGS="-g -O2"                                                                                                           
CGO_LDFLAGS="-g -O2"                                                                                                          
[jaten@biggie tmp]$ go version                                                                                                
go version go1.8rc3 linux/amd64                                                                                               
[jaten@biggie tmp]$ unset CGO_ENABLED                                                                                         
[jaten@biggie tmp]$ cd ..                                                                                                     
[jaten@biggie vhaline]$ make                                                                                                  
cd vhaline && go install && cd ../cmd/vhaline && go install                                                                   
[jaten@biggie vhaline]$ #successful build  

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Work on better caching will fix this. I have a prototype. Not for Go 1.9 but probably for Go 1.10.

That would be wonderful if that was the outcome of this ticket, the “official binary + cross compile + go install” story is the last remaining hurdle to Go developers having a seamless cross compilation experience with our official builds.

On Wed, Feb 8, 2017 at 7:51 AM, Ian Lance Taylor notifications@github.com wrote:

My feeling right now is that if you are using a release, then running go install without explicitly mentioning any standard library package should not attempt to install any standard library package. Clearly if you run go install std or go install net then it should install the standard library package (if it is out of date). But if you don’t do that, I don’t think go install should be trying to write files into GOROOT.

Happy to hear counter-arguments.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/golang/go/issues/18981#issuecomment-278136051, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAcAys1VIUMFRjtrCS5AQseaeynhzgNks5raNlngaJpZM4L5xMh .