Addcall(ld.Ctxt, initfunc, addmoduledata)
// c: c3 retq
o(0xc3)
- if ld.Ctxt.Etextp != nil {
- ld.Ctxt.Etextp.Next = initfunc
- } else {
- ld.Ctxt.Textp = initfunc
- }
- ld.Ctxt.Etextp = initfunc
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
rel.Type = obj.R_PCREL
rel.Add = 4
- if ld.Ctxt.Etextp != nil {
- ld.Ctxt.Etextp.Next = initfunc
- } else {
- ld.Ctxt.Textp = initfunc
- }
- ld.Ctxt.Etextp = initfunc
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
rel.Sym = ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
rel.Type = obj.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference
- if ld.Ctxt.Etextp != nil {
- ld.Ctxt.Etextp.Next = initfunc
- } else {
- ld.Ctxt.Textp = initfunc
- }
- ld.Ctxt.Etextp = initfunc
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
}
Bso.Flush()
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
relocsym(s)
}
for _, sym := range datap {
}
Bso.Flush()
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
dynrelocsym(s)
}
for _, syms := range data {
fmt.Fprintf(Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
}
- blk(Ctxt.Textp, addr, size)
+ blkSlice(Ctxt.Textp, addr, size)
/* again for printing */
if Debug['a'] == 0 {
}
var sym *LSym
- for sym = Ctxt.Textp; sym != nil; sym = sym.Next {
+ for _, sym = range Ctxt.Textp {
if !sym.Attr.Reachable() {
continue
}
sym.P = []byte(data)
sym.Size = int64(len(sym.P))
- sym.Next = Ctxt.Textp
- Ctxt.Textp = sym
+ Ctxt.Textp = append(Ctxt.Textp, nil)
+ copy(Ctxt.Textp[1:], Ctxt.Textp)
+ Ctxt.Textp[0] = sym
}
// assign addresses to text
}
va := uint64(INITTEXT)
sect.Vaddr = va
- for sym := Ctxt.Textp; sym != nil; sym = sym.Next {
+ for _, sym := range Ctxt.Textp {
sym.Sect = sect
if sym.Type&obj.SSUB != 0 {
continue
}
// Remove dead text but keep file information (z symbols).
- var last *LSym
- for s := ctxt.Textp; s != nil; s = s.Next {
- if !s.Attr.Reachable() {
- continue
+ textp := make([]*LSym, 0, len(ctxt.Textp))
+ for _, s := range ctxt.Textp {
+ if s.Attr.Reachable() {
+ textp = append(textp, s)
}
- if last == nil {
- ctxt.Textp = s
- } else {
- last.Next = s
- }
- last = s
- }
- if last == nil {
- ctxt.Textp = nil
- ctxt.Etextp = nil
- } else {
- last.Next = nil
- ctxt.Etextp = last
}
+ ctxt.Textp = textp
}
var markextra = []string{
lang := DW_LANG_Go
- s := Ctxt.Textp
+ s := Ctxt.Textp[0]
dwinfo = newdie(&dwroot, DW_ABRV_COMPUNIT, "go", 0)
newattr(dwinfo, DW_AT_language, DW_CLS_CONSTANT, int64(lang), 0)
var pcfile Pciter
var pcline Pciter
- for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
- s = Ctxt.Cursym
+ for _, Ctxt.Cursym = range Ctxt.Textp {
+ s := Ctxt.Cursym
dwfunc := newdie(dwinfo, DW_ABRV_FUNCTION, s.Name, int(s.Version))
newattr(dwfunc, DW_AT_low_pc, DW_CLS_ADDRESS, s.Value, s)
var deltaBuf []byte
var pcsp Pciter
- for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
+ for _, Ctxt.Cursym = range Ctxt.Textp {
s := Ctxt.Cursym
if s.FuncInfo == nil {
continue
Cput(0)
}
- elfrelocsect(Segtext.Sect, list2slice(Ctxt.Textp))
+ elfrelocsect(Segtext.Sect, Ctxt.Textp)
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
elfrelocsect(sect, datap)
}
log.Fatalf("symbol %s listed multiple times", s.Name)
}
s.Attr |= AttrOnList
- if Ctxt.Etextp != nil {
- Ctxt.Etextp.Next = s
- } else {
- Ctxt.Textp = s
- }
- Ctxt.Etextp = s
+ Ctxt.Textp = append(Ctxt.Textp, s)
for s = s.Sub; s != nil; s = s.Sub {
if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name)
}
s.Attr |= AttrOnList
- Ctxt.Etextp.Next = s
- Ctxt.Etextp = s
+ Ctxt.Textp = append(Ctxt.Textp, s)
}
}
}
log.Fatalf("symbol %s listed multiple times", s.Name)
}
s.Attr |= AttrOnList
- if Ctxt.Etextp != nil {
- Ctxt.Etextp.Next = s
- } else {
- Ctxt.Textp = s
- }
- Ctxt.Etextp = s
+ Ctxt.Textp = append(Ctxt.Textp, s)
for s1 = s.Sub; s1 != nil; s1 = s1.Sub {
if s1.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s1.Name)
}
s1.Attr |= AttrOnList
- Ctxt.Etextp.Next = s1
- Ctxt.Etextp = s1
+ Ctxt.Textp = append(Ctxt.Textp, s1)
}
}
}
log.Fatalf("symbol %s listed multiple times", s.Name)
}
s.Attr |= AttrOnList
- if Ctxt.Etextp != nil {
- Ctxt.Etextp.Next = s
- } else {
- Ctxt.Textp = s
- }
- Ctxt.Etextp = s
+ Ctxt.Textp = append(Ctxt.Textp, s)
for s = s.Sub; s != nil; s = s.Sub {
if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name)
}
s.Attr |= AttrOnList
- Ctxt.Etextp.Next = s
- Ctxt.Etextp = s
+ Ctxt.Textp = append(Ctxt.Textp, s)
}
}
}
// We might have overwritten some functions above (this tends to happen for the
// autogenerated type equality/hashing functions) and we don't want to generated
- // pcln table entries for these any more so unstitch them from the Textp linked
- // list.
- var last *LSym
-
- for s := Ctxt.Textp; s != nil; s = s.Next {
- if s.Type == obj.SDYNIMPORT {
- continue
- }
-
- if last == nil {
- Ctxt.Textp = s
- } else {
- last.Next = s
+ // pcln table entries for these any more so remove them from Textp.
+ textp := make([]*LSym, 0, len(Ctxt.Textp))
+ for _, s := range Ctxt.Textp {
+ if s.Type != obj.SDYNIMPORT {
+ textp = append(textp, s)
}
- last = s
- }
-
- if last == nil {
- Ctxt.Textp = nil
- Ctxt.Etextp = nil
- } else {
- last.Next = nil
- Ctxt.Etextp = last
}
+ Ctxt.Textp = textp
Ctxt.Shlibs = append(Ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f, gcdata_addresses: gcdata_addresses})
}
// Check every function, but do the nosplit functions in a first pass,
// to make the printed failure chains as short as possible.
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
// runtime.racesymbolizethunk is called from gcc-compiled C
// code running on the operating system thread stack.
// It uses more than the usual amount of stack but that's okay.
}
}
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
if !s.Attr.NoSplit() {
Ctxt.Cursym = s
ch.sym = s
}
var off int32
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
put(s, s.Name, 'T', s.Value, s.Size, int(s.Version), s.Gotype)
locals := int32(0)
}
func undef() {
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
undefsym(s)
}
for _, s := range datap {
var i int
var r *Reloc
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
for i = 0; i < len(s.R); i++ {
r = &s.R[i]
if r.Sym == nil {
Diag func(string, ...interface{})
Cursym *LSym
Version int
- Textp *LSym
- Etextp *LSym
+ Textp []*LSym
Nhistfile int32
Filesyms *LSym
Moduledata *LSym
Cput(0)
}
- machorelocsect(Segtext.Sect, list2slice(Ctxt.Textp))
+ machorelocsect(Segtext.Sect, Ctxt.Textp)
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
machorelocsect(sect, datap)
}
log.Fatalf("symbol %s listed multiple times", s.Name)
}
s.Attr |= AttrOnList
- if r.ctxt.Etextp != nil {
- r.ctxt.Etextp.Next = s
- } else {
- r.ctxt.Textp = s
- }
- r.ctxt.Etextp = s
+ r.ctxt.Textp = append(r.ctxt.Textp, s)
}
}
}
nfunc := int32(0)
// Find container symbols, mark them with SCONTAINER
- for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
- if Ctxt.Cursym.Outer != nil {
- Ctxt.Cursym.Outer.Type |= obj.SCONTAINER
+ for _, s := range Ctxt.Textp {
+ if s.Outer != nil {
+ s.Outer.Type |= obj.SCONTAINER
}
}
- for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
- if container(Ctxt.Cursym) == 0 {
+ for _, s := range Ctxt.Textp {
+ if container(s) == 0 {
nfunc++
}
}
nfunc = 0
var last *LSym
- for Ctxt.Cursym = Ctxt.Textp; Ctxt.Cursym != nil; Ctxt.Cursym = Ctxt.Cursym.Next {
+ for _, Ctxt.Cursym = range Ctxt.Textp {
last = Ctxt.Cursym
if container(Ctxt.Cursym) != 0 {
continue
t.Attr |= AttrLocal
// find min and max address
- min := Ctxt.Textp.Value
-
+ min := Ctxt.Textp[0].Value
max := int64(0)
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for _, s := range Ctxt.Textp {
max = s.Value + s.Size
}
indexes[i] = NOIDX
}
idx := int32(0)
- var e *LSym
- var i int32
- var p int64
- var q int64
- for s := Ctxt.Textp; s != nil; s = s.Next {
+ for i, s := range Ctxt.Textp {
if container(s) != 0 {
continue
}
- p = s.Value
- e = s.Next
- for container(e) != 0 {
- e = e.Next
+ p := s.Value
+ var e *LSym
+ i++
+ if i < len(Ctxt.Textp) {
+ e = Ctxt.Textp[i]
+ }
+ for container(e) != 0 && i < len(Ctxt.Textp) {
+ e = Ctxt.Textp[i]
+ i++
}
+ q := max
if e != nil {
q = e.Value
- } else {
- q = max
}
//print("%d: [%lld %lld] %s\n", idx, p, q, s->name);
for ; p < q; p += SUBBUCKETSIZE {
- i = int32((p - min) / SUBBUCKETSIZE)
+ i = int((p - min) / SUBBUCKETSIZE)
if indexes[i] > idx {
indexes[i] = idx
}
}
- i = int32((q - 1 - min) / SUBBUCKETSIZE)
+ i = int((q - 1 - min) / SUBBUCKETSIZE)
if indexes[i] > idx {
indexes[i] = idx
}
Symgrow(Ctxt, t, 4*int64(nbuckets)+int64(n))
// fill in table
- var base int32
- var j int32
for i := int32(0); i < nbuckets; i++ {
- base = indexes[i*SUBBUCKETS]
+ base := indexes[i*SUBBUCKETS]
if base == NOIDX {
Diag("hole in findfunctab")
}
setuint32(Ctxt, t, int64(i)*(4+SUBBUCKETS), uint32(base))
- for j = 0; j < SUBBUCKETS && i*SUBBUCKETS+j < n; j++ {
+ for j := int32(0); j < SUBBUCKETS && i*SUBBUCKETS+j < n; j++ {
idx = indexes[i*SUBBUCKETS+j]
if idx == NOIDX {
Diag("hole in findfunctab")
Lputl(0)
Wputl(0)
- n := perelocsect(Segtext.Sect, list2slice(Ctxt.Textp)) + 1
+ n := perelocsect(Segtext.Sect, Ctxt.Textp) + 1
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
n += perelocsect(sect, datap)
}
//
// This assumes "case 1" from the ABI, where the caller needs
// us to save and restore the TOC pointer.
- pprevtextp := &ld.Ctxt.Textp
-
- for s := *pprevtextp; s != nil; pprevtextp, s = &s.Next, s.Next {
+ for _, s := range ld.Ctxt.Textp {
for i := range s.R {
r := &s.R[i]
if r.Type != 256+ld.R_PPC64_REL24 || r.Sym.Type != obj.SDYNIMPORT {
if stub.Size == 0 {
// Need outer to resolve .TOC.
stub.Outer = s
-
- // Link in to textp before s (we could
- // do it after, but would have to skip
- // the subsymbols)
- *pprevtextp = stub
-
- stub.Next = s
- pprevtextp = &stub.Next
-
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, stub)
gencallstub(1, stub, r.Sym)
}
ld.Ctxt.Arch.ByteOrder.PutUint32(s.P[r.Off+4:], o1)
}
}
-
}
func genaddmoduledata() {
// blr
o(0x4e800020)
- if ld.Ctxt.Etextp != nil {
- ld.Ctxt.Etextp.Next = initfunc
- } else {
- ld.Ctxt.Textp = initfunc
- }
- ld.Ctxt.Etextp = initfunc
-
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
// undef (for debugging)
ld.Adduint32(ld.Ctxt, initfunc, 0)
- if ld.Ctxt.Etextp != nil {
- ld.Ctxt.Etextp.Next = initfunc
- } else {
- ld.Ctxt.Textp = initfunc
- }
- ld.Ctxt.Etextp = initfunc
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Attr |= ld.AttrReachable
// c3 ret
o(0xc3)
- if ld.Ctxt.Etextp != nil {
- ld.Ctxt.Etextp.Next = thunkfunc
- } else {
- ld.Ctxt.Textp = thunkfunc
- }
- ld.Ctxt.Etextp = thunkfunc
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, thunkfunc)
addmoduledata := ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
if addmoduledata.Type == obj.STEXT {
o(0xc3)
- ld.Ctxt.Etextp.Next = initfunc
- ld.Ctxt.Etextp = initfunc
+ ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal