Skip to content

Commit df08c9a

Browse files
committed
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. Change-Id: I1497e3223a641704bf35aa3e904dd0eda2f8ec3e Reviewed-on: https://go-review.googlesource.com/c/go/+/400574 Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 0c6d8bb commit df08c9a

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

src/cmd/link/internal/loader/loader.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,10 @@ func (l *Loader) cloneToExternal(symIdx Sym) {
23412341
// need to access the old symbol content.)
23422342
l.objSyms[symIdx] = objSym{l.extReader.objidx, uint32(pi)}
23432343
l.extReader.syms = append(l.extReader.syms, symIdx)
2344+
2345+
// Some attributes were encoded in the object file. Copy them over.
2346+
l.SetAttrDuplicateOK(symIdx, r.Sym(li).Dupok())
2347+
l.SetAttrShared(symIdx, r.Shared())
23442348
}
23452349

23462350
// 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) {
23612365
// TODO: other attributes?
23622366
}
23632367

2364-
// CopyAttributes copies over all of the attributes of symbol 'src' to
2365-
// symbol 'dst'.
2366-
func (l *Loader) CopyAttributes(src Sym, dst Sym) {
2367-
l.SetAttrReachable(dst, l.AttrReachable(src))
2368-
l.SetAttrOnList(dst, l.AttrOnList(src))
2369-
l.SetAttrLocal(dst, l.AttrLocal(src))
2370-
l.SetAttrNotInSymbolTable(dst, l.AttrNotInSymbolTable(src))
2371-
if l.IsExternal(dst) {
2372-
l.SetAttrVisibilityHidden(dst, l.AttrVisibilityHidden(src))
2373-
l.SetAttrDuplicateOK(dst, l.AttrDuplicateOK(src))
2374-
l.SetAttrShared(dst, l.AttrShared(src))
2375-
l.SetAttrExternal(dst, l.AttrExternal(src))
2376-
} else {
2377-
// Some attributes are modifiable only for external symbols.
2378-
// In such cases, don't try to transfer over the attribute
2379-
// from the source even if there is a clash. This comes up
2380-
// when copying attributes from a dupOK ABI wrapper symbol to
2381-
// the real target symbol (which may not be marked dupOK).
2382-
}
2383-
l.SetAttrSpecial(dst, l.AttrSpecial(src))
2384-
l.SetAttrCgoExportDynamic(dst, l.AttrCgoExportDynamic(src))
2385-
l.SetAttrCgoExportStatic(dst, l.AttrCgoExportStatic(src))
2386-
l.SetAttrReadOnly(dst, l.AttrReadOnly(src))
2387-
}
2388-
23892368
// CreateExtSym creates a new external symbol with the specified name
23902369
// without adding it to any lookup tables, returning a Sym index for it.
23912370
func (l *Loader) CreateExtSym(name string, ver int) Sym {

0 commit comments

Comments
 (0)