diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-04-09 08:56:35 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-04-09 08:33:12 +0000 |
| commit | bf86f5aaada407ff2fed28fe03bc0b892caf4e41 (patch) | |
| tree | eda5a8bb70217931959c147901f049f9cedc6b90 /pkg | |
| parent | 828b7836fa16828b1972d47e38613c9fe72da36c (diff) | |
pkg/cover: move functions to after they are used
This makes code easier to read top-down in the natural order
and Go does not require the inverted declaration order like C/C++.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/cover/backend/dwarf.go | 44 | ||||
| -rw-r--r-- | pkg/cover/report.go | 25 |
2 files changed, 34 insertions, 35 deletions
diff --git a/pkg/cover/backend/dwarf.go b/pkg/cover/backend/dwarf.go index 35ddd27a6..b90bf0cc4 100644 --- a/pkg/cover/backend/dwarf.go +++ b/pkg/cover/backend/dwarf.go @@ -136,28 +136,6 @@ func processModule(params *dwarfParams, module *Module, info *symbolInfo, return result, nil } -// Regexps to parse compiler version string in IsKcovBrokenInCompiler. -// Some targets (e.g. NetBSD) use g++ instead of gcc. -var gccRE = regexp.MustCompile(`gcc|GCC|g\+\+`) -var gccVersionRE = regexp.MustCompile(`(gcc|GCC|g\+\+).* ([0-9]{1,2})\.[0-9]+\.[0-9]+`) - -// GCC < 14 incorrectly tail-calls kcov callbacks, which does not let syzkaller -// verify that collected coverage points have matching callbacks. -// See https://github.com/google/syzkaller/issues/4447 for more information. -func IsKcovBrokenInCompiler(versionStr string) bool { - if !gccRE.MatchString(versionStr) { - return false - } - groups := gccVersionRE.FindStringSubmatch(versionStr) - if len(groups) > 0 { - version, err := strconv.Atoi(groups[2]) - if err == nil { - return version < 14 - } - } - return true -} - func makeDWARFUnsafe(params *dwarfParams) (*Impl, error) { target := params.target objDir := params.objDir @@ -334,6 +312,28 @@ func buildSymbols(symbols []*Symbol, ranges []pcRange, coverPoints [2][]uint64) return symbols } +// Regexps to parse compiler version string in IsKcovBrokenInCompiler. +// Some targets (e.g. NetBSD) use g++ instead of gcc. +var gccRE = regexp.MustCompile(`gcc|GCC|g\+\+`) +var gccVersionRE = regexp.MustCompile(`(gcc|GCC|g\+\+).* ([0-9]{1,2})\.[0-9]+\.[0-9]+`) + +// GCC < 14 incorrectly tail-calls kcov callbacks, which does not let syzkaller +// verify that collected coverage points have matching callbacks. +// See https://github.com/google/syzkaller/issues/4447 for more information. +func IsKcovBrokenInCompiler(versionStr string) bool { + if !gccRE.MatchString(versionStr) { + return false + } + groups := gccVersionRE.FindStringSubmatch(versionStr) + if len(groups) > 0 { + version, err := strconv.Atoi(groups[2]) + if err == nil { + return version < 14 + } + } + return true +} + type symbolInfo struct { textAddr uint64 // Set of addresses that correspond to __sanitizer_cov_trace_pc or its trampolines. diff --git a/pkg/cover/report.go b/pkg/cover/report.go index f52a2bcaa..4e7ec3001 100644 --- a/pkg/cover/report.go +++ b/pkg/cover/report.go @@ -76,19 +76,6 @@ type line struct { pcProgCount map[uint64]int // some lines have multiple BBs } -func coverageCallbackMismatch(debug bool, numPCs int, unmatchedProgPCs map[uint64]bool) error { - debugStr := "" - if debug { - debugStr += "\n\nUnmatched PCs:\n" - for pc := range unmatchedProgPCs { - debugStr += fmt.Sprintf("%x\n", pc) - } - } - // nolint: lll - return fmt.Errorf("%d out of %d PCs returned by kcov do not have matching coverage callbacks. Check the discoverModules() code.%s", - len(unmatchedProgPCs), numPCs, debugStr) -} - type fileMap map[string]*file func (rg *ReportGenerator) prepareFileMap(progs []Prog, debug bool) (fileMap, error) { @@ -181,6 +168,18 @@ func (rg *ReportGenerator) prepareFileMap(progs []Prog, debug bool) (fileMap, er return files, nil } +func coverageCallbackMismatch(debug bool, numPCs int, unmatchedProgPCs map[uint64]bool) error { + debugStr := "" + if debug { + debugStr += "\n\nUnmatched PCs:\n" + for pc := range unmatchedProgPCs { + debugStr += fmt.Sprintf("%x\n", pc) + } + } + return fmt.Errorf("%d out of %d PCs returned by kcov do not have matching coverage callbacks."+ + " Check the discoverModules() code.%s", len(unmatchedProgPCs), numPCs, debugStr) +} + func uniquePCs(progs []Prog) []uint64 { PCs := make(map[uint64]bool) for _, p := range progs { |
