From 9f07cdd99ee70b90e2a5fe998acb48c5fc6e39f2 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Thu, 23 Jan 2020 03:31:49 +1100 Subject: [PATCH] cmd/internal/obj/riscv: restore the ADDI instruction in jalrToSym 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 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/internal/obj/riscv/obj.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 520158119e..6b36a94daa 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -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 -- 2.50.0