mirror of
https://github.com/golang/go
synced 2024-11-07 08:46:19 -07:00
[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: Jeremy Faller <jeremy@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
15634a0230
commit
8011051361
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user