]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: set symbol alignments after dynreloc2
authorCherry Zhang <cherryyz@google.com>
Sun, 26 Apr 2020 18:56:19 +0000 (14:56 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 27 Apr 2020 13:56:05 +0000 (13:56 +0000)
The symbol alignment is set based on its size. In dynreloc2
symbol size may change (e.g. elfdynhash2). So the alignment must
be set after dynreloc2.

Noticed this while debugging nondeterministic build on Solaris.

Idx Name          Size      VMA               LMA               File off  Algn
  8 .hash         000000c8  000000000048add2  000000000048add2  0008add2  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

This doesn't look right, as the section address is not a multiple
of its alignment.

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

index 48eab03314e3981fed1646ae49d06bb30d1a183e..4b3bc2ce02aee8cb8869e5357b132701141bec2d 100644 (file)
@@ -1336,11 +1336,6 @@ func (ctxt *Link) dodata2(symGroupType []sym.SymKind) {
                }
                state.data2[st] = append(state.data2[st], s)
 
-               // Set explicit alignment here, so as to avoid having to update
-               // symbol alignment in doDataSect2, which would cause a concurrent
-               // map read/write violation.
-               state.symalign2(s)
-
                // Similarly with checking the onlist attr.
                if ldr.AttrOnList(s) {
                        log.Fatalf("symbol %s listed multiple times", ldr.SymName(s))
@@ -1362,6 +1357,17 @@ 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)
+               }
+       }
+
        // Sort symbols.
        var wg sync.WaitGroup
        for symn := range state.data2 {