aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/deadcode2.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2019-10-04 22:05:41 -0400
committerCherry Zhang <cherryyz@google.com>2019-10-15 18:55:32 +0000
commitcab29ebd84d3fae2092337684ba82999fe97e947 (patch)
treeb26ffb58eff691b5c6a83c763be6de1aa430835d /src/cmd/link/internal/ld/deadcode2.go
parent90fe9c7c5c19cd0816c8afaa65a7f14d18cd3860 (diff)
downloadgo-cab29ebd84d3fae2092337684ba82999fe97e947.tar.xz
[dev.link] cmd/link: create sym.Symbols after deadcode in newobj mode
With the new object files, now we can run the deadcode pass on indices instead of Symbol structs, so we can delay creating Symbols after the deadcode pass. Then we only need to create reachable symbols. Not create Symbols in LoadNew and LoadRefs, and recombine LoadReloc into LoadFull. Split loadcgo into two parts: the first finds root symbols, the second create Symbols and sets attributes. The first runs before the deadcode pass, while the second runs after. TODO: currently there are still symbols that are not marked reachable but still used. This includes DWARF symbols, file symbols, and type symbols that are referenced by DWARF symbols. We still need to create them (conservatively). Change-Id: I695779c9312be9d49ab1683957ac3e72e1f65a1e Reviewed-on: https://go-review.googlesource.com/c/go/+/199643 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/link/internal/ld/deadcode2.go')
-rw-r--r--src/cmd/link/internal/ld/deadcode2.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/cmd/link/internal/ld/deadcode2.go b/src/cmd/link/internal/ld/deadcode2.go
index a7a17d5097..3067d40c29 100644
--- a/src/cmd/link/internal/ld/deadcode2.go
+++ b/src/cmd/link/internal/ld/deadcode2.go
@@ -76,8 +76,12 @@ func (d *deadcodePass2) init() {
}
}
}
- for _, s := range dynexp {
- d.mark(d.loader.Lookup(s.Name, int(s.Version)))
+ dynexpMap := d.ctxt.cgo_export_dynamic
+ if d.ctxt.LinkMode == LinkExternal {
+ dynexpMap = d.ctxt.cgo_export_static
+ }
+ for exp := range dynexpMap {
+ names = append(names, exp)
}
for _, name := range names {
@@ -215,16 +219,6 @@ func deadcode2(ctxt *Link) {
}
}
}
-
- // Set reachable attr for now.
- for i := 1; i < n; i++ {
- if loader.Reachable.Has(objfile.Sym(i)) {
- s := loader.Syms[i]
- if s != nil && s.Name != "" {
- s.Attr.Set(sym.AttrReachable, true)
- }
- }
- }
}
// methodref2 holds the relocations from a receiver type symbol to its