]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: add hooks for sorting loader.Reloc by offset
authorThan McIntosh <thanm@google.com>
Fri, 13 Dec 2019 18:34:43 +0000 (13:34 -0500)
committerThan McIntosh <thanm@google.com>
Mon, 6 Jan 2020 18:59:04 +0000 (18:59 +0000)
Add support for supporting loader.Reloc by offset, needed by host
object loaders.

Change-Id: I5ac0702ee74ad71531f443e6215558d8151e3a4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/211306
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/loader/loader.go

index 28d8c397e0d6cc912485ac0299d3797eb2bebb82..6ffc67327ebc2a2cf20adf3f70115a3e058903b5 100644 (file)
@@ -1339,6 +1339,14 @@ func (l *Loader) relocs(r *oReader, li int) Relocs {
        }
 }
 
+// RelocByOff implements sort.Interface for sorting relocations by offset.
+
+type RelocByOff []Reloc
+
+func (x RelocByOff) Len() int           { return len(x) }
+func (x RelocByOff) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }
+func (x RelocByOff) Less(i, j int) bool { return x[i].Off < x[j].Off }
+
 // Preload a package: add autolibs, add symbols to the symbol table.
 // Does not read symbol data yet.
 func (l *Loader) Preload(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, unit *sym.CompilationUnit, length int64, pn string, flags int) {