From dba9bcc4e43619cbd94362c3732e4822b3ff2f2a Mon Sep 17 00:00:00 2001 From: xgopilot Date: Thu, 23 Oct 2025 10:30:00 +0000 Subject: [PATCH] fix(ssa): use correct package path for interface metadata in abiInterfaceOf When converting concrete type pointers to interfaces with private methods across packages, the interface metadata's PkgPath was incorrectly set to the current compilation package instead of the interface definition package. This caused the runtime to only fill exported methods in the itab, leaving private method slots as NULL (0x0), which led to segmentation faults when calling these private methods. The fix extracts the package path from the interface's private methods (if any) instead of using the current package path. This ensures the runtime receives the correct package path for the visibility check. Fixes #1370 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang --- ssa/abitype.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ssa/abitype.go b/ssa/abitype.go index 6f465edd..abf8a14f 100644 --- a/ssa/abitype.go +++ b/ssa/abitype.go @@ -187,19 +187,28 @@ func (b Builder) abiInterfaceOf(t *types.Interface) func() Expr { return func() Expr { prog := b.Prog methods := make([]Expr, n) + pkgPath := "" for i := 0; i < n; i++ { m := t.Method(i) mName := m.Name() if !token.IsExported(mName) { + if pkgPath == "" { + if mPkg := m.Pkg(); mPkg != nil { + pkgPath = mPkg.Path() + } + } mName = abi.FullName(m.Pkg(), mName) } methods[i] = b.abiImethodOf(mName, typs[i]) } pkg := b.Pkg + if pkgPath == "" { + pkgPath = pkg.Path() + } fn := pkg.rtFunc("Interface") tSlice := lastParamType(prog, fn) methodSlice := b.SliceLit(tSlice, methods...) - return b.Call(fn, b.Str(pkg.Path()), methodSlice) + return b.Call(fn, b.Str(pkgPath), methodSlice) } }