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

x/tools/go/packages: binary built with Go 1.11.1 but running with Go 1.10.4 can't import C #29595

Closed
dominikh opened this issue Jan 7, 2019 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dominikh
Copy link
Member

dominikh commented Jan 7, 2019

When I compile a program that uses go/packages with Go 1.11.1, but then run the program so that it shells out to a Go 1.10.4, then importing packages that use cgo fails.

$ cat $GOPATH/src/sandbox/bar/bar.go 
package bar

import "C"

$ cat foo.go
package main

import (
	"fmt"

	"golang.org/x/tools/go/packages"
)

func main() {
	cfg := &packages.Config{
		Mode: packages.LoadAllSyntax,
	}
	pkgs, err := packages.Load(cfg, "sandbox/bar")
	fmt.Println(err)
	packages.PrintErrors(pkgs)
}

$ go version
go version go1.11.1 linux/amd64

# Building the program with Go 1.11.1
$ go build foo.go

# Running the program with Go 1.11.1, success
$ ./foo
<nil>

$ PATH=~/go/bin:$PATH go version
go version go1.10.4 linux/amd64

# Running the program with Go 1.10.4, fails
$ PATH=~/go/bin:$PATH ./foo
<nil>
/tmp/gopackages197109030/go-build/runtime_cgo/_cgo_gotypes.go:7:10: could not import runtime/cgo (no metadata for runtime/cgo)

# Plain go build has no issues.
$ PATH=~/go/bin:$PATH go build sandbox/bar; echo $? 
0

# Debug output with Go 1.11.1 and Go 1.10.4 respectively
$ GOPACKAGESDEBUG=1 ./foo                             
2019/01/07 14:45:32 116.362087ms for GOROOT= GOPATH=/home/dominikh/prj/ GO111MODULE= PWD=/tmp go [list -e -json -compiled -test=false -export=false -deps=true -find=false -- sandbox/bar]

$ GOPACKAGESDEBUG=1 PATH=~/go/bin:$PATH ./foo         
2019/01/07 14:45:50 8.65362ms for GOROOT= GOPATH=/home/dominikh/prj/ GO111MODULE= PWD=/tmp go [list -e -json -compiled -test=false -export=false -deps=true -find=false -- sandbox/bar]
2019/01/07 14:45:51 623.45465ms for GOROOT= GOPATH=/home/dominikh/prj/ GO111MODULE= PWD=/tmp go [list -e -json -- sandbox/bar]
2019/01/07 14:45:51 354.261038ms for GOROOT= GOPATH=/home/dominikh/prj/ GO111MODULE= PWD=/tmp go [list -e -json -- internal/race runtime runtime/cgo runtime/internal/atomic runtime/internal/sys sync sync/atomic syscall unsafe]
<nil>
/tmp/gopackages628127153/go-build/runtime_cgo/_cgo_gotypes.go:7:10: could not import runtime/cgo (no metadata for runtime/cgo)

This is surprising, since all version-specific behaviour in go/packages should be dynamically decided at runtime, not at compile time. Wiping ~/.cache/go-build has no effect, either.

/cc @matloob @ianthehat @mvdan

@dominikh dominikh added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 7, 2019
@dominikh dominikh added this to the Unreleased milestone Jan 7, 2019
@mvdan
Copy link
Member

mvdan commented Jan 7, 2019

Just to confirm - does this still happen with the latest repective bugfix releases, 1.11.4 and 1.10.7?

Do you get the same error when loading a module, e.g. with a go.mod outside GOPATH?

@dominikh
Copy link
Member Author

dominikh commented Jan 7, 2019

The same issue occurs with a binary built with 1.11.4 and ran with 1.10.7.
Go 1.10 cannot load modules, so there's nothing for me to test there.

@mvdan
Copy link
Member

mvdan commented Jan 7, 2019

Ah right, brain fart on my part :)

@matloob
Copy link
Contributor

matloob commented Mar 21, 2019

golang.org/cl/166537 has been submitted removing the 1.10 support.

Marking this "Obsolete".

@matloob matloob closed this as completed Mar 21, 2019
@golang golang locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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