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: big array not allocated on heap, which make program panic. #20021

Open
go101 opened this Issue Apr 18, 2017 · 6 comments

Comments

Projects
None yet
7 participants
@go101

go101 commented Apr 18, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 linux/amd64

What did you do?

package main

const N = 1000 * 1000 * 537
var a [N]byte

func main() {
	// this will stack overflow
	for _, v := range a {
	  _ = v
	}

	// edit: blow solo also stack overflow
	var x [N]byte
	var y [N]byte
	_, _ = x, y
}

What did you expect to see?

runs ok

What did you see instead?

crash

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x469cdc, 0xe)
	/sdks/go/src/runtime/panic.go:596 +0x95
runtime.newstack(0x0)
	/sdks/go/src/runtime/stack.go:1089 +0x3f2
runtime.morestack()
	/sdks/go/src/runtime/asm_amd64.s:398 +0x86

goroutine 1 [running]:
main.main()
	/tmp/main.go:6 +0x88 fp=0xc460057f88 sp=0xc460057f80
runtime.main()
	/sdks/go/src/runtime/proc.go:185 +0x20a fp=0xc460057fe0 sp=0xc460057f88
runtime.goexit()
	/sdks/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc460057fe8 sp=0xc460057fe0
exit status 2
@mvdan

This comment has been minimized.

Member

mvdan commented Apr 18, 2017

Worth noting that the spec does not talk of heap nor stack, so if this is a bug it would likely be a compiler one.

Did you try forcing an allocation at run-time, like a := make([]byte, 1000 * 1000 * 537)?

@ianlancetaylor ianlancetaylor changed the title from big array not allocated on heap, which make program panic. to cmd/compile: big array not allocated on heap, which make program panic. Apr 18, 2017

@ianlancetaylor ianlancetaylor added this to the Go1.9Maybe milestone Apr 18, 2017

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Apr 18, 2017

@go101

This comment has been minimized.

go101 commented Apr 18, 2017

@mvdan

package main

const N = 1000 * 1000 * 537

func main() {
	// make is ok
	p := make([]byte, N)
	q := make([]byte, N)
	_, _ = p, q

	// new is also ok
	var u = new([N]byte)
	var v = new([N]byte)
	_, _ = u, v
	
	// blow also stack overflow
	var x [N]byte
	var y [N]byte
	_, _ = x, y
}
@josharian

This comment has been minimized.

Contributor

josharian commented Apr 18, 2017

Related: #10936 and comments on CL 10268.

cc @dr2chase for escape analysis

@valyala

This comment has been minimized.

Contributor

valyala commented Apr 18, 2017

package main

const N = 1000 * 1000 * 537
var a [N]byte

func main() {
	for _, v := range a {
	  _ = v
	}
}

This is a typical trap that the #19817 should address. The workaround is to rewrite the line with range to:

	for _, v := range a[:] {

@bradfitz bradfitz modified the milestones: Go1.9Maybe, Go1.10 Jul 20, 2017

@bradfitz

This comment has been minimized.

Member

bradfitz commented Nov 29, 2017

Go tip (as of 992ce90) has a better error message:

$ go run x.go
# command-line-arguments
./x.go:6:6: stack frame too large (>1GB)

So, some progress. But bumping to Go 1.11.

@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 29, 2017

@bradfitz bradfitz added the NeedsFix label Nov 29, 2017

@gopherbot gopherbot modified the milestones: Go1.11, Unplanned May 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment