On Tue, Aug 30, 2016 at 2:18 AM, chai2010 <chaishus...@gmail.com> wrote:
> The asm function `Sum` try call a Go function `sum`,
> when the `sum` need morestack, it crashed:
>
> // main.go
> func main() {
> println(Sum(100))
> println(Sum(100 * 1000)) // panic!
> }
>
> func Sum(n int) int
>
> func sum(i, j int) int {
> if i <= 0 {
> return j
> }
> return sum(i-1, i+j)
> }
>
> // main_amd64.s
> TEXT ·Sum(SB), $24-16
> MOVQ n+0(FP), AX
> MOVQ AX, 0(SP)
> MOVQ $0, 8(SP)
> CALL ·sum(SB)
> MOVQ 16(SP), AX
> MOVQ AX, ret+8(FP)
> RET
>
> panic message:
>
> Sum(100): 50005000
> runtime: frame ... untyped locals 0xc042233e88+0x18
> fatal error: missing stackmap
>
> runtime stack:
> runtime.throw(0x467c4b, 0x10)
> C:/go/go1.7.windows-amd64/src/runtime/panic.go:566 +0x9c
> runtime.adjustframe(0x6fb40, 0x6fc38, 0x6f901)
> C:/go/go1.7.windows-amd64/src/runtime/stack.go:660 +0x7d2
> runtime.gentraceback(0xffffffffffffffff, 0xc0421b52b0, 0x0, 0xc04201c000,
> 0x0, 0x0, 0x7fffffff, 0x46d898, 0x6fc38, 0x0, ...)
> C:/go/go1.7.windows-amd64/src/runtime/traceback.go:378 +0x10aa
> runtime.copystack(0xc04201c000, 0x100000, 0x6fe01)
> C:/go/go1.7.windows-amd64/src/runtime/stack.go:902 +0x388
> runtime.newstack()
> C:/go/go1.7.windows-amd64/src/runtime/stack.go:1070 +0x37e
> runtime.morestack()
>
> C:/go/go1.7.windows-amd64/src/runtime/asm_amd64.s:366 +0x87

If an assembler function can call into Go, it needs to provide a stack
map that tells the Go stack unwinder which local variables on the
stack are pointers.  In this case none of them are pointers, so you
can just add NO_LOCAL_POINTERS as defined in runtime/funcdata.h.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to