]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: tweaks to data alignment processing
authorThan McIntosh <thanm@google.com>
Thu, 30 Apr 2020 20:07:31 +0000 (16:07 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 1 May 2020 01:51:18 +0000 (01:51 +0000)
Now that the loader's internal storage mechanism for symbol alignment
is array-based and not map-based, we can go back to computing symbol
alignment in the parallel-by-section section of dodata.

With this patch plus the previous one, this produces a small
kubelet speedup:

$ benchstat out.devlink.txt out.align.txt
name                        old time/op  new time/op  delta
RelinkKubelet                13.3s ± 2%   13.1s ± 2%  -1.27%  (p=0.000 n=20+20)
RelinkKubelet-WithoutDebug   7.36s ± 5%   7.14s ± 3%  -3.00%  (p=0.000 n=20+20)

Change-Id: I9eb0e8fea6aeb12f188f499e9031d5a3a23232c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/231221
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/ld/data.go

index 102fcabe47827679e0ac29ba78f7ab47847eac2d..162ef9ba4e3f0e31863e3b17a9278c14e602c12d 100644 (file)
@@ -1436,16 +1436,12 @@ func (ctxt *Link) dodata2(symGroupType []sym.SymKind) {
        // Move any RO data with relocations to a separate section.
        state.makeRelroForSharedLib2(ctxt)
 
-       // Set explicit alignment here, so as to avoid having to update
-       // symbol alignment in doDataSect2, which would cause a concurrent
-       // map read/write violation.
-       // NOTE: this needs to be done after dynreloc2, where symbol size
-       // may change.
-       for _, list := range state.data2 {
-               for _, s := range list {
-                       state.symalign2(s)
-               }
-       }
+       // Set alignment for the symbol with the largest known index,
+       // so as to trigger allocation of the loader's internal
+       // alignment array. This will avoid data races in the parallel
+       // section below.
+       lastSym := loader.Sym(ldr.NSym() - 1)
+       ldr.SetSymAlign(lastSym, ldr.SymAlign(lastSym))
 
        // Sort symbols.
        var wg sync.WaitGroup
@@ -2044,7 +2040,7 @@ func (state *dodataState) dodataSect2(ctxt *Link, symn sym.SymKind, syms []loade
                return si < sj
        })
 
-       // Reap alignment, construct result
+       // Set alignment, construct result
        syms = syms[:0]
        for k := range sl {
                s := sl[k].sym