Skip to content

Commit 80e9a7f

Browse files
committed
cmd/compile: have all or no parameter named in exported signatures
Binary export format only. Make sure we don't accidentally export an unnamed parameter in signatures which expect all named parameters; otherwise we crash during import. Appears to happen for _ (blank) parameter names, as observed in method signatures such as the one at: x/tools/godoc/analysis/analysis.go:76. Fixes #15470. TBR=mdempsky Change-Id: I1b1184bf08c4c09d8a46946539c4b8c341acdb84 Reviewed-on: https://go-review.googlesource.com/22543 Reviewed-by: Robert Griesemer <[email protected]>
1 parent e8d4ffb commit 80e9a7f

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/cmd/compile/internal/gc/bexport.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -819,19 +819,30 @@ func (p *exporter) param(q *Field, n int, numbered bool) {
819819
}
820820
p.typ(t)
821821
if n > 0 {
822-
p.string(parName(q, numbered))
823-
// Because of (re-)exported inlined functions
824-
// the importpkg may not be the package to which this
825-
// function (and thus its parameter) belongs. We need to
826-
// supply the parameter package here. We need the package
827-
// when the function is inlined so we can properly resolve
828-
// the name.
829-
// TODO(gri) This is compiler-specific. Try using importpkg
830-
// here and then update the symbols if we find an inlined
831-
// body only. Otherwise, the parameter name is ignored and
832-
// the package doesn't matter. This would remove an int
833-
// (likely 1 byte) for each named parameter.
834-
p.pkg(q.Sym.Pkg)
822+
if name := parName(q, numbered); name != "" {
823+
p.string(name)
824+
// Because of (re-)exported inlined functions
825+
// the importpkg may not be the package to which this
826+
// function (and thus its parameter) belongs. We need to
827+
// supply the parameter package here. We need the package
828+
// when the function is inlined so we can properly resolve
829+
// the name.
830+
// TODO(gri) This is compiler-specific. Try using importpkg
831+
// here and then update the symbols if we find an inlined
832+
// body only. Otherwise, the parameter name is ignored and
833+
// the package doesn't matter. This would remove an int
834+
// (likely 1 byte) for each named parameter.
835+
p.pkg(q.Sym.Pkg)
836+
} else {
837+
// Sometimes we see an empty name even for n > 0.
838+
// This appears to happen for interface methods
839+
// with _ (blank) parameter names. Make sure we
840+
// have a proper name and package so we don't crash
841+
// during import (see also issue #15470).
842+
// TODO(gri) review parameter encoding
843+
p.string("_")
844+
p.pkg(localpkg)
845+
}
835846
}
836847
// TODO(gri) This is compiler-specific (escape info).
837848
// Move into compiler-specific section eventually?

0 commit comments

Comments
 (0)