aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/loader/loader.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-04-20 18:42:35 -0400
committerCherry Zhang <cherryyz@google.com>2020-04-21 14:29:02 +0000
commit47cac82e36d08198afac646c3f46d24255cf9d61 (patch)
tree37ea1b6be419a51a8c4f0bce427f7f3615adc140 /src/cmd/link/internal/loader/loader.go
parent5cccd7a7246099c3e1d268089ee6795933d7221f (diff)
downloadgo-47cac82e36d08198afac646c3f46d24255cf9d61.tar.gz
go-47cac82e36d08198afac646c3f46d24255cf9d61.zip
[dev.link] cmd/link: convert symtab pass to new style
This is more or less a direct translation, to get things going. There are more things we can do to make it better, especially on the handling of container symbols. Change-Id: I11a0087e402be8d42b9d06869385ead531755272 Reviewed-on: https://go-review.googlesource.com/c/go/+/229125 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
Diffstat (limited to 'src/cmd/link/internal/loader/loader.go')
-rw-r--r--src/cmd/link/internal/loader/loader.go42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index b09832b5c3..75477fd819 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -1398,6 +1398,16 @@ func (l *Loader) SubSym(i Sym) Sym {
return l.sub[i]
}
+// SetOuterSym sets the outer symbol of i to o (without setting
+// sub symbols).
+func (l *Loader) SetOuterSym(i Sym, o Sym) {
+ if o != 0 {
+ l.outer[i] = o
+ } else {
+ delete(l.outer, i)
+ }
+}
+
// Initialize Reachable bitmap and its siblings for running deadcode pass.
func (l *Loader) InitReachable() {
l.growAttrBitmaps(l.NSym() + 1)
@@ -2225,8 +2235,7 @@ func loadObjSyms(l *Loader, syms *sym.Symbols, r *oReader) int {
continue
}
- s := l.addNewSym(gi, name, ver, r.unit, t)
- l.migrateAttributes(gi, s)
+ l.addNewSym(gi, name, ver, r.unit, t)
nr += r.NReloc(i)
}
return nr
@@ -2378,10 +2387,19 @@ func (l *Loader) migrateAttributes(src Sym, dst *sym.Symbol) {
dst.Sub = l.Syms[sub]
}
- // Set sub-symbol attribute. FIXME: would be better to do away
- // with this and just use l.OuterSymbol() != 0 elsewhere within
- // the linker.
- dst.Attr.Set(sym.AttrSubSymbol, dst.Outer != nil)
+ // Set sub-symbol attribute.
+ //
+ // In sym.Symbols world, it uses Outer to record container symbols.
+ // Currently there are two kinds
+ // - Outer symbol covers the address ranges of its sub-symbols.
+ // Outer.Sub is set in this case.
+ // - Outer symbol doesn't conver the address ranges. It is zero-sized
+ // and doesn't have sub-symbols. In the case, the inner symbol is
+ // not actually a "SubSymbol". (Tricky!)
+ //
+ // FIXME: would be better to do away with this and have a better way
+ // to represent container symbols.
+ dst.Attr.Set(sym.AttrSubSymbol, l.outer[src] != 0 && l.sub[l.outer[src]] != 0)
// Copy over dynimplib, dynimpvers, extname.
if name, ok := l.extname[src]; ok {
@@ -2448,10 +2466,11 @@ func loadObjFull(l *Loader, r *oReader) {
continue
}
+ l.migrateAttributes(gi, s)
+ // Be careful not to overwrite attributes set by the linker.
+ // Don't use the attributes from the object file.
+
osym := r.Sym(i)
- dupok := osym.Dupok()
- local := osym.Local()
- makeTypelink := osym.Typelink()
size := osym.Siz()
// Symbol data
@@ -2485,14 +2504,9 @@ func loadObjFull(l *Loader, r *oReader) {
}
s.File = r.pkgprefix[:len(r.pkgprefix)-1]
- if dupok {
- s.Attr |= sym.AttrDuplicateOK
- }
if s.Size < int64(size) {
s.Size = int64(size)
}
- s.Attr.Set(sym.AttrLocal, local)
- s.Attr.Set(sym.AttrMakeTypelink, makeTypelink)
}
}