pkg/bisect: add ccache option

Add option to use ccache in kernel builds.

Signed-off-by: Jouni Hogander <jouni.hoegander@partner.bmw.de>
This commit is contained in:
Jouni Hogander 2020-09-01 16:13:50 +03:00 committed by Dmitry Vyukov
parent 5e8f0f25fa
commit bbb921d248
11 changed files with 35 additions and 8 deletions

View File

@ -22,6 +22,7 @@ type Config struct {
Trace io.Writer Trace io.Writer
Fix bool Fix bool
BinDir string BinDir string
Ccache string
DebugDir string DebugDir string
Timeout time.Duration Timeout time.Duration
Kernel KernelConfig Kernel KernelConfig
@ -448,7 +449,7 @@ func (env *env) build() (*vcs.Commit, string, error) {
return nil, "", fmt.Errorf("kernel clean failed: %v", err) return nil, "", fmt.Errorf("kernel clean failed: %v", err)
} }
kern := &env.cfg.Kernel kern := &env.cfg.Kernel
_, kernelSign, err := env.inst.BuildKernel(bisectEnv.Compiler, kern.Userspace, _, kernelSign, err := env.inst.BuildKernel(bisectEnv.Compiler, env.cfg.Ccache, kern.Userspace,
kern.Cmdline, kern.Sysctl, bisectEnv.KernelConfig) kern.Cmdline, kern.Sysctl, bisectEnv.KernelConfig)
if kernelSign != "" { if kernelSign != "" {
env.log("kernel signature: %v", kernelSign) env.log("kernel signature: %v", kernelSign)

View File

@ -32,7 +32,7 @@ func (env *testEnv) BuildSyzkaller(repo, commit string) error {
return nil return nil
} }
func (env *testEnv) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile string, func (env *testEnv) BuildKernel(compilerBin, cCache, userspaceDir, cmdlineFile, sysctlFile string,
kernelConfig []byte) (string, string, error) { kernelConfig []byte) (string, string, error) {
commit := env.headCommit() commit := env.headCommit()
configHash := hash.String(kernelConfig) configHash := hash.String(kernelConfig)

View File

@ -26,6 +26,7 @@ type Params struct {
KernelDir string KernelDir string
OutputDir string OutputDir string
Compiler string Compiler string
Ccache string
UserspaceDir string UserspaceDir string
CmdlineFile string CmdlineFile string
SysctlFile string SysctlFile string

View File

@ -65,7 +65,24 @@ func (linux) buildKernel(params *Params) error {
case "ppc64le": case "ppc64le":
target = "zImage" target = "zImage"
} }
if err := runMake(params.KernelDir, target, "CC="+params.Compiler); err != nil {
ccParam := params.Compiler
if params.Ccache != "" {
ccParam = params.Ccache + " " + ccParam
// Ensure CONFIG_GCC_PLUGIN_RANDSTRUCT doesn't prevent ccache usage.
// See /Documentation/kbuild/reproducible-builds.rst.
gccPluginsDir := filepath.Join(params.KernelDir, "scripts", "gcc-plugins")
if osutil.IsExist(gccPluginsDir) {
err := osutil.WriteFile(filepath.Join(gccPluginsDir,
"randomize_layout_seed.h"),
[]byte("const char *randstruct_seed = "+
"\"e9db0ca5181da2eedb76eba144df7aba4b7f9359040ee58409765f2bdc4cb3b8\";"))
if err != nil {
return err
}
}
}
if err := runMake(params.KernelDir, target, "CC="+ccParam); err != nil {
return err return err
} }
vmlinux := filepath.Join(params.KernelDir, "vmlinux") vmlinux := filepath.Join(params.KernelDir, "vmlinux")

View File

@ -29,7 +29,7 @@ import (
type Env interface { type Env interface {
BuildSyzkaller(string, string) error BuildSyzkaller(string, string) error
BuildKernel(string, string, string, string, []byte) (string, string, error) BuildKernel(string, string, string, string, string, []byte) (string, string, error)
Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error) Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error)
} }
@ -94,7 +94,7 @@ func (env *env) BuildSyzkaller(repo, commit string) error {
return nil return nil
} }
func (env *env) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile string, kernelConfig []byte) ( func (env *env) BuildKernel(compilerBin, ccacheBin, userspaceDir, cmdlineFile, sysctlFile string, kernelConfig []byte) (
string, string, error) { string, string, error) {
imageDir := filepath.Join(env.cfg.Workdir, "image") imageDir := filepath.Join(env.cfg.Workdir, "image")
params := &build.Params{ params := &build.Params{
@ -104,6 +104,7 @@ func (env *env) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile s
KernelDir: env.cfg.KernelSrc, KernelDir: env.cfg.KernelSrc,
OutputDir: imageDir, OutputDir: imageDir,
Compiler: compilerBin, Compiler: compilerBin,
Ccache: ccacheBin,
UserspaceDir: userspaceDir, UserspaceDir: userspaceDir,
CmdlineFile: cmdlineFile, CmdlineFile: cmdlineFile,
SysctlFile: sysctlFile, SysctlFile: sysctlFile,

View File

@ -124,6 +124,7 @@ func (ctx *linux) EnvForCommit(binDir, commit string, kernelConfig []byte) (*Bis
return nil, err return nil, err
} }
} }
return env, nil return env, nil
} }

View File

@ -405,6 +405,7 @@ func (jp *JobProcessor) bisect(job *Job, mgrcfg *mgrconfig.Config) error {
Timeout: 8 * time.Hour, Timeout: 8 * time.Hour,
Fix: req.Type == dashapi.JobBisectFix, Fix: req.Type == dashapi.JobBisectFix,
BinDir: jp.cfg.BisectBinDir, BinDir: jp.cfg.BisectBinDir,
Ccache: jp.cfg.Ccache,
Kernel: bisect.KernelConfig{ Kernel: bisect.KernelConfig{
Repo: mgr.mgrcfg.Repo, Repo: mgr.mgrcfg.Repo,
Branch: mgr.mgrcfg.Branch, Branch: mgr.mgrcfg.Branch,
@ -527,8 +528,8 @@ func (jp *JobProcessor) testPatch(job *Job, mgrcfg *mgrconfig.Config) error {
} }
log.Logf(0, "job: building kernel...") log.Logf(0, "job: building kernel...")
kernelConfig, _, err := env.BuildKernel(mgr.mgrcfg.Compiler, mgr.mgrcfg.Userspace, mgr.mgrcfg.KernelCmdline, kernelConfig, _, err := env.BuildKernel(mgr.mgrcfg.Compiler, mgr.mgrcfg.Ccache, mgr.mgrcfg.Userspace,
mgr.mgrcfg.KernelSysctl, req.KernelConfig) mgr.mgrcfg.KernelCmdline, mgr.mgrcfg.KernelSysctl, req.KernelConfig)
if err != nil { if err != nil {
return err return err
} }

View File

@ -301,6 +301,7 @@ func (mgr *Manager) build(kernelCommit *vcs.Commit) error {
KernelDir: mgr.kernelDir, KernelDir: mgr.kernelDir,
OutputDir: tmpDir, OutputDir: tmpDir,
Compiler: mgr.mgrcfg.Compiler, Compiler: mgr.mgrcfg.Compiler,
Ccache: mgr.mgrcfg.Ccache,
UserspaceDir: mgr.mgrcfg.Userspace, UserspaceDir: mgr.mgrcfg.Userspace,
CmdlineFile: mgr.mgrcfg.KernelCmdline, CmdlineFile: mgr.mgrcfg.KernelCmdline,
SysctlFile: mgr.mgrcfg.KernelSysctl, SysctlFile: mgr.mgrcfg.KernelSysctl,

View File

@ -93,6 +93,7 @@ type Config struct {
// GCS path to upload coverage reports from managers (optional). // GCS path to upload coverage reports from managers (optional).
CoverUploadPath string `json:"cover_upload_path"` CoverUploadPath string `json:"cover_upload_path"`
BisectBinDir string `json:"bisect_bin_dir"` BisectBinDir string `json:"bisect_bin_dir"`
Ccache string `json:"ccache"`
Managers []*ManagerConfig `json:"managers"` Managers []*ManagerConfig `json:"managers"`
} }
@ -106,6 +107,7 @@ type ManagerConfig struct {
RepoAlias string `json:"repo_alias"` RepoAlias string `json:"repo_alias"`
Branch string `json:"branch"` // Defaults to "master". Branch string `json:"branch"` // Defaults to "master".
Compiler string `json:"compiler"` Compiler string `json:"compiler"`
Ccache string `json:"ccache"`
Userspace string `json:"userspace"` Userspace string `json:"userspace"`
KernelConfig string `json:"kernel_config"` KernelConfig string `json:"kernel_config"`
// Baseline config for bisection, see pkg/bisect.KernelConfig.BaselineConfig. // Baseline config for bisection, see pkg/bisect.KernelConfig.BaselineConfig.

View File

@ -46,6 +46,7 @@ type Config struct {
// gcc versions. A working archive can be downloaded from: // gcc versions. A working archive can be downloaded from:
// https://storage.googleapis.com/syzkaller/bisect_bin.tar.gz // https://storage.googleapis.com/syzkaller/bisect_bin.tar.gz
BinDir string `json:"bin_dir"` BinDir string `json:"bin_dir"`
Ccache string `json:"ccache"`
KernelRepo string `json:"kernel_repo"` KernelRepo string `json:"kernel_repo"`
KernelBranch string `json:"kernel_branch"` KernelBranch string `json:"kernel_branch"`
SyzkallerRepo string `json:"syzkaller_repo"` SyzkallerRepo string `json:"syzkaller_repo"`
@ -86,6 +87,7 @@ func main() {
Trace: os.Stdout, Trace: os.Stdout,
Fix: *flagFix, Fix: *flagFix,
BinDir: mycfg.BinDir, BinDir: mycfg.BinDir,
Ccache: mycfg.Ccache,
DebugDir: *flagCrash, DebugDir: *flagCrash,
Kernel: bisect.KernelConfig{ Kernel: bisect.KernelConfig{
Repo: mycfg.KernelRepo, Repo: mycfg.KernelRepo,

View File

@ -128,7 +128,7 @@ func test(repo vcs.Repo, bisecter vcs.Bisecter, kernelConfig []byte, env instanc
if err := build.Clean(*flagOS, *flagArch, vmType, *flagKernelSrc); err != nil { if err := build.Clean(*flagOS, *flagArch, vmType, *flagKernelSrc); err != nil {
fail(err) fail(err)
} }
_, _, err = env.BuildKernel(bisectEnv.Compiler, *flagUserspace, _, _, err = env.BuildKernel(bisectEnv.Compiler, "", *flagUserspace,
*flagKernelCmdline, *flagKernelSysctl, bisectEnv.KernelConfig) *flagKernelCmdline, *flagKernelSysctl, bisectEnv.KernelConfig)
if err != nil { if err != nil {
if verr, ok := err.(*osutil.VerboseError); ok { if verr, ok := err.(*osutil.VerboseError); ok {