Commit 80110513 authored by Than McIntosh's avatar Than McIntosh

[dev.link] cmd: add flag to mark gotype symbols

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: default avatarJeremy Faller <jeremy@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 15634a02
......@@ -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.
......
......@@ -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)
......
......@@ -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) {
......
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment