Skip to content

Commit c938051

Browse files
randall77gopherbot
authored andcommitted
Revert "cmd/compile: redo arm64 LR/FP save and restore"
This reverts commit 719dfcf. Reason for revert: Causing crashes. Change-Id: I0b8526dd03d82fa074ce4f97f1789eeac702b3eb Reviewed-on: https://go-review.googlesource.com/c/go/+/709755 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 6469954 commit c938051

File tree

23 files changed

+361
-303
lines changed

23 files changed

+361
-303
lines changed

src/cmd/compile/abi-internal.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,19 @@ A function's stack frame, after the frame is created, is laid out as
576576
follows:
577577

578578
+------------------------------+
579-
| return PC |
580-
| frame pointer on entry | ← R29 points to
581579
| ... locals ... |
582580
| ... outgoing arguments ... |
583-
| unused word | ← RSP points to
581+
| return PC | ← RSP points to
582+
| frame pointer on entry |
584583
+------------------------------+ ↓ lower addresses
585584

586585
The "return PC" is loaded to the link register, R30, as part of the
587586
arm64 `CALL` operation.
588587

589-
On entry, a function pushes R30 (the return address) and R29
590-
(the caller's frame pointer) onto the bottom of the stack. It then
591-
subtracts a constant from RSP to open its stack frame.
588+
On entry, a function subtracts from RSP to open its stack frame, and
589+
saves the values of R30 and R29 at the bottom of the frame.
590+
Specifically, R30 is saved at 0(RSP) and R29 is saved at -8(RSP),
591+
after RSP is updated.
592592

593593
A leaf function that does not require any stack space may omit the
594594
saved R30 and R29.

src/cmd/compile/internal/arm64/ggen.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111
)
1212

1313
func padframe(frame int64) int64 {
14-
// arm64 requires frame sizes here that are 8 mod 16.
15-
// With the additional (unused) slot at the bottom of the frame,
16-
// that makes an aligned 16 byte frame.
17-
// Adding a save region for LR+FP does not change the alignment.
18-
if frame != 0 {
19-
frame += (-(frame + 8)) & 15
14+
// arm64 requires that the frame size (not counting saved FP&LR)
15+
// be 16 bytes aligned. If not, pad it.
16+
if frame%16 != 0 {
17+
frame += 16 - (frame % 16)
2018
}
2119
return frame
2220
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
221221

222222
for i := 0; i < len(args); i++ {
223223
a := args[i]
224-
// Offset by size of the unused slot before start of args.
224+
// Offset by size of the saved LR slot.
225225
addr := ssagen.SpillSlotAddr(a, arm64.REGSP, base.Ctxt.Arch.FixedFrameSize)
226226
// Look for double-register operations if we can.
227227
if i < len(args)-1 {

src/cmd/compile/internal/ssagen/pgen.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,10 @@ func StackOffset(slot ssa.LocalSlot) int32 {
393393
case ir.PAUTO:
394394
off = n.FrameOffset()
395395
if base.Ctxt.Arch.FixedFrameSize == 0 {
396-
// x86 return address
397396
off -= int64(types.PtrSize)
398397
}
399398
if buildcfg.FramePointerEnabled {
400-
// frame pointer
401399
off -= int64(types.PtrSize)
402-
if buildcfg.GOARCH == "arm64" {
403-
// arm64 return address also
404-
off -= int64(types.PtrSize)
405-
}
406400
}
407401
}
408402
return int32(off + slot.Off)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7150,15 +7150,14 @@ func defframe(s *State, e *ssafn, f *ssa.Func) {
71507150
// Insert code to zero ambiguously live variables so that the
71517151
// garbage collector only sees initialized values when it
71527152
// looks for pointers.
7153-
// Note: lo/hi are offsets from varp and will be negative.
71547153
var lo, hi int64
71557154

71567155
// Opaque state for backend to use. Current backends use it to
71577156
// keep track of which helper registers have been zeroed.
71587157
var state uint32
71597158

71607159
// Iterate through declarations. Autos are sorted in decreasing
7161-
// frame offset order (least negative to most negative).
7160+
// frame offset order.
71627161
for _, n := range e.curfn.Dcl {
71637162
if !n.Needzero() {
71647163
continue

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ctxt7 struct {
5151
blitrl *obj.Prog
5252
elitrl *obj.Prog
5353
autosize int32
54+
extrasize int32
5455
instoffset int64
5556
pc int64
5657
pool struct {
@@ -1121,7 +1122,8 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
11211122
ctxt.Diag("arm64 ops not initialized, call arm64.buildop first")
11221123
}
11231124

1124-
c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym, autosize: int32(p.To.Offset)}
1125+
c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym, autosize: int32(p.To.Offset & 0xffffffff), extrasize: int32(p.To.Offset >> 32)}
1126+
p.To.Offset &= 0xffffffff // extrasize is no longer needed
11251127

11261128
// Process literal pool and allocate initial program counter for each Prog, before
11271129
// generating branch veneers.
@@ -2117,8 +2119,8 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
21172119
// a.Offset is still relative to pseudo-SP.
21182120
a.Reg = obj.REG_NONE
21192121
}
2120-
// The frame top 16 bytes are for LR/FP
2121-
c.instoffset = int64(c.autosize) + a.Offset - extrasize
2122+
// The frame top 8 or 16 bytes are for FP
2123+
c.instoffset = int64(c.autosize) + a.Offset - int64(c.extrasize)
21222124
return autoclass(c.instoffset)
21232125

21242126
case obj.NAME_PARAM:
@@ -2178,8 +2180,8 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
21782180
// a.Offset is still relative to pseudo-SP.
21792181
a.Reg = obj.REG_NONE
21802182
}
2181-
// The frame top 16 bytes are for LR/FP
2182-
c.instoffset = int64(c.autosize) + a.Offset - extrasize
2183+
// The frame top 8 or 16 bytes are for FP
2184+
c.instoffset = int64(c.autosize) + a.Offset - int64(c.extrasize)
21832185

21842186
case obj.NAME_PARAM:
21852187
if a.Reg == REGSP {

0 commit comments

Comments
 (0)