]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd: add flag to mark gotype symbols
authorThan McIntosh <thanm@google.com>
Wed, 16 Oct 2019 13:13:59 +0000 (09:13 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 17 Oct 2019 14:18:37 +0000 (14:18 +0000)
Add a flag bit to mark symbols in the new object file as containing Go
type information. The use of a flag eliminates the need to do symbol
name matching as part of the new dead code elimination pass, which
should produce a minor speedup.

Change-Id: Iec8700e1139e2c4e310644c0766379865d2d6f82
Reviewed-on: https://go-review.googlesource.com/c/go/+/201399
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/internal/goobj2/objfile.go
src/cmd/internal/obj/objfile2.go
src/cmd/link/internal/ld/deadcode2.go
src/cmd/link/internal/loader/loader.go

index ef32c4873ebf5e0d3cb275c09e73c22f02d4e66c..03b322da6c7c0de1e5ff76391f38ce8548a9f29b 100644 (file)
@@ -205,6 +205,7 @@ const (
        SymFlagLeaf
        SymFlagCFunc
        SymFlagReflectMethod
+       SymFlagGoType
        SymFlagTopFrame
 )
 
@@ -234,6 +235,7 @@ func (s *Sym) Typelink() bool      { return s.Flag&SymFlagTypelink != 0 }
 func (s *Sym) Leaf() bool          { return s.Flag&SymFlagLeaf != 0 }
 func (s *Sym) CFunc() bool         { return s.Flag&SymFlagCFunc != 0 }
 func (s *Sym) ReflectMethod() bool { return s.Flag&SymFlagReflectMethod != 0 }
+func (s *Sym) IsGoType() bool      { return s.Flag&SymFlagGoType != 0 }
 func (s *Sym) TopFrame() bool      { return s.Flag&SymFlagTopFrame != 0 }
 
 // Symbol reference.
index f3389612d6c422a775794a0210bbc787dace3b12..69019e033dde374db4cb716ae63a59c25b588623 100644 (file)
@@ -238,6 +238,9 @@ func (w *writer) Sym(s *LSym) {
        if s.TopFrame() {
                flag |= goobj2.SymFlagTopFrame
        }
+       if strings.HasPrefix(s.Name, "type.") && s.Name[5] != '.' && s.Type == objabi.SRODATA {
+               flag |= goobj2.SymFlagGoType
+       }
        name := s.Name
        if strings.HasPrefix(name, "gofile..") {
                name = filepath.ToSlash(name)
index 259199eea1c69443c8d281acbf52c4b9962212f6..818024069e89e04fb529cfe33beed6673d2911fd 100644 (file)
@@ -108,9 +108,7 @@ func (d *deadcodePass2) flood() {
                symIdx := d.wq.pop()
 
                d.reflectSeen = d.reflectSeen || d.ldr.IsReflectMethod(symIdx)
-
-               name := d.ldr.RawSymName(symIdx)
-               if strings.HasPrefix(name, "type.") && name[5] != '.' { // TODO: use an attribute instead of checking name
+               if d.ldr.IsGoType(symIdx) {
                        p := d.ldr.Data(symIdx)
                        if len(p) != 0 && decodetypeKind(d.ctxt.Arch, p)&kindMask == kindInterface {
                                for _, sig := range decodeIfaceMethods2(d.ldr, d.ctxt.Arch, symIdx) {
index c155f27dcbc2aaa0ad4bcae126970a277ca43234..708e8d0d3ec07d538f45a382542c42cb3c5bf03a 100644 (file)
@@ -364,6 +364,11 @@ func (l *Loader) IsReflectMethod(i Sym) bool {
        return l.SymAttr(i)&goobj2.SymFlagReflectMethod != 0
 }
 
+// Returns whether this is a Go type symbol.
+func (l *Loader) IsGoType(i Sym) bool {
+       return l.SymAttr(i)&goobj2.SymFlagGoType != 0
+}
+
 // Returns the symbol content of the i-th symbol. i is global index.
 func (l *Loader) Data(i Sym) []byte {
        if l.isExternal(i) {