Skip to content

Commit

Permalink
cmd/compile,cmd/internal/obj/riscv: move g register on riscv64
Browse files Browse the repository at this point in the history
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 <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
  • Loading branch information
4a6f656c committed Oct 21, 2020
1 parent 214136b commit 6f45b39
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 218 deletions.
7 changes: 4 additions & 3 deletions src/cmd/compile/internal/ssa/gen/RISCV64Ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
// L = 64 bit int, used when the opcode starts with F

const (
riscv64REG_G = 4
riscv64REG_G = 27
riscv64REG_CTXT = 20
riscv64REG_LR = 1
riscv64REG_SP = 2
riscv64REG_TP = 4
riscv64REG_TMP = 31
riscv64REG_ZERO = 0
)
Expand Down Expand Up @@ -78,8 +79,8 @@ func init() {

// Add general purpose registers to gpMask.
switch r {
// ZERO, and TMP are not in any gp mask.
case riscv64REG_ZERO, riscv64REG_TMP:
// ZERO, TP and TMP are not in any gp mask.
case riscv64REG_ZERO, riscv64REG_TP, riscv64REG_TMP:
case riscv64REG_G:
gpgMask |= mask
gpspsbgMask |= mask
Expand Down
Loading

0 comments on commit 6f45b39

Please sign in to comment.