runtime: add precise stack scan support

Programming / Compilers / GCC - ian [138bc75d-0d04-0410-961f-82ee72b054a4] - 5 December 2018 23:09 EST

This CL adds support of precise stack scan using stack maps to the runtime. The stack maps are generated by the compiler (if supported). Each safepoint is associated with a (real or dummy) landing pad, and its "type info" in the exception table is a pointer to the stack map. When a stack is scanned, the stack map is found by the stack unwinding code by inspecting the exception table (LSDA).

For precise stack scan we need to unwind the stack. There are three cases:

- If a goroutine is scanning its own stack, it can unwind the stack and scan the frames.

- If a goroutine is scanning another, stopped, goroutine, it cannot directly unwind the target stack. We handle this by switching (runtime.gogo) to the target g, letting it unwind and scan the stack, and switch back.

- If we are scanning a goroutine that is blocked in a syscall, we send a signal to the target goroutine's thread, and let the signal handler unwind and scan the stack. Extra care is needed as this races with enter/exit syscall.

Currently this is only implemented on linux.

Reviewed-on: https://go-review.googlesource.com/c/140518

dbf8e8e9c8d runtime: add precise stack scan support
gcc/go/gofrontend/MERGE | 2 +-
libgo/go/runtime/mgcmark.go | 121 ++++++++++++++++-
libgo/go/runtime/os_gccgo.go | 3 +-
libgo/go/runtime/proc.go | 51 ++++++-
libgo/go/runtime/runtime2.go | 5 +
libgo/go/runtime/signal_sighandler.go | 22 +++
libgo/go/runtime/stubs.go | 7 +
libgo/go/runtime/stubs_linux.go | 8 ++
libgo/go/runtime/stubs_nonlinux.go | 8 ++
libgo/runtime/go-unwind.c | 248 ++++++++++++++++++++++++++++++++++
libgo/runtime/proc.c | 73 +++++++++-
libgo/runtime/runtime.h | 13 ++
libgo/runtime/stack.c | 35 +++--
13 files changed, 573 insertions(+), 23 deletions(-)

Upstream: gcc.gnu.org


  • Share