Skip to content

Commit 4212205

Browse files
committed
runtime, reflect: use correctly aligned stack frame sizes on arm64
arm64 requires either no stack frame or a frame with a size that is 8 mod 16 (adding the saved LR will make it 16-aligned). The cmd/internal/obj/arm64 has been silently aligning frames, but it led to a terrible bug when the compiler and obj disagreed on the frame size, and it's just generally confusing, so we're going to make misaligned frames an error instead of something that is silently changed. This CL prepares by updating assembly files. Note that the changes in this CL are already being done silently by cmd/internal/obj/arm64, so there is no semantic effect here, just a clarity effect. For #9880. Change-Id: Ibd6928dc5fdcd896c2bacd0291bf26b364591e28 Reviewed-on: https://go-review.googlesource.com/12845 Reviewed-by: Austin Clements <[email protected]>
1 parent 3952057 commit 4212205

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

src/reflect/asm_arm64.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// See the comment on the declaration of makeFuncStub in makefunc.go
1010
// for more details.
1111
// No arg size here, runtime pulls arg map out of the func value.
12-
TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$16
12+
TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$24
1313
NO_LOCAL_POINTERS
1414
MOVD R26, 8(RSP)
1515
MOVD $argframe+0(FP), R3
@@ -21,7 +21,7 @@ TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$16
2121
// See the comment on the declaration of methodValueCall in makefunc.go
2222
// for more details.
2323
// No arg size here; runtime pulls arg map out of the func value.
24-
TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$16
24+
TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$24
2525
NO_LOCAL_POINTERS
2626
MOVD R26, 8(RSP)
2727
MOVD $argframe+0(FP), R3

src/runtime/asm_arm64.s

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -424,33 +424,35 @@ end: \
424424
BL runtime·callwritebarrier(SB); \
425425
RET
426426

427-
CALLFN(·call16, 16)
428-
CALLFN(·call32, 32)
429-
CALLFN(·call64, 64)
430-
CALLFN(·call128, 128)
431-
CALLFN(·call256, 256)
432-
CALLFN(·call512, 512)
433-
CALLFN(·call1024, 1024)
434-
CALLFN(·call2048, 2048)
435-
CALLFN(·call4096, 4096)
436-
CALLFN(·call8192, 8192)
437-
CALLFN(·call16384, 16384)
438-
CALLFN(·call32768, 32768)
439-
CALLFN(·call65536, 65536)
440-
CALLFN(·call131072, 131072)
441-
CALLFN(·call262144, 262144)
442-
CALLFN(·call524288, 524288)
443-
CALLFN(·call1048576, 1048576)
444-
CALLFN(·call2097152, 2097152)
445-
CALLFN(·call4194304, 4194304)
446-
CALLFN(·call8388608, 8388608)
447-
CALLFN(·call16777216, 16777216)
448-
CALLFN(·call33554432, 33554432)
449-
CALLFN(·call67108864, 67108864)
450-
CALLFN(·call134217728, 134217728)
451-
CALLFN(·call268435456, 268435456)
452-
CALLFN(·call536870912, 536870912)
453-
CALLFN(·call1073741824, 1073741824)
427+
// These have 8 added to make the overall frame size a multiple of 16,
428+
// as required by the ABI. (There is another +8 for the saved LR.)
429+
CALLFN(·call16, 24 )
430+
CALLFN(·call32, 40 )
431+
CALLFN(·call64, 72 )
432+
CALLFN(·call128, 136 )
433+
CALLFN(·call256, 264 )
434+
CALLFN(·call512, 520 )
435+
CALLFN(·call1024, 1032 )
436+
CALLFN(·call2048, 2056 )
437+
CALLFN(·call4096, 4104 )
438+
CALLFN(·call8192, 8200 )
439+
CALLFN(·call16384, 16392 )
440+
CALLFN(·call32768, 32776 )
441+
CALLFN(·call65536, 65544 )
442+
CALLFN(·call131072, 131080 )
443+
CALLFN(·call262144, 262152 )
444+
CALLFN(·call524288, 524296 )
445+
CALLFN(·call1048576, 1048584 )
446+
CALLFN(·call2097152, 2097160 )
447+
CALLFN(·call4194304, 4194312 )
448+
CALLFN(·call8388608, 8388616 )
449+
CALLFN(·call16777216, 16777224 )
450+
CALLFN(·call33554432, 33554440 )
451+
CALLFN(·call67108864, 67108872 )
452+
CALLFN(·call134217728, 134217736 )
453+
CALLFN(·call268435456, 268435464 )
454+
CALLFN(·call536870912, 536870920 )
455+
CALLFN(·call1073741824, 1073741832 )
454456

455457
// bool cas(uint32 *ptr, uint32 old, uint32 new)
456458
// Atomically:
@@ -613,7 +615,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$24-24
613615

614616
// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
615617
// See cgocall.go for more details.
616-
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$16-24
618+
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$24-24
617619
NO_LOCAL_POINTERS
618620

619621
// Load g from thread-local storage.
@@ -721,7 +723,7 @@ droppedm:
721723

722724
// Called from cgo wrappers, this function returns g->m->curg.stack.hi.
723725
// Must obey the gcc calling convention.
724-
TEXT _cgo_topofstack(SB),NOSPLIT,$16
726+
TEXT _cgo_topofstack(SB),NOSPLIT,$24
725727
// g (R28) and REGTMP (R27) might be clobbered by load_g. They
726728
// are callee-save in the gcc calling convention, so save them.
727729
MOVD R27, savedR27-8(SP)

src/runtime/sys_linux_arm64.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEXT runtime·getrlimit(SB),NOSPLIT,$-8-20
115115
MOVW R0, ret+16(FP)
116116
RET
117117

118-
TEXT runtime·usleep(SB),NOSPLIT,$16-4
118+
TEXT runtime·usleep(SB),NOSPLIT,$24-4
119119
MOVWU usec+0(FP), R3
120120
MOVD R3, R5
121121
MOVW $1000000, R4
@@ -180,7 +180,7 @@ TEXT runtime·mincore(SB),NOSPLIT,$-8-28
180180
RET
181181

182182
// func now() (sec int64, nsec int32)
183-
TEXT time·now(SB),NOSPLIT,$16-12
183+
TEXT time·now(SB),NOSPLIT,$24-12
184184
MOVD RSP, R0
185185
MOVD $0, R1
186186
MOVD $SYS_gettimeofday, R8
@@ -193,7 +193,7 @@ TEXT time·now(SB),NOSPLIT,$16-12
193193
MOVW R5, nsec+8(FP)
194194
RET
195195

196-
TEXT runtime·nanotime(SB),NOSPLIT,$16-8
196+
TEXT runtime·nanotime(SB),NOSPLIT,$24-8
197197
MOVW $1, R0 // CLOCK_MONOTONIC
198198
MOVD RSP, R1
199199
MOVD $SYS_clock_gettime, R8

0 commit comments

Comments
 (0)