// ResetRelocs removes all relocations on this symbol.
func (sb *SymbolBuilder) ResetRelocs() {
sb.relocs = sb.relocs[:0]
- sb.reltypes = sb.reltypes[:0]
}
// SetRelocType sets the type of the 'i'-th relocation on this sym to 't'
func (sb *SymbolBuilder) SetRelocType(i int, t objabi.RelocType) {
- sb.relocs[i].SetType(0)
- sb.reltypes[i] = t
+ sb.relocs[i].SetType(uint16(t))
}
// SetRelocSym sets the target sym of the 'i'-th relocation on this sym to 's'
// Add n relocations, return a handle to the relocations.
func (sb *SymbolBuilder) AddRelocs(n int) Relocs {
sb.relocs = append(sb.relocs, make([]goobj.Reloc, n)...)
- sb.reltypes = append(sb.reltypes, make([]objabi.RelocType, n)...)
return sb.l.Relocs(sb.symIdx)
}
func (sb *SymbolBuilder) AddRel(typ objabi.RelocType) (Reloc, int) {
j := len(sb.relocs)
sb.relocs = append(sb.relocs, goobj.Reloc{})
- sb.reltypes = append(sb.reltypes, typ)
+ sb.relocs[j].SetType(uint16(typ))
relocs := sb.Relocs()
return relocs.At(j), j
}
func (p *relocsByOff) Less(i, j int) bool { return p.relocs[i].Off() < p.relocs[j].Off() }
func (p *relocsByOff) Swap(i, j int) {
p.relocs[i], p.relocs[j] = p.relocs[j], p.relocs[i]
- p.reltypes[i], p.reltypes[j] = p.reltypes[j], p.reltypes[i]
}
func (sb *SymbolBuilder) Reachable() bool {
sb.l.SetAttrReachable(sb.symIdx, v)
}
-func (sb *SymbolBuilder) setReachable() {
- sb.SetReachable(true)
-}
-
func (sb *SymbolBuilder) ReadOnly() bool {
return sb.l.AttrReadOnly(sb.symIdx)
}
}
func (sb *SymbolBuilder) AddStringAt(off int64, str string) int64 {
+ strLen := int64(len(str))
+ if off+strLen > int64(len(sb.data)) {
+ panic("attempt to write past end of buffer")
+ }
+ copy(sb.data[off:off+strLen], str)
+ return off + strLen
+}
+
+// AddCStringAt adds str plus a null terminating byte.
+func (sb *SymbolBuilder) AddCStringAt(off int64, str string) int64 {
strLen := int64(len(str))
if off+strLen+1 > int64(len(sb.data)) {
panic("attempt to write past end of buffer")
sb.kind = sym.SNOPTRDATA
}
r := sb.size
- if sb.name == ".shstrtab" {
- // FIXME: find a better mechanism for this
- sb.l.elfsetstring(str, int(r))
- }
sb.data = append(sb.data, str...)
sb.data = append(sb.data, 0)
sb.size = int64(len(sb.data))
return sb.AddAddrPlus(arch, tgt, 0)
}
+func (sb *SymbolBuilder) AddPEImageRelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64 {
+ return sb.addSymRef(tgt, add, objabi.R_PEIMAGEOFF, 4)
+}
+
func (sb *SymbolBuilder) AddPCRelPlus(arch *sys.Arch, tgt Sym, add int64) int64 {
return sb.addSymRef(tgt, add, objabi.R_PCREL, 4)
}