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: dvarint: bad offset for funcdata #52697

Closed
ddaa2000 opened this issue May 4, 2022 · 5 comments
Closed

cmd/compile: panic: dvarint: bad offset for funcdata #52697

ddaa2000 opened this issue May 4, 2022 · 5 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ddaa2000
Copy link

ddaa2000 commented May 4, 2022

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

$ go version
go version go1.18.1 windows/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\ddaa\AppData\Local\go-build
set GOENV=C:\Users\ddaa\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\ddaa\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\ddaa\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\programing\go\bugReview\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ddaa\AppData\Local\Temp\go-build2453048728=/tmp/go-build -gno-rec
ord-gcc-switches

What did you do?

https://go.dev/play/p/SJUm7jbaIjh

What did you expect to see?

The compiler don't panic and compile successfully or report "stack frame too large (>1GB)"

What did you see instead?

panic: dvarint: bad offset for funcdata - 1087887713

goroutine 20 [running]:
cmd/compile/internal/ssagen.dvarint(0xc00031c200?, 0xc0000e8a08?, 0x11?)
/usr/local/go/src/cmd/compile/internal/ssagen/ssa.go:287 +0x205
cmd/compile/internal/ssagen.(*state).emitOpenDeferInfo(0xc0002ead00)
/usr/local/go/src/cmd/compile/internal/ssagen/ssa.go:326 +0xfe
cmd/compile/internal/ssagen.buildssa(0xc0003bef20, 0x1)
/usr/local/go/src/cmd/compile/internal/ssagen/ssa.go:605 +0x1ffd
cmd/compile/internal/ssagen.Compile(0xc0003bef20, 0xc00003cf90?)
/usr/local/go/src/cmd/compile/internal/ssagen/pgen.go:183 +0x4c
cmd/compile/internal/gc.compileFunctions.func4.1(0x0?)
/usr/local/go/src/cmd/compile/internal/gc/compile.go:153 +0x3a
cmd/compile/internal/gc.compileFunctions.func3.1()
/usr/local/go/src/cmd/compile/internal/gc/compile.go:140 +0x4d
created by cmd/compile/internal/gc.compileFunctions.func3
/usr/local/go/src/cmd/compile/internal/gc/compile.go:138 +0x78

Go build failed.

@ddaa2000 ddaa2000 changed the title affected/package: cmd/compile: panic: dvarint: bad offset for funcdata cmd/compile: panic: dvarint: bad offset for funcdata May 4, 2022
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 4, 2022
@dr2chase dr2chase added this to the Backlog milestone May 4, 2022
@dr2chase
Copy link
Contributor

dr2chase commented May 4, 2022

@cherrymui @dr2chase This looks like one of ours, someone has been fuzzing the compiler. I don't know that it actually requires generics.

@dr2chase dr2chase self-assigned this May 19, 2022
@dr2chase
Copy link
Contributor

This is failure to correctly complain about a ginormous stack frame, not generics -- generics just allow us to say "ginormous stack frame" in fewer words. This can be seen by replacing the array dimensions "10" and "6" with constants, and varying them between larger and smaller sizes and watch the error come and go.

That said, we should complain more gracefully.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@rmmh
Copy link
Contributor

rmmh commented Jul 25, 2023

As a simpler reproduction case, this short program fails to compile with panic: dvarint: bad offset for funcdata - 1584000009.

@cuonglm
Copy link
Member

cuonglm commented Oct 13, 2023

The problem comes from emitting open defer info. It's even worse because it could prevent valid code to be compiled. For example, this program should compile ok, but panic during runtime due to stack overflow:

package main

func g() {
	xs := [32537630 / 8][33]int{}
	for _, x := range xs {
		if len(x) > 50 {

		}
	}
}

func main() {
	defer f()
	g()
}

func f() {}

but currently panic during compile time with open defer.

@gopherbot
Copy link

Change https://go.dev/cl/535077 mentions this issue: cmd/compile: relax frame offset check when emitting open defer info

yunginnanet pushed a commit to yunginnanet/go that referenced this issue Oct 20, 2023
The funcdata is encoded as varint, with the upper limit set to 1e9.
However, the stack offsets could be up to 1<<30. Thus emitOpenDeferInfo
will trigger an ICE for function with large frame size.

By using binary.PutUvarint, the frame offset could be encoded correctly
for value larger than 1<<35, allow the compiler to report the error.

Further, the runtime also do validation when reading in the funcdata
value, so a bad offset won't likely cause mis-behavior.

Fixes golang#52697

Change-Id: I084c243c5d24c5d31cc22d5b439f0889e42b107c
Reviewed-on: https://go-review.googlesource.com/c/go/+/535077
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. 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

5 participants