diff options
author | Cherry Mui <cherryyz@google.com> | 2022-04-15 11:52:01 -0400 |
---|---|---|
committer | Heschi Kreinick <heschi@google.com> | 2022-07-06 20:32:07 +0000 |
commit | b80ae102217ad4fefb7e72e060500f42d252a50a (patch) | |
tree | c835fd8e3b4f744121997323094cffa7d607c9b0 | |
parent | e5ca37df46eb9be9002b4beb8095ddf82e822ce2 (diff) | |
download | go-b80ae102217ad4fefb7e72e060500f42d252a50a.tar.gz go-b80ae102217ad4fefb7e72e060500f42d252a50a.zip |
[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 <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
(cherry picked from commit df08c9a82152fd6f2b2811db03b40fea8b6e5e9e)
Reviewed-on: https://go-review.googlesource.com/c/go/+/408820
-rw-r--r-- | src/cmd/link/internal/loader/loader.go | 29 |
1 files changed, 4 insertions, 25 deletions
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 { |