]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/obj/riscv,cmd/link: rework riscv64 call relocations
authorJoel Sing <joel@sing.id.au>
Wed, 16 Aug 2023 15:13:32 +0000 (01:13 +1000)
committerJoel Sing <joel@sing.id.au>
Tue, 19 Sep 2023 18:10:13 +0000 (18:10 +0000)
commitbda5e6c3d07c23d477f68f09e3414e495b12a87e
tree0dc955380cf1ba0bf7c9819e4a6ff5f9eb7192c6
parent3c4f12a7d6bc6839b3dd2f4b04aeca962745afb3
cmd/internal/obj/riscv,cmd/link: rework riscv64 call relocations

The riscv64 assembler and linker generate three types of calls.
Most calls are made via a single JAL instruction, however this is
limited to +/-1MB of text. In the case where a call target is
unreachable (or unknown), the JAL targets an AUIPC+JALR trampoline.
All other cases use AUIPC+JALR pairs, including the case where a
single function exceeds 1MB in text size, potentially making it
impossible to reach trampolines.

Currently, the single instruction JAL call is marked with R_RISCV_CALL
and the two instruction AUIPC+JALR call is marked with
R_RISCV_PCREL_ITYPE, which is also used for memory load instructions.
This means that we have no way to identify that the latter is a call.

Switch to using R_RISCV_CALL to mark the AUIPC+JALR pair (aligning
somewhat with the elf.R_RISCV_CALL, which is deprecated in favour of
elf.R_RISCV_CALL_PLT). Add R_RISCV_JAL and use this to mark the single
instruction JAL direct calls. This is clearer and allows us to map
elf.R_RISCV_CALL_PLT to Go's R_RISCV_CALL.

Add all three types to IsDirectCall, so that direct calls are correctly
identified when a function exceeds 1MB of text.

Fixes #62465

Change-Id: Id3eea09688a2b7d6e481eae9ed0aa0d1f9a3a48f
Reviewed-on: https://go-review.googlesource.com/c/go/+/520095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Than McIntosh <thanm@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/riscv64/asm.go