Skip to content

Commit 2068d56

Browse files
prattmicgopherbot
authored andcommitted
Revert "Revert "Revert "runtime: consolidate function descriptor definitions on PPC64"""
This reverts CL 481075 (a re-apply of previously reverted CL 478917). Reason for revert: CL 481061 causes C TSAN failures and must be reverted. See CL 485275. This CL depends on CL 481061. For #59678. Change-Id: I4bf7f43d9df1ae28e04cd4065552bcbee82ef13f Reviewed-on: https://go-review.googlesource.com/c/go/+/485316 Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Michael Pratt <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent 0e9b2bc commit 2068d56

File tree

6 files changed

+73
-46
lines changed

6 files changed

+73
-46
lines changed

src/runtime/asm_ppc64x.h

+2-18
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

+18-3
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

+13-12
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

+13-4
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

+10-3
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

+17-6
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,7 @@ 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 .
@@ -461,6 +456,13 @@ TEXT sigtramp<>(SB),NOSPLIT|NOFRAME|TOPFRAME,$0
461456
// a function pointer) as R2 may not be preserved when calling this
462457
// function. In those cases, the caller preserves their R2.
463458
TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
459+
#else
460+
// function descriptor for the real sigtramp
461+
TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
462+
DWORD $sigtramp<>(SB)
463+
DWORD $0
464+
DWORD $0
465+
TEXT sigtramp<>(SB),NOSPLIT|NOFRAME|TOPFRAME,$0
464466
#endif
465467
// This is called with ELF calling conventions. Convert to Go.
466468
// Allocate space for argument storage to call runtime.sigtrampgo.
@@ -489,6 +491,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
489491
RET
490492

491493
#ifdef GOARCH_ppc64le
494+
// ppc64le doesn't need function descriptors
492495
TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
493496
// The stack unwinder, presumably written in C, may not be able to
494497
// handle Go frame correctly. So, this function is NOFRAME, and we
@@ -583,6 +586,14 @@ sigtrampnog:
583586
MOVD R12, CTR
584587
MOVD R10, LR // restore LR
585588
JMP (CTR)
589+
#else
590+
// function descriptor for the real sigtramp
591+
TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
592+
DWORD $cgoSigtramp<>(SB)
593+
DWORD $0
594+
DWORD $0
595+
TEXT cgoSigtramp<>(SB),NOSPLIT,$0
596+
JMP sigtramp<>(SB)
586597
#endif
587598

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

0 commit comments

Comments
 (0)