Skip to content

runtime/debug: SetMaxStack doesn't work for sizes >= 4 GB #41228

@vjorlikowski

Description

@vjorlikowski

While experimenting with larger values of k for the "Man or Boy" test (http://rosettacode.org/wiki/Man_or_boy_test#Go), I hit the default maximum stack size limit.

"No problem", say I. "I'll import runtime/debug and increase the stack size."
This works great for k=24, but breaks with k=25...and then, I try to increase the stack size to 4 gigabytes.

Which breaks.

At one byte shy of 4GB for the stack, I get the following error:

vjo@glaucus/pts/9:go/man_or_boy % time ./test     
runtime: goroutine stack exceeds 4294967295-byte limit
runtime: sp=0xc080160368 stack=[0xc080160000, 0xc100160000]
fatal error: stack overflow

runtime stack:
runtime.throw(0x4be4f3, 0xe)
        /home/vjo/local_godev/go/src/runtime/panic.go:1116 +0x72
runtime.newstack()
        /home/vjo/local_godev/go/src/runtime/stack.go:1060 +0x78d
runtime.morestack()
        /home/vjo/local_godev/go/src/runtime/asm_amd64.s:449 +0x8f

At a full 4GB stack, I instead see:

vjo@glaucus/pts/9:go/man_or_boy % time ./test     
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xbf8003e380 pc=0x464281]

runtime stack:
runtime.throw(0x4c3674, 0x2a)
        /home/vjo/local_godev/go/src/runtime/panic.go:1116 +0x72
runtime.sigpanic()
        /home/vjo/local_godev/go/src/runtime/signal_unix.go:704 +0x4ac
runtime.memmove(0xbf8003e370, 0xc080160370, 0x7ffffc90)
        /home/vjo/local_godev/go/src/runtime/memmove_amd64.s:422 +0x501
runtime.copystack(0xc000000180, 0x100000000)
        /home/vjo/local_godev/go/src/runtime/stack.go:884 +0x17e
runtime.newstack()
        /home/vjo/local_godev/go/src/runtime/stack.go:1069 +0x28d
runtime.morestack()
        /home/vjo/local_godev/go/src/runtime/asm_amd64.s:449 +0x8f

The referenced line is here:

VMOVNTDQ Y0, (DI)

I would test without using the AVX instructions for memmove - except, there's no way to force useAVXmemmove to be false.

The version of go I'm using is:

vjo@glaucus/pts/9:go/man_or_boy % go version
go version go1.15.1 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions