From 6827f0d7722ae08cf25cf2212f78bfc6ab8bfd0d Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Tue, 14 Mar 2023 20:50:38 +1100 Subject: [PATCH] runtime: provide and use a GO_PPC64X_HAS_FUNCDESC define Rather than implying that all ppc64 GOARCHs use function descriptors, provide a define for platforms that make use of function descriptors. Condition on GO_PPC64X_HAS_FUNCDESC when choosing whether or not to load the entry address from the first slot of the function descriptor. Updates #56001. Change-Id: I9cdc788f2de70a1262c17d8485b555383d1374b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/476117 Reviewed-by: Dmitri Shuralyov Run-TryBot: Joel Sing Reviewed-by: Lynn Boger TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/runtime/asm_ppc64x.h | 14 ++++++++++++++ src/runtime/asm_ppc64x.s | 14 ++++++-------- src/runtime/cgo/asm_ppc64x.s | 6 ++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/runtime/asm_ppc64x.h b/src/runtime/asm_ppc64x.h index 5e55055fdbc..cce5537a9cb 100644 --- a/src/runtime/asm_ppc64x.h +++ b/src/runtime/asm_ppc64x.h @@ -23,3 +23,17 @@ // and currently always use that much, PIC on ppc64 would need to use 48). #define FIXED_FRAME 32 + +// aix/ppc64 uses XCOFF which has function descriptors. +#ifdef GOOS_aix +#ifdef GOARCH_ppc64 +#define GO_PPC64X_HAS_FUNCDESC +#endif +#endif + +// linux/ppc64 uses ELFv1 which has function descriptors. +#ifdef GOOS_linux +#ifdef GOARCH_ppc64 +#define GO_PPC64X_HAS_FUNCDESC +#endif +#endif diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index 37472c0f794..96a25f4047e 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -38,13 +38,13 @@ TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0 MOVD R3, (g_stack+stack_lo)(g) MOVD R1, (g_stack+stack_hi)(g) - // if there is a _cgo_init, call it using the gcc ABI. + // If there is a _cgo_init, call it using the gcc ABI. MOVD _cgo_init(SB), R12 CMP R0, R12 BEQ nocgo -#ifdef GOARCH_ppc64 - // ppc64 use elf ABI v1. we must get the real entry address from - // first slot of the function descriptor before call. + +#ifdef GO_PPC64X_HAS_FUNCDESC + // Load the real entry address from the first slot of the function descriptor. MOVD 8(R12), R2 MOVD (R12), R12 #endif @@ -597,10 +597,8 @@ g0: // This is a "global call", so put the global entry point in r12 MOVD R3, R12 -#ifdef GOARCH_ppc64 - // ppc64 use elf ABI v1. we must get the real entry address from - // first slot of the function descriptor before call. - // Same for AIX. +#ifdef GO_PPC64X_HAS_FUNCDESC + // Load the real entry address from the first slot of the function descriptor. MOVD 8(R12), R2 MOVD (R12), R12 #endif diff --git a/src/runtime/cgo/asm_ppc64x.s b/src/runtime/cgo/asm_ppc64x.s index c2010050444..fea749670b8 100644 --- a/src/runtime/cgo/asm_ppc64x.s +++ b/src/runtime/cgo/asm_ppc64x.s @@ -30,10 +30,8 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0 BL runtime·reginit(SB) BL runtime·load_g(SB) -#ifdef GOARCH_ppc64 - // ppc64 use elf ABI v1. we must get the real entry address from - // first slot of the function descriptor before call. - // Same for AIX. +#ifdef GO_PPC64X_HAS_FUNCDESC + // Load the real entry address from the first slot of the function descriptor. MOVD 8(R3), R2 MOVD (R3), R3 #endif