return (*Reloc2)(unsafe.Pointer(&r.b[off]))
}
+// Relocs2 returns a pointer to the relocations of the i-th symbol.
+func (r *Reader) Relocs2(i int) []Reloc2 {
+ off := r.RelocOff(i, 0)
+ n := r.NReloc(i)
+ return (*[1 << 20]Reloc2)(unsafe.Pointer(&r.b[off]))[:n:n]
+}
+
// NAux returns the number of aux symbols of the i-th symbol.
func (r *Reader) NAux(i int) int {
auxIdxOff := r.h.Offsets[BlkAuxIdx] + uint32(i*4)
// so we make sure we're pulling in all outer symbols, and their sub
// symbols. This is not ideal, and these carrier/section symbols could
// be removed.
- d.mark(d.ldr.OuterSym(symIdx), symIdx)
- d.mark(d.ldr.SubSym(symIdx), symIdx)
+ if d.ldr.IsExternal(symIdx) {
+ d.mark(d.ldr.OuterSym(symIdx), symIdx)
+ d.mark(d.ldr.SubSym(symIdx), symIdx)
+ }
if len(methods) != 0 {
if !isgotype {
// Relocs encapsulates the set of relocations on a given symbol; an
// instance of this type is returned by the Loader Relocs() method.
type Relocs struct {
- Count int // number of relocs
+ Count int // == len(rs), TODO: remove
+
+ rs []goobj2.Reloc2
li int // local index of symbol whose relocs we're examining
r *oReader // object reader for containing package
// XXX populate a goobj2.Reloc from external reloc record.
// Ugly. Maybe we just want to use this format to store the
// reloc record in the first place?
+ // Also there is more speedup if we could remove the
+ // conditional here.
var b goobj2.Reloc2
b.Set(r.Off, r.Size, 0, r.Add, goobj2.SymRef{PkgIdx: 0, SymIdx: uint32(r.Sym)})
return Reloc2{&b, relocs.r, relocs.l, r.Type}
}
- return Reloc2{relocs.r.Reloc2(relocs.li, j), relocs.r, relocs.l, 0}
+ return Reloc2{&relocs.rs[j], relocs.r, relocs.l, 0}
}
// ReadAll method reads all relocations for a symbol into the
// Relocs returns a Relocs object given a local sym index and reader.
func (l *Loader) relocs(r *oReader, li int) Relocs {
var n int
+ var rs []goobj2.Reloc2
if l.isExtReader(r) {
pp := l.payloads[li]
n = len(pp.relocs)
} else {
- n = r.NReloc(li)
+ rs = r.Relocs2(li)
+ n = len(rs)
}
return Relocs{
Count: n,
+ rs: rs,
li: li,
r: r,
l: l,