Skip to content

Commit

Permalink
fix pkujhd#93, fix fill findfuncbucket error
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonymous authored and eh-steve committed Jan 2, 2024
1 parent 2780e3b commit da303ad
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions ld.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,20 +860,28 @@ func (linker *Linker) buildModule(codeModule *CodeModule, symbolMap map[string]u

// see:^src/cmd/link/internal/ld/pcln.go findfunctab
funcbucket := []findfuncbucket{}
for k, _func := range linker._func {
funcname := gostringnocopy(&linker.funcnametab[_func.nameoff])
x := linker.symMap[funcname].Offset
b := x / pcbucketsize
i := x % pcbucketsize / (pcbucketsize / nsub)
for lb := b - len(funcbucket); lb >= 0; lb-- {
funcbucket = append(funcbucket, findfuncbucket{
idx: uint32(k)})
for k := 0; k < len(linker._func); k++ {
lEntry := int(getfuncentry(linker._func[k], module.text) - module.text)
lb := lEntry / pcbucketsize
li := lEntry % pcbucketsize / (pcbucketsize / nsub)

entry := int(module.maxpc - module.text)
if k < len(linker._func)-1 {
entry = int(getfuncentry(linker._func[k+1], module.text) - module.text)
}
b := entry / pcbucketsize
i := entry % pcbucketsize / (pcbucketsize / nsub)

for m := b - len(funcbucket); m >= 0; m-- {
funcbucket = append(funcbucket, findfuncbucket{idx: uint32(k)})
}
if lb < b {
i = nsub - 1
}
if funcbucket[b].subbuckets[i] == 0 && b != 0 && i != 0 {
if k-int(funcbucket[b].idx) >= pcbucketsize/minfunc {
return fmt.Errorf("over %d func in one funcbuckets", k-int(funcbucket[b].idx))
for n := li + 1; n <= i; n++ {
if funcbucket[lb].subbuckets[n] == 0 {
funcbucket[lb].subbuckets[n] = byte(k - int(funcbucket[lb].idx))
}
funcbucket[b].subbuckets[i] = byte(k - int(funcbucket[b].idx))
}
}
length := len(funcbucket) * FindFuncBucketSize
Expand Down

0 comments on commit da303ad

Please sign in to comment.