wr *bio.Writer
stringMap map[string]uint32
off uint32 // running offset
+
+ b [8]byte // scratch space for writing bytes
}
func NewWriter(wr *bio.Writer) *Writer {
}
func (w *Writer) Uint64(x uint64) {
- var b [8]byte
- binary.LittleEndian.PutUint64(b[:], x)
- w.wr.Write(b[:])
+ binary.LittleEndian.PutUint64(w.b[:], x)
+ w.wr.Write(w.b[:])
w.off += 8
}
func (w *Writer) Uint32(x uint32) {
- var b [4]byte
- binary.LittleEndian.PutUint32(b[:], x)
- w.wr.Write(b[:])
+ binary.LittleEndian.PutUint32(w.b[:4], x)
+ w.wr.Write(w.b[:4])
w.off += 4
}
func (w *Writer) Uint16(x uint16) {
- var b [2]byte
- binary.LittleEndian.PutUint16(b[:], x)
- w.wr.Write(b[:])
+ binary.LittleEndian.PutUint16(w.b[:2], x)
+ w.wr.Write(w.b[:2])
w.off += 2
}
ctxt *Link
pkgpath string // the package import path (escaped), "" if unknown
pkglist []string // list of packages referenced, indexed by ctxt.pkgIdx
+
+ // scratch space for writing (the Write methods escape
+ // as they are interface calls)
+ tmpSym goobj.Sym
+ tmpReloc goobj.Reloc
+ tmpAux goobj.Aux
+ tmpHash64 goobj.Hash64Type
+ tmpHash goobj.HashType
+ tmpRefFlags goobj.RefFlags
+ tmpRefName goobj.RefName
}
// prepare package index list
if s.Size > cutoff {
w.ctxt.Diag("%s: symbol too large (%d bytes > %d bytes)", s.Name, s.Size, cutoff)
}
- var o goobj.Sym
+ o := &w.tmpSym
o.SetName(name, w.Writer)
o.SetABI(abi)
o.SetType(uint8(s.Type))
if !s.ContentAddressable() || len(s.R) != 0 {
panic("Hash of non-content-addressable symbol")
}
- b := contentHash64(s)
- w.Bytes(b[:])
+ w.tmpHash64 = contentHash64(s)
+ w.Bytes(w.tmpHash64[:])
}
func (w *writer) Hash(s *LSym) {
if !s.ContentAddressable() {
panic("Hash of non-content-addressable symbol")
}
- b := w.contentHash(s)
- w.Bytes(b[:])
+ w.tmpHash = w.contentHash(s)
+ w.Bytes(w.tmpHash[:])
}
// contentHashSection returns a mnemonic for s's section.
}
func (w *writer) Reloc(r *Reloc) {
- var o goobj.Reloc
+ o := &w.tmpReloc
o.SetOff(r.Off)
o.SetSiz(r.Siz)
o.SetType(uint16(r.Type))
}
func (w *writer) aux1(typ uint8, rs *LSym) {
- var o goobj.Aux
+ o := &w.tmpAux
o.SetType(typ)
o.SetSym(makeSymRef(rs))
o.Write(w.Writer)
if flag2 == 0 {
return // no need to write zero flags
}
- var o goobj.RefFlags
+ o := &w.tmpRefFlags
o.SetSym(symref)
o.SetFlag2(flag2)
o.Write(w.Writer)
}
seen[rs] = true
symref := makeSymRef(rs)
- var o goobj.RefName
+ o := &w.tmpRefName
o.SetSym(symref)
o.SetName(rs.Name, w.Writer)
o.Write(w.Writer)