aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/loader/loader.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2019-12-11 14:36:17 -0500
committerThan McIntosh <thanm@google.com>2019-12-27 15:05:39 +0000
commitb720014743d7de2e706bb6b54ca914653d86f76c (patch)
treed59d348cb15c6fea327d7bbdc25e9d7b94f095f8 /src/cmd/link/internal/loader/loader.go
parentc6fea80b9582d7c4f86bf88b404ac6ebb33359fd (diff)
downloadgo-b720014743d7de2e706bb6b54ca914653d86f76c.tar.xz
[dev.link] cmd/link: add SymbolBuilder helper
Add SymbolBuilder helper type -- this type provides a set of methods intended to make it easy to manipulate the content of a symbol (type, relocations, data, etc). Change-Id: I579bf8d04650e66d33a9780a6c2347a576c94c6f Reviewed-on: https://go-review.googlesource.com/c/go/+/210178 Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
Diffstat (limited to 'src/cmd/link/internal/loader/loader.go')
-rw-r--r--src/cmd/link/internal/loader/loader.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index 029e10feda..89e312e665 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -211,8 +211,12 @@ type Loader struct {
flags uint32
strictDupMsgs int // number of strict-dup warning/errors, when FlagStrictDups is enabled
+
+ elfsetstring elfsetstringFunc
}
+type elfsetstringFunc func(s *sym.Symbol, str string, off int)
+
// extSymPayload holds the payload (data + relocations) for linker-synthesized
// external symbols (note that symbol value is stored in a separate slice).
type extSymPayload struct {
@@ -229,7 +233,7 @@ const (
FlagStrictDups = 1 << iota
)
-func NewLoader(flags uint32) *Loader {
+func NewLoader(flags uint32, elfsetstring elfsetstringFunc) *Loader {
nbuiltin := goobj2.NBuiltin()
return &Loader{
start: make(map[*oReader]Sym),
@@ -252,6 +256,7 @@ func NewLoader(flags uint32) *Loader {
extStaticSyms: make(map[nameVer]Sym),
builtinSyms: make([]Sym, nbuiltin),
flags: flags,
+ elfsetstring: elfsetstring,
}
}
@@ -392,6 +397,21 @@ func (l *Loader) getPayload(i Sym) *extSymPayload {
return &l.payloads[pi]
}
+func (ms *extSymPayload) Grow(siz int64) {
+ if int64(int(siz)) != siz {
+ log.Fatalf("symgrow size %d too long", siz)
+ }
+ if int64(len(ms.data)) >= siz {
+ return
+ }
+ if cap(ms.data) < int(siz) {
+ cl := len(ms.data)
+ ms.data = append(ms.data, make([]byte, int(siz)+1-cl)...)
+ ms.data = ms.data[0:cl]
+ }
+ ms.data = ms.data[:siz]
+}
+
// Ensure Syms slice has enough space, as well as growing the
// 'payloads' slice.
func (l *Loader) growSyms(i int) {