[dev.link] cmd/link: cleanup of attribute handling code

Minor cleanup of symbol attributes. Specifically:

- if a symbol originally begins life as an object file symbol,
  then is converted to external in cloneToExternal, use the
  previously recorded object file index for the sym to figure
  out if it has read-only data (in the case that there is no
  entry for it in the map in question).

- remove SetAttrShared; only the loader should be populating this
  attribute at symbol creation (it never gets updated later)

- remove unused copyAttributes() method

- comment fixes

Change-Id: Iac7bc6ac310ec89bfe733ddc783970d2a8017478
Reviewed-on: https://go-review.googlesource.com/c/go/+/223667
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2020-03-16 13:56:42 -04:00
parent 626c89bfa3
commit 63ffa1595c

View file

@ -793,19 +793,6 @@ func (l *Loader) AttrShared(i Sym) bool {
return l.attrShared.Has(l.extIndex(i)) return l.attrShared.Has(l.extIndex(i))
} }
// SetAttrShared sets the "shared" property for an external
// symbol (see AttrShared).
func (l *Loader) SetAttrShared(i Sym, v bool) {
if !l.IsExternal(i) {
panic(fmt.Sprintf("tried to set shared attr on non-external symbol %d %s", i, l.SymName(i)))
}
if v {
l.attrShared.Set(l.extIndex(i))
} else {
l.attrShared.Unset(l.extIndex(i))
}
}
// AttrExternal returns true for function symbols loaded from host // AttrExternal returns true for function symbols loaded from host
// object files. // object files.
func (l *Loader) AttrExternal(i Sym) bool { func (l *Loader) AttrExternal(i Sym) bool {
@ -890,7 +877,7 @@ func (l *Loader) AttrCgoExportStatic(i Sym) bool {
return ok return ok
} }
// SetAttrCgoExportStatic sets the "cgo_export_dynamic" for a symbol // SetAttrCgoExportStatic sets the "cgo_export_static" for a symbol
// (see AttrCgoExportStatic). // (see AttrCgoExportStatic).
func (l *Loader) SetAttrCgoExportStatic(i Sym, v bool) { func (l *Loader) SetAttrCgoExportStatic(i Sym, v bool) {
if v { if v {
@ -907,13 +894,17 @@ func (l *Loader) AttrReadOnly(i Sym) bool {
return v return v
} }
if l.IsExternal(i) { if l.IsExternal(i) {
pp := l.getPayload(i)
if pp.objidx != 0 {
return l.objs[pp.objidx].r.ReadOnly()
}
return false return false
} }
r, _ := l.toLocal(i) r, _ := l.toLocal(i)
return r.ReadOnly() return r.ReadOnly()
} }
// SetAttrReadOnly sets the "cgo_export_dynamic" for a symbol // SetAttrReadOnly sets the "data is read only" property for a symbol
// (see AttrReadOnly). // (see AttrReadOnly).
func (l *Loader) SetAttrReadOnly(i Sym, v bool) { func (l *Loader) SetAttrReadOnly(i Sym, v bool) {
l.attrReadOnly[i] = v l.attrReadOnly[i] = v
@ -2255,24 +2246,6 @@ func (l *Loader) cloneToExternal(symIdx Sym) {
l.extReader.syms = append(l.extReader.syms, symIdx) l.extReader.syms = append(l.extReader.syms, symIdx)
} }
// copyAttributes copies over all of the attributes of symbol 'src' to
// symbol 'dst'. The assumption is that 'dst' is an external symbol.
func (l *Loader) copyAttributes(src Sym, dst Sym) {
l.SetAttrReachable(dst, l.AttrReachable(src))
l.SetAttrOnList(dst, l.AttrOnList(src))
l.SetAttrLocal(dst, l.AttrLocal(src))
l.SetAttrNotInSymbolTable(dst, l.AttrNotInSymbolTable(src))
l.SetAttrVisibilityHidden(dst, l.AttrVisibilityHidden(src))
l.SetAttrDuplicateOK(dst, l.AttrDuplicateOK(src))
l.SetAttrShared(dst, l.AttrShared(src))
l.SetAttrExternal(dst, l.AttrExternal(src))
l.SetAttrTopFrame(dst, l.AttrTopFrame(src))
l.SetAttrSpecial(dst, l.AttrSpecial(src))
l.SetAttrCgoExportDynamic(dst, l.AttrCgoExportDynamic(src))
l.SetAttrCgoExportStatic(dst, l.AttrCgoExportStatic(src))
l.SetAttrReadOnly(dst, l.AttrReadOnly(src))
}
// migrateAttributes copies over all of the attributes of symbol 'src' to // migrateAttributes copies over all of the attributes of symbol 'src' to
// sym.Symbol 'dst'. // sym.Symbol 'dst'.
func (l *Loader) migrateAttributes(src Sym, dst *sym.Symbol) { func (l *Loader) migrateAttributes(src Sym, dst *sym.Symbol) {