1
0
mirror of https://github.com/golang/go synced 2024-11-24 01:40:12 -07:00

cmd/link: clean up pclntab

More minor cleanup:

* Code simplification
* Move variable declaration closer to use
* Add docs
* Refactor loop

Change-Id: I6f662cb65038b6ad927eb83757b241ac1ef58943
Reviewed-on: https://go-review.googlesource.com/c/go/+/172078
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2019-04-15 09:25:23 -07:00
parent 3ebd9523bb
commit d3a23874af

View File

@ -201,7 +201,6 @@ func (ctxt *Link) pclntab() {
// function table, alternating PC and offset to func struct [each entry thearch.ptrsize bytes]
// end PC [thearch.ptrsize bytes]
// offset to file table [4 bytes]
nfunc := int32(0)
// Find container symbols and mark them as such.
for _, s := range ctxt.Textp {
@ -210,9 +209,15 @@ func (ctxt *Link) pclntab() {
}
}
// Gather some basic stats and info.
var nfunc int32
for _, s := range ctxt.Textp {
if emitPcln(ctxt, s) {
if !emitPcln(ctxt, s) {
continue
}
nfunc++
if pclntabFirstFunc == nil {
pclntabFirstFunc = s
}
}
@ -234,10 +239,8 @@ func (ctxt *Link) pclntab() {
return nameoff
}
nfunc = 0
var last *sym.Symbol
nfunc = 0 // repurpose nfunc as a running index
for _, s := range ctxt.Textp {
last = s
if !emitPcln(ctxt, s) {
continue
}
@ -246,10 +249,6 @@ func (ctxt *Link) pclntab() {
pcln = &pclntabZpcln
}
if pclntabFirstFunc == nil {
pclntabFirstFunc = s
}
if len(pcln.InlTree) > 0 {
if len(pcln.Pcdata) <= objabi.PCDATA_InlTreeIndex {
// Create inlining pcdata table.
@ -270,7 +269,7 @@ func (ctxt *Link) pclntab() {
}
funcstart := int32(len(ftab.P))
funcstart += int32(-len(ftab.P)) & (int32(ctxt.Arch.PtrSize) - 1)
funcstart += int32(-len(ftab.P)) & (int32(ctxt.Arch.PtrSize) - 1) // align to ptrsize
ftab.SetAddr(ctxt.Arch, 8+int64(ctxt.Arch.PtrSize)+int64(nfunc)*2*int64(ctxt.Arch.PtrSize), s)
ftab.SetUint(ctxt.Arch, 8+int64(ctxt.Arch.PtrSize)+int64(nfunc)*2*int64(ctxt.Arch.PtrSize)+int64(ctxt.Arch.PtrSize), uint64(funcstart))
@ -402,16 +401,15 @@ func (ctxt *Link) pclntab() {
off += 4
}
for i := range pcln.Funcdata {
dataoff := int64(off) + int64(ctxt.Arch.PtrSize)*int64(i)
if pcln.Funcdata[i] == nil {
ftab.SetUint(ctxt.Arch, int64(off)+int64(ctxt.Arch.PtrSize)*int64(i), uint64(pcln.Funcdataoff[i]))
} else {
ftab.SetUint(ctxt.Arch, dataoff, uint64(pcln.Funcdataoff[i]))
continue
}
// TODO: Dedup.
funcdataBytes += pcln.Funcdata[i].Size
ftab.SetAddrPlus(ctxt.Arch, int64(off)+int64(ctxt.Arch.PtrSize)*int64(i), pcln.Funcdata[i], pcln.Funcdataoff[i])
ftab.SetAddrPlus(ctxt.Arch, dataoff, pcln.Funcdata[i], pcln.Funcdataoff[i])
}
}
off += int32(len(pcln.Funcdata)) * int32(ctxt.Arch.PtrSize)
}
@ -423,6 +421,7 @@ func (ctxt *Link) pclntab() {
nfunc++
}
last := ctxt.Textp[len(ctxt.Textp)-1]
pclntabLastFunc = last
// Final entry of table is just end pc.
ftab.SetAddrPlus(ctxt.Arch, 8+int64(ctxt.Arch.PtrSize)+int64(nfunc)*2*int64(ctxt.Arch.PtrSize), last, last.Size)