diff options
| author | Austin Clements <austin@google.com> | 2021-03-29 17:38:20 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2021-04-01 00:51:26 +0000 |
| commit | ec721d92bf35cd47543acf6792acd474fdd39446 (patch) | |
| tree | 9a8c2a9df49cdfb2b9b6e0364c086ebfdfa0e962 /src/runtime/asm_amd64.s | |
| parent | 1f29e69bad3673aa4f9d1c4d1016170b9ced634a (diff) | |
| download | go-ec721d92bf35cd47543acf6792acd474fdd39446.tar.xz | |
runtime: fix uses of ABIInternal PCs in assembly
The covers three kinds of uses:
1. Calls of closures from assembly. These are always ABIInternal calls
without wrappers. I went through every indirect call in the runtime
and I think mcall is the only case of assembly calling a Go closure in
a way that's affected by ABIInternal. systemstack also calls a
closure, but it takes no arguments.
2. Calls of Go functions that expect raw ABIInternal pointers. I also
only found one of these: callbackasm1 -> cgocallback on Windows. These
are trickier to find, though.
3. Finally, I found one case on NetBSD where new OS threads were
directly calling the Go runtime entry-point from assembly via a PC,
rather than going through a wrapper. This meant new threads may not
have special registers set up. In this case, a change on all other
OSes had already forced new thread entry to go through an ABI wrapper,
so I just caught NetBSD up with that change.
With this change, I'm able to run a "hello world" with
GOEXPERIMENT=regabi,regabiargs.
For #40724.
Change-Id: I2a6d0e530c4fd4edf13484d923891c6160d683aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/305669
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/runtime/asm_amd64.s')
| -rw-r--r-- | src/runtime/asm_amd64.s | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index b9efad0681..193d8f00bb 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -285,6 +285,34 @@ TEXT gogo<>(SB), NOSPLIT, $0 // Switch to m->g0's stack, call fn(g). // Fn must never return. It should gogo(&g->sched) // to keep running g. +#ifdef GOEXPERIMENT_REGABI_ARGS +TEXT runtime·mcall<ABIInternal>(SB), NOSPLIT, $0-8 + MOVQ AX, DX // DX = fn + + // save state in g->sched + MOVQ 0(SP), BX // caller's PC + MOVQ BX, (g_sched+gobuf_pc)(R14) + LEAQ fn+0(FP), BX // caller's SP + MOVQ BX, (g_sched+gobuf_sp)(R14) + MOVQ BP, (g_sched+gobuf_bp)(R14) + + // switch to m->g0 & its stack, call fn + MOVQ g_m(R14), BX + MOVQ m_g0(BX), SI // SI = g.m.g0 + CMPQ SI, R14 // if g == m->g0 call badmcall + JNE goodm + JMP runtime·badmcall(SB) +goodm: + MOVQ R14, AX // AX (and arg 0) = g + MOVQ SI, R14 // g = g.m.g0 + get_tls(CX) // Set G in TLS + MOVQ R14, g(CX) + MOVQ (g_sched+gobuf_sp)(R14), SP // sp = g0.sched.sp + MOVQ 0(DX), R12 + CALL R12 // fn(g) + JMP runtime·badmcall2(SB) + RET +#else TEXT runtime·mcall(SB), NOSPLIT, $0-8 MOVQ fn+0(FP), DI @@ -315,6 +343,7 @@ TEXT runtime·mcall(SB), NOSPLIT, $0-8 MOVQ $runtime·badmcall2(SB), AX JMP AX RET +#endif // systemstack_switch is a dummy routine that systemstack leaves at the bottom // of the G stack. We need to distinguish the routine that |
