Skip to content

Commit

Permalink
cmd/internal/obj/arm64: fix return with register
Browse files Browse the repository at this point in the history
ARM64 allows for a register to be specified with a return
instruction. While the assembler parsing and encoding currently
supports this, the preprocess function uses LR unconditionally.
Correct this such that if a register is specified, the register
is used.

Change-Id: I708f6c7e910d141559b60d2d5ee76ae2e1dc3a0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/592796
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: David Chase <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
4a6f656c committed Jun 25, 2024
1 parent b3b4556 commit b1fd047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/cmd/asm/internal/asm/testdata/arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,11 @@ again:
CASPD (R2, R3), (R2), (R8, R9) // 487c2248

// RET
RET
RET // c0035fd6
RET R0 // 00005fd6
RET R6 // c0005fd6
RET R27 // 60035fd6
RET R30 // c0035fd6
RET foo(SB)

// B/BL/B.cond cases, and canonical names JMP, CALL.
Expand Down
12 changes: 7 additions & 5 deletions src/cmd/internal/obj/arm64/obj7.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {

var q *obj.Prog
var q1 *obj.Prog
var retjmp *obj.LSym
for p := c.cursym.Func().Text; p != nil; p = p.Link {
o := p.As
switch o {
Expand Down Expand Up @@ -846,7 +845,10 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
break
}

retjmp = p.To.Sym
retJMP, retReg := p.To.Sym, p.To.Reg
if retReg == 0 {
retReg = REGLINK
}
p.To = obj.Addr{}
if c.cursym.Func().Text.Mark&LEAF != 0 {
if c.autosize != 0 {
Expand Down Expand Up @@ -924,18 +926,18 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
p = q
}

if retjmp != nil { // retjmp
if retJMP != nil {
p.As = AB
p.To.Type = obj.TYPE_BRANCH
p.To.Sym = retjmp
p.To.Sym = retJMP
p.Spadj = +c.autosize
break
}

p.As = obj.ARET
p.To.Type = obj.TYPE_MEM
p.To.Offset = 0
p.To.Reg = REGLINK
p.To.Reg = retReg
p.Spadj = +c.autosize

case AADD, ASUB:
Expand Down

0 comments on commit b1fd047

Please sign in to comment.