]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/internal/obj: sort ctxt.Data on AIX
authorCherry Zhang <cherryyz@google.com>
Sat, 12 Oct 2019 05:07:31 +0000 (01:07 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 14 Oct 2019 16:47:02 +0000 (16:47 +0000)
On AIX, TOC symbols may be created and added to ctxt.Data
concurrently. To ensure reproducible builds, sort ctxt.Data.
This implements the same logic as WriteObjFile does for old
object files.

Change-Id: I2e6e2d7755352848981544a4fb68b828a188c2ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/201021
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/internal/obj/sym.go

index e72ec3e701ae17e475b5ef39e33bb9da591638d2..39d294183d6d57b0cabc912500cc7d01b1d5dedc 100644 (file)
@@ -37,6 +37,7 @@ import (
        "fmt"
        "log"
        "math"
+       "sort"
 )
 
 func Linknew(arch *LinkArch) *Link {
@@ -167,6 +168,16 @@ func (ctxt *Link) NumberSyms(asm bool) {
                return
        }
 
+       if ctxt.Headtype == objabi.Haix {
+               // Data must be sorted to keep a constant order in TOC symbols.
+               // As they are created during Progedit, two symbols can be switched between
+               // two different compilations. Therefore, BuildID will be different.
+               // TODO: find a better place and optimize to only sort TOC symbols
+               sort.Slice(ctxt.Data, func(i, j int) bool {
+                       return ctxt.Data[i].Name < ctxt.Data[j].Name
+               })
+       }
+
        ctxt.pkgIdx = make(map[string]int32)
        ctxt.defs = []*LSym{}
        ctxt.nonpkgdefs = []*LSym{}