]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix _rt0_ppc64x_lib on aix
authorqmuntal <quimmuntal@gmail.com>
Wed, 8 Oct 2025 14:21:21 +0000 (16:21 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Mon, 20 Oct 2025 16:41:43 +0000 (09:41 -0700)
CL 706395 refactored the ppc64 library entry point and missed some
important aix-specific characteristics:

- _rt0_ppc64x_lib should account for the function descriptor when
getting the callback pointer.

- _rt0_ppc64x_lib should only call _cgo_sys_thread_create when
built as a c-archive.

Fixes #75801

Cq-Include-Trybots: luci.golang.try:gotip-linux-ppc64_power10
Change-Id: I343ca09d3b9688ffa585668a6c52f0ad519d6203
Reviewed-on: https://go-review.googlesource.com/c/go/+/710175
Reviewed-by: Paul Murphy <paumurph@redhat.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/runtime/asm_ppc64x.s

index 88d03dcc72c1e684903535eab76a956ecddbd4f8..127010ef9713982731abcd527272b68d5f4637a9 100644 (file)
 // This is called using the host ABI. argc and argv arguments
 // should be in R3 and R4 respectively.
 TEXT _rt0_ppc64x_lib(SB),NOSPLIT|NOFRAME,$0
-       // Convert to Go ABI, and Allocate argument storage for call to newosproc0.
-       STACK_AND_SAVE_HOST_TO_GO_ABI(16)
+       // Start with standard C stack frame layout and linkage, allocate
+       // 16 bytes of argument space, save callee-save regs, and set R0 to $0.
+       // Allocate an extra 16 bytes to account for the larger fixed frame size
+       // of aix/elfv1 (48 vs 32) to ensure 16 bytes of parameter save space.
+       STACK_AND_SAVE_HOST_TO_GO_ABI(32)
+       // The above will not preserve R2 (TOC). Save it in case Go is
+       // compiled without a TOC pointer (e.g -buildmode=default).
+       MOVD    R2, 24(R1)
 
        MOVD    R3, _rt0_ppc64x_lib_argc<>(SB)
        MOVD    R4, _rt0_ppc64x_lib_argv<>(SB)
@@ -28,14 +34,28 @@ TEXT _rt0_ppc64x_lib(SB),NOSPLIT|NOFRAME,$0
        MOVD    R12, CTR
        BL      (CTR)
 
+#ifdef GOOS_aix
+       // See runtime/cgo/gcc_aix_ppc64.c
+       MOVBZ   runtime·isarchive(SB), R3      // Check buildmode = c-archive
+       CMP             $0, R3
+       BEQ             done
+#endif
+
        // Create a new thread to do the runtime initialization and return.
+       // _cgo_sys_thread_create is a C function.
        MOVD    _cgo_sys_thread_create(SB), R12
        CMP     $0, R12
        BEQ     nocgo
        MOVD    $_rt0_ppc64x_lib_go(SB), R3
        MOVD    $0, R4
+#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
        MOVD    R12, CTR
        BL      (CTR)
+       MOVD    24(R1), R2 // Restore the old frame, and R2.
        BR      done
 
 nocgo:
@@ -48,7 +68,7 @@ nocgo:
        BL      (CTR)
 
 done:
-       UNSTACK_AND_RESTORE_GO_TO_HOST_ABI(16)
+       UNSTACK_AND_RESTORE_GO_TO_HOST_ABI(32)
        RET
 
 #ifdef GO_PPC64X_HAS_FUNCDESC