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: Crash on Go 1.10.x with cgo disabled. #29505

Closed
klauspost opened this issue Jan 2, 2019 · 4 comments
Closed

x/tools/go/packages: Crash on Go 1.10.x with cgo disabled. #29505

klauspost opened this issue Jan 2, 2019 · 4 comments

Comments

@klauspost
Copy link
Contributor

klauspost commented Jan 2, 2019

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

$ go version
go version go1.10.7 linux/amd64

Does this issue reproduce with the latest release?

With latest x/tools/go/packages, yes, but the issue doesn't show up when using Go 1.11.x

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/klaus/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/klaus/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build445057936=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Using staticcheck:

go get -u honnef.co/go/tools/...

Checking a package, but disabling cgo:

$GOPATH/test/main.go:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("...")
}

$GOPATH/test/main_test.go:

package main_test

import (
	"os/user"
	"testing"
)

func TestSomething(t *testing.T) {
	t.Log(user.Current())
}

Execute: env CGO_ENABLED=0 staticcheck test

What did you expect to see?

Successful inspection.

What did you see instead?

Crash in the package loader:

klaus@ubuntu:~/gopath/src/test$ env CGO_ENABLED=0 staticcheck test
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x633c0a]

goroutine 1 [running]:
golang.org/x/tools/go/packages.createTestVariants.func1(0x0, 0xc420242f80)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/golist_fallback.go:260 +0x6a
golang.org/x/tools/go/packages.createTestVariants.func1(0xc4202a6460, 0xc420242f80)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/golist_fallback.go:264 +0x179
golang.org/x/tools/go/packages.createTestVariants(0xc420104780, 0xc42025e0e0, 0xc42025e540)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/golist_fallback.go:293 +0x389
golang.org/x/tools/go/packages.golistDriverFallback(0xc4200efa48, 0xc420102320, 0x1, 0x1, 0x0, 0x9f6640, 0xc420102310)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/golist_fallback.go:245 +0x76a
golang.org/x/tools/go/packages.goListDriver.func2(0xc4200efa48, 0xc42009afb0, 0x1, 0x1, 0xffffffffffffffff, 0x1, 0x20)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/golist.go:133 +0xce
golang.org/x/tools/go/packages.goListDriver(0xc4200efa48, 0xc4200ae010, 0x1, 0x1, 0xc4200efa40, 0xc4200efa70, 0xc4200efaa0)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/golist.go:144 +0xa7b
golang.org/x/tools/go/packages.defaultDriver(0xc4200efa48, 0xc4200ae010, 0x1, 0x1, 0x176bae2b017f, 0xc411a91ce0, 0x11a91ce0004455c7)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/packages.go:187 +0x68
golang.org/x/tools/go/packages.Load(0xc42006b830, 0xc4200ae010, 0x1, 0x1, 0x0, 0x98ad0a, 0x6, 0xc5d800, 0xc42006b770)
        /home/klaus/gopath/src/golang.org/x/tools/go/packages/packages.go:172 +0x6f
honnef.co/go/tools/lint/lintutil.Lint(0xc4200ca6c0, 0x4, 0x6, 0xc4200ae010, 0x1, 0x1, 0xc420243e30, 0x410443, 0x8f8d60, 0x8c8980, ...)
        /home/klaus/gopath/src/honnef.co/go/tools/lint/lintutil/util.go:277 +0x2a0
honnef.co/go/tools/lint/lintutil.ProcessFlagSet(0xc4200ca6c0, 0x4, 0x6, 0xc4200ca660)
        /home/klaus/gopath/src/honnef.co/go/tools/lint/lintutil/util.go:178 +0x99b
main.main()
        /home/klaus/gopath/src/honnef.co/go/tools/cmd/staticcheck/staticcheck.go:29 +0x2f2
klaus@ubuntu:~/gopath/src/test$

Seems this error was found in #28040 - but maybe was assumed to be a flaky test?

@gopherbot gopherbot added this to the Unreleased milestone Jan 2, 2019
@klauspost klauspost changed the title x/tools/go/packages: Crash on Go 1.10 with cgo disabled. x/tools/go/packages: Crash on Go 1.10.x with cgo disabled. Jan 2, 2019
@klauspost
Copy link
Contributor Author

Changing this loop to check the imports like this:

		for _, imp := range p.Imports {
			if allPkgs[imp.ID] == nil {
				fmt.Printf("for %s: imported package %s doesn't exist\n", p.ID, imp.ID)
				continue
			}
			if needsVariantRec(allPkgs[imp.ID]) {

Prints out: for os/user: imported package runtime/cgo doesn't exist

I haven't been able to create a simple reproduction case, though.

@klauspost
Copy link
Contributor Author

klauspost commented Jan 2, 2019

Got a reproducer. Updated first post.

Seems to be the additional import loading from tests.

@bradfitz
Copy link
Contributor

bradfitz commented Jan 2, 2019

/cc @heschik @matloob @ianthehat @stamblerre

@matloob matloob self-assigned this Jan 10, 2019
@matloob
Copy link
Contributor

matloob commented Mar 21, 2019

We no longer support Go 1.10.

Marking obsolete

@matloob matloob closed this as completed Mar 21, 2019
@golang golang locked and limited conversation to collaborators Mar 20, 2020
@rsc rsc unassigned matloob Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants