aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/asm
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2021-08-26 01:33:29 +1000
committerJoel Sing <joel@sing.id.au>2021-10-02 17:29:46 +0000
commit3bbc82371eb801ce489f77359f0badc8e469c26d (patch)
tree55c98b96db5bbda6ff7a40fbec2fd52e2f97d6cf /src/cmd/asm
parenta7fe161ccceb330cd1f19cd103a61f8deacbbdc3 (diff)
downloadgo-3bbc82371eb801ce489f77359f0badc8e469c26d.tar.xz
cmd/internal/obj/riscv,cmd/link/internal/riscv64: add call trampolines for riscv64
CALL and JMP on riscv64 are currently implemented as an AUIPC+JALR pair. This means that every call requires two instructions and makes use of the REG_TMP register, even when the symbol would be directly reachable via a single JAL instruction. Add support for call trampolines - CALL and JMP are now implemented as a single JAL instruction, with the linker generating trampolines in the case where the symbol is not reachable (more than +/-1MiB from the JAL instruction), is an unknown symbol or does not yet have an address assigned. Each trampoline contains an AUIPC+JALR pair, which the relocation is applied to. Due to the limited reachability of the JAL instruction, combined with the way that the Go linker currently assigns symbol addresses, there are cases where a call is to a symbol that has no address currently assigned. In this situation we have to assume that a trampoline will be required, however we can patch this up during relocation, potentially calling directly instead. This means that we will end up with trampolines that are unused. In the case of the Go binary, there are around 3,500 trampolines of which approximately 2,300 are unused (around 9200 bytes of machine instructions). Overall, this removes over 72,000 AUIPC instructions from the Go binary. Change-Id: I2d9ecfb85dfc285c7729a3cd0b3a77b6f6c98be0 Reviewed-on: https://go-review.googlesource.com/c/go/+/345051 Trust: Joel Sing <joel@sing.id.au> Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/asm')
-rw-r--r--src/cmd/asm/internal/asm/testdata/riscv64.s13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/cmd/asm/internal/asm/testdata/riscv64.s b/src/cmd/asm/internal/asm/testdata/riscv64.s
index 64b94a2a04..fe911a74f5 100644
--- a/src/cmd/asm/internal/asm/testdata/riscv64.s
+++ b/src/cmd/asm/internal/asm/testdata/riscv64.s
@@ -357,13 +357,12 @@ start:
JMP (X5) // 67800200
JMP 4(X5) // 67804200
- // JMP and CALL to symbol are encoded as:
- // AUIPC $0, TMP
- // JALR $0, TMP
- // with a R_RISCV_PCREL_ITYPE relocation - the linker resolves the
- // real address and updates the immediates for both instructions.
- CALL asmtest(SB) // 970f0000
- JMP asmtest(SB) // 970f0000
+ // CALL and JMP to symbol are encoded as JAL (using LR or ZERO
+ // respectively), with a R_RISCV_CALL relocation. The linker resolves
+ // the real address and updates the immediate, using a trampoline in
+ // the case where the address is not directly reachable.
+ CALL asmtest(SB) // ef000000
+ JMP asmtest(SB) // 6f000000
// Branch pseudo-instructions
BEQZ X5, 2(PC) // 63840200