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 could not read Go build info from zig-cgo-binary: not a Go executable #54947

Closed
afriza opened this issue Sep 8, 2022 · 2 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@afriza
Copy link

afriza commented Sep 8, 2022

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

latest stable

$ go version
go version go1.19.1 linux/amd64

and also gotip

$ go version
go version devel go1.20-cdc6aeb Wed Sep 7 20:54:43 2022 +0000 linux/amd64

zig version

$ zig version
0.9.1

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/username/.cache/go-build"
GOENV="/home/username/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/username/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/username/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/username/go-version-cgo/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3344522317=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"database/sql"
	"fmt"
	"log"
	"runtime/debug"

	_ "github.com/mattn/go-sqlite3"
)

func main() {
	db, err := sql.Open("sqlite3", "file::memory:")
	if err != nil {
		log.Fatalln(err)
	}
	defer db.Close()

	q := "SELECT 1"
	var n int
	err = db.QueryRow(q).Scan(&n)
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("%q => %v\n", q, n)

	if bi, ok := debug.ReadBuildInfo(); ok {
		for _, s := range bi.Settings {
			fmt.Println(s.Key+":", s.Value)
		}
	}
}
$ git clone https://github.com/afriza/go-version-cgo-zig.git
$ cd go-version-cgo-zig
$ CC="zig cc" CXX="zig cc" CGO_ENABLED=1 go build -o out-zig
$ ./out-zig
2022/09/08 15:17:42 "SELECT 1" => 1
-compiler: gc
CGO_ENABLED: 1
CGO_CFLAGS:
CGO_CPPFLAGS:
CGO_CXXFLAGS:
CGO_LDFLAGS:
GOARCH: amd64
GOOS: linux
GOAMD64: v1
vcs: git
vcs.revision: b7517699fa38cdd31c1b9aa8f53c1d46027cab1f
vcs.time: 2022-09-08T08:05:05Z
vcs.modified: false
$ go version -m out-zig
out-zig: could not read Go build info from out-zig: not a Go executable

using gotip

$ alias go=~/go/bin/gotip
$ go version
go version devel go1.20-cdc6aeb Wed Sep 7 20:54:43 2022 +0000 linux/amd64
$ CC="zig cc" CXX="zig cc" CGO_ENABLED=1 go build -o out-zig
$ ./out-zig
2022/09/08 15:48:31 "SELECT 1" => 1
-compiler: gc
CGO_ENABLED: 1
CGO_CFLAGS:
CGO_CPPFLAGS:
CGO_CXXFLAGS:
CGO_LDFLAGS:
GOARCH: amd64
GOOS: linux
GOAMD64: v1
vcs: git
vcs.revision: b7517699fa38cdd31c1b9aa8f53c1d46027cab1f
vcs.time: 2022-09-08T08:05:05Z
vcs.modified: false
$ go version -m out-zig
out-zig: could not read Go build info from out-zig: not a Go executable

What did you expect to see?

out-gcc: go1.19.1
	path	github.com/afriza/go-version-cgo-zig
	mod	github.com/afriza/go-version-cgo-zig	(devel)
	dep	github.com/mattn/go-sqlite3	v1.14.15	h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
	build	-compiler=gc
	build	CGO_ENABLED=1
	build	CGO_CFLAGS=
	build	CGO_CPPFLAGS=
	build	CGO_CXXFLAGS=
	build	CGO_LDFLAGS=
	build	GOARCH=amd64
	build	GOOS=linux
	build	GOAMD64=v1
	build	vcs=git
	build	vcs.revision=b7517699fa38cdd31c1b9aa8f53c1d46027cab1f
	build	vcs.time=2022-09-08T08:05:05Z
	build	vcs.modified=false

What did you see instead?

out-zig: could not read Go build info from out-zig: not a Go executable

Notes

Not sure if this should be fixed on go side or zig side. But my first impression is go side since the binary can run fine and output the correct info.

issue 53681 & CL 391855 do not address this issue.

Maybe @andrewrk has some clue?

@mknyszek
Copy link
Contributor

mknyszek commented Sep 8, 2022

CC @bcmills and also @rsc (for mentioning how BuildInfo is added to the binary in a recent conversation)

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 8, 2022
@mknyszek mknyszek added this to the Backlog milestone Sep 8, 2022
@bcmills bcmills added the GoCommand cmd/go label Sep 8, 2022
@afriza
Copy link
Author

afriza commented Apr 16, 2023

I re-tested/re-compiled the sample code with go v1.20.3 + zig v0.10.1; and go version -m worked. Not sure where/when it was fixed.

@afriza afriza closed this as completed Apr 16, 2023
@golang golang locked and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants