Skip to content

Commit

Permalink
pkg/cover: move PC fix up into RestorePC
Browse files Browse the repository at this point in the history
That is a more reasonable place for it.
Backend.RestorePC also has access to more info about the kernel,
so can do a more precise check.

Also I suspect this fixes coverage filter in presence of the fix up.
I think fix up should happen before coverage filtering in fixUpPCs,
but it was done after so was probably not working.
  • Loading branch information
dvyukov committed Feb 17, 2023
1 parent 04a1e72 commit 10e9060
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
21 changes: 18 additions & 3 deletions pkg/cover/backend/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,28 @@ func makeDWARFUnsafe(target *targets.Target, objDir, srcDir, buildDir string,
Symbolize: func(pcs map[*Module][]uint64) ([]Frame, error) {
return symbolize(target, objDir, srcDir, buildDir, pcs)
},
RestorePC: func(pc uint32) uint64 {
return PreviousInstructionPC(target, RestorePC(pc, uint32(pcBase>>32)))
},
RestorePC: makeRestorePC(target, pcBase),
}
return impl, nil
}

func makeRestorePC(target *targets.Target, pcBase uint64) func(pc uint32) uint64 {
return func(pcLow uint32) uint64 {
pc := PreviousInstructionPC(target, RestorePC(pcLow, uint32(pcBase>>32)))
// On arm64 as PLT is enabled by default, .text section is loaded after .plt section,
// so there is 0x18 bytes offset from module load address for .text section
// we need to remove the 0x18 bytes offset in order to correct module symbol address
if target.Arch == targets.ARM64 {
// TODO: avoid to hardcode the address
// Fix up kernel PCs, but not the test (userspace) PCs.
if pc >= 0x8000000000000000 && pc < 0xffffffd010000000 {
pc -= 0x18
}
}
return pc
}
}

func buildSymbols(symbols []*Symbol, ranges []pcRange, coverPoints [2][]uint64) []*Symbol {
// Assign coverage point PCs to symbols.
// Both symbols and coverage points are sorted, so we do it one pass over both.
Expand Down
19 changes: 0 additions & 19 deletions pkg/cover/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/google/syzkaller/pkg/cover/backend"
"github.com/google/syzkaller/pkg/mgrconfig"
"github.com/google/syzkaller/sys/targets"
)

func (rg *ReportGenerator) DoHTML(w io.Writer, progs []Prog, coverFilter map[uint32]uint32) error {
Expand Down Expand Up @@ -514,24 +513,6 @@ func fixUpPCs(target string, progs []Prog, coverFilter map[uint32]uint32) []Prog
progs[i].PCs = nPCs
}
}

// On arm64 as PLT is enabled by default, .text section is loaded after .plt section,
// so there is 0x18 bytes offset from module load address for .text section
// we need to remove the 0x18 bytes offset in order to correct module symbol address
if target == targets.ARM64 {
for i, prog := range progs {
var nPCs []uint64
for _, pc := range prog.PCs {
// TODO: avoid to hardcode the address
// Fix up kernel PCs, but not the test (userspace) PCs.
if pc >= 0x8000000000000000 && pc < 0xffffffd010000000 {
pc -= 0x18
}
nPCs = append(nPCs, pc)
}
progs[i].PCs = nPCs
}
}
return progs
}

Expand Down

0 comments on commit 10e9060

Please sign in to comment.