aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.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/runtime/proc.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/runtime/proc.go')
-rw-r--r--src/runtime/proc.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 263945dd6c..fa76d3250c 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -244,8 +244,10 @@ func main() {
// list can arrive a few different ways, but it will always
// contain the init tasks computed by the linker for all the
// packages in the program (excluding those added at runtime
- // by package plugin).
- for _, m := range activeModules() {
+ // by package plugin). Run through the modules in dependency
+ // order (the order they are initialized by the dynamic
+ // loader, i.e. they are added to the moduledata linked list).
+ for m := &firstmoduledata; m != nil; m = m.next {
doInit(m.inittasks)
}