aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_linux_amd64.s
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2019-12-18 17:27:27 -0800
committerDan Scales <danscales@google.com>2019-12-20 19:01:41 +0000
commit21713f41d17514a432a881655332fbcde4814b45 (patch)
tree91c0e3d2abcc0589402a8b17aeaa9300ec34f239 /src/runtime/sys_linux_amd64.s
parent3f51350c706c8ff663f12867bcfec98aa9fc46bf (diff)
downloadgo-21713f41d17514a432a881655332fbcde4814b45.tar.gz
go-21713f41d17514a432a881655332fbcde4814b45.zip
runtime: make sure BP is saved in nanotime1/walltime1, else frame pointer may not be preserved
nanotime1 and walltime1 do not preserve BP on linux amd64. Previously, this did not cause a problem, because nanotime/walltime do preserve the BP. But now with mid-stack inlining, nanotime/walltime are usually inlined, so BP is not preserved. So, the BP is now wrong in any function after a call to nanotime()/walltime() on amd64. That means the frame pointer on the stack can be wrong for any further function call made after the nanotime() call (notably runtime.main and various GC functions). [386 doesn't use framepointer.] Fix is to set a frame size of 8 for nanotime1 and walltime1, which means the standard prolog/epilog that saves/restore BP in the stack frame is added. I noticed this while investigating issue 16638 (use frame pointers for runtime.Callers). This change would needed for progress on that issue (which doesn't have a high priority). Verified that this fix works/is useful for issue 16638. Change-Id: I19e19ef2c1a517d737a34928baae034f2eb0b2c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/212079 Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/sys_linux_amd64.s')
-rw-r--r--src/runtime/sys_linux_amd64.s7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s
index 174120f887..9493101460 100644
--- a/src/runtime/sys_linux_amd64.s
+++ b/src/runtime/sys_linux_amd64.s
@@ -205,7 +205,8 @@ TEXT runtime·mincore(SB),NOSPLIT,$0-28
RET
// func walltime1() (sec int64, nsec int32)
-TEXT runtime·walltime1(SB),NOSPLIT,$0-12
+// non-zero frame-size means bp is saved and restored
+TEXT runtime·walltime1(SB),NOSPLIT,$8-12
// We don't know how much stack space the VDSO code will need,
// so switch to g0.
// In particular, a kernel configured with CONFIG_OPTIMIZE_INLINING=n
@@ -262,7 +263,9 @@ fallback:
MOVL DX, nsec+8(FP)
RET
-TEXT runtime·nanotime1(SB),NOSPLIT,$0-8
+// func nanotime1() int64
+// non-zero frame-size means bp is saved and restored
+TEXT runtime·nanotime1(SB),NOSPLIT,$8-8
// Switch to g0 stack. See comment above in runtime·walltime.
MOVQ SP, BP // Save old SP; BP unchanged by C code.