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

Closed
johejo opened this issue Feb 22, 2021 · 5 comments
Closed

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

johejo opened this issue Feb 22, 2021 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@johejo
Copy link

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 22, 2021
@ALTree ALTree added this to the Go1.17 milestone Feb 22, 2021
@ALTree
Copy link
Member

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

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

@ALTree ALTree added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 20, 2021
@ALTree
Copy link
Member

ALTree commented May 9, 2021

I'm labelling this as a Release Blocker because we have packages (like github.com/prometheus/node_exporter, which I just checked still crashes the compiler at the latest commit) that cannot be build on go1.17 due to this bug:

$ cd $(mktemp -d)
$ git clone https://github.com/prometheus/node_exporter
$ cd node_exporter/
$ gotip build .

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

goroutine 743 [running]:
go/build.(*Context).eval(0xd785c0, {0x0, 0x0}, 0xc000408b40)
	/home/alberto/go/src/go/build/build.go:1866 +0x80
go/build.(*Context).shouldBuild(0xd785c0, {0xc00042ad00, 0xc000594510, 0xc000408b40}, 0xc000408b40)
	/home/alberto/go/src/go/build/build.go:1554 +0x333
go/build.(*Context).matchFile(0xd785c0, {0xc0007c5b90, 0x5f}, {0xc00033c6e0, 0x19}, 0xc000408b40, 0xc0002590e0, 0xc0000cff40)
	/home/alberto/go/src/go/build/build.go:1439 +0x967
go/build.(*Context).Import(0xd785c0, {0x988548, 0x1}, {0xc0000d1e60, 0xc00076ec37}, 0x0)
	/home/alberto/go/src/go/build/build.go:844 +0x1c98
go/build.(*Context).ImportDir(...)
	/home/alberto/go/src/go/build/build.go:485
cmd/go/internal/load.loadPackageData.func2()
	/home/alberto/go/src/cmd/go/internal/load/pkg.go:848 +0x1fe
cmd/go/internal/par.(*Cache).Do(0xd77900, {0x8f07e0, 0xc00041b3f0}, 0xc00005be88)
	/home/alberto/go/src/cmd/go/internal/par/work.go:128 +0xc3
cmd/go/internal/load.loadPackageData({0xa62ae0, 0xc00011a000}, {0xc0005879b1, 0x1f}, {0xc000297e91, 0x2d}, {0xc000303710, 0x2b}, {0xc00002e004, 0x21}, ...)
	/home/alberto/go/src/cmd/go/internal/load/pkg.go:840 +0x465
cmd/go/internal/load.(*preload).preloadImports.func1({0xc0005879b1, 0x0})
	/home/alberto/go/src/cmd/go/internal/load/pkg.go:1019 +0xe5
created by cmd/go/internal/load.(*preload).preloadImports
	/home/alberto/go/src/cmd/go/internal/load/pkg.go:1018 +0x2c8


@heschi
Copy link
Contributor

heschi commented May 13, 2021

Weekly check-in: this needs to be investigated before beta 1.

cc @ianlancetaylor

@gopherbot
Copy link

Change https://golang.org/cl/320829 mentions this issue: go/build/constraint: fix parsing of "// +build" (with no args)

thepudds added a commit to thepudds/go-fuzz that referenced this issue May 28, 2021
golang/go#44487 was likely causing tip to fail with a panic for the go-fuzz travis tests, perhaps due to the `// +build` in slides/crash.go and elsewhere.

Also update the tested versions of Go.
dvyukov pushed a commit to dvyukov/go-fuzz that referenced this issue Jun 2, 2021
golang/go#44487 was likely causing tip to fail with a panic for the go-fuzz travis tests, perhaps due to the `// +build` in slides/crash.go and elsewhere.

Also update the tested versions of Go.
@golang golang locked and limited conversation to collaborators May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants