aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-10-13 10:26:47 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-10-13 10:58:20 +0200
commit5ba0ebc3f2626a1fd95bf1ce16e886ebc66d8638 (patch)
tree546d691dc1b5b741ae6dd4e36b51f19278a27bce /pkg
parentc9f222e7b410a336e436f094e24f6465d1cfdc13 (diff)
pkg/cover: support KASLR binaries
See the added comment for explanation. And https://groups.google.com/g/syzkaller/c/EU6wayZkd-U for context.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/cover/report.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/pkg/cover/report.go b/pkg/cover/report.go
index 847b838f7..f61c48d11 100644
--- a/pkg/cover/report.go
+++ b/pkg/cover/report.go
@@ -587,6 +587,7 @@ func readTextRanges(file *elf.File) ([]pcRange, []*compileUnit, error) {
if text == nil {
return nil, nil, fmt.Errorf("no .text section in the object file")
}
+ kaslr := file.Section(".rela.text") != nil
debugInfo, err := file.DWARF()
if err != nil {
return nil, nil, fmt.Errorf("failed to parse DWARF: %v (set CONFIG_DEBUG_INFO=y?)", err)
@@ -618,7 +619,24 @@ func readTextRanges(file *elf.File) ([]pcRange, []*compileUnit, error) {
}
for _, r := range ranges1 {
if r[0] >= r[1] || r[0] < text.Addr || r[1] > text.Addr+text.Size {
- continue
+ if kaslr {
+ // Linux kernel binaries with CONFIG_RANDOMIZE_BASE=y are strange.
+ // .text starts at 0xffffffff81000000 and symbols point there as well,
+ // but PC ranges point to addresses around 0.
+ // So try to add text offset and retry the check.
+ // It's unclear if we also need some offset on top of text.Addr,
+ // it gives approximately correct addresses, but not necessary precisely
+ // correct addresses.
+ // It would be good to add a test for this, but it's unclear what flag
+ // combination will give a similar binary. The following still gives
+ // matching .text/symbols/PC ranges:
+ // gcc test.c -g -fpie -pie -Wl,--section-start=.text=0x33300000
+ r[0] += text.Addr
+ r[1] += text.Addr
+ if r[0] >= r[1] || r[0] < text.Addr || r[1] > text.Addr+text.Size {
+ continue
+ }
+ }
}
ranges = append(ranges, pcRange{r[0], r[1], unit})
}