aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-06-26 15:36:46 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-06-26 15:36:46 +0200
commitbe3706ff1e35ad71759a5803e983c4d35f7c43a8 (patch)
treefb699061fda1937ba13d412fc836cea6e609cf8c /pkg
parent089f11817e3eb5a23bf9fb679dc4e6ad61de48ec (diff)
pkg/build: better support for gvisor race build
Explicitly pass --features=race. Expect linux_amd64_static_stripped as a potential output.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/build/gvisor.go35
1 files changed, 26 insertions, 9 deletions
diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go
index f16557659..f222475d1 100644
--- a/pkg/build/gvisor.go
+++ b/pkg/build/gvisor.go
@@ -6,6 +6,7 @@ package build
import (
"fmt"
"path/filepath"
+ "strings"
"time"
"github.com/google/syzkaller/pkg/osutil"
@@ -13,21 +14,21 @@ import (
type gvisor struct{}
-func (gvisor) build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir,
+func (gvisor gvisor) build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir,
cmdlineFile, sysctlFile string, config []byte) error {
if err := osutil.MkdirAll(outputDir); err != nil {
return err
}
- if _, err := osutil.RunCmd(20*time.Minute, kernelDir, compiler, "build", "--verbose_failures", "runsc"); err != nil {
+ args := []string{"build", "--verbose_failures"}
+ if strings.Contains(" "+string(config)+" ", " -race ") {
+ args = append(args, "--features=race")
+ }
+ args = append(args, "runsc")
+ if _, err := osutil.RunCmd(20*time.Minute, kernelDir, compiler, args...); err != nil {
return err
}
- // Funny it's not possible to understand what bazel actually built...
- runsc := filepath.Join(kernelDir, "bazel-bin", "runsc", "linux_amd64_pure_stripped", "runsc")
- if err := osutil.CopyFile(runsc, filepath.Join(outputDir, "image")); err != nil {
- runsc = filepath.Join(kernelDir, "bazel-bin", "runsc", "linux_amd64_static_race_stripped", "runsc")
- if err := osutil.CopyFile(runsc, filepath.Join(outputDir, "image")); err != nil {
- return err
- }
+ if err := gvisor.copyBinary(kernelDir, outputDir); err != nil {
+ return err
}
if len(config) != 0 {
if err := osutil.WriteFile(filepath.Join(outputDir, "kernel.config"), config); err != nil {
@@ -38,6 +39,22 @@ func (gvisor) build(targetArch, vmType, kernelDir, outputDir, compiler, userspac
return nil
}
+func (gvisor) copyBinary(kernelDir, outputDir string) error {
+ // Funny it's not possible to understand what bazel actually built...
+ for _, typ := range []string{
+ "linux_amd64_pure_stripped",
+ "linux_amd64_static_stripped",
+ "linux_amd64_static_race_stripped",
+ } {
+ runsc := filepath.Join(kernelDir, "bazel-bin", "runsc", typ, "runsc")
+ if !osutil.IsExist(runsc) {
+ continue
+ }
+ return osutil.CopyFile(runsc, filepath.Join(outputDir, "image"))
+ }
+ return fmt.Errorf("failed to locate bazel output")
+}
+
func (gvisor) clean(kernelDir string) error {
// Let's assume that bazel always properly handles build without cleaning (until proven otherwise).
return nil