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
Fix bool
BinDir string
Ccache string
DebugDir string
Timeout time.Duration
Kernel KernelConfig
@ -448,7 +449,7 @@ func (env *env) build() (*vcs.Commit, string, error) {
return nil, "", fmt.Errorf("kernel clean failed: %v", err)
}
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)
if kernelSign != "" {
env.log("kernel signature: %v", kernelSign)

View File

@ -32,7 +32,7 @@ func (env *testEnv) BuildSyzkaller(repo, commit string) error {
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) {
commit := env.headCommit()
configHash := hash.String(kernelConfig)

View File

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

View File

@ -65,7 +65,24 @@ func (linux) buildKernel(params *Params) error {
case "ppc64le":
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
}
vmlinux := filepath.Join(params.KernelDir, "vmlinux")

View File

@ -29,7 +29,7 @@ import (
type Env interface {
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)
}
@ -94,7 +94,7 @@ func (env *env) BuildSyzkaller(repo, commit string) error {
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) {
imageDir := filepath.Join(env.cfg.Workdir, "image")
params := &build.Params{
@ -104,6 +104,7 @@ func (env *env) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile s
KernelDir: env.cfg.KernelSrc,
OutputDir: imageDir,
Compiler: compilerBin,
Ccache: ccacheBin,
UserspaceDir: userspaceDir,
CmdlineFile: cmdlineFile,
SysctlFile: sysctlFile,

View File

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

View File

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

View File

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

View File

@ -93,6 +93,7 @@ type Config struct {
// GCS path to upload coverage reports from managers (optional).
CoverUploadPath string `json:"cover_upload_path"`
BisectBinDir string `json:"bisect_bin_dir"`
Ccache string `json:"ccache"`
Managers []*ManagerConfig `json:"managers"`
}
@ -106,6 +107,7 @@ type ManagerConfig struct {
RepoAlias string `json:"repo_alias"`
Branch string `json:"branch"` // Defaults to "master".
Compiler string `json:"compiler"`
Ccache string `json:"ccache"`
Userspace string `json:"userspace"`
KernelConfig string `json:"kernel_config"`
// 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:
// https://storage.googleapis.com/syzkaller/bisect_bin.tar.gz
BinDir string `json:"bin_dir"`
Ccache string `json:"ccache"`
KernelRepo string `json:"kernel_repo"`
KernelBranch string `json:"kernel_branch"`
SyzkallerRepo string `json:"syzkaller_repo"`
@ -86,6 +87,7 @@ func main() {
Trace: os.Stdout,
Fix: *flagFix,
BinDir: mycfg.BinDir,
Ccache: mycfg.Ccache,
DebugDir: *flagCrash,
Kernel: bisect.KernelConfig{
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 {
fail(err)
}
_, _, err = env.BuildKernel(bisectEnv.Compiler, *flagUserspace,
_, _, err = env.BuildKernel(bisectEnv.Compiler, "", *flagUserspace,
*flagKernelCmdline, *flagKernelSysctl, bisectEnv.KernelConfig)
if err != nil {
if verr, ok := err.(*osutil.VerboseError); ok {