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 build panics with empty old build constraints #44487

Open
johejo opened this issue Feb 22, 2021 · 2 comments
Open

cmd/go: go build panics with empty old build constraints #44487

johejo opened this issue Feb 22, 2021 · 2 comments
Milestone

Comments

@johejo
Copy link

@johejo johejo commented Feb 22, 2021

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

$ go version
go version devel +0f66fb7b85 Sun Feb 21 02:25:41 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

No, tip only.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/heijo/.cache/go-build"
GOENV="/home/heijo/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/heijo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/heijo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/heijo/ghq/go.googlesource.com/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/heijo/ghq/go.googlesource.com/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +0f66fb7b85 Sun Feb 21 02:25:41 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/heijo/ghq/github.com/johejo/gcpanic/go.mod"
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-build1479652299=/tmp/go-build -gno-record-gcc-switches"

What did you do?

// +build

package main

func main() {}
go build .

What did you expect to see?

I'm not sure about build constraints migration behavior, but

go1.16 and go1.15 says

package gcpanic: build constraints exclude all Go files in /home/heijo/ghq/github.com/johejo/gcpanic

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x5b93e0]

goroutine 1 [running]:
go/build.(*Context).eval(0xdf0800, 0x0, 0x0, 0xc0001c0480, 0x0)
        /home/heijo/ghq/go.googlesource.com/go/src/go/build/build.go:1852 +0x60
go/build.(*Context).shouldBuild(0xdf0800, 0xc00002a4e0, 0x19, 0x20, 0xc0001c0480, 0x0, 0x0, 0x40)
        /home/heijo/ghq/go.googlesource.com/go/src/go/build/build.go:1540 +0x26d
go/build.(*Context).matchFile(0xdf0800, 0xc00002ccc0, 0x29, 0xc0000268ea, 0x7, 0xc0001c0480, 0xc0000674e0, 0xc0001b2ac0, 0x0, 0x0, ...)
        /home/heijo/ghq/go.googlesource.com/go/src/go/build/build.go:1425 +0x4f9
go/build.(*Context).Import(0xdf0800, 0xa5af88, 0x1, 0xc00002cc90, 0x29, 0x0, 0xc0001b2980, 0x2, 0x4)
        /home/heijo/ghq/go.googlesource.com/go/src/go/build/build.go:830 +0x13e7
go/build.(*Context).ImportDir(...)
        /home/heijo/ghq/go.googlesource.com/go/src/go/build/build.go:471
cmd/go/internal/modload.resolveLocalPackage(0xa5af88, 0x1, 0x28, 0x0, 0xc0001c9518, 0xc000090538)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/modload/load.go:365 +0xc5
cmd/go/internal/modload.LoadPackages.func1(0x0)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/modload/load.go:213 +0x13a
cmd/go/internal/modload.LoadPackages.func2(0xc08fe93105, 0x9, 0x0)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/modload/load.go:268 +0x49
cmd/go/internal/modload.loadFromRoots(0xc0001c01e0, 0x1, 0x0, 0x1000000, 0x0, 0xc00000e198, 0x30)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/modload/load.go:818 +0x52d
cmd/go/internal/modload.LoadPackages(0xb32800, 0xc0000280d8, 0xc0001c01e0, 0x1, 0x0, 0x1000000, 0xc000079460, 0x1, 0x1, 0xc0000b9bae, ...)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/modload/load.go:261 +0x3b1
cmd/go/internal/load.PackagesAndErrors(0xb32800, 0xc0000280d8, 0xc0000201a0, 0x1, 0x1, 0x0, 0x0, 0x0)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/load/pkg.go:2390 +0x1d4
cmd/go/internal/work.runBuild(0xb32800, 0xc0000280d8, 0xde5660, 0xc0000201a0, 0x1, 0x1)
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/internal/work/build.go:375 +0xa5
main.main()
        /home/heijo/ghq/go.googlesource.com/go/src/cmd/go/main.go:195 +0x724

but using new build constraints

//go:build

package main

func main() {}

go build says

main.go: parsing //go:build line: unexpected end of expression
@ALTree ALTree added this to the Go1.17 milestone Feb 22, 2021
@ALTree
Copy link
Member

@ALTree ALTree commented Feb 22, 2021

cc @rsc

@johejo johejo changed the title cmd/compile: go build panics with empty old build constraints cmd/go: go build panics with empty old build constraints Feb 22, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 26, 2021

Change https://golang.org/cl/296155 mentions this issue: go/build/constraint: do not panic on empty build constraints

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
3 participants