cmd/link/internal/loadpe: allocate comdat definitions map lazily

Switch the "comdatDefinitions" map to lazy allocation; we only need it
for loading PE objects, no point doing an allocation during package
init if we don't need it.

Change-Id: Ie33f2c56e964f35ac2e137840ac021cfaaa897c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/540255
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
This commit is contained in:
Than McIntosh 2023-11-06 14:18:43 -05:00
parent 36f3ec5912
commit 17211b64b6

View File

@ -219,7 +219,7 @@ type peLoaderState struct {
// comdatDefinitions records the names of symbols for which we've
// previously seen a definition in COMDAT. Key is symbol name, value
// is symbol size (or -1 if we're using the "any" strategy).
var comdatDefinitions = make(map[string]int64)
var comdatDefinitions map[string]int64
// Load loads the PE file pn from input.
// Symbols from the object file are created via the loader 'l',
@ -236,6 +236,9 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
pn: pn,
}
createImportSymsState(state.l, state.arch)
if comdatDefinitions == nil {
comdatDefinitions = make(map[string]int64)
}
// Some input files are archives containing multiple of
// object files, and pe.NewFile seeks to the start of