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 -m does not report versions for c-shared DLLs #45234

Open
qmuntal opened this issue Mar 25, 2021 · 2 comments
Open

cmd/go: go version -m does not report versions for c-shared DLLs #45234

qmuntal opened this issue Mar 25, 2021 · 2 comments

Comments

@qmuntal
Copy link
Contributor

@qmuntal qmuntal commented Mar 25, 2021

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

go version go1.16 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\muntal\AppData\Local\go-build
set GOENV=C:\Users\muntal\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\muntal\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\muntal\go
set GOPRIVATE=
set GOPROXY=direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\muntal\AppData\Local\Temp\go-build152390757=/tmp/go-build -gno-record-gcc-switches

What did you do?

go mod init foo

package main

import "C"
import _ "github.com/qmuntal/go3mf"

func main() {}

//export Foo
func Foo() {}

go build -buildmode c-shared -o foo.dll

go version -m foo.dll

What did you expect to see?

foo.dll: go1.16
        path    foo
        mod     foo        (devel)
        dep     github.com/qmuntal/go3mf        v0.20.4 h1:wv4UxD+qo74DZxOaOBJ6W/vMS+OEjTqAedj4Wwa+Bd0=
        dep     github.com/qmuntal/opc  v0.7.10 h1:zbUhx7/qDcgJCQahz2SHV9HHLBKgtaaFWNxEMmXPKAs=

What did you see instead?

foo.dll: not executable file

Context

I want to retrieve dependency information from a go binary built using -buildmode c-shared in windows.

@qmuntal
Copy link
Contributor Author

@qmuntal qmuntal commented Mar 25, 2021

The documentation of go version says that the -m flag can only be used with executables, but looking into the code I think this is just an artificial restriction, as it can parse any pe, elf, macho, and xcoff binaries (version/exe.go). To prove this point if I just rename foo.dll to foo.exe it works as expected.

An easy fix for this issue could be dropping the isExe check and just relying on debug/pe, debug/elf, debug/macho, or debug/xcoff being able to parse the input file.

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
}

if !isExe(file, info) {
if mustPrint {
fmt.Fprintf(os.Stderr, "%s: not executable file\n", file)
}
return
}

@rsc, @mvdan

@bcmills bcmills changed the title cmd/go: go version -m fails on non-exe windows binaries cmd/go: go version -m fails on c-shared DLLs Mar 25, 2021
@bcmills bcmills added this to the Backlog milestone Mar 25, 2021
@bcmills bcmills changed the title cmd/go: go version -m fails on c-shared DLLs cmd/go: go version -m fails does not report versions for c-shared DLLs Mar 25, 2021
@bcmills bcmills changed the title cmd/go: go version -m fails does not report versions for c-shared DLLs cmd/go: go version -m does not report versions for c-shared DLLs Mar 25, 2021
@networkimprov
Copy link

@networkimprov networkimprov commented Mar 27, 2021

@gopherbot add OS-Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants