From c9f633487b6279ff17f1c0b50ccf6bd685e78656 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sat, 12 Oct 2019 01:07:31 -0400 Subject: [PATCH] [dev.link] cmd/internal/obj: sort ctxt.Data on AIX 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 TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh --- src/cmd/internal/obj/sym.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cmd/internal/obj/sym.go b/src/cmd/internal/obj/sym.go index e72ec3e701a..39d294183d6 100644 --- a/src/cmd/internal/obj/sym.go +++ b/src/cmd/internal/obj/sym.go @@ -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{}