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 install -buildmode=pie fails with permission denied #15433

Closed
petercolberg opened this issue Apr 25, 2016 · 4 comments
Closed

cmd/go: go install -buildmode=pie fails with permission denied #15433

petercolberg opened this issue Apr 25, 2016 · 4 comments

Comments

@petercolberg
Copy link

petercolberg commented Apr 25, 2016

I am trying to compile and install a position-independent executable (PIE) of a minimal Go program:

// hello.go
package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

I am using Go 1.6.1 on Debian unstable amd64:

# export GOPATH=$PWD
# export GOBIN=$PWD/_install
# go env
GOARCH="amd64"
GOBIN="/tmp/hello/_install"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/tmp/hello"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Compiling the executable works fine:

# go build -v -buildmode=pie
runtime/internal/sys
runtime/internal/atomic
runtime
errors
internal/race
sync/atomic
math
unicode/utf8
sync
syscall
io
strconv
time
reflect
os
fmt
runtime/cgo
_/tmp/hello

# ./hello 
hello world

Compiling and installing the executable fails with this error:

# go install -v -buildmode=pie
runtime/internal/sys
go install runtime/internal/sys: mkdir /usr/lib/go/pkg/linux_amd64_shared: permission denied
@ianlancetaylor
Copy link
Contributor

In order to run go install, you must have permission to write to GOROOT. In your case GOROOT is /usr/lib/go, but you don't have permission to write there. I don't think there is anything we can do to fix this.

@petercolberg
Copy link
Author

Could you please keep this issue open? I do think this issue can be fixed.

Now I have a slightly better understanding of the problem. The Debian package golang-go ships only the static variants of the standard and runtime libraries, which are installed in /usr/lib/go. Compiling with -buildmode=pie requires the shared variants, however, which are not available; hence go install builds and tries to install these, which (rightly so) fails due to permissions.

What would be the recommended way to install the Go compiler including both static and position-independent shared variants of the standard and runtime libraries? Debian uses src/make.bash for installation, but simply passing GO_LDFLAGS=-buildmode=pie does not seem to work.

@ianlancetaylor
Copy link
Contributor

Debian can run go install -buildmode=pie std to install a version of the standard library ready to build PIE executables.

At this point I don't see a reason to reopen this issue. I don't see anything we can do on the Go side to fix this; any fix has to be on the Debian side. I'm happy to reopen if you have a suggestion for what we can do.

@mwhudson
Copy link
Contributor

I've been meaning to talk on golang-dev about this for a while, so I finally posted https://groups.google.com/d/msg/golang-dev/BcSBfR2CVo8/ArTy2n7WCAAJ

@golang golang locked and limited conversation to collaborators Apr 26, 2017
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