Skip to content

Commit

Permalink
pkg/build: better support for gvisor race build
Browse files Browse the repository at this point in the history
Explicitly pass --features=race.
Expect linux_amd64_static_stripped as a potential output.
  • Loading branch information
dvyukov committed Jun 26, 2018
1 parent 089f118 commit be3706f
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions pkg/build/gvisor.go
Expand Up @@ -6,28 +6,29 @@ package build
import (
"fmt"
"path/filepath"
"strings"
"time"

"github.com/google/syzkaller/pkg/osutil"
)

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 {
Expand All @@ -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
Expand Down

0 comments on commit be3706f

Please sign in to comment.