From 52a5881beeb946363515777a48c8a229ad66dd7a Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 29 Aug 2023 01:15:55 -0700 Subject: [PATCH] cmd/compile: remove vestigial importpath symbol logic The object file format now has an explicit section for tracking which packages were imported, so we don't need to write out importpath symbols for all directly imported packages anymore. However, keep the logic for writing out individual importpath symbols, because it's still relevant to runtime type descriptor generation. Change-Id: I184ff320e894ba43ca0f8a3d2678e4b2bbbe6da5 Reviewed-on: https://go-review.googlesource.com/c/go/+/523875 LUCI-TryBot-Result: Go LUCI Auto-Submit: Matthew Dempsky Reviewed-by: Cherry Mui --- src/cmd/compile/internal/gc/obj.go | 1 - .../compile/internal/reflectdata/reflect.go | 81 +++++++------------ src/cmd/compile/internal/types/pkg.go | 20 ----- 3 files changed, 29 insertions(+), 73 deletions(-) diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go index 2a55043d5a..e090cafb61 100644 --- a/src/cmd/compile/internal/gc/obj.go +++ b/src/cmd/compile/internal/gc/obj.go @@ -112,7 +112,6 @@ func dumpCompilerObj(bout *bio.Writer) { func dumpdata() { reflectdata.WriteGCSymbols() reflectdata.WritePluginTable() - reflectdata.WriteImportStrings() dumpembeds() if reflectdata.ZeroSize > 0 { diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index add708c03f..0a96e8831c 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -412,6 +412,10 @@ func dimportpath(p *types.Pkg) { return } + if p == types.LocalPkg && base.Ctxt.Pkgpath == "" { + panic("missing pkgpath") + } + // If we are compiling the runtime package, there are two runtime packages around // -- localpkg and Pkgs.Runtime. We don't want to produce import path symbols for // both of them, so just produce one for localpkg. @@ -431,10 +435,6 @@ func dgopkgpath(s *obj.LSym, ot int, pkg *types.Pkg) int { return objw.Uintptr(s, ot, 0) } - if pkg == types.LocalPkg && base.Ctxt.Pkgpath == "" { - panic("missing pkgpath") - } - dimportpath(pkg) return objw.SymPtr(s, ot, pkg.Pathsym, 0) } @@ -444,9 +444,6 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int { if pkg == nil { return objw.Uint32(s, ot, 0) } - if pkg == types.LocalPkg && base.Ctxt.Pkgpath == "" { - panic("missing pkgpath") - } dimportpath(pkg) return objw.SymPtrOff(s, ot, pkg.Pathsym) @@ -1367,13 +1364,6 @@ func WritePluginTable() { objw.Global(lsym, int32(ot), int16(obj.RODATA)) } -func WriteImportStrings() { - // generate import strings for imported packages - for _, p := range types.ImportedPkgList() { - dimportpath(p) - } -} - // writtenByWriteBasicTypes reports whether typ is written by WriteBasicTypes. // WriteBasicTypes always writes pointer types; any pointer has been stripped off typ already. func writtenByWriteBasicTypes(typ *types.Type) bool { @@ -1410,45 +1400,32 @@ func WriteBasicTypes() { // another possible choice would be package main, // but using runtime means fewer copies in object files. // The code here needs to be in sync with writtenByWriteBasicTypes above. - if base.Ctxt.Pkgpath == "runtime" { - // Note: always write NewPtr(t) because NeedEmit's caller strips the pointer. - var list []*types.Type - for i := types.Kind(1); i <= types.TBOOL; i++ { - list = append(list, types.Types[i]) - } - list = append(list, - types.Types[types.TSTRING], - types.Types[types.TUNSAFEPTR], - types.AnyType, - types.ErrorType) - for _, t := range list { - writeType(types.NewPtr(t)) - writeType(types.NewPtr(types.NewSlice(t))) - } - - // emit type for func(error) string, - // which is the type of an auto-generated wrapper. - writeType(types.NewPtr(types.NewSignature(nil, []*types.Field{ - types.NewField(base.Pos, nil, types.ErrorType), - }, []*types.Field{ - types.NewField(base.Pos, nil, types.Types[types.TSTRING]), - }))) - - // add paths for runtime and main, which 6l imports implicitly. - dimportpath(ir.Pkgs.Runtime) - - if base.Flag.Race { - dimportpath(types.NewPkg("runtime/race", "")) - } - if base.Flag.MSan { - dimportpath(types.NewPkg("runtime/msan", "")) - } - if base.Flag.ASan { - dimportpath(types.NewPkg("runtime/asan", "")) - } - - dimportpath(types.NewPkg("main", "")) + if base.Ctxt.Pkgpath != "runtime" { + return } + + // Note: always write NewPtr(t) because NeedEmit's caller strips the pointer. + var list []*types.Type + for i := types.Kind(1); i <= types.TBOOL; i++ { + list = append(list, types.Types[i]) + } + list = append(list, + types.Types[types.TSTRING], + types.Types[types.TUNSAFEPTR], + types.AnyType, + types.ErrorType) + for _, t := range list { + writeType(types.NewPtr(t)) + writeType(types.NewPtr(types.NewSlice(t))) + } + + // emit type for func(error) string, + // which is the type of an auto-generated wrapper. + writeType(types.NewPtr(types.NewSignature(nil, []*types.Field{ + types.NewField(base.Pos, nil, types.ErrorType), + }, []*types.Field{ + types.NewField(base.Pos, nil, types.Types[types.TSTRING]), + }))) } type typeAndStr struct { diff --git a/src/cmd/compile/internal/types/pkg.go b/src/cmd/compile/internal/types/pkg.go index 9a21494017..d77b92d2a3 100644 --- a/src/cmd/compile/internal/types/pkg.go +++ b/src/cmd/compile/internal/types/pkg.go @@ -8,7 +8,6 @@ import ( "cmd/internal/obj" "cmd/internal/objabi" "fmt" - "sort" "strconv" "sync" ) @@ -55,25 +54,6 @@ func NewPkg(path, name string) *Pkg { return p } -// ImportedPkgList returns the list of directly imported packages. -// The list is sorted by package path. -func ImportedPkgList() []*Pkg { - var list []*Pkg - for _, p := range pkgMap { - if p.Direct { - list = append(list, p) - } - } - sort.Sort(byPath(list)) - return list -} - -type byPath []*Pkg - -func (a byPath) Len() int { return len(a) } -func (a byPath) Less(i, j int) bool { return a[i].Path < a[j].Path } -func (a byPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } - var nopkg = &Pkg{ Syms: make(map[string]*Sym), } -- 2.50.0