]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: cleanup of attribute handling code
authorThan McIntosh <thanm@google.com>
Mon, 16 Mar 2020 17:56:42 +0000 (13:56 -0400)
committerThan McIntosh <thanm@google.com>
Wed, 18 Mar 2020 22:49:17 +0000 (22:49 +0000)
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>
src/cmd/link/internal/loader/loader.go

index c17fb5a16e0651540fc153545f6d78a9cc3cb061..91798d470ae7b17debf6b6772d64cf4709908b08 100644 (file)
@@ -793,19 +793,6 @@ func (l *Loader) AttrShared(i Sym) bool {
        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
 // object files.
 func (l *Loader) AttrExternal(i Sym) bool {
@@ -890,7 +877,7 @@ func (l *Loader) AttrCgoExportStatic(i Sym) bool {
        return ok
 }
 
-// SetAttrCgoExportStatic sets the "cgo_export_dynamic" for a symbol
+// SetAttrCgoExportStatic sets the "cgo_export_static" for a symbol
 // (see AttrCgoExportStatic).
 func (l *Loader) SetAttrCgoExportStatic(i Sym, v bool) {
        if v {
@@ -907,13 +894,17 @@ func (l *Loader) AttrReadOnly(i Sym) bool {
                return v
        }
        if l.IsExternal(i) {
+               pp := l.getPayload(i)
+               if pp.objidx != 0 {
+                       return l.objs[pp.objidx].r.ReadOnly()
+               }
                return false
        }
        r, _ := l.toLocal(i)
        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).
 func (l *Loader) SetAttrReadOnly(i Sym, v bool) {
        l.attrReadOnly[i] = v
@@ -2255,24 +2246,6 @@ func (l *Loader) cloneToExternal(symIdx Sym) {
        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
 // sym.Symbol 'dst'.
 func (l *Loader) migrateAttributes(src Sym, dst *sym.Symbol) {