]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/link, runtime: initialize packages in shared build mode
authorCherry Mui <cherryyz@google.com>
Wed, 16 Aug 2023 23:49:04 +0000 (19:49 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 20 Sep 2023 14:46:11 +0000 (14:46 +0000)
commitfd54185a8d4e91eb6b34a73360cef0c51eea797e
treed0a325ec26b100db8215299baf51a62257730e99
parent3857a89e7eb872fa22d569e70b7e076bec74ebbb
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>
src/cmd/cgo/internal/testshared/testdata/dep2/dep2.go
src/cmd/cgo/internal/testshared/testdata/depBase/dep.go
src/cmd/cgo/internal/testshared/testdata/depBaseInternal/dep.go [new file with mode: 0644]
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/inittask.go
src/runtime/proc.go