]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/riscv: handle AGETCALLERPC
authorJoel Sing <joel@sing.id.au>
Sun, 3 Nov 2019 17:31:20 +0000 (04:31 +1100)
committerJoel Sing <joel@sing.id.au>
Tue, 24 Dec 2019 04:59:06 +0000 (04:59 +0000)
Updates #27532

Change-Id: Ib3e44ec524ed20bbfbbaf40df22cec335460f3ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/204629
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/internal/obj/riscv/obj.go

index 903b2a0eeb7ca22fd3f06abdb3e2ee2eab3cb4ae..4117438d9511a0e90e225943b0a150480547e08b 100644 (file)
@@ -594,6 +594,22 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        // Additional instruction rewriting. Any rewrites that change the number
        // of instructions must occur here (before jump target resolution).
        for p := cursym.Func.Text; p != nil; p = p.Link {
+               if p.As == obj.AGETCALLERPC {
+                       // Handle AGETCALLERPC early so we can use AMOV, which is then
+                       // rewritten below.
+                       if cursym.Leaf() {
+                               // MOV LR, Rd
+                               p.As = AMOV
+                               p.From.Type = obj.TYPE_REG
+                               p.From.Reg = REG_LR
+                       } else {
+                               // MOV (RSP), Rd
+                               p.As = AMOV
+                               p.From.Type = obj.TYPE_MEM
+                               p.From.Reg = REG_SP
+                       }
+               }
+
                switch p.As {
                case AMOV, AMOVB, AMOVH, AMOVW, AMOVBU, AMOVHU, AMOVWU, AMOVF, AMOVD:
                        // Rewrite MOV pseudo-instructions. This cannot be done in