]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/obj/riscv,cmd/link/internal/riscv64: add call trampolines for riscv64
authorJoel Sing <joel@sing.id.au>
Wed, 25 Aug 2021 15:33:29 +0000 (01:33 +1000)
committerJoel Sing <joel@sing.id.au>
Sat, 2 Oct 2021 17:29:46 +0000 (17:29 +0000)
commit3bbc82371eb801ce489f77359f0badc8e469c26d
tree55c98b96db5bbda6ff7a40fbec2fd52e2f97d6cf
parenta7fe161ccceb330cd1f19cd103a61f8deacbbdc3
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>
src/cmd/asm/internal/asm/testdata/riscv64.s
src/cmd/internal/obj/riscv/cpu.go
src/cmd/internal/obj/riscv/obj.go
src/cmd/internal/objabi/reloctype.go
src/cmd/internal/objabi/reloctype_string.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/pcln.go
src/cmd/link/internal/riscv64/asm.go
src/cmd/link/internal/riscv64/obj.go