]> Cypherpunks repositories - gostls13.git/commit
runtime: fix frame pointer loop on amd64
authorFelix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Tue, 14 Mar 2023 17:25:31 +0000 (18:25 +0100)
committerMichael Pratt <mpratt@google.com>
Thu, 30 Mar 2023 19:17:57 +0000 (19:17 +0000)
commitb52f6d3721da6164687350fff8bd929e934d7725
tree98e60d14088684069f5e5a5156e728464cc318ff
parent8890c3a05f7bf62f455ad2f81a644ba5cae005d8
runtime: fix frame pointer loop on amd64

This commit addresses a regression caused by commit
43f911b0b6c550e6c5b46219d8d0d1ca7ce3f97c (CL 472195) which led to frame
pointer cycles, causing frame pointer unwinders (refer to CL 463835) to
encounter repetitive stack frames.

The issue occurs when mcall invokes fn on g0's stack. fn is expected not
to return but to continue g's execution through gogo(&g.sched). To
achieve this, g.sched must hold the sp, pc, and bp of mcall's caller. CL
472195 mistakenly altered g.sched.bp to store mcall's own bp, causing
gogo to resume execution with a bp value that points downwards into the
now non-existent mcall frame. This results in the next function call
executed by mcall's callee pushing a bp that points to itself on the
stack, creating a pointer loop.

Fix this by dereferencing bp before storing it in g.sched.bp to
reinstate the correct behavior. Although this problem could potentially
be resolved by reverting the mcall-related changes from CL 472195, doing
so would hide mcall's caller frame from async frame pointer unwinders
like Linux perf when unwinding during fn's execution.

Currently, there is no test coverage for frame pointers to validate
these changes. However, runtime/trace.TestTraceSymbolize at CL 463835
will add basic test coverage and can be used to validate this change.

Change-Id: Iad3c42908eeb1b0009fcb839d7fcfffe53d13326
Reviewed-on: https://go-review.googlesource.com/c/go/+/476235
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
src/runtime/asm_amd64.s