aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/deadcode2.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2019-10-16 15:44:04 -0400
committerCherry Zhang <cherryyz@google.com>2019-10-16 22:28:18 +0000
commit2bbf2e0233799ab90bedc82f51a87f7d7aa76920 (patch)
tree7ce35942747ecfb9c7a2a58e580a57787bb369c4 /src/cmd/link/internal/ld/deadcode2.go
parent5caac2f73efe7fc6919f7850d99c35cde02012b5 (diff)
downloadgo-2bbf2e0233799ab90bedc82f51a87f7d7aa76920.tar.xz
[dev.link] cmd/link: add basic shared library support in newobj mode
This CL adds basic shared library support in newobj mode. This is not complete -- there are still tests in misc/cgo/testshared failing. But at least a simple program works, and some tests there pass. Add the mechanism of loading external symbols with contents. (Before, external symbols are always contentless.) This may potentially be also used for other host objects. Change-Id: I68dbf71e7949cc01ebf37ea159084e798ae16925 Reviewed-on: https://go-review.googlesource.com/c/go/+/201537 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
Diffstat (limited to 'src/cmd/link/internal/ld/deadcode2.go')
-rw-r--r--src/cmd/link/internal/ld/deadcode2.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/cmd/link/internal/ld/deadcode2.go b/src/cmd/link/internal/ld/deadcode2.go
index ff5cb60a60..259199eea1 100644
--- a/src/cmd/link/internal/ld/deadcode2.go
+++ b/src/cmd/link/internal/ld/deadcode2.go
@@ -18,9 +18,6 @@ import (
var _ = fmt.Print
// TODO:
-// - Shared object support:
-// It basically marks everything. We could consider using
-// a different mechanism to represent it.
// - Field tracking support:
// It needs to record from where the symbol is referenced.
// - Debug output:
@@ -46,6 +43,19 @@ func (d *deadcodePass2) init() {
d.ldr.InitReachable()
d.ifaceMethod = make(map[methodsig]bool)
+ if d.ctxt.BuildMode == BuildModeShared {
+ // Mark all symbols defined in this library as reachable when
+ // building a shared library.
+ n := d.ldr.NDef()
+ for i := 1; i < n; i++ {
+ s := loader.Sym(i)
+ if !d.ldr.IsDup(s) {
+ d.mark(s)
+ }
+ }
+ return
+ }
+
var names []string
// In a normal binary, start at main.main and the init