]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: remove vestigial importpath symbol logic
authorMatthew Dempsky <mdempsky@google.com>
Tue, 29 Aug 2023 08:15:55 +0000 (01:15 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 29 Aug 2023 20:28:09 +0000 (20:28 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/types/pkg.go

index 2a55043d5a20aa45332504412273cd22ef15eb0e..e090cafb610f4353d618e73637376c66d5fbbb43 100644 (file)
@@ -112,7 +112,6 @@ func dumpCompilerObj(bout *bio.Writer) {
 func dumpdata() {
        reflectdata.WriteGCSymbols()
        reflectdata.WritePluginTable()
-       reflectdata.WriteImportStrings()
        dumpembeds()
 
        if reflectdata.ZeroSize > 0 {
index add708c03fe8dd81b001744f984aabd779566216..0a96e8831cd686eb51e081afbcf2cf7f93ddd952 100644 (file)
@@ -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 {
index 9a2149401729c87e987fa3875d71ff73f091c1cc..d77b92d2a36503a3f0853bc46b9acaf2af7cb0ad 100644 (file)
@@ -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),
 }