Navigation Menu

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 version says file not executable on cross-compiled binary #53681

Closed
inliquid opened this issue Jul 4, 2022 · 7 comments
Closed

cmd/go: go version says file not executable on cross-compiled binary #53681

inliquid opened this issue Jul 4, 2022 · 7 comments
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@inliquid
Copy link

inliquid commented Jul 4, 2022

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

$ go version
go version go1.18.3 windows/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\***\AppData\Local\go-build
set GOENV=C:\Users\***\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\***\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\***\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\***\AppData\Local\Temp\go-build934652975=/tmp/go-build -gno-record-gcc-switches

What did you do?

On a Windows machine I compiled a Linux binary with GOOS=linux go build, then I tried go version <binary> and go version -m <binary>.
In both cases the result was:

<binary>: not executable file

When I run file <binary> I see the following:

<binary>: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=***, not stripped

What did you expect to see?

Build info for that binary.

What did you see instead?

Above message.

@seankhliao
Copy link
Member

Is it for any build executable? can you share a built artifact?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 4, 2022
@inliquid
Copy link
Author

inliquid commented Jul 5, 2022

It's for any executable.

@qmuntal
Copy link
Contributor

qmuntal commented Jul 5, 2022

go version on windows just checks the target file extension, if it ends with .exe it's an executable, else it's not:

// isExe reports whether the file should be considered executable.
func isExe(file string, info fs.FileInfo) bool {
if runtime.GOOS == "windows" {
return strings.HasSuffix(strings.ToLower(file), ".exe")
}
return info.Mode().IsRegular() && info.Mode()&0111 != 0
}

Looking at the code, it works as expected, although I agree it could be smarter. Somehow related to #48187.

@inliquid
Copy link
Author

inliquid commented Jul 5, 2022

Obviously when you compile for other systems extension could be missing. I think this check is unnecessary. Moreover checking executable bit on Unix (if I understand logic correctly) also makes no sense. What if I just unzipped this from the archive and want to check that info. Why should I make it runnable just to be able to analyze contents? This misleads: "runnable" or "allowed to run" != "executable".

@bcmills bcmills added help wanted OS-Windows NeedsFix The path to resolution is known, but the work has not been done. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 7, 2022
@bcmills bcmills added this to the Backlog milestone Jul 7, 2022
@gopherbot
Copy link

Change https://go.dev/cl/391855 mentions this issue: cmd/go: support shared libraries in 'go version'

@qmuntal
Copy link
Contributor

qmuntal commented Jul 8, 2022

I've updated CL 391855 to remove the is-executable check, so all files go through buildinfo.ReadFile regardless of the file extension and the host OS.

@quantonganh
Copy link
Contributor

391855 had been merged, I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

6 participants