From: Cherry Zhang Date: Sun, 26 Apr 2020 18:56:19 +0000 (-0400) Subject: [dev.link] cmd/link: set symbol alignments after dynreloc2 X-Git-Tag: go1.15beta1~270^2^2~24 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f8b74eafd5d2019a7a0fcfc21e037ba5f2f84732;p=gostls13.git [dev.link] cmd/link: set symbol alignments after dynreloc2 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 TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh Reviewed-by: Jeremy Faller --- diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 48eab03314..4b3bc2ce02 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -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 {