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/compile: panic by building with GOSSAFUNC in Go1.15 #40919

Closed
tenntenn opened this issue Aug 20, 2020 · 7 comments
Closed

cmd/compile: panic by building with GOSSAFUNC in Go1.15 #40919

tenntenn opened this issue Aug 20, 2020 · 7 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tenntenn
Copy link
Contributor

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

$ go version
go version go1.15 darwin/amd64

Does this issue reproduce with the latest release?

Yes. It does not happen in Go1.14.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tenntenn/Library/Caches/go-build"
GOENV="/Users/tenntenn/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tenntenn/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tenntenn/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dr/gn16sh9935zcz37xt2ghpk480000gn/T/go-build058106775=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

% cat main.go
package main
func main() {}
% GOSSAFUNC=main go build main.go
# runtime
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x12708a7]
goroutine 121 [running]:
cmd/compile/internal/ssa.(*Func).Fatalf(...)
	/usr/local/go/src/cmd/compile/internal/ssa/func.go:625
cmd/compile/internal/ssa.NewHTMLWriter(0x1843e7d, 0x8, 0xc00555bce0, 0x0, 0x0, 0x1)
	/usr/local/go/src/cmd/compile/internal/ssa/html.go:33 +0xe7
cmd/compile/internal/gc.buildssa(0xc00194c840, 0x2, 0x0)
	/usr/local/go/src/cmd/compile/internal/gc/ssa.go:342 +0x1172
cmd/compile/internal/gc.compileSSA(0xc00194c840, 0x2)
	/usr/local/go/src/cmd/compile/internal/gc/pgen.go:317 +0x5d
cmd/compile/internal/gc.compileFunctions.func2(0xc00448f080, 0xc0008f7e80, 0x2)
	/usr/local/go/src/cmd/compile/internal/gc/pgen.go:382 +0x4d
created by cmd/compile/internal/gc.compileFunctions
	/usr/local/go/src/cmd/compile/internal/gc/pgen.go:380 +0x129

What did you expect to see?

Build successfully and generate ssa.html.

What did you see instead?

panic has been occurred.

@randall77
Copy link
Contributor

It's trying to print you an error because it couldn't open the ssa.html file. Is the directory not writeable? Ah, maybe its trying to print an ssa.html for runtime.main, and you have the Go distribution directories read only. I can reproduce by making the runtime directory unwriteable.

Part of the problem is GOSSAFUNC uses a package-local name, so it can match in multiple packages, including stdlib.
I'm not sure why it is crashing when it tries to print you an error. That's something we should probably fix in the distribution.

@randall77
Copy link
Contributor

I see now. The error writer tries to use the entry block's line number to annotate the error, but the entry block has not been set yet. Oops.

@gopherbot
Copy link

Change https://golang.org/cl/249497 mentions this issue: cmd/compile: define starting block before opening html writer

@randall77 randall77 added this to the Go1.16 milestone Aug 20, 2020
@randall77 randall77 added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 20, 2020
@randall77
Copy link
Contributor

I don't think this is worth backporting, GOSSAFUNC is a best-effort service.
The fix will come out in 1.16. Until then, make the destination directory (or directories) writeable. Use a unique function name to prevent collision with stdlib names, if needed.

@nmiyake
Copy link
Contributor

nmiyake commented Aug 20, 2020

As noted already, the specific panic here seems to be around error printing. The underlying issue that causes the error in this case seems like it could be similar to #33278, so it may be helpful to consult that issue for reference (it looks like using go tool compile instead of go build may be sufficient to work around the issue).

@dr2chase
Copy link
Contributor

@gopherbot
Copy link

Change https://golang.org/cl/250340 mentions this issue: cmd/compile: also check package.function for GOSSAFUNC match

gopherbot pushed a commit that referenced this issue Aug 25, 2020
Old behavior is still enabled because it doesn't hurt to leave
it in and existing users of this feature (there are dozens of
us!) will not be surprised.  Adding this finer control allows
users to avoid writing ssa.html where they can't, shouldn't, or
just don't want to.

Example, both ways:

$ GOSSAFUNC="(*Reader).Reset" go test -c -o ./a compress/gzip
dumped SSA to bytes/ssa.html
dumped SSA to strings/ssa.html
dumped SSA to bufio/ssa.html
dumped SSA to compress/gzip/ssa.html

$ GOSSAFUNC="compress/gzip.(*Reader).Reset" go test -c -o ./a compress/gzip
dumped SSA to compress/gzip/ssa.html

Updates #40919.

Change-Id: I06b77c3c1d326372a32651570b5dd6e56dfb1d7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/250340
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
@golang golang locked and limited conversation to collaborators Aug 25, 2021
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.
Projects
None yet
Development

No branches or pull requests

5 participants