Go: cmd/go: result of 'go build -o' is missing the executable bit, and the resulting file does not execute (despite adding +x)

Created on 28 Aug 2019  ·  4Comments  ·  Source: golang/go

Very likely this is an issue with my set up, but I cannot figure out what is going on.

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

$ go version
go version go1.12.9 darwin/amd64

Does this issue reproduce with the latest release?

Not sure about the tip, go1.12.9 is the latest available release on Homebrew for macOS.

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

go env Output

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ahmetb/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ahmetb/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/ahmetb/.homebrew/Cellar/go/1.12.9/libexec"
GOTMPDIR=""
GOTOOLDIR="/Users/ahmetb/.homebrew/Cellar/go/1.12.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ahmetb/workspace/run-latencies/cmd/probe/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/h7/n46zg3md4l57vzsgxcs355hw00dl55/T/go-build623969830=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

GOPATH unset, have a very simple program:

$ tree
.
├── go.mod
└── main.go
rm -rf  ~/go/bin/probe
go build -o ~/go/bin/probe .
stat ~/go/bin/probe

Observe the executable file is 0644/-rw-r--r--.

I don't think my shell somehow magically got some umask that's causing files to be marked as non-executable.

What did you expect to see?

The file created from go build -o should have +x bits set.

What did you see instead?

The resulting file from go build -o executable file is 0644/-rw-r--r--.

Most helpful comment

Looks like I'm an idiot, my package name was not main.
Also not sure why go install works when package name is not main.

All 4 comments

Weird enough the resulting file is actually not executable even after chmod +xing.

It seems like the binary is treated as a script:

/Users/ahmetb/go/bin/probe: line 1: syntax error near unexpected token `newline'
/Users/ahmetb/go/bin/probe: line 1: `!<arch>'

image

Looks like I'm an idiot, my package name was not main.
Also not sure why go install works when package name is not main.

Really glad I found this post, just helped me and a buddy out :)

me also VERY glad i found this)

Was this page helpful?
0 / 5 - 0 ratings