Skip to content

Commit dc20a19

Browse files
committed
reserve 48 bytes stack for ppc64
1 parent 89f2540 commit dc20a19

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-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 leaset.
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+
//golang has experimental support for linux/ppc64 now, see comments in 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#ifdef GOOS_aix
1414
#define cgoCalleeStackSize 48
1515
#else
16+
#ifdef GOARCH_ppc64le
1617
#define cgoCalleeStackSize 32
18+
#else
19+
#define cgoCalleeStackSize 48
1720
#endif
1821

1922
TEXT runtime·rt0_go(SB),NOSPLIT,$0
@@ -94,6 +97,11 @@ nocgo:
9497
MOVDU R0, -8(R1)
9598
MOVDU R0, -8(R1)
9699
MOVDU R0, -8(R1)
100+
#ifdef GOARCH_ppc64
101+
// ppc64 requires 48 bytes at least.
102+
MOVDU R0, -8(R1)
103+
MOVDU R0, -8(R1)
104+
#endif
97105
BL runtime·newproc(SB)
98106
ADD $(16+FIXED_FRAME), R1
99107

@@ -199,6 +207,11 @@ TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8
199207
MOVDU R0, -8(R1)
200208
MOVDU R0, -8(R1)
201209
MOVDU R0, -8(R1)
210+
#ifdef GOARCH_ppc64
211+
// ppc64 requires 48 bytes at least.
212+
MOVDU R0, -8(R1)
213+
MOVDU R0, -8(R1)
214+
#endif
202215
BL (CTR)
203216
MOVD 24(R1), R2
204217
BR runtime·badmcall2(SB)
@@ -565,7 +578,11 @@ TEXT gosave<>(SB),NOSPLIT|NOFRAME,$0
565578
#ifdef GOOS_aix
566579
#define asmcgocallSaveOffset cgoCalleeStackSize + 8
567580
#else
581+
#ifdef GOARCH_ppc64le
568582
#define asmcgocallSaveOffset cgoCalleeStackSize
583+
#else
584+
#define asmcgocallSaveOffset cgoCalleeStackSize + 8
585+
#endif
569586
#endif
570587

571588
// 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)