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: result of 'go build -o' is missing the executable bit, and the resulting file does not execute (despite adding +x) #33889

Closed
ahmetb opened this issue Aug 27, 2019 · 4 comments

Comments

@ahmetb
Copy link

ahmetb commented Aug 27, 2019

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--.

@ahmetb
Copy link
Author

ahmetb commented Aug 27, 2019

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

@ahmetb ahmetb changed the title cmd/go: result of 'go build -o' is missing the executable bit cmd/go: result of 'go build -o' is missing the executable bit, and the resulting file does not execute (despite adding +x) Aug 27, 2019
@ahmetb
Copy link
Author

ahmetb commented Aug 27, 2019

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.

@ahmetb ahmetb closed this as completed Aug 27, 2019
@jwachmann
Copy link

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

@nmerkulov
Copy link

me also VERY glad i found this)

@golang golang locked as resolved and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants