mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: clear frame pointer at thread entry points
There are a few places in the runtime where new threads enter Go code with a possibly invalid frame pointer. mstart is the entry point for new Ms, and rt0_go is the entrypoint for the program. As we try to introduce frame pointer unwinding in more places (e.g. for heap profiling in CL 540476 or for execution trace events on the system stack in CL 593835), we see these functions on the stack. We need to ensure that they have valid frame pointers. These functions are both considered the "top" (first) frame frame of the call stack, so this CL sets the frame pointer register to 0 in these functions. Updates #63630 Change-Id: I6a6a6964a9ebc6f68ba23d2616e5fb6f19677f97 Reviewed-on: https://go-review.googlesource.com/c/go/+/721020 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
6919858338
commit
eda2e8c683
2 changed files with 30 additions and 0 deletions
|
|
@ -181,6 +181,14 @@ TEXT runtime·rt0_go(SB),NOSPLIT|NOFRAME|TOPFRAME,$0
|
||||||
MOVQ AX, 24(SP)
|
MOVQ AX, 24(SP)
|
||||||
MOVQ BX, 32(SP)
|
MOVQ BX, 32(SP)
|
||||||
|
|
||||||
|
// This is typically the entry point for Go programs.
|
||||||
|
// Call stack unwinding must not proceed past this frame.
|
||||||
|
// Set the frame pointer register to 0 so that frame pointer-based unwinders
|
||||||
|
// (which don't use debug info for performance reasons)
|
||||||
|
// won't attempt to unwind past this function.
|
||||||
|
// See go.dev/issue/63630
|
||||||
|
MOVQ $0, BP
|
||||||
|
|
||||||
// create istack out of the given (operating system) stack.
|
// create istack out of the given (operating system) stack.
|
||||||
// _cgo_init may update stackguard.
|
// _cgo_init may update stackguard.
|
||||||
MOVQ $runtime·g0(SB), DI
|
MOVQ $runtime·g0(SB), DI
|
||||||
|
|
@ -408,6 +416,13 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0
|
||||||
RET
|
RET
|
||||||
|
|
||||||
TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
|
TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
|
||||||
|
// This is the root frame of new Go-created OS threads.
|
||||||
|
// Call stack unwinding must not proceed past this frame.
|
||||||
|
// Set the frame pointer register to 0 so that frame pointer-based unwinders
|
||||||
|
// (which don't use debug info for performance reasons)
|
||||||
|
// won't attempt to unwind past this function.
|
||||||
|
// See go.dev/issue/63630
|
||||||
|
MOVD $0, BP
|
||||||
CALL runtime·mstart0(SB)
|
CALL runtime·mstart0(SB)
|
||||||
RET // not reached
|
RET // not reached
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,14 @@ TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
|
||||||
MOVW R0, 8(RSP) // argc
|
MOVW R0, 8(RSP) // argc
|
||||||
MOVD R1, 16(RSP) // argv
|
MOVD R1, 16(RSP) // argv
|
||||||
|
|
||||||
|
// This is typically the entry point for Go programs.
|
||||||
|
// Call stack unwinding must not proceed past this frame.
|
||||||
|
// Set the frame pointer register to 0 so that frame pointer-based unwinders
|
||||||
|
// (which don't use debug info for performance reasons)
|
||||||
|
// won't attempt to unwind past this function.
|
||||||
|
// See go.dev/issue/63630
|
||||||
|
MOVD $0, R29
|
||||||
|
|
||||||
#ifdef TLS_darwin
|
#ifdef TLS_darwin
|
||||||
// Initialize TLS.
|
// Initialize TLS.
|
||||||
MOVD ZR, g // clear g, make sure it's not junk.
|
MOVD ZR, g // clear g, make sure it's not junk.
|
||||||
|
|
@ -248,6 +256,13 @@ TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0
|
||||||
RET
|
RET
|
||||||
|
|
||||||
TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME,$0
|
TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME,$0
|
||||||
|
// This is the root frame of new Go-created OS threads.
|
||||||
|
// Call stack unwinding must not proceed past this frame.
|
||||||
|
// Set the frame pointer register to 0 so that frame pointer-based unwinders
|
||||||
|
// (which don't use debug info for performance reasons)
|
||||||
|
// won't attempt to unwind past this function.
|
||||||
|
// See go.dev/issue/63630
|
||||||
|
MOVD $0, R29
|
||||||
BL runtime·mstart0(SB)
|
BL runtime·mstart0(SB)
|
||||||
RET // not reached
|
RET // not reached
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue