aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2021-07-16 14:57:55 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2021-07-20 13:39:45 +0200
commit2fe31df39f956886ef214b5b028362964aa07a53 (patch)
tree2f94fc7eb2b84927d3059e85fa0e198ba4380ec0 /pkg
parentb5969a9bdd1769ae7dc56682c4dbb8bc8f2ab7c3 (diff)
all: capture compiler id during the build process
Default compilers are specified in the OS- and platform-dependent logic. It is more convenient to extract info about them during the kernel build itself, rather than during the manager object initialization. Apply the necessary changes throughout the code that is involved in building the kernels and processing information about this process.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/bisect/bisect.go17
-rw-r--r--pkg/bisect/bisect_test.go12
-rw-r--r--pkg/build/build.go46
-rw-r--r--pkg/build/build_test.go2
-rw-r--r--pkg/instance/instance.go12
5 files changed, 53 insertions, 36 deletions
diff --git a/pkg/bisect/bisect.go b/pkg/bisect/bisect.go
index 0454cf68c..b2ec3dd46 100644
--- a/pkg/bisect/bisect.go
+++ b/pkg/bisect/bisect.go
@@ -410,24 +410,23 @@ func (env *env) build() (*vcs.Commit, string, error) {
if err != nil {
return nil, "", err
}
- compilerID, err := build.CompilerIdentity(bisectEnv.Compiler)
- if err != nil {
- return nil, "", err
- }
- env.log("testing commit %v with %v", current.Hash, compilerID)
+ env.log("testing commit %v", current.Hash)
buildStart := time.Now()
mgr := env.cfg.Manager
if err := build.Clean(mgr.TargetOS, mgr.TargetVMArch, mgr.Type, mgr.KernelSrc); err != nil {
return nil, "", fmt.Errorf("kernel clean failed: %v", err)
}
kern := &env.cfg.Kernel
- _, kernelSign, err := env.inst.BuildKernel(bisectEnv.Compiler, env.cfg.Ccache, kern.Userspace,
+ _, imageDetails, 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)
+ if imageDetails.CompilerID != "" {
+ env.log("compiler: %v", imageDetails.CompilerID)
+ }
+ if imageDetails.Signature != "" {
+ env.log("kernel signature: %v", imageDetails.Signature)
}
env.buildTime += time.Since(buildStart)
- return current, kernelSign, err
+ return current, imageDetails.Signature, err
}
func (env *env) test() (*testResult, error) {
diff --git a/pkg/bisect/bisect_test.go b/pkg/bisect/bisect_test.go
index e71903c98..7a05afb36 100644
--- a/pkg/bisect/bisect_test.go
+++ b/pkg/bisect/bisect_test.go
@@ -10,6 +10,7 @@ import (
"strconv"
"testing"
+ "github.com/google/syzkaller/pkg/build"
"github.com/google/syzkaller/pkg/debugtracer"
"github.com/google/syzkaller/pkg/hash"
"github.com/google/syzkaller/pkg/instance"
@@ -34,18 +35,19 @@ func (env *testEnv) BuildSyzkaller(repo, commit string) error {
}
func (env *testEnv) BuildKernel(compilerBin, cCache, userspaceDir, cmdlineFile, sysctlFile string,
- kernelConfig []byte) (string, string, error) {
+ kernelConfig []byte) (string, build.ImageDetails, error) {
commit := env.headCommit()
configHash := hash.String(kernelConfig)
- kernelSign := fmt.Sprintf("%v-%v", commit, configHash)
+ details := build.ImageDetails{}
+ details.Signature = fmt.Sprintf("%v-%v", commit, configHash)
if commit >= env.test.sameBinaryStart && commit <= env.test.sameBinaryEnd {
- kernelSign = "same-sign-" + configHash
+ details.Signature = "same-sign-" + configHash
}
env.config = string(kernelConfig)
if env.config == "baseline-fails" {
- return "", kernelSign, fmt.Errorf("failure")
+ return "", details, fmt.Errorf("failure")
}
- return "", kernelSign, nil
+ return "", details, nil
}
func (env *testEnv) Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error) {
diff --git a/pkg/build/build.go b/pkg/build/build.go
index 3b3387f4d..ba971ec94 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -34,6 +34,12 @@ type Params struct {
Config []byte
}
+// Information that is returned from the Image function.
+type ImageDetails struct {
+ Signature string
+ CompilerID string
+}
+
// Image creates a disk image for the specified OS/ARCH/VM.
// Kernel is taken from KernelDir, userspace system is taken from UserspaceDir.
// If CmdlineFile is not empty, contents of the file are appended to the kernel command line.
@@ -46,42 +52,52 @@ type Params struct {
// - kernel.config: actual kernel config used during build
// - obj/: directory with kernel object files (this should match KernelObject
// specified in sys/targets, e.g. vmlinux for linux)
-// The returned string is a kernel ID that will be the same for kernels with the
-// same runtime behavior, and different for kernels with different runtime
+// The returned structure contains a kernel ID that will be the same for kernels
+// with the same runtime behavior, and different for kernels with different runtime
// behavior. Binary equal builds, or builds that differ only in e.g. debug info,
// have the same ID. The ID may be empty if OS implementation does not have
// a way to calculate such IDs.
-func Image(params Params) (string, error) {
+// Also that structure provides a compiler ID field that contains the name and
+// the version of the compiler/toolchain that was used to build the kernel.
+// The CompilerID field is not guaranteed to be non-empty.
+func Image(params Params) (details ImageDetails, err error) {
builder, err := getBuilder(params.TargetOS, params.TargetArch, params.VMType)
if err != nil {
- return "", err
+ return
}
- if err := osutil.MkdirAll(filepath.Join(params.OutputDir, "obj")); err != nil {
- return "", err
+ if err = osutil.MkdirAll(filepath.Join(params.OutputDir, "obj")); err != nil {
+ return
}
if len(params.Config) != 0 {
// Write kernel config early, so that it's captured on build failures.
- if err := osutil.WriteFile(filepath.Join(params.OutputDir, "kernel.config"), params.Config); err != nil {
- return "", fmt.Errorf("failed to write config file: %v", err)
+ if err = osutil.WriteFile(filepath.Join(params.OutputDir, "kernel.config"), params.Config); err != nil {
+ err = fmt.Errorf("failed to write config file: %v", err)
+ return
}
}
err = builder.build(params)
if err != nil {
- return "", extractRootCause(err, params.TargetOS, params.KernelDir)
+ err = extractRootCause(err, params.TargetOS, params.KernelDir)
+ return
}
if key := filepath.Join(params.OutputDir, "key"); osutil.IsExist(key) {
if err := os.Chmod(key, 0600); err != nil {
- return "", fmt.Errorf("failed to chmod 0600 %v: %v", key, err)
+ return details, fmt.Errorf("failed to chmod 0600 %v: %v", key, err)
}
}
- sign := ""
if signer, ok := builder.(signer); ok {
- sign, err = signer.sign(params)
+ details.Signature, err = signer.sign(params)
+ if err != nil {
+ return
+ }
+ }
+ if details.CompilerID == "" {
+ details.CompilerID, err = compilerIdentity(params.Compiler)
if err != nil {
- return "", err
+ return
}
}
- return sign, nil
+ return
}
func Clean(targetOS, targetArch, vmType, kernelDir string) error {
@@ -147,7 +163,7 @@ func getBuilder(targetOS, targetArch, vmType string) (builder, error) {
return nil, fmt.Errorf("unsupported image type %v/%v/%v", targetOS, targetArch, vmType)
}
-func CompilerIdentity(compiler string) (string, error) {
+func compilerIdentity(compiler string) (string, error) {
if compiler == "" {
return "", nil
}
diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go
index 7a7c2c1be..40c725d0d 100644
--- a/pkg/build/build_test.go
+++ b/pkg/build/build_test.go
@@ -19,7 +19,7 @@ func TestCompilerIdentity(t *testing.T) {
if _, err := exec.LookPath(compiler); err != nil {
t.Skipf("compiler '%v' is not found: %v", compiler, err)
}
- id, err := CompilerIdentity(compiler)
+ id, err := compilerIdentity(compiler)
if err != nil {
t.Fatalf("failed: %v", err)
}
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index 3e28f2170..70846711f 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -29,7 +29,7 @@ import (
type Env interface {
BuildSyzkaller(string, string) error
- BuildKernel(string, string, string, string, string, []byte) (string, string, error)
+ BuildKernel(string, string, string, string, string, []byte) (string, build.ImageDetails, error)
Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error)
}
@@ -106,7 +106,7 @@ func (env *env) BuildSyzkaller(repoURL, commit string) error {
}
func (env *env) BuildKernel(compilerBin, ccacheBin, userspaceDir, cmdlineFile, sysctlFile string, kernelConfig []byte) (
- string, string, error) {
+ string, build.ImageDetails, error) {
imageDir := filepath.Join(env.cfg.Workdir, "image")
params := build.Params{
TargetOS: env.cfg.TargetOS,
@@ -121,18 +121,18 @@ func (env *env) BuildKernel(compilerBin, ccacheBin, userspaceDir, cmdlineFile, s
SysctlFile: sysctlFile,
Config: kernelConfig,
}
- kernelSign, err := build.Image(params)
+ details, err := build.Image(params)
if err != nil {
- return "", "", err
+ return "", details, err
}
if err := SetConfigImage(env.cfg, imageDir, true); err != nil {
- return "", "", err
+ return "", details, err
}
kernelConfigFile := filepath.Join(imageDir, "kernel.config")
if !osutil.IsExist(kernelConfigFile) {
kernelConfigFile = ""
}
- return kernelConfigFile, kernelSign, nil
+ return kernelConfigFile, details, nil
}
func SetConfigImage(cfg *mgrconfig.Config, imageDir string, reliable bool) error {