Debian Codegraph @

debian/patches/0006-Replace-go-linkname-stubs-with-local-implementations.patch

raw
1 From: Reinhard Tartler <[email protected]>
2 Date: Wed, 30 Sep 2026 20:13:38 +0000
3 Subject: Replace go:linkname stubs with local implementations
4
5 classify_call.go reached into golang.org/x/tools/go/types/typeutil with
6 //go:linkname to access the unexported functions usedIdent and
7 interfaceMethod. Upstream x/tools removed both symbols in commit 6cbeeac
8 ("internal/typesinternal: avoid linkname hacks"), which shipped in
9 golang.org/x/tools v0.49.0, and instead moved the implementations into
10 its own internal/typesinternal package.
11
12 go-tools 2026.2.1 pins a development snapshot of x/tools via go.mod, so
13 the stubs compile against upstream's tree but the release Debian actually
14 ships no longer defines them. The typesinternal test binary therefore
15 fails to link with:
16
17 relocation target golang.org/x/tools/go/types/typeutil.usedIdent not defined
18 relocation target golang.org/x/tools/go/types/typeutil.interfaceMethod not defined
19
20 Replace the stubs with local copies of the implementations, taken from
21 golang.org/x/tools/internal/typesinternal/classify_call.go as of
22 v0.49.0. This keeps behaviour identical to the released upstream code and
23 removes the dependence on another project's unexported symbols.
24
25 Forwarded: https://github.com/dominikh/go-tools/issues/1751
26 Bug: https://github.com/dominikh/go-tools/issues/1751
27 Last-Update: 2026-09-30
28 ---
29 .../xtools-internal/typesinternal/classify_call.go | 31 +++++++++++++++++-----
30 1 file changed, 24 insertions(+), 7 deletions(-)
31
32 diff --git a/internal/xtools-internal/typesinternal/classify_call.go b/internal/xtools-internal/typesinternal/classify_call.go
33 index 7ebe976..54d073a 100644
34 --- a/internal/xtools-internal/typesinternal/classify_call.go
35 +++ b/internal/xtools-internal/typesinternal/classify_call.go
36 @@ -8,7 +8,6 @@ import (
37 "fmt"
38 "go/ast"
39 "go/types"
40 - _ "unsafe" // for go:linkname hack
41 )
42
43 // CallKind describes the function position of an [*ast.CallExpr].
44 @@ -127,11 +126,29 @@ func ClassifyCall(info *types.Info, call *ast.CallExpr) CallKind {
45 // Note: if e is an instantiated function or method, UsedIdent returns
46 // the corresponding generic function or method on the generic type.
47 func UsedIdent(info *types.Info, e ast.Expr) *ast.Ident {
48 - return usedIdent(info, e)
49 -}
50 + if info.Types == nil || info.Uses == nil {
51 + panic("one of info.Types or info.Uses is nil; both must be populated")
52 + }
53 + // Look through type instantiation if necessary.
54 + switch d := ast.Unparen(e).(type) {
55 + case *ast.IndexExpr:
56 + if info.Types[d.Index].IsType() {
57 + e = d.X
58 + }
59 + case *ast.IndexListExpr:
60 + e = d.X
61 + }
62
63 -//go:linkname usedIdent golang.org/x/tools/go/types/typeutil.usedIdent
64 -func usedIdent(info *types.Info, e ast.Expr) *ast.Ident
65 + switch e := ast.Unparen(e).(type) {
66 + case *ast.Ident:
67 + return e
68 + case *ast.SelectorExpr:
69 + return e.Sel
70 + }
71 + return nil
72 +}
73
74 -//go:linkname interfaceMethod golang.org/x/tools/go/types/typeutil.interfaceMethod
75 -func interfaceMethod(f *types.Func) bool
76 +func interfaceMethod(f *types.Func) bool {
77 + recv := f.Signature().Recv()
78 + return recv != nil && types.IsInterface(recv.Type())
79 +}