Skip to content

Commit e72cd86

Browse files
committed
Revert "runtime: consolidate function descriptor definitions on PPC64"
This reverts CL 478917. Reason for revert: need to revert CL 392854, and this caused a conflict. Change-Id: I02c3285de5635b431a99adc8790c8310d1c4e6a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/481059 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Run-TryBot: Cherry Mui <[email protected]>
1 parent 63ef905 commit e72cd86

File tree

6 files changed

+73
-46
lines changed

6 files changed

+73
-46
lines changed

src/runtime/asm_ppc64x.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,16 @@
2424

2525
#define FIXED_FRAME 32
2626

27-
// aix/ppc64 uses XCOFF which uses function descriptors.
28-
// AIX cannot perform the TOC relocation in a text section.
29-
// Therefore, these descriptors must live in a data section.
27+
// aix/ppc64 uses XCOFF which has function descriptors.
3028
#ifdef GOOS_aix
3129
#ifdef GOARCH_ppc64
3230
#define GO_PPC64X_HAS_FUNCDESC
33-
#define DEFINE_PPC64X_FUNCDESC(funcname, localfuncname) \
34-
DATA funcname+0(SB)/8, $localfuncname(SB) \
35-
DATA funcname+8(SB)/8, $TOC(SB) \
36-
DATA funcname+16(SB)/8, $0 \
37-
GLOBL funcname(SB), NOPTR, $24
3831
#endif
3932
#endif
4033

41-
// linux/ppc64 uses ELFv1 which uses function descriptors.
42-
// These must also look like ABI0 functions on linux/ppc64
43-
// to work with abi.FuncPCABI0(sigtramp) in os_linux.go.
44-
// Only static codegen is supported on linux/ppc64, so TOC
45-
// is not needed.
34+
// linux/ppc64 uses ELFv1 which has function descriptors.
4635
#ifdef GOOS_linux
4736
#ifdef GOARCH_ppc64
4837
#define GO_PPC64X_HAS_FUNCDESC
49-
#define DEFINE_PPC64X_FUNCDESC(funcname, localfuncname) \
50-
TEXT funcname(SB),NOSPLIT|NOFRAME,$0 \
51-
DWORD $localfuncname(SB) \
52-
DWORD $0 \
53-
DWORD $0
5438
#endif
5539
#endif

src/runtime/asm_ppc64x.s

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,26 @@ TEXT runtime·setg(SB), NOSPLIT, $0-8
771771
BL runtime·save_g(SB)
772772
RET
773773

774-
#ifdef GO_PPC64X_HAS_FUNCDESC
775-
DEFINE_PPC64X_FUNCDESC(setg_gcc<>, _setg_gcc<>)
776-
TEXT _setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
774+
#ifdef GOARCH_ppc64
775+
#ifdef GOOS_aix
776+
DATA setg_gcc<>+0(SB)/8, $_setg_gcc<>(SB)
777+
DATA setg_gcc<>+8(SB)/8, $TOC(SB)
778+
DATA setg_gcc<>+16(SB)/8, $0
779+
GLOBL setg_gcc<>(SB), NOPTR, $24
777780
#else
778781
TEXT setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
782+
DWORD $_setg_gcc<>(SB)
783+
DWORD $0
784+
DWORD $0
785+
#endif
786+
#endif
787+
788+
// void setg_gcc(G*); set g in C TLS.
789+
// Must obey the gcc calling convention.
790+
#ifdef GOARCH_ppc64le
791+
TEXT setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
792+
#else
793+
TEXT _setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
779794
#endif
780795
// The standard prologue clobbers R31, which is callee-save in
781796
// the C ABI, so we have to use $-8-0 and save LR ourselves.

src/runtime/cgo/asm_ppc64x.s

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@
77
#include "textflag.h"
88
#include "asm_ppc64x.h"
99

10-
#ifdef GO_PPC64X_HAS_FUNCDESC
11-
// crosscall2 is marked with go:cgo_export_static. On AIX, this creates and exports
12-
// the symbol name and descriptor as the AIX linker expects, but does not work if
13-
// referenced from within Go. Create and use an aliased descriptor of crosscall2
14-
// to workaround this.
15-
DEFINE_PPC64X_FUNCDESC(_crosscall2<>, crosscall2)
16-
#define CROSSCALL2_FPTR $_crosscall2<>(SB)
17-
#else
18-
#define CROSSCALL2_FPTR $crosscall2(SB)
19-
#endif
20-
2110
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
2211
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
2312
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
2413
MOVD _crosscall2_ptr(SB), R5
25-
MOVD CROSSCALL2_FPTR, R6
14+
#ifdef GOARCH_ppc64
15+
MOVD $_crosscall2<>(SB), R6
16+
#else
17+
MOVD $crosscall2(SB), R6
18+
#endif
2619
MOVD R6, (R5)
2720
RET
2821

22+
#ifdef GO_PPC64X_HAS_FUNCDESC
23+
// _crosscall2<> is a function descriptor to the real crosscall2.
24+
DATA _crosscall2<>+0(SB)/8, $crosscall2(SB)
25+
DATA _crosscall2<>+8(SB)/8, $TOC(SB)
26+
DATA _crosscall2<>+16(SB)/8, $0
27+
GLOBL _crosscall2<>(SB), NOPTR, $24
28+
#endif
29+
2930
// Called by C code generated by cmd/cgo.
3031
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
3132
// Saves C callee-saved registers and calls cgocallback with three arguments.

src/runtime/rt0_aix_ppc64.s

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
// license that can be found in the LICENSE file.
44

55
#include "textflag.h"
6-
#include "asm_ppc64x.h"
76

87
// _rt0_ppc64_aix is a function descriptor of the entrypoint function
98
// __start. This name is needed by cmd/link.
10-
DEFINE_PPC64X_FUNCDESC(_rt0_ppc64_aix, __start<>)
9+
DATA _rt0_ppc64_aix+0(SB)/8, $__start<>(SB)
10+
DATA _rt0_ppc64_aix+8(SB)/8, $TOC(SB)
11+
GLOBL _rt0_ppc64_aix(SB), NOPTR, $16
12+
1113

1214
// The starting function must return in the loader to
1315
// initialise some libraries, especially libthread which
@@ -35,7 +37,11 @@ TEXT __start<>(SB),NOSPLIT,$-8
3537
BL _main(SB)
3638

3739

38-
DEFINE_PPC64X_FUNCDESC(main, _main)
40+
DATA main+0(SB)/8, $_main(SB)
41+
DATA main+8(SB)/8, $TOC(SB)
42+
DATA main+16(SB)/8, $0
43+
GLOBL main(SB), NOPTR, $24
44+
3945
TEXT _main(SB),NOSPLIT,$-8
4046
MOVD $runtime·rt0_go(SB), R12
4147
MOVD R12, CTR
@@ -175,7 +181,10 @@ done:
175181
MOVD R0, LR
176182
RET
177183

178-
DEFINE_PPC64X_FUNCDESC(_rt0_ppc64_aix_lib_go, __rt0_ppc64_aix_lib_go)
184+
DATA _rt0_ppc64_aix_lib_go+0(SB)/8, $__rt0_ppc64_aix_lib_go(SB)
185+
DATA _rt0_ppc64_aix_lib_go+8(SB)/8, $TOC(SB)
186+
DATA _rt0_ppc64_aix_lib_go+16(SB)/8, $0
187+
GLOBL _rt0_ppc64_aix_lib_go(SB), NOPTR, $24
179188

180189
TEXT __rt0_ppc64_aix_lib_go(SB),NOSPLIT,$0
181190
MOVD _rt0_ppc64_aix_lib_argc<>(SB), R3

src/runtime/rt0_linux_ppc64.s

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
// license that can be found in the LICENSE file.
44

55
#include "textflag.h"
6-
#include "asm_ppc64x.h"
76

8-
DEFINE_PPC64X_FUNCDESC(_rt0_ppc64_linux, _main<>)
9-
DEFINE_PPC64X_FUNCDESC(main, _main<>)
7+
// actually a function descriptor for _main<>(SB)
8+
TEXT _rt0_ppc64_linux(SB),NOSPLIT,$0
9+
DWORD $_main<>(SB)
10+
DWORD $0
11+
DWORD $0
12+
13+
TEXT main(SB),NOSPLIT,$0
14+
DWORD $_main<>(SB)
15+
DWORD $0
16+
DWORD $0
1017

1118
TEXT _main<>(SB),NOSPLIT,$-8
1219
// In a statically linked binary, the stack contains argc,

src/runtime/sys_linux_ppc64x.s

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,18 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
447447
MOVD 24(R1), R2
448448
RET
449449

450-
#ifdef GO_PPC64X_HAS_FUNCDESC
451-
DEFINE_PPC64X_FUNCDESC(runtime·sigtramp, sigtramp<>)
452-
// cgo isn't supported on ppc64, but we need to supply a cgoSigTramp function.
453-
DEFINE_PPC64X_FUNCDESC(runtime·cgoSigtramp, sigtramp<>)
454-
TEXT sigtramp<>(SB),NOSPLIT|NOFRAME|TOPFRAME,$0
455-
#else
450+
#ifdef GOARCH_ppc64le
456451
// ppc64le doesn't need function descriptors
457452
// Save callee-save registers in the case of signal forwarding.
458453
// Same as on ARM64 https://golang.org/issue/31827 .
459454
TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
455+
#else
456+
// function descriptor for the real sigtramp
457+
TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
458+
DWORD $sigtramp<>(SB)
459+
DWORD $0
460+
DWORD $0
461+
TEXT sigtramp<>(SB),NOSPLIT|NOFRAME|TOPFRAME,$0
460462
#endif
461463
// Start with standard C stack frame layout and linkage.
462464
MOVD LR, R0
@@ -625,6 +627,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
625627
RET
626628

627629
#ifdef GOARCH_ppc64le
630+
// ppc64le doesn't need function descriptors
628631
TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
629632
// The stack unwinder, presumably written in C, may not be able to
630633
// handle Go frame correctly. So, this function is NOFRAME, and we
@@ -719,6 +722,14 @@ sigtrampnog:
719722
MOVD R12, CTR
720723
MOVD R10, LR // restore LR
721724
JMP (CTR)
725+
#else
726+
// function descriptor for the real sigtramp
727+
TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
728+
DWORD $cgoSigtramp<>(SB)
729+
DWORD $0
730+
DWORD $0
731+
TEXT cgoSigtramp<>(SB),NOSPLIT,$0
732+
JMP sigtramp<>(SB)
722733
#endif
723734

724735
// Used by cgoSigtramp to inspect without clobbering R30/R31 via runtime.load_g.

0 commit comments

Comments
 (0)