From: Cherry Mui Date: Fri, 15 Apr 2022 15:52:01 +0000 (-0400) Subject: [release-branch.go1.18] cmd/link: preserve symbol attributes when cloning to external X-Git-Tag: go1.18.4~12 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b80ae102217ad4fefb7e72e060500f42d252a50a;p=gostls13.git [release-branch.go1.18] cmd/link: preserve symbol attributes when cloning to external 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. For #53107. Backporting this CL as the fix of #53107 depends on it. Change-Id: I1497e3223a641704bf35aa3e904dd0eda2f8ec3e Reviewed-on: https://go-review.googlesource.com/c/go/+/400574 Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh (cherry picked from commit df08c9a82152fd6f2b2811db03b40fea8b6e5e9e) Reviewed-on: https://go-review.googlesource.com/c/go/+/408820 --- diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 34c1c6a4c8..371a84ab2e 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -2351,6 +2351,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 @@ -2371,31 +2375,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 {