From 79a5963585ac032cd3f390a37b5d276f7f9d0b5c Mon Sep 17 00:00:00 2001 From: Space Meyer Date: Tue, 13 Sep 2022 15:24:23 +0000 Subject: pkg/bisect: use default compiler during bisection where possible This allows us to bisect at least recently introduced bugs, where the manager that found the bug uses a non standard compiler. This is usefull during development of a new sanitizer for which a compiler with non-upstreamed patches is required. --- pkg/vcs/linux.go | 42 +++++++++++++++++++++++++----------------- pkg/vcs/linux_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ pkg/vcs/testos.go | 6 ++++-- pkg/vcs/vcs.go | 4 ++-- 4 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 pkg/vcs/linux_test.go (limited to 'pkg/vcs') diff --git a/pkg/vcs/linux.go b/pkg/vcs/linux.go index 8ee801430..5e2ccf3e1 100644 --- a/pkg/vcs/linux.go +++ b/pkg/vcs/linux.go @@ -42,14 +42,14 @@ func newLinux(dir string, opts []RepoOpt, vmType string) *linux { } } -func (ctx *linux) PreviousReleaseTags(commit, bisectCompiler string) ([]string, error) { +func (ctx *linux) PreviousReleaseTags(commit, compilerType string) ([]string, error) { tags, err := ctx.git.previousReleaseTags(commit, false, false, false) if err != nil { return nil, err } cutoff := "" - if bisectCompiler == "gcc" { + if compilerType == "gcc" { // Initially we tried to stop at 3.8 because: // v3.8 does not work with modern perl, and as we go further in history // make stops to work, then binutils, glibc, etc. So we stop at v3.8. @@ -70,7 +70,7 @@ func (ctx *linux) PreviousReleaseTags(commit, bisectCompiler string) ([]string, // even more (as new releases are produced). Next good candidate may be 4.11 // because then we won't need gcc 5.5. cutoff = "v4.5" - } else if bisectCompiler == "clang" { + } else if compilerType == "clang" { // v5.3 was the first release with solid clang support, however I was able to // compile v5.1..v5.3 using a newer defconfig + make oldconfig. Everything older // would require further cherry-picks. @@ -132,7 +132,9 @@ func gitReleaseTagToInt(tag string, includeRC bool) uint64 { return v1*1e9 + v2*1e6 + rc*1e3 + v3 } -func (ctx *linux) EnvForCommit(bisectCompiler, binDir, commit string, kernelConfig []byte) (*BisectEnv, error) { +func (ctx *linux) EnvForCommit( + defaultCompiler, compilerType, binDir, commit string, kernelConfig []byte, +) (*BisectEnv, error) { tagList, err := ctx.previousReleaseTags(commit, true, false, false) if err != nil { return nil, err @@ -148,12 +150,12 @@ func (ctx *linux) EnvForCommit(bisectCompiler, binDir, commit string, kernelConf linuxAlterConfigs(cf, tags) compiler := "" - if bisectCompiler == "gcc" { - compiler = filepath.Join(binDir, "gcc-"+linuxGCCVersion(tags), "bin", "gcc") - } else if bisectCompiler == "clang" { - compiler = filepath.Join(binDir, "llvm-"+linuxClangVersion(tags), "bin", "clang") + if compilerType == "gcc" { + compiler = linuxGCCPath(tags, binDir, defaultCompiler) + } else if compilerType == "clang" { + compiler = linuxClangPath(tags, binDir, defaultCompiler) } else { - return nil, fmt.Errorf("unsupported bisect compiler: %v", bisectCompiler) + return nil, fmt.Errorf("unsupported bisect compiler: %v", compilerType) } env := &BisectEnv{ @@ -180,28 +182,34 @@ func (ctx *linux) EnvForCommit(bisectCompiler, binDir, commit string, kernelConf return env, nil } -func linuxClangVersion(tags map[string]bool) string { +func linuxClangPath(tags map[string]bool, binDir, defaultCompiler string) string { + version := "" switch { case tags["v5.9"]: - return "14.0.6" + // Verified to work with 14.0.6. + return defaultCompiler default: // everything before v5.3 might not work great // everything before v5.1 does not work - return "9.0.1" + version = "9.0.1" } + return filepath.Join(binDir, "llvm-"+version, "bin", "clang") } -func linuxGCCVersion(tags map[string]bool) string { +func linuxGCCPath(tags map[string]bool, binDir, defaultCompiler string) string { + version := "" switch { case tags["v5.9"]: - return "10.1.0" + // Verified to work with 10.1.0. + return defaultCompiler case tags["v4.12"]: - return "8.1.0" + version = "8.1.0" case tags["v4.11"]: - return "7.3.0" + version = "7.3.0" default: - return "5.5.0" + version = "5.5.0" } + return filepath.Join(binDir, "gcc-"+version, "bin", "gcc") } func linuxAlterConfigs(cf *kconfig.ConfigFile, tags map[string]bool) { diff --git a/pkg/vcs/linux_test.go b/pkg/vcs/linux_test.go new file mode 100644 index 000000000..1865aa2d6 --- /dev/null +++ b/pkg/vcs/linux_test.go @@ -0,0 +1,50 @@ +// Copyright 2022 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package vcs + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestClangVersion(t *testing.T) { + defaultCompiler := "/some/default/compiler" + binDir := "/some/dir/" + tags := make(map[string]bool) + + // No tags case. + actual := linuxClangPath(tags, binDir, defaultCompiler) + expected := binDir + "llvm-9.0.1/bin/clang" + assert.Equal(t, actual, expected, "unexpected clang path") + + // Recent tag case. + tags["v5.9"] = true + actual = linuxClangPath(tags, binDir, defaultCompiler) + expected = defaultCompiler + assert.Equal(t, actual, expected, "unexpected clang path") +} + +func TestGCCVersion(t *testing.T) { + defaultCompiler := "/some/default/compiler" + binDir := "/some/dir/" + tags := make(map[string]bool) + + // No tags case. + actual := linuxGCCPath(tags, binDir, defaultCompiler) + expected := binDir + "gcc-5.5.0/bin/gcc" + assert.Equal(t, actual, expected, "unexpected gcc path") + + // Somewhat old tag case. + tags["v4.12"] = true + actual = linuxGCCPath(tags, binDir, defaultCompiler) + expected = binDir + "gcc-8.1.0/bin/gcc" + assert.Equal(t, actual, expected, "unexpected gcc path") + + // Recent tag case. + tags["v5.9"] = true + actual = linuxGCCPath(tags, binDir, defaultCompiler) + expected = defaultCompiler + assert.Equal(t, actual, expected, "unexpected gcc path") +} diff --git a/pkg/vcs/testos.go b/pkg/vcs/testos.go index 0053a528e..fe7c3790f 100644 --- a/pkg/vcs/testos.go +++ b/pkg/vcs/testos.go @@ -22,11 +22,13 @@ func newTestos(dir string, opts []RepoOpt) *testos { } } -func (ctx *testos) PreviousReleaseTags(commit, bisectCompiler string) ([]string, error) { +func (ctx *testos) PreviousReleaseTags(commit, compilerType string) ([]string, error) { return ctx.git.previousReleaseTags(commit, false, false, false) } -func (ctx *testos) EnvForCommit(bisectCompiler, binDir, commit string, kernelConfig []byte) (*BisectEnv, error) { +func (ctx *testos) EnvForCommit( + defaultCompiler, compilerType, binDir, commit string, kernelConfig []byte, +) (*BisectEnv, error) { return &BisectEnv{KernelConfig: kernelConfig}, nil } diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index 50e45252e..4b4f26e06 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -79,11 +79,11 @@ type Bisecter interface { // PreviousReleaseTags returns list of preceding release tags that are reachable from the given commit. // If the commit itself has a release tag, this tag is not included. - PreviousReleaseTags(commit, bisectCompiler string) ([]string, error) + PreviousReleaseTags(commit, compilerType string) ([]string, error) IsRelease(commit string) (bool, error) - EnvForCommit(bisectCompiler, binDir, commit string, kernelConfig []byte) (*BisectEnv, error) + EnvForCommit(defaultCompiler, compilerType, binDir, commit string, kernelConfig []byte) (*BisectEnv, error) } type ConfigMinimizer interface { -- cgit mrf-deployment