1
0
mirror of https://github.com/golang/go synced 2024-11-23 09:30:03 -07:00

cmd/link: convert textp into a slice

Updates #15374

Change-Id: I3ea715735862fe9550b88d7a29def6cb9d4419a6
Reviewed-on: https://go-review.googlesource.com/22243
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
This commit is contained in:
David Crawshaw 2016-04-19 14:02:21 -04:00
parent 5a0881a1d1
commit 7d56215bcb
19 changed files with 71 additions and 168 deletions

View File

@ -86,12 +86,7 @@ func gentext() {
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

View File

@ -95,12 +95,7 @@ func gentext() {
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

View File

@ -78,12 +78,7 @@ func gentext() {
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

View File

@ -648,7 +648,7 @@ func reloc() {
}
Bso.Flush()
for s := Ctxt.Textp; s != nil; s = s.Next {
for _, s := range Ctxt.Textp {
relocsym(s)
}
for _, sym := range datap {
@ -724,7 +724,7 @@ func dynreloc(data *[obj.SXREF][]*LSym) {
}
Bso.Flush()
for s := Ctxt.Textp; s != nil; s = s.Next {
for _, s := range Ctxt.Textp {
dynrelocsym(s)
}
for _, syms := range data {
@ -791,7 +791,7 @@ func Codeblk(addr int64, size int64) {
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 {
@ -799,7 +799,7 @@ func Codeblk(addr int64, size int64) {
}
var sym *LSym
for sym = Ctxt.Textp; sym != nil; sym = sym.Next {
for _, sym = range Ctxt.Textp {
if !sym.Attr.Reachable() {
continue
}
@ -1893,8 +1893,9 @@ func textbuildid() {
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
@ -1914,7 +1915,7 @@ func textaddress() {
}
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

View File

@ -119,25 +119,13 @@ func deadcode(ctxt *Link) {
}
// 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{

View File

@ -1432,7 +1432,7 @@ func writelines(prev *LSym) *LSym {
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)
@ -1502,8 +1502,8 @@ func writelines(prev *LSym) *LSym {
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)
@ -1696,7 +1696,7 @@ func writeframes(prev *LSym) *LSym {
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

View File

@ -1727,7 +1727,7 @@ func Elfemitreloc() {
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)
}

View File

@ -842,19 +842,13 @@ func ldelf(f *bio.Reader, pkg string, length int64, pn string) {
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)
}
}
}

View File

@ -707,19 +707,13 @@ func ldmacho(f *bio.Reader, pkg string, length int64, pn string) {
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)
}
}
}

View File

@ -435,19 +435,13 @@ func ldpe(f *bio.Reader, pkg string, length int64, pn string) {
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)
}
}
}

View File

@ -1545,30 +1545,14 @@ func ldshlibsyms(shlib string) {
// 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
// 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)
}
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
Ctxt.Shlibs = append(Ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f, gcdata_addresses: gcdata_addresses})
}
@ -1682,7 +1666,7 @@ func dostkcheck() {
// 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.
@ -1697,7 +1681,7 @@ func dostkcheck() {
}
}
for s := Ctxt.Textp; s != nil; s = s.Next {
for _, s := range Ctxt.Textp {
if !s.Attr.NoSplit() {
Ctxt.Cursym = s
ch.sym = s
@ -1995,7 +1979,7 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
}
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)
@ -2105,7 +2089,7 @@ func undefsym(s *LSym) {
}
func undef() {
for s := Ctxt.Textp; s != nil; s = s.Next {
for _, s := range Ctxt.Textp {
undefsym(s)
}
for _, s := range datap {
@ -2123,7 +2107,7 @@ func callgraph() {
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 {

View File

@ -178,8 +178,7 @@ type Link struct {
Diag func(string, ...interface{})
Cursym *LSym
Version int
Textp *LSym
Etextp *LSym
Textp []*LSym
Nhistfile int32
Filesyms *LSym
Moduledata *LSym

View File

@ -852,7 +852,7 @@ func Machoemitreloc() {
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)
}

View File

@ -398,12 +398,7 @@ overwrite:
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)
}
}
}

View File

@ -224,14 +224,14 @@ func pclntab() {
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++
}
}
@ -246,7 +246,7 @@ func pclntab() {
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
@ -401,10 +401,9 @@ func findfunctab() {
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
}
@ -417,34 +416,34 @@ func findfunctab() {
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
}
@ -457,15 +456,13 @@ func findfunctab() {
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")

View File

@ -831,7 +831,7 @@ func peemitreloc(text, data, ctors *IMAGE_SECTION_HEADER) {
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)
}

View File

@ -87,9 +87,7 @@ func genplt() {
//
// 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 {
@ -110,15 +108,7 @@ func genplt() {
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)
}
@ -131,7 +121,6 @@ func genplt() {
ld.Ctxt.Arch.ByteOrder.PutUint32(s.P[r.Off+4:], o1)
}
}
}
func genaddmoduledata() {
@ -187,13 +176,7 @@ 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

View File

@ -90,12 +90,7 @@ func gentext() {
// 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

View File

@ -69,12 +69,7 @@ func gentext() {
// 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 {
@ -130,8 +125,7 @@ func gentext() {
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