Skip to content

Commit 6f45b39

Browse files
committed
cmd/compile,cmd/internal/obj/riscv: move g register on riscv64
The original riscv64 port used the thread pointer (TP aka X4) register for the g pointer, however this register is also used when TLS support is required, resulting in a conflict (for example, when a signal is received we have no way of readily knowing if X4 contains a pointer to the TCB or a pointer to a g). In order to support cgo, free up the X4 register by moving g to X27. This unfortunately means that the X4 register is unused in non-cgo mode, however the alternative is to not support cgo on this platform. Update #36641 Change-Id: Idcaf3e8ccbe42972a1b8943aeefde7149d9c960a Reviewed-on: https://go-review.googlesource.com/c/go/+/263477 Trust: Joel Sing <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 214136b commit 6f45b39

File tree

4 files changed

+219
-218
lines changed

4 files changed

+219
-218
lines changed

src/cmd/compile/internal/ssa/gen/RISCV64Ops.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import (
2424
// L = 64 bit int, used when the opcode starts with F
2525

2626
const (
27-
riscv64REG_G = 4
27+
riscv64REG_G = 27
2828
riscv64REG_CTXT = 20
2929
riscv64REG_LR = 1
3030
riscv64REG_SP = 2
31+
riscv64REG_TP = 4
3132
riscv64REG_TMP = 31
3233
riscv64REG_ZERO = 0
3334
)
@@ -78,8 +79,8 @@ func init() {
7879

7980
// Add general purpose registers to gpMask.
8081
switch r {
81-
// ZERO, and TMP are not in any gp mask.
82-
case riscv64REG_ZERO, riscv64REG_TMP:
82+
// ZERO, TP and TMP are not in any gp mask.
83+
case riscv64REG_ZERO, riscv64REG_TP, riscv64REG_TMP:
8384
case riscv64REG_G:
8485
gpgMask |= mask
8586
gpspsbgMask |= mask

0 commit comments

Comments
 (0)