From de6abd78893e91f26337eb399644b7a6bc3ea583 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 20 Dec 2022 17:26:18 -0500 Subject: [PATCH] runtime/internal/startlinetest: work around shared buildmode linking issue The runtime/internal/startlinetest package contains a call to a function defined in runtime_test. Generally this is fine as this package is only linked in for runtime_test. Except that for "go install -buildmode=shared std", which include all packages in std, including this test-only internal package. In this mode, the caller is included in the linking but the callee is not, causing linking error. Work around it by calling runtime_test.callerStartLine via a function pointer. The function pointer is only set in runtime_test. In the shared std build, the function pointer will not be set, and this is fine. Fixes #57334. Change-Id: I7d871c50ce6599c6ea2802cf6e14bb749deab220 Reviewed-on: https://go-review.googlesource.com/c/go/+/458696 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Run-TryBot: Cherry Mui --- src/runtime/internal/startlinetest/func_amd64.go | 3 +++ src/runtime/internal/startlinetest/func_amd64.s | 3 ++- src/runtime/start_line_amd64_test.go | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/runtime/internal/startlinetest/func_amd64.go b/src/runtime/internal/startlinetest/func_amd64.go index 6cd9a3f417..ab7063d615 100644 --- a/src/runtime/internal/startlinetest/func_amd64.go +++ b/src/runtime/internal/startlinetest/func_amd64.go @@ -8,3 +8,6 @@ package startlinetest // Defined in func_amd64.s, this is a trivial assembly function that calls // runtime_test.callerStartLine. func AsmFunc() int + +// Provided by runtime_test. +var CallerStartLine func(bool) int diff --git a/src/runtime/internal/startlinetest/func_amd64.s b/src/runtime/internal/startlinetest/func_amd64.s index ace5b34e70..96982bedab 100644 --- a/src/runtime/internal/startlinetest/func_amd64.s +++ b/src/runtime/internal/startlinetest/func_amd64.s @@ -23,5 +23,6 @@ TEXT ·AsmFunc(SB),NOSPLIT,$8-0 NO_LOCAL_POINTERS MOVQ $0, AX // wantInlined - CALL runtime_test·callerStartLine(SB) + MOVQ ·CallerStartLine(SB), DX + CALL (DX) RET diff --git a/src/runtime/start_line_amd64_test.go b/src/runtime/start_line_amd64_test.go index 57001e71de..305ed0b126 100644 --- a/src/runtime/start_line_amd64_test.go +++ b/src/runtime/start_line_amd64_test.go @@ -13,6 +13,8 @@ import ( // is only tested on amd64 to avoid the need for a proliferation of per-arch // copies of this function. func TestStartLineAsm(t *testing.T) { + startlinetest.CallerStartLine = callerStartLine + const wantLine = 23 got := startlinetest.AsmFunc() if got != wantLine { -- 2.50.0