Skip to content

Commit 3b6ffd0

Browse files
committed
reserve 48 bytes in stack frame for ppc64
1 parent 89f2540 commit 3b6ffd0

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

src/cmd/internal/obj/link.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,13 @@ func (ctxt *Link) FixedFrameSize() int64 {
684684
case sys.AMD64, sys.I386, sys.Wasm:
685685
return 0
686686
case sys.PPC64:
687-
// PIC code on ppc64le requires 32 bytes of stack, and it's easier to
688-
// just use that much stack always on ppc64x.
689-
return int64(4 * ctxt.Arch.PtrSize)
687+
// PIC code on ppc64le requires 32 bytes of stack.
688+
// ppc64 requires 48 bytes at least.
689+
if ctxt.Arch.Name == "ppc64le" {
690+
return int64(4 * ctxt.Arch.PtrSize)
691+
} else {
692+
return int64(6 * ctxt.Arch.PtrSize)
693+
}
690694
default:
691695
return int64(ctxt.Arch.PtrSize)
692696
}

src/cmd/link/internal/ld/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ func determineLinkMode(ctxt *Link) {
247247
}
248248
ctxt.LinkMode = LinkInternal
249249
case "1":
250-
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" {
250+
// We have experimental support for linux/ppc64 now, see https://github.com/golang/go/issues/13192.
251+
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" && objabi.GOOS != "linux" {
251252
Exitf("external linking requested via GO_EXTLINK_ENABLED but not supported for %s/ppc64", objabi.GOOS)
252253
}
253254
ctxt.LinkMode = LinkExternal
@@ -261,7 +262,7 @@ func determineLinkMode(ctxt *Link) {
261262
} else {
262263
ctxt.LinkMode = LinkInternal
263264
}
264-
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" && ctxt.LinkMode == LinkExternal {
265+
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" && objabi.GOOS != "linux" && ctxt.LinkMode == LinkExternal {
265266
Exitf("external linking is not supported for %s/ppc64", objabi.GOOS)
266267
}
267268
}
@@ -270,7 +271,7 @@ func determineLinkMode(ctxt *Link) {
270271
Exitf("internal linking requested but external linking required: %s", reason)
271272
}
272273
case LinkExternal:
273-
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" {
274+
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" && objabi.GOOS != "linux" {
274275
Exitf("external linking not supported for %s/ppc64", objabi.GOOS)
275276
}
276277
}

src/runtime/asm_ppc64x.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
//
2121
// The reason for using a constant is to make supporting PIC easier (although
2222
// we only support PIC on ppc64le which has a minimum 32 bytes of stack frame,
23-
// and currently always use that much, PIC on ppc64 would need to use 48).
24-
23+
// PIC on ppc64 would need to use 48).
24+
#ifdef GOARCH_ppc64le
2525
#define FIXED_FRAME 32
26+
#else
27+
#define FIXED_FRAME 48
28+
#endif

src/runtime/asm_ppc64x.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
#ifdef GOOS_aix
1414
#define cgoCalleeStackSize 48
1515
#else
16+
#ifdef GOARCH_ppc64le
1617
#define cgoCalleeStackSize 32
18+
#else
19+
#define cgoCalleeStackSize 48
20+
#endif
1721
#endif
1822

1923
TEXT runtime·rt0_go(SB),NOSPLIT,$0
@@ -94,6 +98,11 @@ nocgo:
9498
MOVDU R0, -8(R1)
9599
MOVDU R0, -8(R1)
96100
MOVDU R0, -8(R1)
101+
#ifdef GOARCH_ppc64
102+
// ppc64 requires 48 bytes at least.
103+
MOVDU R0, -8(R1)
104+
MOVDU R0, -8(R1)
105+
#endif
97106
BL runtime·newproc(SB)
98107
ADD $(16+FIXED_FRAME), R1
99108

@@ -199,6 +208,11 @@ TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8
199208
MOVDU R0, -8(R1)
200209
MOVDU R0, -8(R1)
201210
MOVDU R0, -8(R1)
211+
#ifdef GOARCH_ppc64
212+
// ppc64 requires 48 bytes at least.
213+
MOVDU R0, -8(R1)
214+
MOVDU R0, -8(R1)
215+
#endif
202216
BL (CTR)
203217
MOVD 24(R1), R2
204218
BR runtime·badmcall2(SB)
@@ -565,7 +579,11 @@ TEXT gosave<>(SB),NOSPLIT|NOFRAME,$0
565579
#ifdef GOOS_aix
566580
#define asmcgocallSaveOffset cgoCalleeStackSize + 8
567581
#else
582+
#ifdef GOARCH_ppc64le
568583
#define asmcgocallSaveOffset cgoCalleeStackSize
584+
#else
585+
#define asmcgocallSaveOffset cgoCalleeStackSize + 8
586+
#endif
569587
#endif
570588

571589
// func asmcgocall(fn, arg unsafe.Pointer) int32

src/runtime/internal/sys/arch_ppc64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const (
1111
PCQuantum = 4
1212
Int64Align = 8
1313
HugePageSize = 0
14-
MinFrameSize = 32
14+
MinFrameSize = 48
1515
)
1616

1717
type Uintreg uint64

src/runtime/rt0_linux_ppc64.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TEXT _main<>(SB),NOSPLIT,$-8
1818
// There is no TLS base pointer.
1919
//
2020
// TODO(austin): Support ABI v1 dynamic linking entry point
21+
XOR R0, R0
2122
MOVD $runtime·rt0_go(SB), R12
2223
MOVD R12, CTR
2324
MOVBZ runtime·iscgo(SB), R5

0 commit comments

Comments
 (0)