]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/riscv: restore the ADDI instruction in jalrToSym
authorJoel Sing <joel@sing.id.au>
Wed, 22 Jan 2020 16:31:49 +0000 (03:31 +1100)
committerJoel Sing <joel@sing.id.au>
Thu, 23 Jan 2020 07:39:53 +0000 (07:39 +0000)
While this instruction is not needed for the relocation (the lower immediate
can be patched directly into the JALR instruction), other code currently
depends on the jump sequence being 12 bytes (or three instructions) long.
Put the ADDI instruction back until these can be found and fixed.

Updates #27532

Change-Id: Idb73d716be8eb2eb796591b30f1ec4dc104f2bf8
Reviewed-on: https://go-review.googlesource.com/c/go/+/215840
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/obj/riscv/obj.go

index 520158119ecdcff1200d9598f3635435e145b796..6b36a94daaa613c956c8b12da1b90cdd399e2831 100644 (file)
@@ -55,6 +55,15 @@ func jalrToSym(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc, lr int16) *ob
        p.Mark |= NEED_PCREL_ITYPE_RELOC
        p = obj.Appendp(p, newprog)
 
+       // TODO(jsing): This instruction is not necessary, as the lower bits
+       // of the immediate can be encoded directly in the JALR instruction.
+       // However, other code currently depends on jalrToSym being 12 bytes...
+       p.As = AADDI
+       p.From = obj.Addr{Type: obj.TYPE_CONST}
+       p.Reg = REG_TMP
+       p.To = obj.Addr{Type: obj.TYPE_REG, Reg: REG_TMP}
+       p = obj.Appendp(p, newprog)
+
        // Leave Sym only for the CALL reloc in assemble.
        p.As = AJALR
        p.From.Type = obj.TYPE_REG