aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/deadcode.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-08-16 19:49:04 -0400
committerCherry Mui <cherryyz@google.com>2023-09-20 14:46:11 +0000
commitfd54185a8d4e91eb6b34a73360cef0c51eea797e (patch)
treed0a325ec26b100db8215299baf51a62257730e99 /src/cmd/link/internal/ld/deadcode.go
parent3857a89e7eb872fa22d569e70b7e076bec74ebbb (diff)
downloadgo-fd54185a8d4e91eb6b34a73360cef0c51eea797e.tar.xz
cmd/link, runtime: initialize packages in shared build mode
Currently, for the shared build mode, we don't generate the module inittasks. Instead, we rely on the main executable to do the initialization, for both the executable and the shared library. But, with the model as of CL 478916, the main executable only has relocations to packages that are directly imported. It won't see the dependency edges between packages within a shared library. Therefore indirect dependencies are not included, and thus not initialized. E.g. main imports a, which imports b, but main doesn't directly import b. a and b are in a shared object. When linking main, it sees main depends on a, so it generates main's inittasks to run a's init before main's, but it doesn't know b, so b's init doesn't run. This CL makes it initialize all packages in a shared library when the library is loaded, as any of them could potentially be imported, directly or indirectly. Also, in the runtime, when running the init functions, make sure to go through the DSOs in dependency order. Otherwise packages can be initialized in the wrong order. Fixes #61973. Change-Id: I2a090336fe9fa0d6c7e43912f3ab233c9c47e247 Reviewed-on: https://go-review.googlesource.com/c/go/+/520375 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/link/internal/ld/deadcode.go')
-rw-r--r--src/cmd/link/internal/ld/deadcode.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go
index a051e43401..70b4a7ca30 100644
--- a/src/cmd/link/internal/ld/deadcode.go
+++ b/src/cmd/link/internal/ld/deadcode.go
@@ -51,6 +51,7 @@ func (d *deadcodePass) init() {
s := loader.Sym(i)
d.mark(s, 0)
}
+ d.mark(d.ctxt.mainInittasks, 0)
return
}