Skip to content

Commit e811639

Browse files
abner-chencxen0n
authored andcommitted
cmd/internal/obj/loong64: save LR after decrementing SP
Refer to CL 413428 and 412474, for loong64, like mips, s390x and riscv, there is no single instruction that saves the LR and decrements the SP, so we also need to insert an instruction to save the LR after decrementing the SP. Fixes golang#56623. Updates golang#53374. Change-Id: I3de040792f0a041d3d2a98ea89c23a2dd2f4ad10
1 parent a6d4692 commit e811639

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/cmd/asm/internal/asm/testdata/loong64.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "../../../../../runtime/textflag.h"
66
// TODO: cover more instruction
77

8-
TEXT foo(SB),DUPOK|NOSPLIT,$0
9-
JAL 1(PC) //CALL 1(PC) //000c0054
8+
TEXT foo(SB),DUPOK|NOSPLIT|NOFRAME,$0
9+
JAL 1(PC) //CALL 1(PC) //00040054
1010
JAL (R4) //CALL (R4) //8100004c
11-
JAL foo(SB) //CALL foo(SB) //00100054
11+
JAL foo(SB) //CALL foo(SB) //00080054

src/cmd/internal/obj/loong64/obj.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,20 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
260260
q.Spadj = +autosize
261261

262262
q = c.ctxt.EndUnsafePoint(q, c.newprog, -1)
263+
264+
// On Linux, in a cgo binary we may get a SIGSETXID signal early on
265+
// before the signal stack is set, as glibc doesn't allow us to block
266+
// SIGSETXID. So a signal may land on the current stack and clobber
267+
// the content below the SP. We store the LR again after the SP is
268+
// decremented.
269+
q = obj.Appendp(q, newprog)
270+
q.As = mov
271+
q.Pos = p.Pos
272+
q.From.Type = obj.TYPE_REG
273+
q.From.Reg = REGLINK
274+
q.To.Type = obj.TYPE_MEM
275+
q.To.Offset = 0
276+
q.To.Reg = REGSP
263277
}
264278

265279
if c.cursym.Func().Text.From.Sym.Wrapper() && c.cursym.Func().Text.Mark&LEAF == 0 {

0 commit comments

Comments
 (0)