Skip to content

Commit

Permalink
cmd/internal/obj: sort relocations
Browse files Browse the repository at this point in the history
At least on some platforms (e.g. PE dynamic loader) relocations
need to be sorted in address order. Currently we don't always emit
relocations in address order: e.g. for array literal with out-of-
order element initializers, or out-of-order DATA instructions in
assembly code. Sort them.

No test for now as I can't reproduce the failure for golang#51923.

Fixes golang#51923.

Change-Id: Ifec5d3476e027bb927bcefd6e45c40ebeccee4ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/396195
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
  • Loading branch information
cherrymui committed Mar 28, 2022
1 parent 33987b4 commit 1a9972e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/cmd/internal/obj/objfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func WriteObjFile(ctxt *Link, b *bio.Writer) {
h.Offsets[goobj.BlkReloc] = w.Offset()
for _, list := range lists {
for _, s := range list {
sort.Sort(relocByOff(s.R)) // some platforms (e.g. PE) requires relocations in address order
for i := range s.R {
w.Reloc(&s.R[i])
}
Expand Down

0 comments on commit 1a9972e

Please sign in to comment.