]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/link/internal/loader/symbolbuilder.go
cmd/link/internal/loader: remove some dead code
[gostls13.git] / src / cmd / link / internal / loader / symbolbuilder.go
index 5d37da8ac6fac22d80a2316411766f1c16b6aee2..b9eaca7fb6fd61c9e41b6d5d1b90220dbb1831ea 100644 (file)
@@ -121,13 +121,11 @@ func (sb *SymbolBuilder) Relocs() Relocs {
 // 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'
@@ -143,7 +141,6 @@ func (sb *SymbolBuilder) SetRelocAdd(i int, a int64) {
 // 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)
 }
 
@@ -152,7 +149,7 @@ func (sb *SymbolBuilder) AddRelocs(n int) Relocs {
 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
 }
@@ -169,7 +166,6 @@ func (p *relocsByOff) Len() int           { return len(p.relocs) }
 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 {
@@ -180,10 +176,6 @@ func (sb *SymbolBuilder) SetReachable(v 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)
 }
@@ -312,6 +304,16 @@ func (sb *SymbolBuilder) SetAddr(arch *sys.Arch, off int64, tgt Sym) int64 {
 }
 
 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")
@@ -326,10 +328,6 @@ func (sb *SymbolBuilder) Addstring(str string) int64 {
                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))
@@ -381,6 +379,10 @@ func (sb *SymbolBuilder) AddAddr(arch *sys.Arch, tgt Sym) int64 {
        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)
 }