1
0
mirror of https://github.com/golang/go synced 2024-11-18 17:14:45 -07:00

[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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-04-26 14:56:19 -04:00
parent e77639f3a4
commit f8b74eafd5

View 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 {