From 0ad46889a140c3b2e72b8aa4a47ac242571c521f Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 8 Apr 2021 17:38:25 -0400 Subject: [PATCH] cmd/compile/abi-internal: declare X15 scratch in function bodies X15 must be zero at function calls and returns, but can be used as scratch in the middle of a function. This allows things like memmove and the hashing functions to use X15 temporarily, as long as they set it back to 0 before returning. This CL also clarifies the distinction between register meanings on function call versus function return, since some of them have fixed meanings at both call and return, while others only have a fixed meaning at calls. Updates #40724. Change-Id: I9dad3abde42cd4d2788e8435cde6d55073dd75a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/308929 Trust: Austin Clements Reviewed-by: Cherry Zhang --- src/cmd/compile/abi-internal.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/abi-internal.md b/src/cmd/compile/abi-internal.md index b457f6ee74..aa61fcc544 100644 --- a/src/cmd/compile/abi-internal.md +++ b/src/cmd/compile/abi-internal.md @@ -401,16 +401,16 @@ without corrupting arguments or results. Special-purpose registers are as follows: -| Register | Call meaning | Body meaning | +| Register | Call meaning | Return meaning | Body meaning | | --- | --- | --- | -| RSP | Stack pointer | Fixed | -| RBP | Frame pointer | Fixed | -| RDX | Closure context pointer | Scratch | -| R12 | None | Scratch | -| R13 | None | Scratch | -| R14 | Current goroutine | Scratch | -| R15 | GOT reference temporary | Fixed if dynlink | -| X15 | Zero value | Fixed | +| RSP | Stack pointer | Same | Same | +| RBP | Frame pointer | Same | Same | +| RDX | Closure context pointer | Scratch | Scratch | +| R12 | Scratch | Scratch | Scratch | +| R13 | Scratch | Scratch | Scratch | +| R14 | Current goroutine | Same | Scratch | +| R15 | GOT reference temporary if dynlink | Same | Same | +| X15 | Zero value | Same | Scratch | *Rationale*: These register meanings are compatible with Go’s stack-based calling convention except for R14 and X15, which will have @@ -428,6 +428,10 @@ single-byte registers available to be a net win. functions often have to bulk zero their stack frames, and this is more efficient with a designated zero register. +*Implementation note*: Registers with fixed meaning at calls but not +in function bodies must be initialized by "injected" calls such as +signal-based panics. + #### Stack layout The stack pointer, RSP, grows down and is always aligned to 8 bytes.