From: Than McIntosh Date: Wed, 4 Dec 2019 14:47:22 +0000 (-0500) Subject: [dev.link] cmd/link: avoid allsyms loop in initarray setup X-Git-Tag: go1.15beta1~679^2~174 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=29f886e427c1686fd79fc4c4052b22634a5b13d8;p=gostls13.git [dev.link] cmd/link: avoid allsyms loop in initarray setup In the linker's symtab() function, avoid looping over the context's Syms.Allsyms array to locate the entry symbol when setting up the init array section; do an explicit ABI0 symbol lookup instead. This is a minor efficiency tweak / code cleanup. Fixes #20205. Change-Id: I2ebc17a3cb2cd63e9f5052bc80f1b0ac72c960e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/209838 Run-TryBot: Than McIntosh Reviewed-by: Jeremy Faller TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index bba623eb48..b6734f69cc 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -326,12 +326,11 @@ func textsectionmap(ctxt *Link) uint32 { } func (ctxt *Link) symtab() { - switch ctxt.BuildMode { - case BuildModeCArchive, BuildModeCShared: - for _, s := range ctxt.Syms.Allsym { - // Create a new entry in the .init_array section that points to the - // library initializer function. - if s.Name == *flagEntrySymbol && ctxt.HeadType != objabi.Haix { + if ctxt.HeadType != objabi.Haix { + switch ctxt.BuildMode { + case BuildModeCArchive, BuildModeCShared: + s := ctxt.Syms.ROLookup(*flagEntrySymbol, sym.SymVerABI0) + if s != nil { addinitarrdata(ctxt, s) } }