]> Cypherpunks repositories - gostls13.git/commit
runtime: fix infinite callstack of cgo on arm64
authorXiangdong Ji <xiangdong.ji@arm.com>
Fri, 27 Mar 2020 11:04:21 +0000 (11:04 +0000)
committerIan Lance Taylor <iant@golang.org>
Wed, 8 Apr 2020 03:46:37 +0000 (03:46 +0000)
commit8e121b1587bd921ea84c7da49cab3f48dc6b8f36
tree783c23c4aa58b8a916663e5268d777ac7f0f059e
parent0a820007e70fdd038950f28254c6269cd9588c02
runtime: fix infinite callstack of cgo on arm64

This change adds CFA information to the assembly function 'crosscall1'
and reorgnizes its code to establish well-formed prologue and epilogue.
It will fix an infinite callstack issue when debugging cgo program with
GDB on arm64.

Brief root cause analysis:

GDB's aarch64 unwinder parses prologue to determine current frame's size
and previous PC&SP if CFA information is not available.

The unwinder parses the prologue of 'crosscall1' to determine a frame size
of 0x10, then turns to its next frame trying to compute its previous PC&SP
as they are not saved on current frame's stack as per its 'traditional frame
unwind' rules, which ends up getting an endless frame chain like:
    [callee]  : pc:<pc0>, sp:<sp0>
    crosscall1: pc:<pc1>, sp:<sp0>+0x10
    [caller]  : pc:<pc1>, sp:<sp0>+0x10+0x10
    [caller]  : pc:<pc1>, sp:<sp0>+0x10+0x10+0x10
    ...
GDB fails to detect the 'caller' frame is same as 'crosscall1' and terminate
unwinding since SP increases everytime.

Fixes #37238
Change-Id: Ia6bd8555828541a3a61f7dc9b94dfa00775ec52a
Reviewed-on: https://go-review.googlesource.com/c/go/+/226999
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/cgo/gcc_arm64.S
src/runtime/runtime-gdb_test.go