]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: sort relocations
authorCherry Mui <cherryyz@google.com>
Mon, 28 Mar 2022 16:46:46 +0000 (12:46 -0400)
committerCherry Mui <cherryyz@google.com>
Mon, 28 Mar 2022 19:46:07 +0000 (19:46 +0000)
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 #51923.

Fixes #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>
src/cmd/internal/obj/objfile.go

index e7bc45ccdf088e3c6bd2ac02c306c079e621e3bb..7bae31f343034d62dcfb79027d3103494bb4cd39 100644 (file)
@@ -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])
                        }