1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:04:49 -07:00

reflect, runtime, runtime/cgo: use ppc64 asm constant for fixed frame size

Shared libraries on ppc64le will require a larger minimum stack frame (because
the ABI mandates that the TOC pointer is available at 24(R1)). Part 3 of that
is using a #define in the ppc64 assembly to refer to the size of the fixed
part of the stack (finding all these took me about a week!).

Change-Id: I50f22fe1c47af1ec59da1bd7ea8f84a4750df9b7
Reviewed-on: https://go-review.googlesource.com/15525
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2015-10-08 22:34:29 +13:00
parent 97055dc1f1
commit b8f8969fbd
6 changed files with 79 additions and 42 deletions

View File

@ -626,6 +626,8 @@ func install(dir string) {
pathf("%s/src/runtime/textflag.h", goroot), 0)
copyfile(pathf("%s/pkg/include/funcdata.h", goroot),
pathf("%s/src/runtime/funcdata.h", goroot), 0)
copyfile(pathf("%s/pkg/include/asm_ppc64x.h", goroot),
pathf("%s/src/runtime/asm_ppc64x.h", goroot), 0)
}
// Generate any missing files; regenerate existing ones.

View File

@ -6,6 +6,7 @@
#include "textflag.h"
#include "funcdata.h"
#include "asm_ppc64x.h"
// makeFuncStub is the code half of the function returned by MakeFunc.
// See the comment on the declaration of makeFuncStub in makefunc.go
@ -13,9 +14,9 @@
// No arg size here, runtime pulls arg map out of the func value.
TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$16
NO_LOCAL_POINTERS
MOVD R11, 8(R1)
MOVD R11, FIXED_FRAME+0(R1)
MOVD $argframe+0(FP), R3
MOVD R3, 16(R1)
MOVD R3, FIXED_FRAME+8(R1)
BL ·callReflect(SB)
RET
@ -25,8 +26,8 @@ TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$16
// No arg size here; runtime pulls arg map out of the func value.
TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$16
NO_LOCAL_POINTERS
MOVD R11, 8(R1)
MOVD R11, FIXED_FRAME+0(R1)
MOVD $argframe+0(FP), R3
MOVD R3, 16(R1)
MOVD R3, FIXED_FRAME+8(R1)
BL ·callMethod(SB)
RET

31
src/runtime/asm_ppc64x.h Normal file
View File

@ -0,0 +1,31 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// FIXED_FRAME defines the size of the fixed part of a stack frame. A stack
// frame looks like this:
//
// +---------------------+
// | local variable area |
// +---------------------+
// | argument area |
// +---------------------+ <- R1+FIXED_FRAME
// | fixed area |
// +---------------------+ <- R1
//
// So a function that sets up a stack frame at all uses as least FIXED_FRAME
// bytes of stack. This mostly affects assembly that calls other functions
// with arguments (the arguments should be stored at FIXED_FRAME+0(R1),
// FIXED_FRAME+8(R1) etc) and some other low-level places.
//
// The reason for using a constant is when code is compiled as PIC on ppc64le
// the fixed part of the stack is 32 bytes large (although PIC is not actually
// supported yet).
#ifdef GOARCH_ppc64
#define FIXED_FRAME 8
#endif
#ifdef GOARCH_ppc64le
#define FIXED_FRAME 8
#endif

View File

@ -8,6 +8,7 @@
#include "go_tls.h"
#include "funcdata.h"
#include "textflag.h"
#include "asm_ppc64x.h"
TEXT runtime·rt0_go(SB),NOSPLIT,$0
// R1 = stack; R3 = argc; R4 = argv; R13 = C TLS base pointer
@ -15,9 +16,9 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0
// initialize essential registers
BL runtime·reginit(SB)
SUB $24, R1
MOVW R3, 8(R1) // argc
MOVD R4, 16(R1) // argv
SUB $(FIXED_FRAME+16), R1
MOVW R3, FIXED_FRAME+0(R1) // argc
MOVD R4, FIXED_FRAME+8(R1) // argv
// create istack out of the given (operating system) stack.
// _cgo_init may update stackguard.
@ -225,7 +226,7 @@ switch:
BL runtime·save_g(SB)
MOVD (g_sched+gobuf_sp)(g), R3
// make it look like mstart called systemstack on g0, to stop traceback
SUB $8, R3
SUB $FIXED_FRAME, R3
MOVD $runtime·mstart(SB), R4
MOVD R4, 0(R3)
MOVD R3, R1
@ -381,7 +382,7 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \
MOVD arg+16(FP), R3; \
MOVWZ argsize+24(FP), R4; \
MOVD R1, R5; \
ADD $(8-1), R5; \
ADD $(FIXED_FRAME-1), R5; \
SUB $1, R3; \
ADD R5, R4; \
CMP R5, R4; \
@ -403,7 +404,7 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \
ADD R6, R5; \
ADD R6, R3; \
SUB R6, R4; \
ADD $(8-1), R5; \
ADD $(FIXED_FRAME-1), R5; \
SUB $1, R3; \
ADD R5, R4; \
loop: \
@ -418,10 +419,10 @@ end: \
MOVD arg+16(FP), R3; \
MOVWZ n+24(FP), R4; \
MOVWZ retoffset+28(FP), R6; \
MOVD R7, 8(R1); \
MOVD R3, 16(R1); \
MOVD R4, 24(R1); \
MOVD R6, 32(R1); \
MOVD R7, FIXED_FRAME+0(R1); \
MOVD R3, FIXED_FRAME+8(R1); \
MOVD R4, FIXED_FRAME+16(R1); \
MOVD R6, FIXED_FRAME+24(R1); \
BL runtime·callwritebarrier(SB); \
RET
@ -676,7 +677,7 @@ TEXT runtime·jmpdefer(SB), NOSPLIT|NOFRAME, $0-16
MOVD fv+0(FP), R11
MOVD argp+8(FP), R1
SUB $8, R1
SUB $FIXED_FRAME, R1
MOVD 0(R11), R3
MOVD R3, CTR
BR (CTR)
@ -750,11 +751,11 @@ g0:
// cgocallback_gofunc.
TEXT runtime·cgocallback(SB),NOSPLIT,$24-24
MOVD $fn+0(FP), R3
MOVD R3, 8(R1)
MOVD R3, FIXED_FRAME+0(R1)
MOVD frame+8(FP), R3
MOVD R3, 16(R1)
MOVD R3, FIXED_FRAME+8(R1)
MOVD framesize+16(FP), R3
MOVD R3, 24(R1)
MOVD R3, FIXED_FRAME+16(R1)
MOVD $runtime·cgocallback_gofunc(SB), R3
MOVD R3, CTR
BL (CTR)
@ -831,14 +832,14 @@ havem:
BL runtime·save_g(SB)
MOVD (g_sched+gobuf_sp)(g), R4 // prepare stack as R4
MOVD (g_sched+gobuf_pc)(g), R5
MOVD R5, -24(R4)
MOVD $-24(R4), R1
MOVD R5, -(FIXED_FRAME+16)(R4)
MOVD $-(FIXED_FRAME+16)(R4), R1
BL runtime·cgocallbackg(SB)
// Restore g->sched (== m->curg->sched) from saved values.
MOVD 0(R1), R5
MOVD R5, (g_sched+gobuf_pc)(g)
MOVD $24(R1), R4
MOVD $(FIXED_FRAME+16)(R1), R4
MOVD R4, (g_sched+gobuf_sp)(g)
// Switch back to m->g0's stack and restore m->g0->sched.sp.
@ -890,34 +891,34 @@ TEXT setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
RET
TEXT runtime·getcallerpc(SB),NOSPLIT,$8-16
MOVD 16(R1), R3 // LR saved by caller
MOVD FIXED_FRAME+8(R1), R3 // LR saved by caller
MOVD runtime·stackBarrierPC(SB), R4
CMP R3, R4
BNE nobar
// Get original return PC.
BL runtime·nextBarrierPC(SB)
MOVD 8(R1), R3
MOVD FIXED_FRAME+0(R1), R3
nobar:
MOVD R3, ret+8(FP)
RET
TEXT runtime·setcallerpc(SB),NOSPLIT,$8-16
MOVD pc+8(FP), R3
MOVD 16(R1), R4
MOVD FIXED_FRAME+8(R1), R4
MOVD runtime·stackBarrierPC(SB), R5
CMP R4, R5
BEQ setbar
MOVD R3, 16(R1) // set LR in caller
MOVD R3, FIXED_FRAME+8(R1) // set LR in caller
RET
setbar:
// Set the stack barrier return PC.
MOVD R3, 8(R1)
MOVD R3, FIXED_FRAME+0(R1)
BL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
MOVD argp+0(FP), R3
SUB $8, R3
SUB $FIXED_FRAME, R3
MOVD R3, ret+8(FP)
RET
@ -949,11 +950,11 @@ TEXT runtime·memhash_varlen(SB),NOSPLIT,$40-24
MOVD p+0(FP), R3
MOVD h+8(FP), R4
MOVD 8(R11), R5
MOVD R3, 8(R1)
MOVD R4, 16(R1)
MOVD R5, 24(R1)
MOVD R3, FIXED_FRAME+0(R1)
MOVD R4, FIXED_FRAME+8(R1)
MOVD R5, FIXED_FRAME+16(R1)
BL runtime·memhash(SB)
MOVD 32(R1), R3
MOVD FIXED_FRAME+24(R1), R3
MOVD R3, ret+16(FP)
RET
@ -996,11 +997,11 @@ TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17
CMP R3, R4
BEQ eq
MOVD 8(R11), R5 // compiler stores size at offset 8 in the closure
MOVD R3, 8(R1)
MOVD R4, 16(R1)
MOVD R5, 24(R1)
MOVD R3, FIXED_FRAME+0(R1)
MOVD R4, FIXED_FRAME+8(R1)
MOVD R5, FIXED_FRAME+16(R1)
BL runtime·memeq(SB)
MOVBZ 32(R1), R3
MOVBZ FIXED_FRAME+24(R1), R3
MOVB R3, ret+16(FP)
RET
eq:

View File

@ -5,6 +5,7 @@
// +build ppc64 ppc64le
#include "textflag.h"
#include "asm_ppc64x.h"
/*
* void crosscall2(void (*fn)(void*, int32), void*, int32)
@ -21,18 +22,18 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
BL saveregs2<>(SB)
MOVDU R1, (-288-3*8)(R1)
MOVDU R1, (-288-2*8-FIXED_FRAME)(R1)
// Initialize Go ABI environment
BL runtime·reginit(SB)
BL runtime·load_g(SB)
MOVD R3, CTR
MOVD R4, 8(R1)
MOVD R5, 16(R1)
MOVD R4, FIXED_FRAME+0(R1)
MOVD R5, FIXED_FRAME+8(R1)
BL (CTR)
ADD $(288+3*8), R1
ADD $(288+2*8+FIXED_FRAME), R1
BL restoreregs2<>(SB)

View File

@ -12,6 +12,7 @@
#include "go_asm.h"
#include "go_tls.h"
#include "textflag.h"
#include "asm_ppc64x.h"
#define SYS_exit 1
#define SYS_read 3
@ -231,9 +232,9 @@ TEXT runtime·_sigtramp(SB),NOSPLIT,$64
BEQ 2(PC)
BL runtime·load_g(SB)
MOVW R3, 8(R1)
MOVD R4, 16(R1)
MOVD R5, 24(R1)
MOVW R3, FIXED_FRAME+0(R1)
MOVD R4, FIXED_FRAME+8(R1)
MOVD R5, FIXED_FRAME+16(R1)
MOVD $runtime·sigtrampgo(SB), R31
MOVD R31, CTR
BL (CTR)