diff options
| author | Cherry Zhang <cherryyz@google.com> | 2020-07-06 16:03:33 -0400 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-04-18 22:58:13 +0000 |
| commit | a41a29ad19c25c3475a65b7265fcad870d954c2a (patch) | |
| tree | 1e85e028636dfa5295849099451a78addfe76828 /src/runtime/stack.go | |
| parent | 1064335047776c371599c2d7ba716ffadd26d28b (diff) | |
| download | go-a41a29ad19c25c3475a65b7265fcad870d954c2a.tar.xz | |
runtime: adjust frame pointer on stack copy on ARM64
Frame pointer is enabled on ARM64. When copying stacks, the
saved frame pointers need to be adjusted.
Updates #39524, #40044.
Fixes #58432.
Change-Id: I73651fdfd1a6cccae26a5ce02e7e86f6c2fb9bf7
Reviewed-on: https://go-review.googlesource.com/c/go/+/241158
Reviewed-by: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/stack.go')
| -rw-r--r-- | src/runtime/stack.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/runtime/stack.go b/src/runtime/stack.go index 14e1a75ccd..e1e6c7e82a 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -537,7 +537,7 @@ var ptrnames = []string{ // +------------------+ <- frame->argp // | return address | // +------------------+ -// | caller's BP (*) | (*) if framepointer_enabled && varp < sp +// | caller's BP (*) | (*) if framepointer_enabled && varp > sp // +------------------+ <- frame->varp // | locals | // +------------------+ @@ -549,6 +549,8 @@ var ptrnames = []string{ // | args from caller | // +------------------+ <- frame->argp // | caller's retaddr | +// +------------------+ +// | caller's FP (*) | (*) on ARM64, if framepointer_enabled && varp > sp // +------------------+ <- frame->varp // | locals | // +------------------+ @@ -556,6 +558,9 @@ var ptrnames = []string{ // +------------------+ // | return address | // +------------------+ <- frame->sp +// +// varp > sp means that the function has a frame; +// varp == sp means frameless function. type adjustinfo struct { old stack @@ -673,9 +678,8 @@ func adjustframe(frame *stkframe, adjinfo *adjustinfo) { adjustpointers(unsafe.Pointer(frame.varp-size), &locals, adjinfo, f) } - // Adjust saved base pointer if there is one. - // TODO what about arm64 frame pointer adjustment? - if goarch.ArchFamily == goarch.AMD64 && frame.argp-frame.varp == 2*goarch.PtrSize { + // Adjust saved frame pointer if there is one. + if (goarch.ArchFamily == goarch.AMD64 || goarch.ArchFamily == goarch.ARM64) && frame.argp-frame.varp == 2*goarch.PtrSize { if stackDebug >= 3 { print(" saved bp\n") } @@ -689,6 +693,10 @@ func adjustframe(frame *stkframe, adjinfo *adjustinfo) { throw("bad frame pointer") } } + // On AMD64, this is the caller's frame pointer saved in the current + // frame. + // On ARM64, this is the frame pointer of the caller's caller saved + // by the caller in its frame (one word below its SP). adjustpointer(adjinfo, unsafe.Pointer(frame.varp)) } @@ -750,7 +758,17 @@ func adjustctxt(gp *g, adjinfo *adjustinfo) { throw("bad top frame pointer") } } + oldfp := gp.sched.bp adjustpointer(adjinfo, unsafe.Pointer(&gp.sched.bp)) + if GOARCH == "arm64" { + // On ARM64, the frame pointer is saved one word *below* the SP, + // which is not copied or adjusted in any frame. Do it explicitly + // here. + if oldfp == gp.sched.sp-goarch.PtrSize { + memmove(unsafe.Pointer(gp.sched.bp), unsafe.Pointer(oldfp), goarch.PtrSize) + adjustpointer(adjinfo, unsafe.Pointer(gp.sched.bp)) + } + } } func adjustdefers(gp *g, adjinfo *adjustinfo) { |
