aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/loader/loader.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2019-12-13 11:51:15 -0500
committerThan McIntosh <thanm@google.com>2019-12-18 14:24:45 +0000
commite6b044b20040f76a5602a7fe6fc3d6e994376df1 (patch)
treea49fe6dfd40f160ceb2b1f7cd5ebab5574883679 /src/cmd/link/internal/loader/loader.go
parentb658c62e9c5861f8c2bcc6323572998ef5ee0567 (diff)
downloadgo-e6b044b20040f76a5602a7fe6fc3d6e994376df1.tar.xz
[dev.link] cmd/link: add storage and methods for read/write of Sym value
Add loader methods SymValue() and SetSymValue() to get/set the value of a symbol by global index. Change-Id: Ifc71480fc34c719ad00506d0828edf36c1a57119 Reviewed-on: https://go-review.googlesource.com/c/go/+/211302 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>
Diffstat (limited to 'src/cmd/link/internal/loader/loader.go')
-rw-r--r--src/cmd/link/internal/loader/loader.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index 0a6887ca8a..f238df7f5a 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -157,6 +157,7 @@ type Loader struct {
overwrite map[Sym]Sym // overwrite[i]=j if symbol j overwrites symbol i
payloads []extSymPayload // contents of linker-materialized external syms
+ values []int64 // symbol values, indexed by global sym index
itablink map[Sym]struct{} // itablink[j] defined if j is go.itablink.*
@@ -197,11 +198,10 @@ type Loader struct {
}
// extSymPayload holds the payload (data + relocations) for linker-synthesized
-// external symbols.
+// external symbols (note that symbol value is stored in a separate slice).
type extSymPayload struct {
name string // TODO: would this be better as offset into str table?
size int64
- value int64
ver int
kind sym.SymKind
relocs []Reloc
@@ -247,6 +247,7 @@ func (l *Loader) addObj(pkg string, r *oReader) Sym {
l.start[r] = i
l.objs = append(l.objs, objIdx{r, i, i + Sym(n) - 1})
l.max += Sym(n)
+ l.growValues(int(l.max))
return i
}
@@ -373,6 +374,7 @@ func (l *Loader) growSyms(i int) {
}
l.Syms = append(l.Syms, make([]*sym.Symbol, i+1-n)...)
l.payloads = append(l.payloads, make([]extSymPayload, i+1-n)...)
+ l.growValues(int(i) + 1)
l.growAttrBitmaps(int(i) + 1)
}
@@ -832,6 +834,24 @@ func (l *Loader) IsItabLink(i Sym) bool {
return false
}
+// growValues grows the slice used to store symbol values.
+func (l *Loader) growValues(reqLen int) {
+ curLen := len(l.values)
+ if reqLen > curLen {
+ l.values = append(l.values, make([]int64, reqLen+1-curLen)...)
+ }
+}
+
+// SymValue returns the value of the i-th symbol. i is global index.
+func (l *Loader) SymValue(i Sym) int64 {
+ return l.values[i]
+}
+
+// SetSymValue sets the value of the i-th symbol. i is global index.
+func (l *Loader) SetSymValue(i Sym, val int64) {
+ l.values[i] = val
+}
+
// Returns the symbol content of the i-th symbol. i is global index.
func (l *Loader) Data(i Sym) []byte {
if l.IsExternal(i) {