From a3096ec503adf5ff62c4b0fdc418950119556810 Mon Sep 17 00:00:00 2001 From: George Adams Date: Wed, 27 May 2026 12:22:23 +0100 Subject: [PATCH] internal/fakecgo: remove runtime.load_g references Go 1.27 (golang/go@aee6009) enforces stricter checklinkname for assembly symbols. runtime.load_g is now //go:linknamestd (std-only), causing linker errors for non-std packages that reference it. In crosscall2, the load_g call is unnecessary because runtime.cgocallback already calls load_g internally. Remove it from all 6 architectures that had it (arm, arm64, loong64, ppc64le, riscv64, s390x). The amd64 and 386 variants already did not call it. In setg_trampoline on ppc64le, replace the load_g call with a direct assignment to the g register from the saved newg argument, since setg_gcc has already stored it into TLS. This resolves the runtime.load_g linker error. The runtime.cgocallback reference remains and will need an upstream Go change or the -ldflags='-checklinkname=0' workaround until then. --- internal/fakecgo/asm_arm.s | 2 -- internal/fakecgo/asm_arm64.s | 1 - internal/fakecgo/asm_loong64.s | 2 -- internal/fakecgo/asm_ppc64le.s | 3 --- internal/fakecgo/asm_riscv64.s | 1 - internal/fakecgo/asm_s390x.s | 3 --- internal/fakecgo/trampolines_ppc64le.s | 8 ++++++-- 7 files changed, 6 insertions(+), 14 deletions(-) diff --git a/internal/fakecgo/asm_arm.s b/internal/fakecgo/asm_arm.s index 68034e60..a45f1f83 100644 --- a/internal/fakecgo/asm_arm.s +++ b/internal/fakecgo/asm_arm.s @@ -32,8 +32,6 @@ TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0 MOVD F14, (13*4+8*7)(R13) MOVD F15, (13*4+8*8)(R13) - BL runtime·load_g(SB) - // We set up the arguments to cgocallback when saving registers above. BL runtime·cgocallback(SB) diff --git a/internal/fakecgo/asm_arm64.s b/internal/fakecgo/asm_arm64.s index 50e5261d..67b0d607 100644 --- a/internal/fakecgo/asm_arm64.s +++ b/internal/fakecgo/asm_arm64.s @@ -25,7 +25,6 @@ TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0 STP (R29, R30), (8*22)(RSP) // Initialize Go ABI environment - BL runtime·load_g(SB) BL runtime·cgocallback(SB) RESTORE_R19_TO_R28(8*4) diff --git a/internal/fakecgo/asm_loong64.s b/internal/fakecgo/asm_loong64.s index e81df86a..9c06c9a4 100644 --- a/internal/fakecgo/asm_loong64.s +++ b/internal/fakecgo/asm_loong64.s @@ -27,8 +27,6 @@ TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0 MOVV R1, (22*8)(R3) // Initialize Go ABI environment - JAL runtime·load_g(SB) - JAL runtime·cgocallback(SB) RESTORE_R22_TO_R31((4*8)) diff --git a/internal/fakecgo/asm_ppc64le.s b/internal/fakecgo/asm_ppc64le.s index 6d1938cd..0392c53c 100644 --- a/internal/fakecgo/asm_ppc64le.s +++ b/internal/fakecgo/asm_ppc64le.s @@ -50,9 +50,6 @@ TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0 // Initialize R0 to 0 as expected by Go MOVD $0, R0 - // Load the current g. - BL runtime·load_g(SB) - // Set up arguments for cgocallback MOVD R3, FIXED_FRAME+0(R1) // fn unsafe.Pointer MOVD R4, FIXED_FRAME+8(R1) // a unsafe.Pointer diff --git a/internal/fakecgo/asm_riscv64.s b/internal/fakecgo/asm_riscv64.s index d34699e5..01214234 100644 --- a/internal/fakecgo/asm_riscv64.s +++ b/internal/fakecgo/asm_riscv64.s @@ -25,7 +25,6 @@ TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0 SAVE_FPR((8*17)) // Initialize Go ABI environment - CALL runtime·load_g(SB) CALL runtime·cgocallback(SB) RESTORE_GPR((8*4)) diff --git a/internal/fakecgo/asm_s390x.s b/internal/fakecgo/asm_s390x.s index b6446650..f40db4a0 100644 --- a/internal/fakecgo/asm_s390x.s +++ b/internal/fakecgo/asm_s390x.s @@ -27,9 +27,6 @@ TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0 FMOVD F14, 80(R15) FMOVD F15, 88(R15) - // Initialize Go ABI environment. - BL runtime·load_g(SB) - MOVD R2, 8(R15) // fn unsafe.Pointer MOVD R3, 16(R15) // a unsafe.Pointer diff --git a/internal/fakecgo/trampolines_ppc64le.s b/internal/fakecgo/trampolines_ppc64le.s index 944677a7..f34661f2 100644 --- a/internal/fakecgo/trampolines_ppc64le.s +++ b/internal/fakecgo/trampolines_ppc64le.s @@ -47,15 +47,19 @@ TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0-0 // func setg_trampoline(setg uintptr, g uintptr) TEXT ·setg_trampoline(SB), NOSPLIT, $16-16 - MOVD R31, 8(R1) // save R31 (load_g clobbers it) + MOVD R31, 8(R1) // save R31 MOVD setg+0(FP), R12 MOVD newg+8(FP), R3 + MOVD R3, 16(R1) // save newg before call + MOVD R12, CTR CALL CTR - CALL runtime·load_g(SB) + // Assign g directly instead of calling runtime·load_g + // setg_gcc has already stored newg into TLS; put it in the g register too. + MOVD 16(R1), g MOVD 8(R1), R31 XOR R0, R0, R0