From: Reinhard Tartler Date: Wed, 30 Sep 2026 20:13:38 +0000 Subject: Replace go:linkname stubs with local implementations classify_call.go reached into golang.org/x/tools/go/types/typeutil with //go:linkname to access the unexported functions usedIdent and interfaceMethod. Upstream x/tools removed both symbols in commit 6cbeeac ("internal/typesinternal: avoid linkname hacks"), which shipped in golang.org/x/tools v0.49.0, and instead moved the implementations into its own internal/typesinternal package. go-tools 2026.2.1 pins a development snapshot of x/tools via go.mod, so the stubs compile against upstream's tree but the release Debian actually ships no longer defines them. The typesinternal test binary therefore fails to link with: relocation target golang.org/x/tools/go/types/typeutil.usedIdent not defined relocation target golang.org/x/tools/go/types/typeutil.interfaceMethod not defined Replace the stubs with local copies of the implementations, taken from golang.org/x/tools/internal/typesinternal/classify_call.go as of v0.49.0. This keeps behaviour identical to the released upstream code and removes the dependence on another project's unexported symbols. Forwarded: https://github.com/dominikh/go-tools/issues/1751 Bug: https://github.com/dominikh/go-tools/issues/1751 Last-Update: 2026-09-30 --- .../xtools-internal/typesinternal/classify_call.go | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/xtools-internal/typesinternal/classify_call.go b/internal/xtools-internal/typesinternal/classify_call.go index 7ebe976..54d073a 100644 --- a/internal/xtools-internal/typesinternal/classify_call.go +++ b/internal/xtools-internal/typesinternal/classify_call.go @@ -8,7 +8,6 @@ import ( "fmt" "go/ast" "go/types" - _ "unsafe" // for go:linkname hack ) // CallKind describes the function position of an [*ast.CallExpr]. @@ -127,11 +126,29 @@ func ClassifyCall(info *types.Info, call *ast.CallExpr) CallKind { // Note: if e is an instantiated function or method, UsedIdent returns // the corresponding generic function or method on the generic type. func UsedIdent(info *types.Info, e ast.Expr) *ast.Ident { - return usedIdent(info, e) -} + if info.Types == nil || info.Uses == nil { + panic("one of info.Types or info.Uses is nil; both must be populated") + } + // Look through type instantiation if necessary. + switch d := ast.Unparen(e).(type) { + case *ast.IndexExpr: + if info.Types[d.Index].IsType() { + e = d.X + } + case *ast.IndexListExpr: + e = d.X + } -//go:linkname usedIdent golang.org/x/tools/go/types/typeutil.usedIdent -func usedIdent(info *types.Info, e ast.Expr) *ast.Ident + switch e := ast.Unparen(e).(type) { + case *ast.Ident: + return e + case *ast.SelectorExpr: + return e.Sel + } + return nil +} -//go:linkname interfaceMethod golang.org/x/tools/go/types/typeutil.interfaceMethod -func interfaceMethod(f *types.Func) bool +func interfaceMethod(f *types.Func) bool { + recv := f.Signature().Recv() + return recv != nil && types.IsInterface(recv.Type()) +}