Skip to content

Commit 11b4aee

Browse files
cherrymuirandall77
authored andcommitted
cmd/compile: mark R16, R17 clobbered for non-standard calls on ARM64
On ARM64, (external) linker generated trampoline may clobber R16 and R17. In CL 183842 we change Duff's devices not to use those registers. However, this is not enough. The register allocator also needs to know that these registers may be clobbered in any calls that don't follow the standard Go calling convention. This include Duff's devices and the write barrier. Fixes #32773, second attempt. Change-Id: Ia52a891d9bbb8515c927617dd53aee5af5bd9aa4 Reviewed-on: https://go-review.googlesource.com/c/go/+/184437 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Meng Zhuo <[email protected]> Reviewed-by: Keith Randall <[email protected]> Trust: Meng Zhuo <[email protected]>
1 parent 5834ce1 commit 11b4aee

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

src/cmd/compile/internal/ssa/gen/ARM64Ops.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,14 @@ func init() {
512512
// auxint = offset into duffzero code to start executing
513513
// returns mem
514514
// R20 changed as side effect
515+
// R16 and R17 may be clobbered by linker trampoline.
515516
{
516517
name: "DUFFZERO",
517518
aux: "Int64",
518519
argLength: 2,
519520
reg: regInfo{
520521
inputs: []regMask{buildReg("R20")},
521-
clobbers: buildReg("R20 R30"),
522+
clobbers: buildReg("R16 R17 R20 R30"),
522523
},
523524
faultOnNilArg0: true,
524525
unsafePoint: true, // FP maintenance around DUFFZERO can be clobbered by interrupts
@@ -552,13 +553,14 @@ func init() {
552553
// auxint = offset into duffcopy code to start executing
553554
// returns mem
554555
// R20, R21 changed as side effect
556+
// R16 and R17 may be clobbered by linker trampoline.
555557
{
556558
name: "DUFFCOPY",
557559
aux: "Int64",
558560
argLength: 3,
559561
reg: regInfo{
560562
inputs: []regMask{buildReg("R21"), buildReg("R20")},
561-
clobbers: buildReg("R20 R21 R26 R30"),
563+
clobbers: buildReg("R16 R17 R20 R21 R26 R30"),
562564
},
563565
faultOnNilArg0: true,
564566
faultOnNilArg1: true,
@@ -717,7 +719,8 @@ func init() {
717719
// LoweredWB invokes runtime.gcWriteBarrier. arg0=destptr, arg1=srcptr, arg2=mem, aux=runtime.gcWriteBarrier
718720
// It saves all GP registers if necessary,
719721
// but clobbers R30 (LR) because it's a call.
720-
{name: "LoweredWB", argLength: 3, reg: regInfo{inputs: []regMask{buildReg("R2"), buildReg("R3")}, clobbers: (callerSave &^ gpg) | buildReg("R30")}, clobberFlags: true, aux: "Sym", symEffect: "None"},
722+
// R16 and R17 may be clobbered by linker trampoline.
723+
{name: "LoweredWB", argLength: 3, reg: regInfo{inputs: []regMask{buildReg("R2"), buildReg("R3")}, clobbers: (callerSave &^ gpg) | buildReg("R16 R17 R30")}, clobberFlags: true, aux: "Sym", symEffect: "None"},
721724

722725
// There are three of these functions so that they can have three different register inputs.
723726
// When we check 0 <= c <= cap (A), then 0 <= b <= c (B), then 0 <= a <= b (C), we want the

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/asm_arm64.s

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,10 @@ TEXT ·checkASM(SB),NOSPLIT,$0-1
11581158
// It does not clobber any general-purpose registers,
11591159
// but may clobber others (e.g., floating point registers)
11601160
// The act of CALLing gcWriteBarrier will clobber R30 (LR).
1161-
TEXT runtime·gcWriteBarrier(SB),NOSPLIT,$216
1161+
TEXT runtime·gcWriteBarrier(SB),NOSPLIT,$200
11621162
// Save the registers clobbered by the fast path.
1163-
MOVD R0, 200(RSP)
1164-
MOVD R1, 208(RSP)
1163+
MOVD R0, 184(RSP)
1164+
MOVD R1, 192(RSP)
11651165
MOVD g_m(g), R0
11661166
MOVD m_p(R0), R0
11671167
MOVD (p_wbBuf+wbBuf_next)(R0), R1
@@ -1177,8 +1177,8 @@ TEXT runtime·gcWriteBarrier(SB),NOSPLIT,$216
11771177
// Is the buffer full? (flags set in CMP above)
11781178
BEQ flush
11791179
ret:
1180-
MOVD 200(RSP), R0
1181-
MOVD 208(RSP), R1
1180+
MOVD 184(RSP), R0
1181+
MOVD 192(RSP), R1
11821182
// Do the write.
11831183
MOVD R3, (R2)
11841184
RET
@@ -1202,17 +1202,16 @@ flush:
12021202
MOVD R13, 96(RSP)
12031203
MOVD R14, 104(RSP)
12041204
MOVD R15, 112(RSP)
1205-
MOVD R16, 120(RSP)
1206-
MOVD R17, 128(RSP)
1205+
// R16, R17 may be clobbered by linker trampoline
12071206
// R18 is unused.
1208-
MOVD R19, 136(RSP)
1209-
MOVD R20, 144(RSP)
1210-
MOVD R21, 152(RSP)
1211-
MOVD R22, 160(RSP)
1212-
MOVD R23, 168(RSP)
1213-
MOVD R24, 176(RSP)
1214-
MOVD R25, 184(RSP)
1215-
MOVD R26, 192(RSP)
1207+
MOVD R19, 120(RSP)
1208+
MOVD R20, 128(RSP)
1209+
MOVD R21, 136(RSP)
1210+
MOVD R22, 144(RSP)
1211+
MOVD R23, 152(RSP)
1212+
MOVD R24, 160(RSP)
1213+
MOVD R25, 168(RSP)
1214+
MOVD R26, 176(RSP)
12161215
// R27 is temp register.
12171216
// R28 is g.
12181217
// R29 is frame pointer (unused).
@@ -1236,16 +1235,14 @@ flush:
12361235
MOVD 96(RSP), R13
12371236
MOVD 104(RSP), R14
12381237
MOVD 112(RSP), R15
1239-
MOVD 120(RSP), R16
1240-
MOVD 128(RSP), R17
1241-
MOVD 136(RSP), R19
1242-
MOVD 144(RSP), R20
1243-
MOVD 152(RSP), R21
1244-
MOVD 160(RSP), R22
1245-
MOVD 168(RSP), R23
1246-
MOVD 176(RSP), R24
1247-
MOVD 184(RSP), R25
1248-
MOVD 192(RSP), R26
1238+
MOVD 120(RSP), R19
1239+
MOVD 128(RSP), R20
1240+
MOVD 136(RSP), R21
1241+
MOVD 144(RSP), R22
1242+
MOVD 152(RSP), R23
1243+
MOVD 160(RSP), R24
1244+
MOVD 168(RSP), R25
1245+
MOVD 176(RSP), R26
12491246
JMP ret
12501247

12511248
// Note: these functions use a special calling convention to save generated code space.

0 commit comments

Comments
 (0)