]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: mark type namedata symbols content-addressable
authorCherry Zhang <cherryyz@google.com>
Mon, 28 Sep 2020 17:10:30 +0000 (13:10 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 29 Sep 2020 17:25:24 +0000 (17:25 +0000)
Type namedata symbols are for type/field/method names and package
paths. We can use content-addressable symbol mechanism for them.

Change-Id: I923fda17b7094c7a0e46aad7c450622eb3826294
Reviewed-on: https://go-review.googlesource.com/c/go/+/257960
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/compile/internal/gc/reflect.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/sym.go
src/cmd/link/internal/loader/loader.go

index ae3e2f8e658ead80bdbe5bdf4c7302ea97ce572d..21429af782eb963a7ae6e822c273689732dd56fa 100644 (file)
@@ -511,6 +511,7 @@ func dimportpath(p *types.Pkg) {
        s := Ctxt.Lookup("type..importpath." + p.Prefix + ".")
        ot := dnameData(s, 0, str, "", nil, false)
        ggloblsym(s, int32(ot), obj.DUPOK|obj.RODATA)
+       s.Set(obj.AttrContentAddressable, true)
        p.Pathsym = s
 }
 
@@ -638,6 +639,7 @@ func dname(name, tag string, pkg *types.Pkg, exported bool) *obj.LSym {
        }
        ot := dnameData(s, 0, name, tag, pkg, exported)
        ggloblsym(s, int32(ot), obj.DUPOK|obj.RODATA)
+       s.Set(obj.AttrContentAddressable, true)
        return s
 }
 
index e4b96205684af8d33c9f6c103b1190ad04c01dab..186016c9706c67d89e4d4e8e4c72f02e788398d4 100644 (file)
@@ -372,6 +372,13 @@ func contentHash64(s *LSym) goobj.Hash64Type {
 // hashed symbols.
 func (w *writer) contentHash(s *LSym) goobj.HashType {
        h := sha1.New()
+       // Don't dedup type symbols with others, as they are in a different
+       // section.
+       if strings.HasPrefix(s.Name, "type.") {
+               h.Write([]byte{'T'})
+       } else {
+               h.Write([]byte{0})
+       }
        // The compiler trims trailing zeros _sometimes_. We just do
        // it always.
        h.Write(bytes.TrimRight(s.P, "\x00"))
index d58877ee152f595e9d5c345b8d1b75bff87bef4e..e5d7b2cbfdb9f0a77ec17d2229199f5280c6071e 100644 (file)
@@ -38,6 +38,7 @@ import (
        "log"
        "math"
        "sort"
+       "strings"
 )
 
 func Linknew(arch *LinkArch) *Link {
@@ -204,7 +205,9 @@ func (ctxt *Link) NumberSyms() {
                // if Pkgpath is unknown, cannot hash symbols with relocations, as it
                // may reference named symbols whose names are not fully expanded.
                if s.ContentAddressable() && (ctxt.Pkgpath != "" || len(s.R) == 0) {
-                       if len(s.P) <= 8 && len(s.R) == 0 { // we can use short hash only for symbols without relocations
+                       if len(s.P) <= 8 && len(s.R) == 0 && !strings.HasPrefix(s.Name, "type.") {
+                               // We can use short hash only for symbols without relocations.
+                               // Don't use short hash for type symbols, as they need special handling.
                                s.PkgIdx = goobj.PkgIdxHashed64
                                s.SymIdx = hashed64idx
                                if hashed64idx != int32(len(ctxt.hashed64defs)) {
index ea99233f67ca1e970c82c78396547cb001b50369..4025edc23f7a33c78157ccc84486d21a2d1ca4ba 100644 (file)
@@ -2153,11 +2153,11 @@ func (l *Loader) LoadNonpkgSyms(arch *sys.Arch) {
        l.npkgsyms = l.NSym()
        // Preallocate some space (a few hundreds KB) for some symbols.
        // As of Go 1.15, linking cmd/compile has ~8000 hashed64 symbols and
-       // ~13000 hashed symbols.
+       // ~27000 hashed symbols.
        st := loadState{
                l:            l,
                hashed64Syms: make(map[uint64]symAndSize, 10000),
-               hashedSyms:   make(map[goobj.HashType]symAndSize, 15000),
+               hashedSyms:   make(map[goobj.HashType]symAndSize, 30000),
        }
        for _, o := range l.objs[goObjStart:] {
                st.preloadSyms(o.r, hashed64Def)