]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: preserve symbol attributes when cloning to external
authorCherry Mui <cherryyz@google.com>
Fri, 15 Apr 2022 15:52:01 +0000 (11:52 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 15 Apr 2022 19:02:54 +0000 (19:02 +0000)
There are some symbol attributes that are encoded in the object
file. Currently, they are lost when cloning a symbol to external.
Copy them over.

Also delete CopyAttributes as it is no longer called anywhere.

Change-Id: I1497e3223a641704bf35aa3e904dd0eda2f8ec3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/400574
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/loader/loader.go

index 6fa443a13fc537522c0b168ee6f838f398153cc6..a069540035a542b1c856113b87aedd42f91be5c5 100644 (file)
@@ -2341,6 +2341,10 @@ func (l *Loader) cloneToExternal(symIdx Sym) {
        // need to access the old symbol content.)
        l.objSyms[symIdx] = objSym{l.extReader.objidx, uint32(pi)}
        l.extReader.syms = append(l.extReader.syms, symIdx)
+
+       // Some attributes were encoded in the object file. Copy them over.
+       l.SetAttrDuplicateOK(symIdx, r.Sym(li).Dupok())
+       l.SetAttrShared(symIdx, r.Shared())
 }
 
 // Copy the payload of symbol src to dst. Both src and dst must be external
@@ -2361,31 +2365,6 @@ func (l *Loader) CopySym(src, dst Sym) {
        // TODO: other attributes?
 }
 
-// CopyAttributes copies over all of the attributes of symbol 'src' to
-// symbol 'dst'.
-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))
-       if l.IsExternal(dst) {
-               l.SetAttrVisibilityHidden(dst, l.AttrVisibilityHidden(src))
-               l.SetAttrDuplicateOK(dst, l.AttrDuplicateOK(src))
-               l.SetAttrShared(dst, l.AttrShared(src))
-               l.SetAttrExternal(dst, l.AttrExternal(src))
-       } else {
-               // Some attributes are modifiable only for external symbols.
-               // In such cases, don't try to transfer over the attribute
-               // from the source even if there is a clash. This comes up
-               // when copying attributes from a dupOK ABI wrapper symbol to
-               // the real target symbol (which may not be marked dupOK).
-       }
-       l.SetAttrSpecial(dst, l.AttrSpecial(src))
-       l.SetAttrCgoExportDynamic(dst, l.AttrCgoExportDynamic(src))
-       l.SetAttrCgoExportStatic(dst, l.AttrCgoExportStatic(src))
-       l.SetAttrReadOnly(dst, l.AttrReadOnly(src))
-}
-
 // CreateExtSym creates a new external symbol with the specified name
 // without adding it to any lookup tables, returning a Sym index for it.
 func (l *Loader) CreateExtSym(name string, ver int) Sym {